7168550: [macosx] duplicate OGL context state changes related to vertex cache
Reviewed-by: bae, swingler
--- a/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m Sat May 12 18:50:27 2012 +0400
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLSurfaceData.m Tue May 15 15:04:10 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/jdk/src/share/native/sun/java2d/opengl/OGLContext.h Sat May 12 18:50:27 2012 +0400
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLContext.h Tue May 15 15:04:10 2012 +0400
@@ -84,6 +84,7 @@
GLdouble *xformMatrix;
GLuint blitTextureID;
GLint textureFunction;
+ jboolean vertexCacheEnabled;
} OGLContext;
/**
--- a/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c Sat May 12 18:50:27 2012 +0400
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c Tue May 15 15:04:10 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/jdk/src/share/native/sun/java2d/opengl/OGLVertexCache.c Sat May 12 18:50:27 2012 +0400
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLVertexCache.c Tue May 15 15:04:10 2012 +0400
@@ -67,29 +67,31 @@
} while (0)
jboolean
-OGLVertexCache_InitVertexCache()
+OGLVertexCache_InitVertexCache(OGLContext *oglc)
{
J2dTraceLn(J2D_TRACE_INFO, "OGLVertexCache_InitVertexCache");
- if (vertexCache != NULL) {
- return JNI_TRUE;
- }
-
- 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;
+ }
}
- 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);
+ 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);
+ j2d_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ j2d_glEnableClientState(GL_COLOR_ARRAY);
+ j2d_glEnableClientState(GL_VERTEX_ARRAY);
+
+ oglc->vertexCacheEnabled = JNI_TRUE;
+ }
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/jdk/src/share/native/sun/java2d/opengl/OGLVertexCache.h Sat May 12 18:50:27 2012 +0400
+++ b/jdk/src/share/native/sun/java2d/opengl/OGLVertexCache.h Tue May 15 15:04:10 2012 +0400
@@ -65,7 +65,7 @@
/**
* Exported methods.
*/
-jboolean OGLVertexCache_InitVertexCache();
+jboolean OGLVertexCache_InitVertexCache(OGLContext *oglc);
void OGLVertexCache_FlushVertexCache();
void OGLVertexCache_RestoreColorState(OGLContext *oglc);