Path: blob/master/src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.h
41159 views
/*1* Copyright (c) 2003, 2019, 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 OGLSurfaceData_h_Included26#define OGLSurfaceData_h_Included2728#include "java_awt_image_AffineTransformOp.h"29#include "sun_java2d_opengl_OGLSurfaceData.h"30#include "sun_java2d_pipe_hw_AccelSurface.h"3132#include "J2D_GL/gl.h"33#include "SurfaceData.h"34#include "Trace.h"35#include "OGLFuncs.h"3637typedef struct _OGLSDOps OGLSDOps;3839/**40* The OGLPixelFormat structure contains all the information OpenGL needs to41* know when copying from or into a particular system memory image buffer (via42* glDrawPixels(), glReadPixels, glTexSubImage2D(), etc).43*44* GLenum format;45* The pixel format parameter used in glDrawPixels() and other similar calls.46* Indicates the component ordering for each pixel (e.g. GL_BGRA).47*48* GLenum type;49* The pixel data type parameter used in glDrawPixels() and other similar50* calls. Indicates the data type for an entire pixel or for each component51* in a pixel (e.g. GL_UNSIGNED_BYTE with GL_BGR means a pixel consists of52* 3 unsigned byte components, blue first, then green, then red;53* GL_UNSIGNED_INT_8_8_8_8_REV with GL_BGRA means a pixel consists of 154* unsigned integer comprised of four byte components, alpha first, then red,55* then green, then blue).56*57* jint alignment;58* The byte alignment parameter used in glPixelStorei(GL_UNPACK_ALIGNMENT). A59* value of 4 indicates that each pixel starts on a 4-byte aligned region in60* memory, and so on. This alignment parameter helps OpenGL speed up pixel61* transfer operations by transferring memory in aligned blocks.62*63* jboolean hasAlpha;64* If true, indicates that this pixel format contains an alpha component.65*66* jboolean isPremult;67* If true, indicates that this pixel format contains color components that68* have been pre-multiplied by their corresponding alpha component.69*/70typedef struct {71GLenum format;72GLenum type;73jint alignment;74jboolean hasAlpha;75jboolean isPremult;76} OGLPixelFormat;7778/**79* The OGLSDOps structure describes a native OpenGL surface and contains all80* information pertaining to the native surface. Some information about81* the more important/different fields:82*83* void *privOps;84* Pointer to native-specific (GLX, WGL, etc.) SurfaceData info, such as the85* native Drawable handle and GraphicsConfig data.86*87* jobject graphicsConfig;;88* Strong reference to the OGLGraphicsConfig used by this OGLSurfaceData.89*90* jint drawableType;91* The surface type; can be any one of the surface type constants defined92* below (OGLSD_WINDOW, OGLSD_TEXTURE, etc).93*94* GLenum activeBuffer;95* Can be either GL_FRONT if this is the front buffer surface of an onscreen96* window or a pbuffer surface, or GL_BACK if this is the backbuffer surface97* of an onscreen window.98*99* jboolean isOpaque;100* If true, the surface should be treated as being fully opaque. If101* the underlying surface (e.g. pbuffer) has an alpha channel and isOpaque102* is true, then we should take appropriate action (i.e. call glColorMask()103* to disable writes into the alpha channel) to ensure that the surface104* remains fully opaque.105*106* jboolean needsInit;107* If true, the surface requires some one-time initialization, which should108* be performed after a context has been made current to the surface for109* the first time.110*111* jint x/yOffset112* The offset in pixels of the OpenGL viewport origin from the lower-left113* corner of the heavyweight drawable. For example, a top-level frame on114* Windows XP has lower-left insets of (4,4). The OpenGL viewport origin115* would typically begin at the lower-left corner of the client region (inside116* the frame decorations), but AWT/Swing will take the insets into account117* when rendering into that window. So in order to account for this, we118* need to adjust the OpenGL viewport origin by an x/yOffset of (-4,-4). On119* X11, top-level frames typically don't have this insets issue, so their120* x/yOffset would be (0,0) (the same applies to pbuffers).121*122* jint width/height;123* The cached surface bounds. For offscreen surface types (OGLSD_FBOBJECT,124* OGLSD_TEXTURE, etc.) these values must remain constant. Onscreen window125* surfaces (OGLSD_WINDOW, OGLSD_FLIP_BACKBUFFER, etc.) may have their126* bounds changed in response to a programmatic or user-initiated event, so127* these values represent the last known dimensions. To determine the true128* current bounds of this surface, query the native Drawable through the129* privOps field.130*131* GLuint textureID;132* The texture object handle, as generated by glGenTextures(). If this value133* is zero, the texture has not yet been initialized.134*135* jint textureWidth/Height;136* The actual bounds of the texture object for this surface. If the137* GL_ARB_texture_non_power_of_two extension is not present, the dimensions138* of an OpenGL texture object must be a power-of-two (e.g. 64x32 or 128x512).139* The texture image that we care about has dimensions specified by the width140* and height fields in this OGLSDOps structure. For example, if the image141* to be stored in the texture has dimensions 115x47, the actual OpenGL142* texture we allocate will have dimensions 128x64 to meet the pow2143* restriction. The image bounds within the texture can be accessed using144* floating point texture coordinates in the range [0.0,1.0].145*146* GLenum textureTarget;147* The texture target of the texture object for this surface. If this148* surface is not backed by a texture, this value is set to zero. Otherwise,149* this value is GL_TEXTURE_RECTANGLE_ARB when the GL_ARB_texture_rectangle150* extension is in use; if not, it is set to GL_TEXTURE_2D.151*152* GLint textureFilter;153* The current filter state for this texture object (can be either GL_NEAREST154* or GL_LINEAR). We cache this value here and check it before updating155* the filter state to avoid redundant calls to glTexParameteri() when the156* filter state remains constant (see the OGLSD_UPDATE_TEXTURE_FILTER()157* macro below).158*159* GLuint fbobjectID, depthID;160* The object handles for the framebuffer object and depth renderbuffer161* associated with this surface. These fields are only used when162* drawableType is OGLSD_FBOBJECT, otherwise they are zero.163*/164struct _OGLSDOps {165SurfaceDataOps sdOps;166void *privOps;167jobject graphicsConfig;168jint drawableType;169GLenum activeBuffer;170jboolean isOpaque;171jboolean needsInit;172jint xOffset;173jint yOffset;174jint width;175jint height;176GLuint textureID;177jint textureWidth;178jint textureHeight;179GLenum textureTarget;180GLint textureFilter;181GLuint fbobjectID;182GLuint depthID;183};184185/**186* The following convenience macros are used when rendering rectangles (either187* a single rectangle, or a whole series of them). To render a single188* rectangle, simply invoke the GLRECT() macro. To render a whole series of189* rectangles, such as spans in a complex shape, first invoke GLRECT_BEGIN(),190* then invoke the appropriate inner loop macro (either XYXY or XYWH) for191* each rectangle, and finally invoke GLRECT_END() to notify OpenGL that the192* vertex list is complete. Care should be taken to avoid calling OpenGL193* commands (besides GLRECT_BODY_*()) inside the BEGIN/END pair.194*/195196#define GLRECT_BEGIN j2d_glBegin(GL_QUADS)197198#define GLRECT_BODY_XYXY(x1, y1, x2, y2) \199do { \200j2d_glVertex2i(x1, y1); \201j2d_glVertex2i(x2, y1); \202j2d_glVertex2i(x2, y2); \203j2d_glVertex2i(x1, y2); \204} while (0)205206#define GLRECT_BODY_XYWH(x, y, w, h) \207GLRECT_BODY_XYXY(x, y, (x) + (w), (y) + (h))208209#define GLRECT_END j2d_glEnd()210211#define GLRECT(x, y, w, h) \212do { \213GLRECT_BEGIN; \214GLRECT_BODY_XYWH(x, y, w, h); \215GLRECT_END; \216} while (0)217218/**219* These are shorthand names for the surface type constants defined in220* OGLSurfaceData.java.221*/222#define OGLSD_UNDEFINED sun_java2d_pipe_hw_AccelSurface_UNDEFINED223#define OGLSD_WINDOW sun_java2d_pipe_hw_AccelSurface_WINDOW224#define OGLSD_TEXTURE sun_java2d_pipe_hw_AccelSurface_TEXTURE225#define OGLSD_FLIP_BACKBUFFER sun_java2d_pipe_hw_AccelSurface_FLIP_BACKBUFFER226#define OGLSD_FBOBJECT sun_java2d_pipe_hw_AccelSurface_RT_TEXTURE227228/**229* These are shorthand names for the filtering method constants used by230* image transform methods.231*/232#define OGLSD_XFORM_DEFAULT 0233#define OGLSD_XFORM_NEAREST_NEIGHBOR \234java_awt_image_AffineTransformOp_TYPE_NEAREST_NEIGHBOR235#define OGLSD_XFORM_BILINEAR \236java_awt_image_AffineTransformOp_TYPE_BILINEAR237238/**239* Helper macros that update the current texture filter state only when240* it needs to be changed, which helps reduce overhead for small texturing241* operations. The filter state is set on a per-texture (not per-context)242* basis; for example, it is possible for one texture to be using GL_NEAREST243* while another texture uses GL_LINEAR under the same context.244*/245#define OGLSD_INIT_TEXTURE_FILTER(oglSDOps, filter) \246do { \247j2d_glTexParameteri((oglSDOps)->textureTarget, \248GL_TEXTURE_MAG_FILTER, (filter)); \249j2d_glTexParameteri((oglSDOps)->textureTarget, \250GL_TEXTURE_MIN_FILTER, (filter)); \251(oglSDOps)->textureFilter = (filter); \252} while (0)253254#define OGLSD_UPDATE_TEXTURE_FILTER(oglSDOps, filter) \255do { \256if ((oglSDOps)->textureFilter != (filter)) { \257OGLSD_INIT_TEXTURE_FILTER(oglSDOps, filter); \258} \259} while (0)260261/**262* Convenience macros for setting the texture wrap mode for a given target.263* The texture wrap mode should be reset to our default value of264* GL_CLAMP_TO_EDGE by calling OGLSD_RESET_TEXTURE_WRAP() when a texture265* is first created. If another mode is needed (e.g. GL_REPEAT in the case266* of TexturePaint acceleration), one can call the OGLSD_UPDATE_TEXTURE_WRAP()267* macro to easily set up the new wrap mode. However, it is important to268* restore the wrap mode back to its default value (by calling the269* OGLSD_RESET_TEXTURE_WRAP() macro) when the operation is finished.270*/271#define OGLSD_UPDATE_TEXTURE_WRAP(target, wrap) \272do { \273j2d_glTexParameteri((target), GL_TEXTURE_WRAP_S, (wrap)); \274j2d_glTexParameteri((target), GL_TEXTURE_WRAP_T, (wrap)); \275} while (0)276277#define OGLSD_RESET_TEXTURE_WRAP(target) \278OGLSD_UPDATE_TEXTURE_WRAP(target, GL_CLAMP_TO_EDGE)279280/**281* Exported methods.282*/283jint OGLSD_Lock(JNIEnv *env,284SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo,285jint lockflags);286void OGLSD_GetRasInfo(JNIEnv *env,287SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo);288void OGLSD_Unlock(JNIEnv *env,289SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo);290void OGLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops);291void OGLSD_Delete(JNIEnv *env, OGLSDOps *oglsdo);292jint OGLSD_NextPowerOfTwo(jint val, jint max);293jboolean OGLSD_InitFBObject(GLuint *fbobjectID, GLuint *depthID,294GLuint textureID, GLenum textureTarget,295jint textureWidth, jint textureHeight);296297#endif /* OGLSurfaceData_h_Included */298299300