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