src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    28
#include <stdlib.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "sun_java2d_opengl_OGLTextRenderer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "OGLContext.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "OGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "OGLRenderQueue.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "OGLTextRenderer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "OGLVertexCache.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "AccelGlyphCache.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "fontscalerdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The following constants define the inner and outer bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * accelerated glyph cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define OGLTR_CACHE_WIDTH       512
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define OGLTR_CACHE_HEIGHT      512
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    49
#define OGLTR_CACHE_CELL_WIDTH  32
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    50
#define OGLTR_CACHE_CELL_HEIGHT 32
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The current "glyph mode" state.  This variable is used to track the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * codepath used to render a particular glyph.  This variable is reset to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * MODE_NOT_INITED at the beginning of every call to OGLTR_DrawGlyphList().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * As each glyph is rendered, the glyphMode variable is updated to reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the current mode, so if the current mode is the same as the mode used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * to render the previous glyph, we can avoid doing costly setup operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * each time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
typedef enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    MODE_NOT_INITED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    MODE_USE_CACHE_GRAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    MODE_USE_CACHE_LCD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    MODE_NO_CACHE_GRAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    MODE_NO_CACHE_LCD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
} GlyphMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
static GlyphMode glyphMode = MODE_NOT_INITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/**
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    71
 * There are two separate glyph caches: for AA and for LCD.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    72
 * Once one of them is initialized as either GRAY or LCD, it
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    73
 * stays in that mode for the duration of the application.  It should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * be safe to use this one glyph cache for all screens in a multimon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * environment, since the glyph cache texture is shared between all contexts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * and (in theory) OpenGL drivers should be smart enough to manage that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * texture across all screens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    79
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    80
static GlyphCacheInfo *glyphCacheLCD = NULL;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
    81
static GlyphCacheInfo *glyphCacheAA = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The handle to the LCD text fragment program object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static GLhandleARB lcdTextProgram = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * This value tracks the previous LCD contrast setting, so if the contrast
31171
59d8e7712c0b 8085910: OGL text renderer: gamma lut cleanup
bae
parents: 31158
diff changeset
    90
 * value hasn't changed since the last time the gamma uniforms were
59d8e7712c0b 8085910: OGL text renderer: gamma lut cleanup
bae
parents: 31158
diff changeset
    91
 * updated (not very common), then we can skip updating the unforms.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static jint lastLCDContrast = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * This value tracks the previous LCD rgbOrder setting, so if the rgbOrder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * value has changed since the last time, it indicates that we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * invalidate the cache, which may already store glyph images in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * order.  Note that in most real world applications this value will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * change over the course of the application, but tests like Font2DTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * allow for changing the ordering at runtime, so we need to handle that case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static jboolean lastRGBOrder = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * This constant defines the size of the tile to use in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * OGLTR_DrawLCDGlyphNoCache() method.  See below for more on why we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * restrict this value to a particular size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#define OGLTR_NOCACHE_TILE_SIZE 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * These constants define the size of the "cached destination" texture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * This texture is only used when rendering LCD-optimized text, as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * codepath needs direct access to the destination.  There is no way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * access the framebuffer directly from an OpenGL shader, so we need to first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * copy the destination region corresponding to a particular glyph into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * this cached texture, and then that texture will be accessed inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * shader.  Copying the destination into this cached texture can be a very
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * expensive operation (accounting for about half the rendering time for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * LCD text), so to mitigate this cost we try to bulk read a horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * region of the destination at a time.  (These values are empirically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * derived for the common case where text runs horizontally.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * Note: It is assumed in various calculations below that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *     (OGLTR_CACHED_DEST_WIDTH  >= OGLTR_CACHE_CELL_WIDTH)  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *     (OGLTR_CACHED_DEST_WIDTH  >= OGLTR_NOCACHE_TILE_SIZE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *     (OGLTR_CACHED_DEST_HEIGHT >= OGLTR_CACHE_CELL_HEIGHT) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *     (OGLTR_CACHED_DEST_HEIGHT >= OGLTR_NOCACHE_TILE_SIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#define OGLTR_CACHED_DEST_WIDTH  512
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   132
#define OGLTR_CACHED_DEST_HEIGHT (OGLTR_CACHE_CELL_HEIGHT * 2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * The handle to the "cached destination" texture object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
static GLuint cachedDestTextureID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * The current bounds of the "cached destination" texture, in destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * coordinate space.  The width/height of these bounds will not exceed the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * OGLTR_CACHED_DEST_WIDTH/HEIGHT values defined above.  These bounds are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * only considered valid when the isCachedDestValid flag is JNI_TRUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
static SurfaceDataBounds cachedDestBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * This flag indicates whether the "cached destination" texture contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * valid data.  This flag is reset to JNI_FALSE at the beginning of every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * call to OGLTR_DrawGlyphList().  Once we copy valid destination data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * into the cached texture, this flag is set to JNI_TRUE.  This way, we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * limit the number of times we need to copy destination data, which is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * very costly operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
static jboolean isCachedDestValid = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * The bounds of the previously rendered LCD glyph, in destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * coordinate space.  We use these bounds to determine whether the glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * currently being rendered overlaps the previously rendered glyph (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * its bounding box intersects that of the previously rendered glyph).  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * so, we need to re-read the destination area associated with that previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * glyph so that we can correctly blend with the actual destination data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
static SurfaceDataBounds previousGlyphBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * Initializes the one glyph cache (texture and data structure).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * If lcdCache is JNI_TRUE, the texture will contain RGB data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * otherwise we will simply store the grayscale/monochrome glyph images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * as intensity values (which work well with the GL_MODULATE function).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
OGLTR_InitGlyphCache(jboolean lcdCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    GlyphCacheInfo *gcinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    GLclampf priority = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    GLenum internalFormat = lcdCache ? GL_RGB8 : GL_INTENSITY8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    GLenum pixelFormat = lcdCache ? GL_RGB : GL_LUMINANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_InitGlyphCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // init glyph cache data structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    gcinfo = AccelGlyphCache_Init(OGLTR_CACHE_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                  OGLTR_CACHE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                  OGLTR_CACHE_CELL_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                  OGLTR_CACHE_CELL_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                  OGLVertexCache_FlushVertexCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (gcinfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                      "OGLTR_InitGlyphCache: could not init OGL glyph cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    // init cache texture object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    j2d_glGenTextures(1, &gcinfo->cacheID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    j2d_glBindTexture(GL_TEXTURE_2D, gcinfo->cacheID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    j2d_glPrioritizeTextures(1, &gcinfo->cacheID, &priority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    j2d_glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                     OGLTR_CACHE_WIDTH, OGLTR_CACHE_HEIGHT, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                     pixelFormat, GL_UNSIGNED_BYTE, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   206
    if (lcdCache) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   207
        glyphCacheLCD = gcinfo;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   208
    } else {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   209
        glyphCacheAA = gcinfo;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   210
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * Adds the given glyph to the glyph cache (texture and data structure)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * associated with the given OGLContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
static void
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   220
OGLTR_AddToGlyphCache(GlyphInfo *glyph, GLenum pixelFormat)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
{
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   222
    CacheCellInfo *ccinfo;
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   223
    GlyphCacheInfo *gcinfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_AddToGlyphCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   227
    if (pixelFormat == GL_LUMINANCE) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   228
        gcinfo = glyphCacheAA;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   229
    } else {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   230
        gcinfo = glyphCacheLCD;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   231
    }
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   232
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   233
    if ((gcinfo == NULL) || (glyph->image == NULL)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   237
    AccelGlyphCache_AddGlyph(gcinfo, glyph);
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   238
    ccinfo = (CacheCellInfo *) glyph->cellInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   240
    if (ccinfo != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // store glyph image in texture cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   243
                            ccinfo->x, ccinfo->y,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            glyph->width, glyph->height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            pixelFormat, GL_UNSIGNED_BYTE, glyph->image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * This is the GLSL fragment shader source code for rendering LCD-optimized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * text.  Do not be frightened; it is much easier to understand than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * equivalent ASM-like fragment program!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * The "uniform" variables at the top are initialized once the program is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * linked, and are updated at runtime as needed (e.g. when the source color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * changes, we will modify the "src_adj" value in OGLTR_UpdateLCDTextColor()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * The "main" function is executed for each "fragment" (or pixel) in the
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   259
 * glyph image. The pow() routine operates on vectors, gives precise results,
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   260
 * and provides acceptable level of performance, so we use it to perform
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   261
 * the gamma adjustment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * The variables involved in the equation can be expressed as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 *   Cs = Color component of the source (foreground color) [0.0, 1.0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 *   Cd = Color component of the destination (background color) [0.0, 1.0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *   Cr = Color component to be written to the destination [0.0, 1.0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *   Ag = Glyph alpha (aka intensity or coverage) [0.0, 1.0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *   Ga = Gamma adjustment in the range [1.0, 2.5]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *   (^ means raised to the power)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * And here is the theoretical equation approximated by this shader:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *            Cr = (Ag*(Cs^Ga) + (1-Ag)*(Cd^Ga)) ^ (1/Ga)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
static const char *lcdTextShaderSource =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    "uniform vec3 src_adj;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    "uniform sampler2D glyph_tex;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    "uniform sampler2D dst_tex;"
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   280
    "uniform vec3 gamma;"
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   281
    "uniform vec3 invgamma;"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    "void main(void)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    "{"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         // load the RGB value from the glyph image at the current texcoord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    "    vec3 glyph_clr = vec3(texture2D(glyph_tex, gl_TexCoord[0].st));"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    "    if (glyph_clr == vec3(0.0)) {"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
             // zero coverage, so skip this fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    "        discard;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    "    }"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         // load the RGB value from the corresponding destination pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    "    vec3 dst_clr = vec3(texture2D(dst_tex, gl_TexCoord[1].st));"
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   293
         // gamma adjust the dest color
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   294
    "    vec3 dst_adj = pow(dst_clr.rgb, gamma);"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         // linearly interpolate the three color values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    "    vec3 result = mix(dst_adj, src_adj, glyph_clr);"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         // gamma re-adjust the resulting color (alpha is always set to 1.0)
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   298
    "    gl_FragColor = vec4(pow(result.rgb, invgamma), 1.0);"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * Compiles and links the LCD text shader program.  If successful, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * function returns a handle to the newly created shader program; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * returns 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
static GLhandleARB
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   307
OGLTR_CreateLCDTextProgram(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    GLhandleARB lcdTextProgram;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    GLint loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_CreateLCDTextProgram");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    lcdTextProgram = OGLContext_CreateFragmentProgram(lcdTextShaderSource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    if (lcdTextProgram == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                      "OGLTR_CreateLCDTextProgram: error creating program");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    // "use" the program object temporarily so that we can set the uniforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    j2d_glUseProgramObjectARB(lcdTextProgram);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    // set the "uniform" values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    loc = j2d_glGetUniformLocationARB(lcdTextProgram, "glyph_tex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    j2d_glUniform1iARB(loc, 0); // texture unit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    loc = j2d_glGetUniformLocationARB(lcdTextProgram, "dst_tex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    j2d_glUniform1iARB(loc, 1); // texture unit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    // "unuse" the program object; it will be re-bound later as needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    j2d_glUseProgramObjectARB(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    return lcdTextProgram;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
/**
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   337
 * (Re)Initializes the gamma related uniforms.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 * The given contrast value is an int in the range [100, 250] which we will
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   340
 * then scale to fit in the range [1.0, 2.5].
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
OGLTR_UpdateLCDTextContrast(jint contrast)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
{
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   345
    double g = ((double)contrast) / 100.0;
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   346
    double ig = 1.0 / g;
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   347
    GLint loc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    J2dTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                "OGLTR_UpdateLCDTextContrast: contrast=%d", contrast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   352
    loc = j2d_glGetUniformLocationARB(lcdTextProgram, "gamma");
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   353
    j2d_glUniform3fARB(loc, g, g, g);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
31158
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   355
    loc = j2d_glGetUniformLocationARB(lcdTextProgram, "invgamma");
062c7363dd12 8023794: [macosx] LCD Rendering hints seems not working without FRACTIONALMETRICS=ON
bae
parents: 26751
diff changeset
   356
    j2d_glUniform3fARB(loc, ig, ig, ig);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * Updates the current gamma-adjusted source color ("src_adj") of the LCD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * text shader program.  Note that we could calculate this value in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 * shader (e.g. just as we do for "dst_adj"), but would be unnecessary work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * (and a measurable performance hit, maybe around 5%) since this value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * constant over the entire glyph list.  So instead we just calculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * gamma-adjusted value once and update the uniform parameter of the LCD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * shader as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
OGLTR_UpdateLCDTextColor(jint contrast)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    double gamma = ((double)contrast) / 100.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    GLfloat radj, gadj, badj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    GLfloat clr[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    GLint loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    J2dTraceLn1(J2D_TRACE_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                "OGLTR_UpdateLCDTextColor: contrast=%d", contrast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Note: Ideally we would update the "src_adj" uniform parameter only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * when there is a change in the source color.  Fortunately, the cost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * of querying the current OpenGL color state and updating the uniform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * value is quite small, and in the common case we only need to do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * once per GlyphList, so we gain little from trying to optimize too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * eagerly here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    // get the current OpenGL primary color state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    j2d_glGetFloatv(GL_CURRENT_COLOR, clr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    // gamma adjust the primary color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    radj = (GLfloat)pow(clr[0], gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    gadj = (GLfloat)pow(clr[1], gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    badj = (GLfloat)pow(clr[2], gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    // update the "src_adj" parameter of the shader program with this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    loc = j2d_glGetUniformLocationARB(lcdTextProgram, "src_adj");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    j2d_glUniform3fARB(loc, radj, gadj, badj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 * Enables the LCD text shader and updates any related state, such as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
 * gamma lookup table textures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
static jboolean
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   410
OGLTR_EnableLCDGlyphModeState(GLuint glyphTextureID,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   411
                              GLuint dstTextureID,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   412
                              jint contrast)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    // bind the texture containing glyph data to texture unit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    j2d_glActiveTextureARB(GL_TEXTURE0_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    j2d_glBindTexture(GL_TEXTURE_2D, glyphTextureID);
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   417
    j2d_glEnable(GL_TEXTURE_2D);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // bind the texture tile containing destination data to texture unit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    j2d_glActiveTextureARB(GL_TEXTURE1_ARB);
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   421
    if (dstTextureID != 0) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   422
        j2d_glBindTexture(GL_TEXTURE_2D, dstTextureID);
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   423
    } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (cachedDestTextureID == 0) {
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   425
            cachedDestTextureID =
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   426
                OGLContext_CreateBlitTexture(GL_RGB8, GL_RGB,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   427
                                             OGLTR_CACHED_DEST_WIDTH,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   428
                                             OGLTR_CACHED_DEST_HEIGHT);
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   429
            if (cachedDestTextureID == 0) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   430
                return JNI_FALSE;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   431
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   433
        j2d_glBindTexture(GL_TEXTURE_2D, cachedDestTextureID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    // note that GL_TEXTURE_2D was already enabled for texture unit 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    // but we need to explicitly enable it for texture unit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    j2d_glEnable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // create the LCD text shader, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    if (lcdTextProgram == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        lcdTextProgram = OGLTR_CreateLCDTextProgram();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (lcdTextProgram == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // enable the LCD text shader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    j2d_glUseProgramObjectARB(lcdTextProgram);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // update the current contrast settings, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    if (lastLCDContrast != contrast) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (!OGLTR_UpdateLCDTextContrast(contrast)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        lastLCDContrast = contrast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    // update the current color settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    if (!OGLTR_UpdateLCDTextColor(contrast)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
OGLTR_EnableGlyphVertexCache(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_EnableGlyphVertexCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
12652
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 12047
diff changeset
   472
    if (!OGLVertexCache_InitVertexCache(oglc)) {
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 12047
diff changeset
   473
        return;
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 12047
diff changeset
   474
    }
6fddf8394164 7168550: [macosx] duplicate OGL context state changes related to vertex cache
dcherepanov
parents: 12047
diff changeset
   475
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   476
    if (glyphCacheAA == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (!OGLTR_InitGlyphCache(JNI_FALSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    j2d_glEnable(GL_TEXTURE_2D);
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   483
    j2d_glBindTexture(GL_TEXTURE_2D, glyphCacheAA->cacheID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    // for grayscale/monochrome text, the current OpenGL source color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // is modulated with the glyph image as part of the texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    // application stage, so we use GL_MODULATE here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
OGLTR_DisableGlyphVertexCache(OGLContext *oglc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_DisableGlyphVertexCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    OGLVertexCache_FlushVertexCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    OGLVertexCache_RestoreColorState(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    j2d_glDisable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
 * Disables any pending state associated with the current "glyph mode".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   511
OGLTR_DisableGlyphModeState(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    switch (glyphMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    case MODE_NO_CACHE_LCD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        /* FALLTHROUGH */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    case MODE_USE_CACHE_LCD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        j2d_glUseProgramObjectARB(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        j2d_glActiveTextureARB(GL_TEXTURE1_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        j2d_glDisable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        j2d_glActiveTextureARB(GL_TEXTURE0_ARB);
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   526
        j2d_glDisable(GL_TEXTURE_2D);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    case MODE_NO_CACHE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    case MODE_USE_CACHE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    case MODE_NOT_INITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
OGLTR_DrawGrayscaleGlyphViaCache(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                 GlyphInfo *ginfo, jint x, jint y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    CacheCellInfo *cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    jfloat x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    if (glyphMode != MODE_USE_CACHE_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        OGLTR_DisableGlyphModeState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        CHECK_PREVIOUS_OP(OGL_STATE_GLYPH_OP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        glyphMode = MODE_USE_CACHE_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    if (ginfo->cellInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        // attempt to add glyph to accelerated glyph cache
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   552
        OGLTR_AddToGlyphCache(ginfo, GL_LUMINANCE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (ginfo->cellInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            // we'll just no-op in the rare case that the cell is NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   560
    cell = (CacheCellInfo *) (ginfo->cellInfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    cell->timesRendered++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    x1 = (jfloat)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    y1 = (jfloat)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    x2 = x1 + ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    y2 = y1 + ginfo->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    OGLVertexCache_AddGlyphQuad(oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                cell->tx1, cell->ty1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                cell->tx2, cell->ty2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * Evaluates to true if the rectangle defined by gx1/gy1/gx2/gy2 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * inside outerBounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
#define INSIDE(gx1, gy1, gx2, gy2, outerBounds) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    (((gx1) >= outerBounds.x1) && ((gy1) >= outerBounds.y1) && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     ((gx2) <= outerBounds.x2) && ((gy2) <= outerBounds.y2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
 * Evaluates to true if the rectangle defined by gx1/gy1/gx2/gy2 intersects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
 * the rectangle defined by bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
#define INTERSECTS(gx1, gy1, gx2, gy2, bounds) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    ((bounds.x2 > (gx1)) && (bounds.y2 > (gy1)) && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     (bounds.x1 < (gx2)) && (bounds.y1 < (gy2)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
 * This method checks to see if the given LCD glyph bounds fall within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
 * cached destination texture bounds.  If so, this method can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
 * immediately.  If not, this method will copy a chunk of framebuffer data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
 * into the cached destination texture and then update the current cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
 * destination bounds before returning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
OGLTR_UpdateCachedDestination(OGLSDOps *dstOps, GlyphInfo *ginfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                              jint gx1, jint gy1, jint gx2, jint gy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                              jint glyphIndex, jint totalGlyphs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    jint dx1, dy1, dx2, dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    jint dx1adj, dy1adj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    if (isCachedDestValid && INSIDE(gx1, gy1, gx2, gy2, cachedDestBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        // glyph is already within the cached destination bounds; no need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        // to read back the entire destination region again, but we do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        // need to see if the current glyph overlaps the previous glyph...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (INTERSECTS(gx1, gy1, gx2, gy2, previousGlyphBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            // the current glyph overlaps the destination region touched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            // by the previous glyph, so now we need to read back the part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            // of the destination corresponding to the previous glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            dx1 = previousGlyphBounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            dy1 = previousGlyphBounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            dx2 = previousGlyphBounds.x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            dy2 = previousGlyphBounds.y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            // this accounts for lower-left origin of the destination region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            dx1adj = dstOps->xOffset + dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            dy1adj = dstOps->yOffset + dstOps->height - dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            // copy destination into subregion of cached texture tile:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            //   dx1-cachedDestBounds.x1 == +xoffset from left side of texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            //   cachedDestBounds.y2-dy2 == +yoffset from bottom of texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            j2d_glActiveTextureARB(GL_TEXTURE1_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                    dx1 - cachedDestBounds.x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                    cachedDestBounds.y2 - dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                    dx1adj, dy1adj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                    dx2-dx1, dy2-dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        jint remainingWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // destination region is not valid, so we need to read back a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // chunk of the destination into our cached texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        // position the upper-left corner of the destination region on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        // "top" line of glyph list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        // REMIND: this isn't ideal; it would be better if we had some idea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        //         of the bounding box of the whole glyph list (this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        //         do-able, but would require iterating through the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        //         list up front, which may present its own problems)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        dx1 = gx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        dy1 = gy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        if (ginfo->advanceX > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            // estimate the width based on our current position in the glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            // list and using the x advance of the current glyph (this is just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            // a quick and dirty heuristic; if this is a "thin" glyph image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            // then we're likely to underestimate, and if it's "thick" then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            // may end up reading back more than we need to)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            remainingWidth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                (jint)(ginfo->advanceX * (totalGlyphs - glyphIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            if (remainingWidth > OGLTR_CACHED_DEST_WIDTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                remainingWidth = OGLTR_CACHED_DEST_WIDTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            } else if (remainingWidth < ginfo->width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                // in some cases, the x-advance may be slightly smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                // than the actual width of the glyph; if so, adjust our
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 12652
diff changeset
   663
                // estimate so that we can accommodate the entire glyph
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                remainingWidth = ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            // a negative advance is possible when rendering rotated text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            // in which case it is difficult to estimate an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            // region for readback, so we will pick a region that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            // encompasses just the current glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            remainingWidth = ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        dx2 = dx1 + remainingWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // estimate the height (this is another sloppy heuristic; we'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // make the cached destination region tall enough to encompass most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // glyphs that are small enough to fit in the glyph cache, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // we add a little something extra to account for descenders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        dy2 = dy1 + OGLTR_CACHE_CELL_HEIGHT + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // this accounts for lower-left origin of the destination region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        dx1adj = dstOps->xOffset + dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        dy1adj = dstOps->yOffset + dstOps->height - dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        // copy destination into cached texture tile (the lower-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        // of the destination region will be positioned at the lower-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // corner (0,0) of the texture)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        j2d_glActiveTextureARB(GL_TEXTURE1_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                0, 0, dx1adj, dy1adj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                dx2-dx1, dy2-dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        // update the cached bounds and mark it valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        cachedDestBounds.x1 = dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        cachedDestBounds.y1 = dy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        cachedDestBounds.x2 = dx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        cachedDestBounds.y2 = dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        isCachedDestValid = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    // always update the previous glyph bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    previousGlyphBounds.x1 = gx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    previousGlyphBounds.y1 = gy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    previousGlyphBounds.x2 = gx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    previousGlyphBounds.y2 = gy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
OGLTR_DrawLCDGlyphViaCache(OGLContext *oglc, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                           GlyphInfo *ginfo, jint x, jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                           jint glyphIndex, jint totalGlyphs,
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   712
                           jboolean rgbOrder, jint contrast,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   713
                            GLuint dstTextureID)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    CacheCellInfo *cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    jint dx1, dy1, dx2, dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    jfloat dtx1, dty1, dtx2, dty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    if (glyphMode != MODE_USE_CACHE_LCD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        OGLTR_DisableGlyphModeState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        CHECK_PREVIOUS_OP(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   724
        if (glyphCacheLCD == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (!OGLTR_InitGlyphCache(JNI_TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        if (rgbOrder != lastRGBOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            // need to invalidate the cache in this case; see comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // for lastRGBOrder above
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   733
            AccelGlyphCache_Invalidate(glyphCacheLCD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            lastRGBOrder = rgbOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   737
        if (!OGLTR_EnableLCDGlyphModeState(glyphCacheLCD->cacheID,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   738
                                           dstTextureID, contrast))
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   739
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        // when a fragment shader is enabled, the texture function state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // ignored, so the following line is not needed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        // OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        glyphMode = MODE_USE_CACHE_LCD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    if (ginfo->cellInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        // rowBytes will always be a multiple of 3, so the following is safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, ginfo->rowBytes / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        // make sure the glyph cache texture is bound to texture unit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        j2d_glActiveTextureARB(GL_TEXTURE0_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        // attempt to add glyph to accelerated glyph cache
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   758
        OGLTR_AddToGlyphCache(ginfo, rgbOrder ? GL_RGB : GL_BGR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (ginfo->cellInfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            // we'll just no-op in the rare case that the cell is NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 2
diff changeset
   766
    cell = (CacheCellInfo *) (ginfo->cellInfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    cell->timesRendered++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    // location of the glyph in the destination's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    dx1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    dy1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    dx2 = dx1 + ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    dy2 = dy1 + ginfo->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   775
    if (dstTextureID == 0) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   776
        // copy destination into second cached texture, if necessary
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   777
        OGLTR_UpdateCachedDestination(dstOps, ginfo,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   778
                                      dx1, dy1, dx2, dy2,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   779
                                      glyphIndex, totalGlyphs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   781
        // texture coordinates of the destination tile
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   782
        dtx1 = ((jfloat)(dx1 - cachedDestBounds.x1)) / OGLTR_CACHED_DEST_WIDTH;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   783
        dty1 = ((jfloat)(cachedDestBounds.y2 - dy1)) / OGLTR_CACHED_DEST_HEIGHT;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   784
        dtx2 = ((jfloat)(dx2 - cachedDestBounds.x1)) / OGLTR_CACHED_DEST_WIDTH;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   785
        dty2 = ((jfloat)(cachedDestBounds.y2 - dy2)) / OGLTR_CACHED_DEST_HEIGHT;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   786
    } else {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   787
        jint gw = ginfo->width;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   788
        jint gh = ginfo->height;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   789
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   790
        // this accounts for lower-left origin of the destination region
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   791
        jint dxadj = dstOps->xOffset + x;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   792
        jint dyadj = dstOps->yOffset + dstOps->height - (y + gh);
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   793
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   794
        // update the remaining destination texture coordinates
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   795
        dtx1 =((GLfloat)dxadj) / dstOps->textureWidth;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   796
        dtx2 = ((GLfloat)dxadj + gw) / dstOps->textureWidth;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   797
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   798
        dty1 = ((GLfloat)dyadj + gh) / dstOps->textureHeight;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   799
        dty2 = ((GLfloat)dyadj) / dstOps->textureHeight;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   800
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   801
        j2d_glTextureBarrierNV();
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   802
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    // render composed texture to the destination surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    j2d_glBegin(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, cell->tx1, cell->ty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx1, dty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    j2d_glVertex2i(dx1, dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, cell->tx2, cell->ty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx2, dty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    j2d_glVertex2i(dx2, dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, cell->tx2, cell->ty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx2, dty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    j2d_glVertex2i(dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, cell->tx1, cell->ty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx1, dty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    j2d_glVertex2i(dx1, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    j2d_glEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
OGLTR_DrawGrayscaleGlyphNoCache(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                                GlyphInfo *ginfo, jint x, jint y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    jint tw, th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    jint sx, sy, sw, sh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    jint x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    jint w = ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    jint h = ginfo->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    if (glyphMode != MODE_NO_CACHE_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        OGLTR_DisableGlyphModeState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        CHECK_PREVIOUS_OP(OGL_STATE_MASK_OP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        glyphMode = MODE_NO_CACHE_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    x0 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    tw = OGLVC_MASK_CACHE_TILE_WIDTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    th = OGLVC_MASK_CACHE_TILE_HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    for (sy = 0; sy < h; sy += th, y += th) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        x = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        sh = ((sy + th) > h) ? (h - sy) : th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        for (sx = 0; sx < w; sx += tw, x += tw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            sw = ((sx + tw) > w) ? (w - sx) : tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            OGLVertexCache_AddMaskQuad(oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                       sx, sy, x, y, sw, sh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                                       w, ginfo->image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
OGLTR_DrawLCDGlyphNoCache(OGLContext *oglc, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                          GlyphInfo *ginfo, jint x, jint y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                          jint rowBytesOffset,
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   863
                          jboolean rgbOrder, jint contrast,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   864
                          GLuint dstTextureID)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    GLfloat tx1, ty1, tx2, ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    GLfloat dtx1, dty1, dtx2, dty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    jint tw, th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    jint sx, sy, sw, sh, dxadj, dyadj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    jint x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    jint w = ginfo->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    jint h = ginfo->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    GLenum pixelFormat = rgbOrder ? GL_RGB : GL_BGR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    if (glyphMode != MODE_NO_CACHE_LCD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        OGLTR_DisableGlyphModeState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        CHECK_PREVIOUS_OP(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        if (oglc->blitTextureID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (!OGLContext_InitBlitTileTexture(oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   886
        if (!OGLTR_EnableLCDGlyphModeState(oglc->blitTextureID,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   887
                                           dstTextureID, contrast))
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   888
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        // when a fragment shader is enabled, the texture function state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        // ignored, so the following line is not needed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        // OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        glyphMode = MODE_NO_CACHE_LCD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    // rowBytes will always be a multiple of 3, so the following is safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, ginfo->rowBytes / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    x0 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    tx1 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    ty1 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    dtx1 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    dty2 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    tw = OGLTR_NOCACHE_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    th = OGLTR_NOCACHE_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    for (sy = 0; sy < h; sy += th, y += th) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        x = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        sh = ((sy + th) > h) ? (h - sy) : th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        for (sx = 0; sx < w; sx += tw, x += tw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            sw = ((sx + tw) > w) ? (w - sx) : tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            // update the source pointer offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, sx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, sy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            // copy LCD mask into glyph texture tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            j2d_glActiveTextureARB(GL_TEXTURE0_ARB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                                0, 0, sw, sh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                pixelFormat, GL_UNSIGNED_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                ginfo->image + rowBytesOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            // update the lower-right glyph texture coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            tx2 = ((GLfloat)sw) / OGLC_BLIT_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            ty2 = ((GLfloat)sh) / OGLC_BLIT_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            // this accounts for lower-left origin of the destination region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            dxadj = dstOps->xOffset + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            dyadj = dstOps->yOffset + dstOps->height - (y + sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   936
            if (dstTextureID == 0) {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   937
                // copy destination into cached texture tile (the lower-left
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   938
                // corner of the destination region will be positioned at the
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   939
                // lower-left corner (0,0) of the texture)
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   940
                j2d_glActiveTextureARB(GL_TEXTURE1_ARB);
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   941
                j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   942
                                        0, 0,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   943
                                        dxadj, dyadj,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   944
                                        sw, sh);
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   945
                // update the remaining destination texture coordinates
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   946
                dtx2 = ((GLfloat)sw) / OGLTR_CACHED_DEST_WIDTH;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   947
                dty1 = ((GLfloat)sh) / OGLTR_CACHED_DEST_HEIGHT;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   948
            } else {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   949
                // use the destination texture directly
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   950
                // update the remaining destination texture coordinates
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   951
                dtx1 =((GLfloat)dxadj) / dstOps->textureWidth;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   952
                dtx2 = ((GLfloat)dxadj + sw) / dstOps->textureWidth;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   954
                dty1 = ((GLfloat)dyadj + sh) / dstOps->textureHeight;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   955
                dty2 = ((GLfloat)dyadj) / dstOps->textureHeight;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   956
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   957
                j2d_glTextureBarrierNV();
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   958
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // render composed texture to the destination surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            j2d_glBegin(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, tx1, ty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx1, dty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            j2d_glVertex2i(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, tx2, ty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx2, dty1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            j2d_glVertex2i(x + sw, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, tx2, ty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx2, dty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            j2d_glVertex2i(x + sw, y + sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            j2d_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, tx1, ty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            j2d_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, dtx1, dty2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            j2d_glVertex2i(x, y + sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            j2d_glEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
// see DrawGlyphList.c for more on this macro...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
#define FLOOR_ASSIGN(l, r) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    if ((r)<0) (l) = ((int)floor(r)); else (l) = ((int)(r))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
OGLTR_DrawGlyphList(JNIEnv *env, OGLContext *oglc, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    jint totalGlyphs, jboolean usePositions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    jfloat glyphListOrigX, jfloat glyphListOrigY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    unsigned char *images, unsigned char *positions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    int glyphCounter;
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
   993
    GLuint dstTextureID = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_DrawGlyphList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    RETURN_IF_NULL(images);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    if (usePositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        RETURN_IF_NULL(positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    glyphMode = MODE_NOT_INITED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    isCachedDestValid = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1007
    // We have to obtain an information about destination content
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1008
    // in order to render lcd glyphs. It could be done by copying
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1009
    // a part of desitination buffer into an intermediate texture
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1010
    // using glCopyTexSubImage2D(). However, on macosx this path is
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1011
    // slow, and it dramatically reduces the overall speed of lcd
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1012
    // text rendering.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1013
    //
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1014
    // In some cases, we can use a texture from the destination
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1015
    // surface data in oredr to avoid this slow reading routine.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1016
    // It requires:
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1017
    //  * An appropriate textureTarget for the destination SD.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1018
    //    In particular, we need GL_TEXTURE_2D
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1019
    //  * Means to prevent read-after-write problem.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1020
    //    At the moment, a GL_NV_texture_barrier extension is used
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1021
    //    to achieve this.
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1022
    if (OGLC_IS_CAP_PRESENT(oglc, CAPS_EXT_TEXBARRIER) &&
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1023
        dstOps->textureTarget == GL_TEXTURE_2D)
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1024
    {
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1025
        dstTextureID = dstOps->textureID;
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1026
    }
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1027
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        jint x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        jfloat glyphx, glyphy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        jboolean grayscale, ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        GlyphInfo *ginfo = (GlyphInfo *)jlong_to_ptr(NEXT_LONG(images));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        if (ginfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            // this shouldn't happen, but if it does we'll just break out...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                          "OGLTR_DrawGlyphList: glyph info is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        grayscale = (ginfo->rowBytes == ginfo->width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        if (usePositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            jfloat posx = NEXT_FLOAT(positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            jfloat posy = NEXT_FLOAT(positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            glyphx = glyphListOrigX + posx + ginfo->topLeftX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            glyphy = glyphListOrigY + posy + ginfo->topLeftY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            FLOOR_ASSIGN(x, glyphx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            FLOOR_ASSIGN(y, glyphy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            glyphx = glyphListOrigX + ginfo->topLeftX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            glyphy = glyphListOrigY + ginfo->topLeftY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            FLOOR_ASSIGN(x, glyphx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            FLOOR_ASSIGN(y, glyphy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            glyphListOrigX += ginfo->advanceX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            glyphListOrigY += ginfo->advanceY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        if (ginfo->image == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        if (grayscale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            // grayscale or monochrome glyph data
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1065
            if (ginfo->width <= OGLTR_CACHE_CELL_WIDTH &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                ginfo->height <= OGLTR_CACHE_CELL_HEIGHT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                ok = OGLTR_DrawGrayscaleGlyphViaCache(oglc, ginfo, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                ok = OGLTR_DrawGrayscaleGlyphNoCache(oglc, ginfo, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            // LCD-optimized glyph data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            jint rowBytesOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            if (subPixPos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                jint frac = (jint)((glyphx - x) * 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                if (frac != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    rowBytesOffset = 3 - frac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    x += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            if (rowBytesOffset == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                ginfo->width <= OGLTR_CACHE_CELL_WIDTH &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                ginfo->height <= OGLTR_CACHE_CELL_HEIGHT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                ok = OGLTR_DrawLCDGlyphViaCache(oglc, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                                                ginfo, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                                glyphCounter, totalGlyphs,
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1091
                                                rgbOrder, lcdContrast,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1092
                                                dstTextureID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                ok = OGLTR_DrawLCDGlyphNoCache(oglc, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                                               ginfo, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                                               rowBytesOffset,
31882
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1097
                                               rgbOrder, lcdContrast,
0268245131a9 8087201: OGL: rendering of lcd text is slow
bae
parents: 31171
diff changeset
  1098
                                               dstTextureID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        if (!ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    OGLTR_DisableGlyphModeState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
Java_sun_java2d_opengl_OGLTextRenderer_drawGlyphList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    (JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     jint numGlyphs, jboolean usePositions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     jfloat glyphListOrigX, jfloat glyphListOrigY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     jlongArray imgArray, jfloatArray posArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    unsigned char *images;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    J2dTraceLn(J2D_TRACE_INFO, "OGLTextRenderer_drawGlyphList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    images = (unsigned char *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        (*env)->GetPrimitiveArrayCritical(env, imgArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    if (images != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        OGLContext *oglc = OGLRenderQueue_GetCurrentContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        OGLSDOps *dstOps = OGLRenderQueue_GetCurrentDestination();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        if (usePositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            unsigned char *positions = (unsigned char *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            if (positions != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                OGLTR_DrawGlyphList(env, oglc, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                                    numGlyphs, usePositions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                                    subPixPos, rgbOrder, lcdContrast,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                                    glyphListOrigX, glyphListOrigY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                                    images, positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                (*env)->ReleasePrimitiveArrayCritical(env, posArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                                                      positions, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            OGLTR_DrawGlyphList(env, oglc, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                numGlyphs, usePositions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                                subPixPos, rgbOrder, lcdContrast,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                                glyphListOrigX, glyphListOrigY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                                images, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        // 6358147: reset current state, and ensure rendering is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // flushed to dest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        if (oglc != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            j2d_glFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        (*env)->ReleasePrimitiveArrayCritical(env, imgArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                              images, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
#endif /* !HEADLESS */