1 /*
2 * Copyright (c) 2004, 2015, 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_DOUBLEBUFFERED \
126 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_DOUBLEBUFFERED
127 #define CAPS_EXT_LCD_SHADER \
128 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_LCD_SHADER
129 #define CAPS_EXT_BIOP_SHADER \
130 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_BIOP_SHADER
131 #define CAPS_EXT_GRAD_SHADER \
132 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_GRAD_SHADER
133 #define CAPS_EXT_TEXRECT \
134 sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_TEXRECT
135
136 /**
137 * Evaluates to true if the given capability bitmask is present for the
138 * given OGLContext. Note that only the constant name needs to be passed as
139 * a parameter, as this macro will automatically prepend the full package
140 * and class name to the constant name.
141 */
142 #define OGLC_IS_CAP_PRESENT(oglc, cap) (((oglc)->caps & (cap)) != 0)
143
144 /**
145 * At startup we will embed one of the following values in the caps field
146 * of OGLContext. Later we can use this information to select
147 * the codepath that offers the best performance for that vendor's
148 * hardware and/or drivers.
149 */
150 #define OGLC_VENDOR_OTHER 0
151 #define OGLC_VENDOR_ATI 1
152 #define OGLC_VENDOR_NVIDIA 2
153 #define OGLC_VENDOR_INTEL 3
154
155 #define OGLC_VCAP_MASK 0x3
156 #define OGLC_VCAP_OFFSET 24
157
158 #define OGLC_GET_VENDOR(oglc) \
159 (((oglc)->caps >> OGLC_VCAP_OFFSET) & OGLC_VCAP_MASK)
160
161 /**
162 * This constant determines the size of the shared tile texture used
163 * by a number of image rendering methods. For example, the blit tile texture
164 * will have dimensions with width OGLC_BLIT_TILE_SIZE and height
165 * OGLC_BLIT_TILE_SIZE (the tile will always be square).
166 */
167 #define OGLC_BLIT_TILE_SIZE 128
168
169 /**
170 * Helper macros that update the current texture function state only when
171 * it needs to be changed, which helps reduce overhead for small texturing
172 * operations. The filter state is set on a per-context (not per-texture)
173 * basis; for example, if we apply one texture using GL_MODULATE followed by
174 * another texture using GL_MODULATE (under the same context), there is no
175 * need to set the texture function the second time, as that would be
176 * redundant.
177 */
178 #define OGLC_INIT_TEXTURE_FUNCTION(oglc, func) \
179 do { \
180 j2d_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, (func)); \
181 (oglc)->textureFunction = (func); \
182 } while (0)
183
184 #define OGLC_UPDATE_TEXTURE_FUNCTION(oglc, func) \
185 do { \
186 if ((oglc)->textureFunction != (func)) { \
187 OGLC_INIT_TEXTURE_FUNCTION(oglc, func); \
188 } \
189 } while (0)
190
191 /**
192 * Exported methods.
193 */
194 OGLContext *OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst);
195 void OGLContext_ResetClip(OGLContext *oglc);
196 void OGLContext_SetRectClip(OGLContext *oglc, OGLSDOps *dstOps,
197 jint x1, jint y1, jint x2, jint y2);
198 void OGLContext_BeginShapeClip(OGLContext *oglc);
199 void OGLContext_EndShapeClip(OGLContext *oglc, OGLSDOps *dstOps);
200 void OGLContext_SetExtraAlpha(jfloat ea);
201 void OGLContext_ResetComposite(OGLContext *oglc);
202 void OGLContext_SetAlphaComposite(OGLContext *oglc,
203 jint rule, jfloat extraAlpha, jint flags);
204 void OGLContext_SetXorComposite(OGLContext *oglc, jint xorPixel);
205 void OGLContext_ResetTransform(OGLContext *oglc);
206 void OGLContext_SetTransform(OGLContext *oglc,
207 jdouble m00, jdouble m10,
208 jdouble m01, jdouble m11,
209 jdouble m02, jdouble m12);
210
211 jboolean OGLContext_InitBlitTileTexture(OGLContext *oglc);
212 GLuint OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat,
213 GLuint width, GLuint height);
214
215 void OGLContext_DestroyContextResources(OGLContext *oglc);
216
217 jboolean OGLContext_IsExtensionAvailable(const char *extString, char *extName);
218 void OGLContext_GetExtensionInfo(JNIEnv *env, jint *caps);
219 jboolean OGLContext_IsVersionSupported(const unsigned char *versionstr);
220
221 GLhandleARB OGLContext_CreateFragmentProgram(const char *fragmentShaderSource);
222
223 #endif /* OGLContext_h_Included */
--- EOF ---