changeset 5037:533eb1663b90

7168550: [macosx] duplicate OGL context state changes related to vertex cache Reviewed-by: bae
author dcherepanov
date Mon, 28 May 2012 13:46:42 +0400
parents 9fa6e878fcdb
children 36a5fa410439
files src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m src/share/native/sun/java2d/opengl/OGLContext.h src/share/native/sun/java2d/opengl/OGLTextRenderer.c src/share/native/sun/java2d/opengl/OGLVertexCache.c src/share/native/sun/java2d/opengl/OGLVertexCache.h
diffstat 6 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Mon May 28 13:36:51 2012 +0400
+++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Mon May 28 13:46:42 2012 +0400
@@ -312,10 +312,7 @@
 
     GLint contextVirtualScreen = [context currentVirtualScreen];
 #if USE_NSVIEW_FOR_SCRATCH
-    /* the scratch surface will be set to the view
-     * later on the flusher thread by OGLSD_SetScratchSurface.
-     */
-    //[context setView: scratchSurface];
+    [context setView: scratchSurface];
 #else
     [context
         setPixelBuffer: scratchSurface
--- a/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m	Mon May 28 13:36:51 2012 +0400
+++ b/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m	Mon May 28 13:46:42 2012 +0400
@@ -204,7 +204,8 @@
         if (!CGLSD_MakeCurrentToScratch(env, oglc)) {
             return NULL;
         }
-    } else if ([NSOpenGLContext currentContext] == nil) {
+    // make sure our context is current
+    } else if ([NSOpenGLContext currentContext] != ctxinfo->context) {
         [ctxinfo->context makeCurrentContext];
     }
 
--- a/src/share/native/sun/java2d/opengl/OGLContext.h	Mon May 28 13:36:51 2012 +0400
+++ b/src/share/native/sun/java2d/opengl/OGLContext.h	Mon May 28 13:46:42 2012 +0400
@@ -84,6 +84,7 @@
     GLdouble   *xformMatrix;
     GLuint     blitTextureID;
     GLint      textureFunction;
+    jboolean   vertexCacheEnabled;
 } OGLContext;
 
 /**
--- a/src/share/native/sun/java2d/opengl/OGLTextRenderer.c	Mon May 28 13:36:51 2012 +0400
+++ b/src/share/native/sun/java2d/opengl/OGLTextRenderer.c	Mon May 28 13:46:42 2012 +0400
@@ -202,11 +202,6 @@
 
     J2dTraceLn(J2D_TRACE_INFO, "OGLTR_InitGlyphCache");
 
-    // init vertex cache (if it hasn't been already)
-    if (!OGLVertexCache_InitVertexCache()) {
-        return JNI_FALSE;
-    }
-
     // init glyph cache data structure
     gcinfo = AccelGlyphCache_Init(OGLTR_CACHE_WIDTH,
                                   OGLTR_CACHE_HEIGHT,
@@ -583,6 +578,10 @@
 {
     J2dTraceLn(J2D_TRACE_INFO, "OGLTR_EnableGlyphVertexCache");
 
+    if (!OGLVertexCache_InitVertexCache(oglc)) {
+        return;
+    }
+
     if (glyphCache == NULL) {
         if (!OGLTR_InitGlyphCache(JNI_FALSE)) {
             return;
--- a/src/share/native/sun/java2d/opengl/OGLVertexCache.c	Mon May 28 13:36:51 2012 +0400
+++ b/src/share/native/sun/java2d/opengl/OGLVertexCache.c	Mon May 28 13:46:42 2012 +0400
@@ -67,30 +67,32 @@
     } while (0)
 
 jboolean
-OGLVertexCache_InitVertexCache()
+OGLVertexCache_InitVertexCache(OGLContext *oglc)
 {
     J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_InitVertexCache");
 
-    if (vertexCache != NULL) {
-        return JNI_TRUE;
+    if (vertexCache == NULL) {
+        vertexCache = (J2DVertex *)malloc(OGLVC_MAX_INDEX * sizeof(J2DVertex));
+        if (vertexCache == NULL) {
+            return JNI_FALSE;
+        }
     }
 
-    vertexCache = (J2DVertex *)malloc(OGLVC_MAX_INDEX * sizeof(J2DVertex));
-    if (vertexCache == NULL) {
-        return JNI_FALSE;
+    if (!oglc->vertexCacheEnabled) {
+        j2d_glTexCoordPointer(2, GL_FLOAT,
+                              sizeof(J2DVertex), vertexCache);
+        j2d_glColorPointer(4, GL_UNSIGNED_BYTE,
+                           sizeof(J2DVertex), ((jfloat *)vertexCache) + 2);
+        j2d_glVertexPointer(2, GL_FLOAT,
+                            sizeof(J2DVertex), ((jfloat *)vertexCache) + 3);
+
+        j2d_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+        j2d_glEnableClientState(GL_COLOR_ARRAY);
+        j2d_glEnableClientState(GL_VERTEX_ARRAY);
+
+        oglc->vertexCacheEnabled = JNI_TRUE;
     }
 
-    j2d_glTexCoordPointer(2, GL_FLOAT,
-                          sizeof(J2DVertex), vertexCache);
-    j2d_glColorPointer(4, GL_UNSIGNED_BYTE,
-                       sizeof(J2DVertex), ((jfloat *)vertexCache) + 2);
-    j2d_glVertexPointer(2, GL_FLOAT,
-                        sizeof(J2DVertex), ((jfloat *)vertexCache) + 3);
-
-    j2d_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-    j2d_glEnableClientState(GL_COLOR_ARRAY);
-    j2d_glEnableClientState(GL_VERTEX_ARRAY);
-
     return JNI_TRUE;
 }
 
@@ -149,10 +151,6 @@
 {
     J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_InitMaskCache");
 
-    if (!OGLVertexCache_InitVertexCache()) {
-        return JNI_FALSE;
-    }
-
     maskCacheTexID =
         OGLContext_CreateBlitTexture(GL_INTENSITY8, GL_LUMINANCE,
                                      OGLVC_MASK_CACHE_WIDTH_IN_TEXELS,
@@ -179,6 +177,10 @@
 {
     J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_EnableMaskCache");
 
+    if (!OGLVertexCache_InitVertexCache(oglc)) {
+        return;
+    }
+
     if (maskCacheTexID == 0) {
         if (!OGLVertexCache_InitMaskCache()) {
             return;
--- a/src/share/native/sun/java2d/opengl/OGLVertexCache.h	Mon May 28 13:36:51 2012 +0400
+++ b/src/share/native/sun/java2d/opengl/OGLVertexCache.h	Mon May 28 13:46:42 2012 +0400
@@ -65,7 +65,7 @@
 /**
  * Exported methods.
  */
-jboolean OGLVertexCache_InitVertexCache();
+jboolean OGLVertexCache_InitVertexCache(OGLContext *oglc);
 void OGLVertexCache_FlushVertexCache();
 void OGLVertexCache_RestoreColorState(OGLContext *oglc);