Path: blob/master/src/java.desktop/windows/classes/sun/java2d/d3d/D3DContext.java
41159 views
/*1* Copyright (c) 2007, 2021, 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;2829import sun.java2d.pipe.BufferedContext;30import sun.java2d.pipe.RenderBuffer;31import sun.java2d.pipe.RenderQueue;32import sun.java2d.pipe.hw.ContextCapabilities;3334import static sun.java2d.pipe.BufferedOpCodes.INVALIDATE_CONTEXT;35import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;3637/**38* Note that the RenderQueue lock must be acquired before calling any of39* the methods in this class.40*/41final class D3DContext extends BufferedContext {4243private final D3DGraphicsDevice device;4445D3DContext(RenderQueue rq, D3DGraphicsDevice device) {46super(rq);47this.device = device;48}4950/**51* Invalidates the currentContext field to ensure that we properly52* revalidate the D3DContext (make it current, etc.) next time through53* the validate() method. This is typically invoked from methods54* that affect the current context state (e.g. disposing a context or55* surface).56*/57static void invalidateCurrentContext() {58// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();5960// invalidate the current Java-level context so that we61// revalidate everything the next time around62if (currentContext != null) {63currentContext.invalidateContext();64currentContext = null;65}6667// invalidate the context reference at the native level, and68// then flush the queue so that we have no pending operations69// dependent on the current context70D3DRenderQueue rq = D3DRenderQueue.getInstance();71rq.ensureCapacity(4);72rq.getBuffer().putInt(INVALIDATE_CONTEXT);73rq.flushNow();74}7576/**77* Sets the current context on the native level to be the one passed as78* the argument.79* If the context is not the same as the defaultContext the latter80* will be reset to null.81*82* This call is needed when copying from a SW surface to a Texture83* (the upload test) or copying from d3d to SW surface to make sure we84* have the correct current context.85*86* @param d3dc the context to be made current on the native level87*/88static void setScratchSurface(D3DContext d3dc) {89// assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();9091// invalidate the current context92if (d3dc != currentContext) {93currentContext = null;94}9596// set the scratch context97D3DRenderQueue rq = D3DRenderQueue.getInstance();98RenderBuffer buf = rq.getBuffer();99rq.ensureCapacity(8);100buf.putInt(SET_SCRATCH_SURFACE);101buf.putInt(d3dc.getDevice().getScreen());102}103104D3DGraphicsDevice getDevice() {105return device;106}107108static class D3DContextCaps extends ContextCapabilities {109/**110* Indicates the presence of pixel shaders (v2.0 or greater).111* This cap will only be set if the hardware supports the minimum number112* of texture units.113*/114@Native static final int CAPS_LCD_SHADER = (FIRST_PRIVATE_CAP << 0);115/**116* Indicates the presence of pixel shaders (v2.0 or greater).117* This cap will only be set if the hardware meets our118* minimum requirements.119*/120@Native static final int CAPS_BIOP_SHADER = (FIRST_PRIVATE_CAP << 1);121/**122* Indicates that the device was successfully initialized and can123* be safely used.124*/125@Native static final int CAPS_DEVICE_OK = (FIRST_PRIVATE_CAP << 2);126/**127* Indicates that the device has all of the necessary capabilities128* to support the Antialiasing Pixel Shader program.129*/130@Native static final int CAPS_AA_SHADER = (FIRST_PRIVATE_CAP << 3);131132D3DContextCaps(int caps, String adapterId) {133super(caps, adapterId);134}135136@Override137public String toString() {138StringBuilder buf = new StringBuilder(super.toString());139if ((caps & CAPS_LCD_SHADER) != 0) {140buf.append("CAPS_LCD_SHADER|");141}142if ((caps & CAPS_BIOP_SHADER) != 0) {143buf.append("CAPS_BIOP_SHADER|");144}145if ((caps & CAPS_AA_SHADER) != 0) {146buf.append("CAPS_AA_SHADER|");147}148if ((caps & CAPS_DEVICE_OK) != 0) {149buf.append("CAPS_DEVICE_OK|");150}151return buf.toString();152}153}154}155156157