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