Path: blob/master/src/java.desktop/share/native/common/java2d/opengl/OGLContext.h
41159 views
/*1* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef OGLContext_h_Included26#define OGLContext_h_Included2728#include "sun_java2d_pipe_BufferedContext.h"29#include "sun_java2d_opengl_OGLContext.h"30#include "sun_java2d_opengl_OGLContext_OGLContextCaps.h"3132#include "j2d_md.h"33#include "J2D_GL/gl.h"34#include "OGLSurfaceData.h"3536/**37* The OGLBlendRule structure encapsulates the two enumerated values that38* comprise a given Porter-Duff blending (compositing) rule. For example,39* the "SrcOver" rule can be represented by:40* rule.src = GL_ONE;41* rule.dst = GL_ONE_MINUS_SRC_ALPHA;42*43* GLenum src;44* The constant representing the source factor in this Porter-Duff rule.45*46* GLenum dst;47* The constant representing the destination factor in this Porter-Duff rule.48*/49typedef struct {50GLenum src;51GLenum dst;52} OGLBlendRule;5354/**55* The OGLContext structure contains cached state relevant to the native56* OpenGL context stored within the native ctxInfo field. Each Java-level57* OGLContext object is associated with a native-level OGLContext structure.58* The caps field is a bitfield that expresses the capabilities of the59* GraphicsConfig associated with this context (see OGLContext.java for60* the definitions of each capability bit). The other fields are61* simply cached values of various elements of the context state, typically62* used in the OGLContext.set*() methods.63*64* Note that the textureFunction field is implicitly set to zero when the65* OGLContext is created. The acceptable values (e.g. GL_MODULATE,66* GL_REPLACE) for this field are never zero, which means we will always67* validate the texture function state upon the first call to the68* OGLC_UPDATE_TEXTURE_FUNCTION() macro.69*/70typedef struct {71void *ctxInfo;72jint caps;73jint compState;74jfloat extraAlpha;75jint xorPixel;76jint pixel;77jubyte r;78jubyte g;79jubyte b;80jubyte a;81jint paintState;82jboolean useMask;83GLdouble *xformMatrix;84GLuint blitTextureID;85GLint textureFunction;86jboolean vertexCacheEnabled;87} OGLContext;8889/**90* See BufferedContext.java for more on these flags...91*/92#define OGLC_NO_CONTEXT_FLAGS \93sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS94#define OGLC_SRC_IS_OPAQUE \95sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE96#define OGLC_USE_MASK \97sun_java2d_pipe_BufferedContext_USE_MASK9899/**100* See OGLContext.java for more on these flags.101*/102#define CAPS_EMPTY \103sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EMPTY104#define CAPS_RT_PLAIN_ALPHA \105sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_PLAIN_ALPHA106#define CAPS_RT_TEXTURE_ALPHA \107sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_TEXTURE_ALPHA108#define CAPS_RT_TEXTURE_OPAQUE \109sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_RT_TEXTURE_OPAQUE110#define CAPS_MULTITEXTURE \111sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_MULTITEXTURE112#define CAPS_TEXNONPOW2 \113sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_TEXNONPOW2114#define CAPS_TEXNONSQUARE \115sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_TEXNONSQUARE116#define CAPS_PS20 \117sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_PS20118#define CAPS_PS30 \119sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_PS30120#define LAST_SHARED_CAP \121sun_java2d_opengl_OGLContext_OGLContextCaps_LAST_SHARED_CAP122#define CAPS_EXT_FBOBJECT \123sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_FBOBJECT124#define CAPS_DOUBLEBUFFERED \125sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_DOUBLEBUFFERED126#define CAPS_EXT_LCD_SHADER \127sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_LCD_SHADER128#define CAPS_EXT_BIOP_SHADER \129sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_BIOP_SHADER130#define CAPS_EXT_GRAD_SHADER \131sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_GRAD_SHADER132#define CAPS_EXT_TEXRECT \133sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_TEXRECT134#define CAPS_EXT_TEXBARRIER \135sun_java2d_opengl_OGLContext_OGLContextCaps_CAPS_EXT_TEXBARRIER136137/**138* Evaluates to true if the given capability bitmask is present for the139* given OGLContext. Note that only the constant name needs to be passed as140* a parameter, as this macro will automatically prepend the full package141* and class name to the constant name.142*/143#define OGLC_IS_CAP_PRESENT(oglc, cap) (((oglc)->caps & (cap)) != 0)144145/**146* At startup we will embed one of the following values in the caps field147* of OGLContext. Later we can use this information to select148* the codepath that offers the best performance for that vendor's149* hardware and/or drivers.150*/151#define OGLC_VENDOR_OTHER 0152#define OGLC_VENDOR_ATI 1153#define OGLC_VENDOR_NVIDIA 2154#define OGLC_VENDOR_INTEL 3155156#define OGLC_VCAP_MASK 0x3157#define OGLC_VCAP_OFFSET 24158159#define OGLC_GET_VENDOR(oglc) \160(((oglc)->caps >> OGLC_VCAP_OFFSET) & OGLC_VCAP_MASK)161162/**163* This constant determines the size of the shared tile texture used164* by a number of image rendering methods. For example, the blit tile texture165* will have dimensions with width OGLC_BLIT_TILE_SIZE and height166* OGLC_BLIT_TILE_SIZE (the tile will always be square).167*/168#define OGLC_BLIT_TILE_SIZE 128169170/**171* Helper macros that update the current texture function state only when172* it needs to be changed, which helps reduce overhead for small texturing173* operations. The filter state is set on a per-context (not per-texture)174* basis; for example, if we apply one texture using GL_MODULATE followed by175* another texture using GL_MODULATE (under the same context), there is no176* need to set the texture function the second time, as that would be177* redundant.178*/179#define OGLC_INIT_TEXTURE_FUNCTION(oglc, func) \180do { \181j2d_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, (func)); \182(oglc)->textureFunction = (func); \183} while (0)184185#define OGLC_UPDATE_TEXTURE_FUNCTION(oglc, func) \186do { \187if ((oglc)->textureFunction != (func)) { \188OGLC_INIT_TEXTURE_FUNCTION(oglc, func); \189} \190} while (0)191192/**193* Exported methods.194*/195OGLContext *OGLContext_SetSurfaces(JNIEnv *env, jlong pSrc, jlong pDst);196void OGLContext_ResetClip(OGLContext *oglc);197void OGLContext_SetRectClip(OGLContext *oglc, OGLSDOps *dstOps,198jint x1, jint y1, jint x2, jint y2);199void OGLContext_BeginShapeClip(OGLContext *oglc);200void OGLContext_EndShapeClip(OGLContext *oglc, OGLSDOps *dstOps);201void OGLContext_SetExtraAlpha(jfloat ea);202void OGLContext_ResetComposite(OGLContext *oglc);203void OGLContext_SetAlphaComposite(OGLContext *oglc,204jint rule, jfloat extraAlpha, jint flags);205void OGLContext_SetXorComposite(OGLContext *oglc, jint xorPixel);206void OGLContext_ResetTransform(OGLContext *oglc);207void OGLContext_SetTransform(OGLContext *oglc,208jdouble m00, jdouble m10,209jdouble m01, jdouble m11,210jdouble m02, jdouble m12);211212jboolean OGLContext_InitBlitTileTexture(OGLContext *oglc);213GLuint OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat,214GLuint width, GLuint height);215216void OGLContext_DestroyContextResources(OGLContext *oglc);217218jboolean OGLContext_IsExtensionAvailable(const char *extString, char *extName);219void OGLContext_GetExtensionInfo(JNIEnv *env, jint *caps);220jboolean OGLContext_IsVersionSupported(const unsigned char *versionstr);221222GLhandleARB OGLContext_CreateFragmentProgram(const char *fragmentShaderSource);223224#endif /* OGLContext_h_Included */225226227