< prev index next >

src/java.desktop/windows/classes/sun/java2d/d3d/D3DContext.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.d3d;
  27 
  28 import java.lang.annotation.Native;

  29 import sun.java2d.pipe.BufferedContext;
  30 import sun.java2d.pipe.RenderBuffer;
  31 import sun.java2d.pipe.RenderQueue;
  32 import sun.java2d.pipe.hw.ContextCapabilities;
  33 import static sun.java2d.pipe.BufferedOpCodes.*;
  34 import static sun.java2d.pipe.hw.ContextCapabilities.*;
  35 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
  36 
  37 /**
  38  * Note that the RenderQueue lock must be acquired before calling any of
  39  * the methods in this class.
  40  */
  41 class D3DContext extends BufferedContext {
  42 
  43     private final D3DGraphicsDevice device;
  44 
  45     D3DContext(RenderQueue rq, D3DGraphicsDevice device) {
  46         super(rq);
  47         this.device = device;
  48     }
  49 
  50     /**
  51      * Invalidates the currentContext field to ensure that we properly
  52      * revalidate the D3DContext (make it current, etc.) next time through
  53      * the validate() method.  This is typically invoked from methods
  54      * that affect the current context state (e.g. disposing a context or
  55      * surface).
  56      */
  57     static void invalidateCurrentContext() {
  58         // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
  59 
  60         // invalidate the current Java-level context so that we
  61         // revalidate everything the next time around


  84      * have the correct current context.
  85      *
  86      * @param d3dc the context to be made current on the native level
  87      */
  88     static void setScratchSurface(D3DContext d3dc) {
  89         // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
  90 
  91         // invalidate the current context
  92         if (d3dc != currentContext) {
  93             currentContext = null;
  94         }
  95 
  96         // set the scratch context
  97         D3DRenderQueue rq = D3DRenderQueue.getInstance();
  98         RenderBuffer buf = rq.getBuffer();
  99         rq.ensureCapacity(8);
 100         buf.putInt(SET_SCRATCH_SURFACE);
 101         buf.putInt(d3dc.getDevice().getScreen());
 102     }
 103 
 104     public RenderQueue getRenderQueue() {
 105         return D3DRenderQueue.getInstance();
 106     }
 107 
 108     @Override
 109     public void saveState() {
 110         // assert rq.lock.isHeldByCurrentThread();
 111 
 112         // reset all attributes of this and current contexts
 113         invalidateContext();
 114         invalidateCurrentContext();
 115 
 116         setScratchSurface(this);
 117 
 118         // save the state on the native level
 119         rq.ensureCapacity(4);
 120         buf.putInt(SAVE_STATE);
 121         rq.flushNow();
 122     }
 123 
 124     @Override
 125     public void restoreState() {
 126         // assert rq.lock.isHeldByCurrentThread();
 127 
 128         // reset all attributes of this and current contexts
 129         invalidateContext();
 130         invalidateCurrentContext();
 131 
 132         setScratchSurface(this);
 133 
 134         // restore the state on the native level
 135         rq.ensureCapacity(4);
 136         buf.putInt(RESTORE_STATE);
 137         rq.flushNow();
 138     }
 139 
 140     D3DGraphicsDevice getDevice() {
 141         return device;
 142     }
 143 
 144     static class D3DContextCaps extends ContextCapabilities {
 145         /**
 146          * Indicates the presence of pixel shaders (v2.0 or greater).
 147          * This cap will only be set if the hardware supports the minimum number
 148          * of texture units.
 149          */
 150     @Native static final int CAPS_LCD_SHADER       = (FIRST_PRIVATE_CAP << 0);
 151         /**
 152          * Indicates the presence of pixel shaders (v2.0 or greater).
 153          * This cap will only be set if the hardware meets our
 154          * minimum requirements.
 155          */
 156     @Native static final int CAPS_BIOP_SHADER      = (FIRST_PRIVATE_CAP << 1);
 157         /**
 158          * Indicates that the device was successfully initialized and can
 159          * be safely used.


   1 /*
   2  * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.d3d;
  27 
  28 import java.lang.annotation.Native;
  29 
  30 import sun.java2d.pipe.BufferedContext;
  31 import sun.java2d.pipe.RenderBuffer;
  32 import sun.java2d.pipe.RenderQueue;
  33 import sun.java2d.pipe.hw.ContextCapabilities;
  34 
  35 import static sun.java2d.pipe.BufferedOpCodes.INVALIDATE_CONTEXT;
  36 import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;
  37 
  38 /**
  39  * Note that the RenderQueue lock must be acquired before calling any of
  40  * the methods in this class.
  41  */
  42 final class D3DContext extends BufferedContext {
  43 
  44     private final D3DGraphicsDevice device;
  45 
  46     D3DContext(RenderQueue rq, D3DGraphicsDevice device) {
  47         super(rq);
  48         this.device = device;
  49     }
  50 
  51     /**
  52      * Invalidates the currentContext field to ensure that we properly
  53      * revalidate the D3DContext (make it current, etc.) next time through
  54      * the validate() method.  This is typically invoked from methods
  55      * that affect the current context state (e.g. disposing a context or
  56      * surface).
  57      */
  58     static void invalidateCurrentContext() {
  59         // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
  60 
  61         // invalidate the current Java-level context so that we
  62         // revalidate everything the next time around


  85      * have the correct current context.
  86      *
  87      * @param d3dc the context to be made current on the native level
  88      */
  89     static void setScratchSurface(D3DContext d3dc) {
  90         // assert D3DRenderQueue.getInstance().lock.isHeldByCurrentThread();
  91 
  92         // invalidate the current context
  93         if (d3dc != currentContext) {
  94             currentContext = null;
  95         }
  96 
  97         // set the scratch context
  98         D3DRenderQueue rq = D3DRenderQueue.getInstance();
  99         RenderBuffer buf = rq.getBuffer();
 100         rq.ensureCapacity(8);
 101         buf.putInt(SET_SCRATCH_SURFACE);
 102         buf.putInt(d3dc.getDevice().getScreen());
 103     }
 104 




































 105     D3DGraphicsDevice getDevice() {
 106         return device;
 107     }
 108 
 109     static class D3DContextCaps extends ContextCapabilities {
 110         /**
 111          * Indicates the presence of pixel shaders (v2.0 or greater).
 112          * This cap will only be set if the hardware supports the minimum number
 113          * of texture units.
 114          */
 115     @Native static final int CAPS_LCD_SHADER       = (FIRST_PRIVATE_CAP << 0);
 116         /**
 117          * Indicates the presence of pixel shaders (v2.0 or greater).
 118          * This cap will only be set if the hardware meets our
 119          * minimum requirements.
 120          */
 121     @Native static final int CAPS_BIOP_SHADER      = (FIRST_PRIVATE_CAP << 1);
 122         /**
 123          * Indicates that the device was successfully initialized and can
 124          * be safely used.


< prev index next >