diff -r 5a7d72dafbee src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c --- a/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c +++ b/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c @@ -46,8 +46,8 @@ */ #define OGLTR_CACHE_WIDTH 512 #define OGLTR_CACHE_HEIGHT 512 -#define OGLTR_CACHE_CELL_WIDTH 16 -#define OGLTR_CACHE_CELL_HEIGHT 16 +#define OGLTR_CACHE_CELL_WIDTH 32 +#define OGLTR_CACHE_CELL_HEIGHT 32 /** * The current "glyph mode" state. This variable is used to track the @@ -413,14 +413,20 @@ * gamma lookup table textures. */ static jboolean -OGLTR_EnableLCDGlyphModeState(GLuint glyphTextureID, jint contrast) +OGLTR_EnableLCDGlyphModeState(GLuint glyphTextureID, + GLuint dstTextureID, + jint contrast) { // bind the texture containing glyph data to texture unit 0 j2d_glActiveTextureARB(GL_TEXTURE0_ARB); j2d_glBindTexture(GL_TEXTURE_2D, glyphTextureID); + j2d_glEnable(GL_TEXTURE_2D); // bind the texture tile containing destination data to texture unit 1 j2d_glActiveTextureARB(GL_TEXTURE1_ARB); + if (dstTextureID != 0) { + j2d_glBindTexture(GL_TEXTURE_2D, dstTextureID); + } else { if (cachedDestTextureID == 0) { cachedDestTextureID = OGLContext_CreateBlitTexture(GL_RGB8, GL_RGB, @@ -431,6 +437,7 @@ } } j2d_glBindTexture(GL_TEXTURE_2D, cachedDestTextureID); + } // note that GL_TEXTURE_2D was already enabled for texture unit 0, // but we need to explicitly enable it for texture unit 1 @@ -522,6 +529,8 @@ j2d_glActiveTextureARB(GL_TEXTURE1_ARB); j2d_glDisable(GL_TEXTURE_2D); j2d_glActiveTextureARB(GL_TEXTURE0_ARB); + j2d_glDisable(GL_TEXTURE_2D); + break; case MODE_NO_CACHE_GRAY: @@ -712,6 +721,8 @@ CacheCellInfo *cell; jint dx1, dy1, dx2, dy2; jfloat dtx1, dty1, dtx2, dty2; + GLuint dstTextureID = (dstOps->textureTarget == GL_TEXTURE_2D) ? + dstOps->textureID : 0; if (glyphMode != MODE_USE_CACHE_LCD) { OGLTR_DisableGlyphModeState(); @@ -731,7 +742,9 @@ lastRGBOrder = rgbOrder; } - if (!OGLTR_EnableLCDGlyphModeState(glyphCache->cacheID, contrast)) { + if (!OGLTR_EnableLCDGlyphModeState(glyphCache->cacheID, + dstTextureID, contrast)) + { return JNI_FALSE; } @@ -767,6 +780,7 @@ dx2 = dx1 + ginfo->width; dy2 = dy1 + ginfo->height; + if (dstTextureID == 0) { // copy destination into second cached texture, if necessary OGLTR_UpdateCachedDestination(dstOps, ginfo, dx1, dy1, dx2, dy2, @@ -777,7 +791,21 @@ dty1 = ((jfloat)(cachedDestBounds.y2 - dy1)) / OGLTR_CACHED_DEST_HEIGHT; dtx2 = ((jfloat)(dx2 - cachedDestBounds.x1)) / OGLTR_CACHED_DEST_WIDTH; dty2 = ((jfloat)(cachedDestBounds.y2 - dy2)) / OGLTR_CACHED_DEST_HEIGHT; + } else { + jint gw = ginfo->width; + jint gh = ginfo->height; + // this accounts for lower-left origin of the destination region + jint dxadj = dstOps->xOffset + x; + jint dyadj = dstOps->yOffset + dstOps->height - (y + gh); + + // update the remaining destination texture coordinates + dtx1 =((GLfloat)dxadj) / ((GLfloat)dstOps->textureWidth); + dtx2 = ((GLfloat)dxadj + gw) / ((GLfloat)dstOps->textureWidth); + + dty1 = ((GLfloat)dyadj + gh) / ((GLfloat)dstOps->textureHeight); + dty2 = ((GLfloat)dyadj) / ((GLfloat)dstOps->textureHeight); + } // render composed texture to the destination surface j2d_glBegin(GL_QUADS); j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, cell->tx1, cell->ty1); @@ -847,6 +875,8 @@ jint w = ginfo->width; jint h = ginfo->height; GLenum pixelFormat = rgbOrder ? GL_RGB : GL_BGR; + GLuint dstTextureID = (dstOps->textureTarget == GL_TEXTURE_2D) ? + dstOps->textureID : 0; if (glyphMode != MODE_NO_CACHE_LCD) { OGLTR_DisableGlyphModeState(); @@ -859,7 +889,9 @@ } } - if (!OGLTR_EnableLCDGlyphModeState(oglc->blitTextureID, contrast)) { + if (!OGLTR_EnableLCDGlyphModeState(oglc->blitTextureID, + dstTextureID, contrast)) + { return JNI_FALSE; } @@ -907,6 +939,7 @@ dxadj = dstOps->xOffset + x; dyadj = dstOps->yOffset + dstOps->height - (y + sh); + if (dstTextureID == 0) { // copy destination into cached texture tile (the lower-left // corner of the destination region will be positioned at the // lower-left corner (0,0) of the texture) @@ -915,10 +948,18 @@ 0, 0, dxadj, dyadj, sw, sh); - // update the remaining destination texture coordinates dtx2 = ((GLfloat)sw) / OGLTR_CACHED_DEST_WIDTH; dty1 = ((GLfloat)sh) / OGLTR_CACHED_DEST_HEIGHT; + } else { + // use the destination texture directly + // update the remaining destination texture coordinates + dtx1 =((GLfloat)dxadj) / ((GLfloat)dstOps->textureWidth); + dtx2 = ((GLfloat)dxadj + sw) / ((GLfloat)dstOps->textureWidth); + + dty1 = ((GLfloat)dyadj + sh) / ((GLfloat)dstOps->textureHeight); + dty2 = ((GLfloat)dyadj) / ((GLfloat)dstOps->textureHeight); + } // render composed texture to the destination surface j2d_glBegin(GL_QUADS);