src/share/classes/sun/java2d/opengl/OGLContext.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2008, 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.opengl;
  27 
  28 import sun.java2d.pipe.BufferedContext;
  29 import sun.java2d.pipe.RenderBuffer;
  30 import sun.java2d.pipe.RenderQueue;
  31 import sun.java2d.pipe.hw.ContextCapabilities;
  32 import static sun.java2d.pipe.BufferedOpCodes.*;
  33 import static sun.java2d.pipe.hw.ContextCapabilities.*;
  34 
  35 import javax.tools.annotation.GenerateNativeHeader;
  36 
  37 /**
  38  * Note that the RenderQueue lock must be acquired before calling any of
  39  * the methods in this class.
  40  */
  41 public class OGLContext extends BufferedContext {
  42 
  43     private final OGLGraphicsConfig config;
  44 
  45     OGLContext(RenderQueue rq, OGLGraphicsConfig config) {
  46         super(rq);
  47         this.config = config;
  48     }
  49 
  50     /**
  51      * Convenience method that delegates to setScratchSurface() below.
  52      */
  53     static void setScratchSurface(OGLGraphicsConfig gc) {
  54         setScratchSurface(gc.getNativeConfigInfo());
  55     }


 138         buf.putInt(SAVE_STATE);
 139         rq.flushNow();
 140     }
 141 
 142     @Override
 143     public void restoreState() {
 144         // assert rq.lock.isHeldByCurrentThread();
 145 
 146         // reset all attributes of this and current contexts
 147         invalidateContext();
 148         invalidateCurrentContext();
 149 
 150         setScratchSurface(config);
 151 
 152         // restore the state on the native level
 153         rq.ensureCapacity(4);
 154         buf.putInt(RESTORE_STATE);
 155         rq.flushNow();
 156     }
 157 
 158     /* No native methods here, but the constants are needed in the supporting JNI code */
 159     @GenerateNativeHeader
 160     static class OGLContextCaps extends ContextCapabilities {
 161         /**
 162          * Indicates the presence of the GL_EXT_framebuffer_object extension.
 163          * This cap will only be set if the fbobject system property has been
 164          * enabled and we are able to create an FBO with depth buffer.
 165          */
 166         static final int CAPS_EXT_FBOBJECT     =
 167                 (CAPS_RT_TEXTURE_ALPHA | CAPS_RT_TEXTURE_OPAQUE);
 168         /** Indicates that the context supports a stored alpha channel. */
 169         static final int CAPS_STORED_ALPHA     = CAPS_RT_PLAIN_ALPHA;
 170         /** Indicates that the context is doublebuffered. */
 171         static final int CAPS_DOUBLEBUFFERED   = (FIRST_PRIVATE_CAP << 0);
 172         /**
 173          * Indicates the presence of the GL_ARB_fragment_shader extension.
 174          * This cap will only be set if the lcdshader system property has been
 175          * enabled and the hardware supports the minimum number of texture units
 176          */
 177         static final int CAPS_EXT_LCD_SHADER   = (FIRST_PRIVATE_CAP << 1);
 178         /**
 179          * Indicates the presence of the GL_ARB_fragment_shader extension.
 180          * This cap will only be set if the biopshader system property has been
 181          * enabled and the hardware meets our minimum requirements.
 182          */
 183         static final int CAPS_EXT_BIOP_SHADER  = (FIRST_PRIVATE_CAP << 2);
 184         /**
 185          * Indicates the presence of the GL_ARB_fragment_shader extension.
 186          * This cap will only be set if the gradshader system property has been
 187          * enabled and the hardware meets our minimum requirements.
 188          */
 189         static final int CAPS_EXT_GRAD_SHADER  = (FIRST_PRIVATE_CAP << 3);
 190         /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
 191         static final int CAPS_EXT_TEXRECT      = (FIRST_PRIVATE_CAP << 4);
 192 
 193         OGLContextCaps(int caps, String adapterId) {
 194             super(caps, adapterId);
 195         }
 196 
 197         @Override
 198         public String toString() {
 199             StringBuffer buf = new StringBuffer(super.toString());
 200             if ((caps & CAPS_EXT_FBOBJECT) != 0) {
 201                 buf.append("CAPS_EXT_FBOBJECT|");
 202             }
 203             if ((caps & CAPS_STORED_ALPHA) != 0) {
 204                 buf.append("CAPS_STORED_ALPHA|");
 205             }
 206             if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
 207                 buf.append("CAPS_DOUBLEBUFFERED|");
 208             }
 209             if ((caps & CAPS_EXT_LCD_SHADER) != 0) {
 210                 buf.append("CAPS_EXT_LCD_SHADER|");
 211             }
   1 /*
   2  * Copyright (c) 2004, 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.opengl;
  27 
  28 import sun.java2d.pipe.BufferedContext;
  29 import sun.java2d.pipe.RenderBuffer;
  30 import sun.java2d.pipe.RenderQueue;
  31 import sun.java2d.pipe.hw.ContextCapabilities;
  32 import static sun.java2d.pipe.BufferedOpCodes.*;
  33 import static sun.java2d.pipe.hw.ContextCapabilities.*;
  34 
  35 import java.lang.annotation.Native;
  36 
  37 /**
  38  * Note that the RenderQueue lock must be acquired before calling any of
  39  * the methods in this class.
  40  */
  41 public class OGLContext extends BufferedContext {
  42 
  43     private final OGLGraphicsConfig config;
  44 
  45     OGLContext(RenderQueue rq, OGLGraphicsConfig config) {
  46         super(rq);
  47         this.config = config;
  48     }
  49 
  50     /**
  51      * Convenience method that delegates to setScratchSurface() below.
  52      */
  53     static void setScratchSurface(OGLGraphicsConfig gc) {
  54         setScratchSurface(gc.getNativeConfigInfo());
  55     }


 138         buf.putInt(SAVE_STATE);
 139         rq.flushNow();
 140     }
 141 
 142     @Override
 143     public void restoreState() {
 144         // assert rq.lock.isHeldByCurrentThread();
 145 
 146         // reset all attributes of this and current contexts
 147         invalidateContext();
 148         invalidateCurrentContext();
 149 
 150         setScratchSurface(config);
 151 
 152         // restore the state on the native level
 153         rq.ensureCapacity(4);
 154         buf.putInt(RESTORE_STATE);
 155         rq.flushNow();
 156     }
 157 


 158     static class OGLContextCaps extends ContextCapabilities {
 159         /**
 160          * Indicates the presence of the GL_EXT_framebuffer_object extension.
 161          * This cap will only be set if the fbobject system property has been
 162          * enabled and we are able to create an FBO with depth buffer.
 163          */
 164     @Native static final int CAPS_EXT_FBOBJECT     =
 165                 (CAPS_RT_TEXTURE_ALPHA | CAPS_RT_TEXTURE_OPAQUE);
 166         /** Indicates that the context supports a stored alpha channel. */
 167     @Native static final int CAPS_STORED_ALPHA     = CAPS_RT_PLAIN_ALPHA;
 168         /** Indicates that the context is doublebuffered. */
 169     @Native static final int CAPS_DOUBLEBUFFERED   = (FIRST_PRIVATE_CAP << 0);
 170         /**
 171          * Indicates the presence of the GL_ARB_fragment_shader extension.
 172          * This cap will only be set if the lcdshader system property has been
 173          * enabled and the hardware supports the minimum number of texture units
 174          */
 175     @Native static final int CAPS_EXT_LCD_SHADER   = (FIRST_PRIVATE_CAP << 1);
 176         /**
 177          * Indicates the presence of the GL_ARB_fragment_shader extension.
 178          * This cap will only be set if the biopshader system property has been
 179          * enabled and the hardware meets our minimum requirements.
 180          */
 181     @Native static final int CAPS_EXT_BIOP_SHADER  = (FIRST_PRIVATE_CAP << 2);
 182         /**
 183          * Indicates the presence of the GL_ARB_fragment_shader extension.
 184          * This cap will only be set if the gradshader system property has been
 185          * enabled and the hardware meets our minimum requirements.
 186          */
 187     @Native static final int CAPS_EXT_GRAD_SHADER  = (FIRST_PRIVATE_CAP << 3);
 188         /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
 189     @Native static final int CAPS_EXT_TEXRECT      = (FIRST_PRIVATE_CAP << 4);
 190 
 191         OGLContextCaps(int caps, String adapterId) {
 192             super(caps, adapterId);
 193         }
 194 
 195         @Override
 196         public String toString() {
 197             StringBuffer buf = new StringBuffer(super.toString());
 198             if ((caps & CAPS_EXT_FBOBJECT) != 0) {
 199                 buf.append("CAPS_EXT_FBOBJECT|");
 200             }
 201             if ((caps & CAPS_STORED_ALPHA) != 0) {
 202                 buf.append("CAPS_STORED_ALPHA|");
 203             }
 204             if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
 205                 buf.append("CAPS_DOUBLEBUFFERED|");
 206             }
 207             if ((caps & CAPS_EXT_LCD_SHADER) != 0) {
 208                 buf.append("CAPS_EXT_LCD_SHADER|");
 209             }