Print this page
rev 54883 : JDK-8220154 Improve java2d rendering performance on macOS by using Metal framework

Split Close
Expand all
Collapse all
          --- old/src/java.desktop/share/classes/sun/java2d/opengl/OGLContext.java
          +++ new/src/java.desktop/share/classes/sun/java2d/opengl/OGLContext.java
↓ open down ↓ 34 lines elided ↑ open up ↑
  35   35  import java.lang.annotation.Native;
  36   36  
  37   37  /**
  38   38   * Note that the RenderQueue lock must be acquired before calling any of
  39   39   * the methods in this class.
  40   40   */
  41   41  public class OGLContext extends BufferedContext {
  42   42  
  43   43      private final OGLGraphicsConfig config;
  44   44  
  45      -    OGLContext(RenderQueue rq, OGLGraphicsConfig config) {
       45 +    public OGLContext(RenderQueue rq, OGLGraphicsConfig config) {
  46   46          super(rq);
  47   47          this.config = config;
  48   48      }
  49   49  
  50   50      /**
  51   51       * Convenience method that delegates to setScratchSurface() below.
  52   52       */
  53   53      static void setScratchSurface(OGLGraphicsConfig gc) {
  54   54          setScratchSurface(gc.getNativeConfigInfo());
  55   55      }
↓ open down ↓ 8 lines elided ↑ open up ↑
  64   64       * depending on the capabilities of that GraphicsConfig.  For example,
  65   65       * if the GraphicsConfig supports the GL_ARB_texture_non_power_of_two
  66   66       * extension, then we should be able to make a non-pow2 texture for this
  67   67       * GraphicsConfig once we make the context current to the scratch surface.
  68   68       *
  69   69       * This method should be used for operations with an OpenGL texture
  70   70       * as the destination surface (e.g. a sw->texture blit loop), or in those
  71   71       * situations where we may not otherwise have a current context (e.g.
  72   72       * when disposing a texture-based surface).
  73   73       */
  74      -    static void setScratchSurface(long pConfigInfo) {
       74 +    public static void setScratchSurface(long pConfigInfo) {
  75   75          // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
  76   76  
  77   77          // invalidate the current context
  78   78          currentContext = null;
  79   79  
  80   80          // set the scratch context
  81   81          OGLRenderQueue rq = OGLRenderQueue.getInstance();
  82   82          RenderBuffer buf = rq.getBuffer();
  83   83          rq.ensureCapacityAndAlignment(12, 4);
  84   84          buf.putInt(SET_SCRATCH_SURFACE);
  85   85          buf.putLong(pConfigInfo);
  86   86      }
  87   87  
  88   88      /**
  89   89       * Invalidates the currentContext field to ensure that we properly
  90   90       * revalidate the OGLContext (make it current, etc.) next time through
  91   91       * the validate() method.  This is typically invoked from methods
  92   92       * that affect the current context state (e.g. disposing a context or
  93   93       * surface).
  94   94       */
  95      -    static void invalidateCurrentContext() {
       95 +    public static void invalidateCurrentContext() {
  96   96          // assert OGLRenderQueue.getInstance().lock.isHeldByCurrentThread();
  97   97  
  98   98          // invalidate the current Java-level context so that we
  99   99          // revalidate everything the next time around
 100  100          if (currentContext != null) {
 101  101              currentContext.invalidateContext();
 102  102              currentContext = null;
 103  103          }
 104  104  
 105  105          // invalidate the context reference at the native level, and
↓ open down ↓ 8 lines elided ↑ open up ↑
 114  114      public RenderQueue getRenderQueue() {
 115  115          return OGLRenderQueue.getInstance();
 116  116      }
 117  117  
 118  118      /**
 119  119       * Returns a string representing adapter id (vendor, renderer, version).
 120  120       * Must be called on the rendering thread.
 121  121       *
 122  122       * @return an id string for the adapter
 123  123       */
 124      -    static final native String getOGLIdString();
      124 +    public static final native String getOGLIdString();
 125  125  
 126  126      @Override
 127  127      public void saveState() {
 128  128          // assert rq.lock.isHeldByCurrentThread();
 129  129  
 130  130          // reset all attributes of this and current contexts
 131  131          invalidateContext();
 132  132          invalidateCurrentContext();
 133  133  
 134  134          setScratchSurface(config);
↓ open down ↓ 13 lines elided ↑ open up ↑
 148  148          invalidateCurrentContext();
 149  149  
 150  150          setScratchSurface(config);
 151  151  
 152  152          // restore the state on the native level
 153  153          rq.ensureCapacity(4);
 154  154          buf.putInt(RESTORE_STATE);
 155  155          rq.flushNow();
 156  156      }
 157  157  
 158      -    static class OGLContextCaps extends ContextCapabilities {
      158 +    public static class OGLContextCaps extends ContextCapabilities {
 159  159          /**
 160  160           * Indicates the presence of the GL_EXT_framebuffer_object extension.
 161  161           * This cap will only be set if the fbobject system property has been
 162  162           * enabled and we are able to create an FBO with depth buffer.
 163  163           */
 164  164          @Native
 165      -        static final int CAPS_EXT_FBOBJECT     =
      165 +        public static final int CAPS_EXT_FBOBJECT     =
 166  166                  (CAPS_RT_TEXTURE_ALPHA | CAPS_RT_TEXTURE_OPAQUE);
 167  167          /** Indicates that the context is doublebuffered. */
 168  168          @Native
 169      -        static final int CAPS_DOUBLEBUFFERED   = (FIRST_PRIVATE_CAP << 0);
      169 +        public static final int CAPS_DOUBLEBUFFERED   = (FIRST_PRIVATE_CAP << 0);
 170  170          /**
 171  171           * Indicates the presence of the GL_ARB_fragment_shader extension.
 172  172           * This cap will only be set if the lcdshader system property has been
 173  173           * enabled and the hardware supports the minimum number of texture units
 174  174           */
 175  175          @Native
 176  176          static final int CAPS_EXT_LCD_SHADER   = (FIRST_PRIVATE_CAP << 1);
 177  177          /**
 178  178           * Indicates the presence of the GL_ARB_fragment_shader extension.
 179  179           * This cap will only be set if the biopshader system property has been
↓ open down ↓ 9 lines elided ↑ open up ↑
 189  189          @Native
 190  190          static final int CAPS_EXT_GRAD_SHADER  = (FIRST_PRIVATE_CAP << 3);
 191  191          /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
 192  192          @Native
 193  193          static final int CAPS_EXT_TEXRECT      = (FIRST_PRIVATE_CAP << 4);
 194  194          /** Indicates the presence of the GL_NV_texture_barrier extension. */
 195  195          @Native
 196  196          static final int CAPS_EXT_TEXBARRIER = (FIRST_PRIVATE_CAP << 5);
 197  197  
 198  198  
 199      -        OGLContextCaps(int caps, String adapterId) {
      199 +        public OGLContextCaps(int caps, String adapterId) {
 200  200              super(caps, adapterId);
 201  201          }
 202  202  
 203  203          @Override
 204  204          public String toString() {
 205  205              StringBuilder sb = new StringBuilder(super.toString());
 206  206              if ((caps & CAPS_EXT_FBOBJECT) != 0) {
 207  207                  sb.append("CAPS_EXT_FBOBJECT|");
 208  208              }
 209  209              if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
↓ open down ↓ 21 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX