0N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.d3d;
0N/A
430N/Aimport sun.java2d.pipe.BufferedContext;
430N/Aimport sun.java2d.pipe.RenderBuffer;
430N/Aimport sun.java2d.pipe.RenderQueue;
430N/Aimport sun.java2d.pipe.hw.ContextCapabilities;
430N/Aimport static sun.java2d.pipe.BufferedOpCodes.*;
430N/Aimport static sun.java2d.pipe.hw.ContextCapabilities.*;
430N/Aimport static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
0N/A
430N/A/**
430N/A * Note that the RenderQueue lock must be acquired before calling any of
430N/A * the methods in this class.
430N/A */
430N/Aclass D3DContext extends BufferedContext {
0N/A
430N/A private final D3DGraphicsDevice device;
0N/A
430N/A D3DContext(RenderQueue rq, D3DGraphicsDevice device) {
430N/A super(rq);
430N/A this.device = device;
0N/A }
0N/A
0N/A /**
430N/A * Invalidates the currentContext field to ensure that we properly
430N/A * revalidate the D3DContext (make it current, etc.) next time through
430N/A * the validate() method. This is typically invoked from methods
430N/A * that affect the current context state (e.g. disposing a context or
430N/A * surface).
0N/A */
430N/A static void invalidateCurrentContext() {
430N/A // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
430N/A
430N/A // invalidate the current Java-level context so that we
430N/A // revalidate everything the next time around
430N/A if (currentContext != null) {
430N/A currentContext.invalidateContext();
430N/A currentContext = null;
0N/A }
430N/A
430N/A // invalidate the context reference at the native level, and
430N/A // then flush the queue so that we have no pending operations
430N/A // dependent on the current context
430N/A D3DRenderQueue rq = D3DRenderQueue.getInstance();
430N/A rq.ensureCapacity(4);
430N/A rq.getBuffer().putInt(INVALIDATE_CONTEXT);
430N/A rq.flushNow();
0N/A }
0N/A
0N/A /**
430N/A * Sets the current context on the native level to be the one passed as
430N/A * the argument.
430N/A * If the context is not the same as the defaultContext the latter
430N/A * will be reset to null.
0N/A *
430N/A * This call is needed when copying from a SW surface to a Texture
430N/A * (the upload test) or copying from d3d to SW surface to make sure we
430N/A * have the correct current context.
0N/A *
430N/A * @param d3dc the context to be made current on the native level
0N/A */
430N/A static void setScratchSurface(D3DContext d3dc) {
430N/A // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
0N/A
430N/A // invalidate the current context
430N/A if (d3dc != currentContext) {
430N/A currentContext = null;
0N/A }
0N/A
430N/A // set the scratch context
430N/A D3DRenderQueue rq = D3DRenderQueue.getInstance();
430N/A RenderBuffer buf = rq.getBuffer();
430N/A rq.ensureCapacity(8);
430N/A buf.putInt(SET_SCRATCH_SURFACE);
430N/A buf.putInt(d3dc.getDevice().getScreen());
430N/A }
0N/A
430N/A public RenderQueue getRenderQueue() {
430N/A return D3DRenderQueue.getInstance();
430N/A }
430N/A
430N/A @Override
430N/A public void saveState() {
430N/A // assert rq.lock.isHeldByCurrentThread();
0N/A
430N/A // reset all attributes of this and current contexts
430N/A invalidateContext();
430N/A invalidateCurrentContext();
430N/A
430N/A setScratchSurface(this);
0N/A
430N/A // save the state on the native level
430N/A rq.ensureCapacity(4);
430N/A buf.putInt(SAVE_STATE);
430N/A rq.flushNow();
430N/A }
430N/A
430N/A @Override
430N/A public void restoreState() {
430N/A // assert rq.lock.isHeldByCurrentThread();
430N/A
430N/A // reset all attributes of this and current contexts
430N/A invalidateContext();
430N/A invalidateCurrentContext();
0N/A
430N/A setScratchSurface(this);
430N/A
430N/A // restore the state on the native level
430N/A rq.ensureCapacity(4);
430N/A buf.putInt(RESTORE_STATE);
430N/A rq.flushNow();
430N/A }
430N/A
430N/A D3DGraphicsDevice getDevice() {
430N/A return device;
430N/A }
430N/A
430N/A static class D3DContextCaps extends ContextCapabilities {
430N/A /**
430N/A * Indicates the presence of pixel shaders (v2.0 or greater).
430N/A * This cap will only be set if the hardware supports the minimum number
430N/A * of texture units.
430N/A */
430N/A static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0);
430N/A /**
430N/A * Indicates the presence of pixel shaders (v2.0 or greater).
430N/A * This cap will only be set if the hardware meets our
430N/A * minimum requirements.
430N/A */
430N/A static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1);
430N/A /**
430N/A * Indicates that the device was successfully initialized and can
430N/A * be safely used.
430N/A */
430N/A static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2);
430N/A /**
430N/A * Indicates that the device has all of the necessary capabilities
430N/A * to support the Antialiasing Pixel Shader program.
430N/A */
430N/A static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3);
430N/A
430N/A D3DContextCaps(int caps, String adapterId) {
430N/A super(caps, adapterId);
0N/A }
0N/A
430N/A @Override
430N/A public String toString() {
430N/A StringBuffer buf = new StringBuffer(super.toString());
430N/A if ((caps & CAPS_LCD_SHADER) != 0) {
430N/A buf.append("CAPS_LCD_SHADER|");
0N/A }
430N/A if ((caps & CAPS_BIOP_SHADER) != 0) {
430N/A buf.append("CAPS_BIOP_SHADER|");
0N/A }
430N/A if ((caps & CAPS_AA_SHADER) != 0) {
430N/A buf.append("CAPS_AA_SHADER|");
0N/A }
430N/A if ((caps & CAPS_DEVICE_OK) != 0) {
430N/A buf.append("CAPS_DEVICE_OK|");
430N/A }
430N/A return buf.toString();
0N/A }
0N/A }
0N/A}