Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/d3d/D3DContext.java
32288 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.d3d;2627import java.lang.annotation.Native;28import sun.java2d.pipe.BufferedContext;29import sun.java2d.pipe.RenderBuffer;30import sun.java2d.pipe.RenderQueue;31import sun.java2d.pipe.hw.ContextCapabilities;32import static sun.java2d.pipe.BufferedOpCodes.*;33import static sun.java2d.pipe.hw.ContextCapabilities.*;34import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;3536/**37* Note that the RenderQueue lock must be acquired before calling any of38* the methods in this class.39*/40class D3DContext extends BufferedContext {4142private final D3DGraphicsDevice device;4344D3DContext(RenderQueue rq, D3DGraphicsDevice device) {45super(rq);46this.device = device;47}4849/**50* Invalidates the currentContext field to ensure that we properly51* revalidate the D3DContext (make it current, etc.) next time through52* the validate() method. This is typically invoked from methods53* that affect the current context state (e.g. disposing a context or54* surface).55*/56static void invalidateCurrentContext() {57// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();5859// invalidate the current Java-level context so that we60// revalidate everything the next time around61if (currentContext != null) {62currentContext.invalidateContext();63currentContext = null;64}6566// invalidate the context reference at the native level, and67// then flush the queue so that we have no pending operations68// dependent on the current context69D3DRenderQueue rq = D3DRenderQueue.getInstance();70rq.ensureCapacity(4);71rq.getBuffer().putInt(INVALIDATE_CONTEXT);72rq.flushNow();73}7475/**76* Sets the current context on the native level to be the one passed as77* the argument.78* If the context is not the same as the defaultContext the latter79* will be reset to null.80*81* This call is needed when copying from a SW surface to a Texture82* (the upload test) or copying from d3d to SW surface to make sure we83* have the correct current context.84*85* @param d3dc the context to be made current on the native level86*/87static void setScratchSurface(D3DContext d3dc) {88// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();8990// invalidate the current context91if (d3dc != currentContext) {92currentContext = null;93}9495// set the scratch context96D3DRenderQueue rq = D3DRenderQueue.getInstance();97RenderBuffer buf = rq.getBuffer();98rq.ensureCapacity(8);99buf.putInt(SET_SCRATCH_SURFACE);100buf.putInt(d3dc.getDevice().getScreen());101}102103public RenderQueue getRenderQueue() {104return D3DRenderQueue.getInstance();105}106107@Override108public void saveState() {109// assert rq.lock.isHeldByCurrentThread();110111// reset all attributes of this and current contexts112invalidateContext();113invalidateCurrentContext();114115setScratchSurface(this);116117// save the state on the native level118rq.ensureCapacity(4);119buf.putInt(SAVE_STATE);120rq.flushNow();121}122123@Override124public void restoreState() {125// assert rq.lock.isHeldByCurrentThread();126127// reset all attributes of this and current contexts128invalidateContext();129invalidateCurrentContext();130131setScratchSurface(this);132133// restore the state on the native level134rq.ensureCapacity(4);135buf.putInt(RESTORE_STATE);136rq.flushNow();137}138139D3DGraphicsDevice getDevice() {140return device;141}142143static class D3DContextCaps extends ContextCapabilities {144/**145* Indicates the presence of pixel shaders (v2.0 or greater).146* This cap will only be set if the hardware supports the minimum number147* of texture units.148*/149@Native static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0);150/**151* Indicates the presence of pixel shaders (v2.0 or greater).152* This cap will only be set if the hardware meets our153* minimum requirements.154*/155@Native static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1);156/**157* Indicates that the device was successfully initialized and can158* be safely used.159*/160@Native static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2);161/**162* Indicates that the device has all of the necessary capabilities163* to support the Antialiasing Pixel Shader program.164*/165@Native static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3);166167D3DContextCaps(int caps, String adapterId) {168super(caps, adapterId);169}170171@Override172public String toString() {173StringBuffer buf = new StringBuffer(super.toString());174if ((caps & CAPS_LCD_SHADER) != 0) {175buf.append("CAPS_LCD_SHADER|");176}177if ((caps & CAPS_BIOP_SHADER) != 0) {178buf.append("CAPS_BIOP_SHADER|");179}180if ((caps & CAPS_AA_SHADER) != 0) {181buf.append("CAPS_AA_SHADER|");182}183if ((caps & CAPS_DEVICE_OK) != 0) {184buf.append("CAPS_DEVICE_OK|");185}186return buf.toString();187}188}189}190191192