annotate src/share/native/sun/java2d/opengl/OGLContext.h @ 11015:5b49ef2244cf

8087201: OGL: rendering of lcd text is slow Reviewed-by: serb, prr
author bae
date Thu, 09 Jul 2015 18:28:54 +0300
parents 7c7758fec30c
children
rev   line source
duke@0 1 /*
lana@9000 2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 #ifndef OGLContext_h_Included
duke@0 27 #define OGLContext_h_Included
duke@0 28
duke@0 29 #include "sun_java2d_pipe_BufferedContext.h"
duke@0 30 #include "sun_java2d_opengl_OGLContext.h"
tdv@430 31 #include "sun_java2d_opengl_OGLContext_OGLContextCaps.h"
duke@0 32
duke@0 33 #include "j2d_md.h"
duke@0 34 #include "J2D_GL/gl.h"
duke@0 35 #include "OGLSurfaceData.h"
duke@0 36
duke@0 37 /**
duke@0 38 * The OGLBlendRule structure encapsulates the two enumerated values that
duke@0 39 * comprise a given Porter-Duff blending (compositing) rule. For example,
duke@0 40 * the "SrcOver" rule can be represented by:
duke@0 41 * rule.src = GL_ONE;
duke@0 42 * rule.dst = GL_ONE_MINUS_SRC_ALPHA;
duke@0 43 *
duke@0 44 * GLenum src;
duke@0 45 * The constant representing the source factor in this Porter-Duff rule.
duke@0 46 *
duke@0 47 * GLenum dst;
duke@0 48 * The constant representing the destination factor in this Porter-Duff rule.
duke@0 49 */
duke@0 50 typedef struct {
duke@0 51 GLenum src;
duke@0 52 GLenum dst;
duke@0 53 } OGLBlendRule;
duke@0 54
duke@0 55 /**
duke@0 56 * The OGLContext structure contains cached state relevant to the native
duke@0 57 * OpenGL context stored within the native ctxInfo field. Each Java-level
duke@0 58 * OGLContext object is associated with a native-level OGLContext structure.
duke@0 59 * The caps field is a bitfield that expresses the capabilities of the
duke@0 60 * GraphicsConfig associated with this context (see OGLContext.java for
duke@0 61 * the definitions of each capability bit). The other fields are
duke@0 62 * simply cached values of various elements of the context state, typically
duke@0 63 * used in the OGLContext.set*() methods.
duke@0 64 *
duke@0 65 * Note that the textureFunction field is implicitly set to zero when the
duke@0 66 * OGLContext is created. The acceptable values (e.g. GL_MODULATE,
duke@0 67 * GL_REPLACE) for this field are never zero, which means we will always
duke@0 68 * validate the texture function state upon the first call to the
duke@0 69 * OGLC_UPDATE_TEXTURE_FUNCTION() macro.
duke@0 70 */
duke@0 71 typedef struct {
duke@0 72 void *ctxInfo;
duke@0 73 jint caps;
duke@0 74 jint compState;
duke@0 75 jfloat extraAlpha;
duke@0 76 jint xorPixel;
duke@0 77 jint pixel;
duke@0 78 jubyte r;
duke@0 79 jubyte g;
duke@0 80 jubyte b;
duke@0 81 jubyte a;
duke@0 82 jint paintState;
duke@0 83 jboolean useMask;
duke@0 84 GLdouble *xformMatrix;
duke@0 85 GLuint blitTextureID;
duke@0 86 GLint textureFunction;
dcherepanov@5363 87 jboolean vertexCacheEnabled;
duke@0 88 } OGLContext;
duke@0 89
duke@0 90 /**
duke@0 91 * See BufferedContext.java for more on these flags...
duke@0 92 */
duke@0 93 #define OGLC_NO_CONTEXT_FLAGS \
duke@0 94 sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS
duke@0 95 #define OGLC_SRC_IS_OPAQUE \
duke@0 96 sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE
duke@0 97 #define OGLC_USE_MASK \
duke@0 98 sun_java2d_pipe_BufferedContext_USE_MASK
duke@0 99
duke@0 100 /**
tdv@430 101 * See OGLContext.java for more on these flags.
tdv@430 102 */
tdv@430 103 #define CAPS_EMPTY \
tdv@430 104 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EMPTY
tdv@430 105 #define CAPS_RT_PLAIN_ALPHA \
tdv@430 106 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_PLAIN_ALPHA
tdv@430 107 #define CAPS_RT_TEXTURE_ALPHA \
tdv@430 108 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_TEXTURE_ALPHA
tdv@430 109 #define CAPS_RT_TEXTURE_OPAQUE \
tdv@430 110 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_TEXTURE_OPAQUE
tdv@430 111 #define CAPS_MULTITEXTURE \
tdv@430 112 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_MULTITEXTURE
tdv@430 113 #define CAPS_TEXNONPOW2 \
tdv@430 114 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_TEXNONPOW2
tdv@430 115 #define CAPS_TEXNONSQUARE \
tdv@430 116 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_TEXNONSQUARE
tdv@430 117 #define CAPS_PS20 \
tdv@430 118 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_PS20
tdv@430 119 #define CAPS_PS30 \
tdv@430 120 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_PS30
tdv@430 121 #define LAST_SHARED_CAP \
tdv@430 122 sun_java2d_opengl_OGLContext_OGLContextCaps_LAST_SHARED_CAP
tdv@430 123 #define CAPS_EXT_FBOBJECT \
tdv@430 124 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_FBOBJECT
tdv@430 125 #define CAPS_STORED_ALPHA \
tdv@430 126 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_STORED_ALPHA
tdv@430 127 #define CAPS_DOUBLEBUFFERED \
tdv@430 128 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_DOUBLEBUFFERED
tdv@430 129 #define CAPS_EXT_LCD_SHADER \
tdv@430 130 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_LCD_SHADER
tdv@430 131 #define CAPS_EXT_BIOP_SHADER \
tdv@430 132 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_BIOP_SHADER
tdv@430 133 #define CAPS_EXT_GRAD_SHADER \
tdv@430 134 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_GRAD_SHADER
tdv@430 135 #define CAPS_EXT_TEXRECT \
tdv@430 136 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_TEXRECT
bae@11015 137 #define CAPS_EXT_TEXBARRIER \
bae@11015 138 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_TEXBARRIER
tdv@430 139
tdv@430 140 /**
duke@0 141 * Evaluates to true if the given capability bitmask is present for the
duke@0 142 * given OGLContext. Note that only the constant name needs to be passed as
duke@0 143 * a parameter, as this macro will automatically prepend the full package
duke@0 144 * and class name to the constant name.
duke@0 145 */
tdv@430 146 #define OGLC_IS_CAP_PRESENT(oglc, cap) (((oglc)->caps & (cap)) != 0)
duke@0 147
duke@0 148 /**
duke@0 149 * At startup we will embed one of the following values in the caps field
duke@0 150 * of OGLContext. Later we can use this information to select
duke@0 151 * the codepath that offers the best performance for that vendor's
duke@0 152 * hardware and/or drivers.
duke@0 153 */
duke@0 154 #define OGLC_VENDOR_OTHER 0
duke@0 155 #define OGLC_VENDOR_ATI 1
duke@0 156 #define OGLC_VENDOR_NVIDIA 2
serb@10382 157 #define OGLC_VENDOR_INTEL 3
duke@0 158
duke@0 159 #define OGLC_VCAP_MASK 0x3
duke@0 160 #define OGLC_VCAP_OFFSET 24
duke@0 161
duke@0 162 #define OGLC_GET_VENDOR(oglc) \
duke@0 163 (((oglc)->caps >> OGLC_VCAP_OFFSET) & OGLC_VCAP_MASK)
duke@0 164
duke@0 165 /**
duke@0 166 * This constant determines the size of the shared tile texture used
duke@0 167 * by a number of image rendering methods. For example, the blit tile texture
duke@0 168 * will have dimensions with width OGLC_BLIT_TILE_SIZE and height
duke@0 169 * OGLC_BLIT_TILE_SIZE (the tile will always be square).
duke@0 170 */
duke@0 171 #define OGLC_BLIT_TILE_SIZE 128
duke@0 172
duke@0 173 /**
duke@0 174 * Helper macros that update the current texture function state only when
duke@0 175 * it needs to be changed, which helps reduce overhead for small texturing
duke@0 176 * operations. The filter state is set on a per-context (not per-texture)
duke@0 177 * basis; for example, if we apply one texture using GL_MODULATE followed by
duke@0 178 * another texture using GL_MODULATE (under the same context), there is no
duke@0 179 * need to set the texture function the second time, as that would be
duke@0 180 * redundant.
duke@0 181 */
duke@0 182 #define OGLC_INIT_TEXTURE_FUNCTION(oglc, func) \
duke@0 183 do { \
duke@0 184 j2d_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, (func)); \
duke@0 185 (oglc)->textureFunction = (func); \
duke@0 186 } while (0)
duke@0 187
duke@0 188 #define OGLC_UPDATE_TEXTURE_FUNCTION(oglc, func) \
duke@0 189 do { \
duke@0 190 if ((oglc)->textureFunction != (func)) { \
duke@0 191 OGLC_INIT_TEXTURE_FUNCTION(oglc, func); \
duke@0 192 } \
duke@0 193 } while (0)
duke@0 194
duke@0 195 /**
duke@0 196 * Exported methods.
duke@0 197 */
duke@0 198 OGLContext *OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst);
duke@0 199 void OGLContext_ResetClip(OGLContext *oglc);
duke@0 200 void OGLContext_SetRectClip(OGLContext *oglc, OGLSDOps *dstOps,
duke@0 201 jint x1, jint y1, jint x2, jint y2);
duke@0 202 void OGLContext_BeginShapeClip(OGLContext *oglc);
duke@0 203 void OGLContext_EndShapeClip(OGLContext *oglc, OGLSDOps *dstOps);
duke@0 204 void OGLContext_SetExtraAlpha(jfloat ea);
duke@0 205 void OGLContext_ResetComposite(OGLContext *oglc);
duke@0 206 void OGLContext_SetAlphaComposite(OGLContext *oglc,
duke@0 207 jint rule, jfloat extraAlpha, jint flags);
duke@0 208 void OGLContext_SetXorComposite(OGLContext *oglc, jint xorPixel);
duke@0 209 void OGLContext_ResetTransform(OGLContext *oglc);
duke@0 210 void OGLContext_SetTransform(OGLContext *oglc,
duke@0 211 jdouble m00, jdouble m10,
duke@0 212 jdouble m01, jdouble m11,
duke@0 213 jdouble m02, jdouble m12);
duke@0 214
duke@0 215 jboolean OGLContext_InitBlitTileTexture(OGLContext *oglc);
duke@0 216 GLuint OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat,
duke@0 217 GLuint width, GLuint height);
duke@0 218
duke@0 219 void OGLContext_DestroyContextResources(OGLContext *oglc);
duke@0 220
duke@0 221 jboolean OGLContext_IsExtensionAvailable(const char *extString, char *extName);
duke@0 222 void OGLContext_GetExtensionInfo(JNIEnv *env, jint *caps);
duke@0 223 jboolean OGLContext_IsVersionSupported(const unsigned char *versionstr);
duke@0 224
duke@0 225 GLhandleARB OGLContext_CreateFragmentProgram(const char *fragmentShaderSource);
duke@0 226
duke@0 227 #endif /* OGLContext_h_Included */