0N/A/*
2362N/A * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef OGLSurfaceData_h_Included
0N/A#define OGLSurfaceData_h_Included
0N/A
0N/A#include "java_awt_image_AffineTransformOp.h"
0N/A#include "sun_java2d_opengl_OGLSurfaceData.h"
430N/A#include "sun_java2d_pipe_hw_AccelSurface.h"
0N/A
0N/A#include "J2D_GL/gl.h"
0N/A#include "SurfaceData.h"
0N/A#include "Trace.h"
0N/A#include "OGLFuncs.h"
0N/A
0N/Atypedef struct _OGLSDOps OGLSDOps;
0N/A
0N/A/**
0N/A * The OGLPixelFormat structure contains all the information OpenGL needs to
0N/A * know when copying from or into a particular system memory image buffer (via
0N/A * glDrawPixels(), glReadPixels, glTexSubImage2D(), etc).
0N/A *
0N/A * GLenum format;
0N/A * The pixel format parameter used in glDrawPixels() and other similar calls.
0N/A * Indicates the component ordering for each pixel (e.g. GL_BGRA).
0N/A *
0N/A * GLenum type;
0N/A * The pixel data type parameter used in glDrawPixels() and other similar
0N/A * calls. Indicates the data type for an entire pixel or for each component
0N/A * in a pixel (e.g. GL_UNSIGNED_BYTE with GL_BGR means a pixel consists of
0N/A * 3 unsigned byte components, blue first, then green, then red;
0N/A * GL_UNSIGNED_INT_8_8_8_8_REV with GL_BGRA means a pixel consists of 1
0N/A * unsigned integer comprised of four byte components, alpha first, then red,
0N/A * then green, then blue).
0N/A *
0N/A * jint alignment;
0N/A * The byte alignment parameter used in glPixelStorei(GL_UNPACK_ALIGNMENT). A
0N/A * value of 4 indicates that each pixel starts on a 4-byte aligned region in
0N/A * memory, and so on. This alignment parameter helps OpenGL speed up pixel
0N/A * transfer operations by transferring memory in aligned blocks.
0N/A *
0N/A * jboolean hasAlpha;
0N/A * If true, indicates that this pixel format contains an alpha component.
0N/A *
0N/A * jboolean isPremult;
0N/A * If true, indicates that this pixel format contains color components that
0N/A * have been pre-multiplied by their corresponding alpha component.
0N/A */
0N/Atypedef struct {
0N/A GLenum format;
0N/A GLenum type;
0N/A jint alignment;
0N/A jboolean hasAlpha;
0N/A jboolean isPremult;
0N/A} OGLPixelFormat;
0N/A
0N/A/**
0N/A * The OGLSDOps structure describes a native OpenGL surface and contains all
0N/A * information pertaining to the native surface. Some information about
0N/A * the more important/different fields:
0N/A *
0N/A * void *privOps;
0N/A * Pointer to native-specific (GLX, WGL, etc.) SurfaceData info, such as the
0N/A * native Drawable handle and GraphicsConfig data.
0N/A *
0N/A * jint drawableType;
0N/A * The surface type; can be any one of the surface type constants defined
0N/A * below (OGLSD_WINDOW, OGLSD_TEXTURE, etc).
0N/A *
0N/A * GLenum activeBuffer;
0N/A * Can be either GL_FRONT if this is the front buffer surface of an onscreen
0N/A * window or a pbuffer surface, or GL_BACK if this is the backbuffer surface
0N/A * of an onscreen window.
0N/A *
0N/A * jboolean isOpaque;
0N/A * If true, the surface should be treated as being fully opaque. If
0N/A * the underlying surface (e.g. pbuffer) has an alpha channel and isOpaque
0N/A * is true, then we should take appropriate action (i.e. call glColorMask()
0N/A * to disable writes into the alpha channel) to ensure that the surface
0N/A * remains fully opaque.
0N/A *
0N/A * jboolean needsInit;
0N/A * If true, the surface requires some one-time initialization, which should
0N/A * be performed after a context has been made current to the surface for
0N/A * the first time.
0N/A *
0N/A * jint x/yOffset
0N/A * The offset in pixels of the OpenGL viewport origin from the lower-left
0N/A * corner of the heavyweight drawable. For example, a top-level frame on
0N/A * Windows XP has lower-left insets of (4,4). The OpenGL viewport origin
0N/A * would typically begin at the lower-left corner of the client region (inside
0N/A * the frame decorations), but AWT/Swing will take the insets into account
0N/A * when rendering into that window. So in order to account for this, we
0N/A * need to adjust the OpenGL viewport origin by an x/yOffset of (-4,-4). On
0N/A * X11, top-level frames typically don't have this insets issue, so their
0N/A * x/yOffset would be (0,0) (the same applies to pbuffers).
0N/A *
0N/A * jint width/height;
0N/A * The cached surface bounds. For offscreen surface types (OGLSD_PBUFFER,
0N/A * OGLSD_TEXTURE, etc.) these values must remain constant. Onscreen window
0N/A * surfaces (OGLSD_WINDOW, OGLSD_FLIP_BACKBUFFER, etc.) may have their
0N/A * bounds changed in response to a programmatic or user-initiated event, so
0N/A * these values represent the last known dimensions. To determine the true
0N/A * current bounds of this surface, query the native Drawable through the
0N/A * privOps field.
0N/A *
0N/A * GLuint textureID;
0N/A * The texture object handle, as generated by glGenTextures(). If this value
0N/A * is zero, the texture has not yet been initialized.
0N/A *
0N/A * jint textureWidth/Height;
0N/A * The actual bounds of the texture object for this surface. If the
0N/A * GL_ARB_texture_non_power_of_two extension is not present, the dimensions
0N/A * of an OpenGL texture object must be a power-of-two (e.g. 64x32 or 128x512).
0N/A * The texture image that we care about has dimensions specified by the width
0N/A * and height fields in this OGLSDOps structure. For example, if the image
0N/A * to be stored in the texture has dimensions 115x47, the actual OpenGL
0N/A * texture we allocate will have dimensions 128x64 to meet the pow2
0N/A * restriction. The image bounds within the texture can be accessed using
0N/A * floating point texture coordinates in the range [0.0,1.0].
0N/A *
0N/A * GLenum textureTarget;
0N/A * The texture target of the texture object for this surface. If this
0N/A * surface is not backed by a texture, this value is set to zero. Otherwise,
0N/A * this value is GL_TEXTURE_RECTANGLE_ARB when the GL_ARB_texture_rectangle
0N/A * extension is in use; if not, it is set to GL_TEXTURE_2D.
0N/A *
0N/A * GLint textureFilter;
0N/A * The current filter state for this texture object (can be either GL_NEAREST
0N/A * or GL_LINEAR). We cache this value here and check it before updating
0N/A * the filter state to avoid redundant calls to glTexParameteri() when the
0N/A * filter state remains constant (see the OGLSD_UPDATE_TEXTURE_FILTER()
0N/A * macro below).
0N/A *
0N/A * GLuint fbobjectID, depthID;
0N/A * The object handles for the framebuffer object and depth renderbuffer
0N/A * associated with this surface. These fields are only used when
0N/A * drawableType is OGLSD_FBOBJECT, otherwise they are zero.
0N/A */
0N/Astruct _OGLSDOps {
0N/A SurfaceDataOps sdOps;
0N/A void *privOps;
0N/A jint drawableType;
0N/A GLenum activeBuffer;
0N/A jboolean isOpaque;
0N/A jboolean needsInit;
0N/A jint xOffset;
0N/A jint yOffset;
0N/A jint width;
0N/A jint height;
0N/A GLuint textureID;
0N/A jint textureWidth;
0N/A jint textureHeight;
0N/A GLenum textureTarget;
0N/A GLint textureFilter;
0N/A GLuint fbobjectID;
0N/A GLuint depthID;
0N/A};
0N/A
0N/A/**
0N/A * The following convenience macros are used when rendering rectangles (either
0N/A * a single rectangle, or a whole series of them). To render a single
0N/A * rectangle, simply invoke the GLRECT() macro. To render a whole series of
0N/A * rectangles, such as spans in a complex shape, first invoke GLRECT_BEGIN(),
0N/A * then invoke the appropriate inner loop macro (either XYXY or XYWH) for
0N/A * each rectangle, and finally invoke GLRECT_END() to notify OpenGL that the
0N/A * vertex list is complete. Care should be taken to avoid calling OpenGL
0N/A * commands (besides GLRECT_BODY_*()) inside the BEGIN/END pair.
0N/A */
0N/A
0N/A#define GLRECT_BEGIN j2d_glBegin(GL_QUADS)
0N/A
0N/A#define GLRECT_BODY_XYXY(x1, y1, x2, y2) \
0N/A do { \
0N/A j2d_glVertex2i(x1, y1); \
0N/A j2d_glVertex2i(x2, y1); \
0N/A j2d_glVertex2i(x2, y2); \
0N/A j2d_glVertex2i(x1, y2); \
0N/A } while (0)
0N/A
0N/A#define GLRECT_BODY_XYWH(x, y, w, h) \
0N/A GLRECT_BODY_XYXY(x, y, (x) + (w), (y) + (h))
0N/A
0N/A#define GLRECT_END j2d_glEnd()
0N/A
0N/A#define GLRECT(x, y, w, h) \
0N/A do { \
0N/A GLRECT_BEGIN; \
0N/A GLRECT_BODY_XYWH(x, y, w, h); \
0N/A GLRECT_END; \
0N/A } while (0)
0N/A
0N/A/**
0N/A * These are shorthand names for the surface type constants defined in
0N/A * OGLSurfaceData.java.
0N/A */
430N/A#define OGLSD_UNDEFINED sun_java2d_pipe_hw_AccelSurface_UNDEFINED
430N/A#define OGLSD_WINDOW sun_java2d_pipe_hw_AccelSurface_WINDOW
430N/A#define OGLSD_PBUFFER sun_java2d_pipe_hw_AccelSurface_RT_PLAIN
430N/A#define OGLSD_TEXTURE sun_java2d_pipe_hw_AccelSurface_TEXTURE
430N/A#define OGLSD_FLIP_BACKBUFFER sun_java2d_pipe_hw_AccelSurface_FLIP_BACKBUFFER
430N/A#define OGLSD_FBOBJECT sun_java2d_pipe_hw_AccelSurface_RT_TEXTURE
0N/A
0N/A/**
0N/A * These are shorthand names for the filtering method constants used by
0N/A * image transform methods.
0N/A */
0N/A#define OGLSD_XFORM_DEFAULT 0
0N/A#define OGLSD_XFORM_NEAREST_NEIGHBOR \
0N/A java_awt_image_AffineTransformOp_TYPE_NEAREST_NEIGHBOR
0N/A#define OGLSD_XFORM_BILINEAR \
0N/A java_awt_image_AffineTransformOp_TYPE_BILINEAR
0N/A
0N/A/**
0N/A * Helper macros that update the current texture filter state only when
0N/A * it needs to be changed, which helps reduce overhead for small texturing
0N/A * operations. The filter state is set on a per-texture (not per-context)
0N/A * basis; for example, it is possible for one texture to be using GL_NEAREST
0N/A * while another texture uses GL_LINEAR under the same context.
0N/A */
0N/A#define OGLSD_INIT_TEXTURE_FILTER(oglSDOps, filter) \
0N/A do { \
0N/A j2d_glTexParameteri((oglSDOps)->textureTarget, \
0N/A GL_TEXTURE_MAG_FILTER, (filter)); \
0N/A j2d_glTexParameteri((oglSDOps)->textureTarget, \
0N/A GL_TEXTURE_MIN_FILTER, (filter)); \
0N/A (oglSDOps)->textureFilter = (filter); \
0N/A } while (0)
0N/A
0N/A#define OGLSD_UPDATE_TEXTURE_FILTER(oglSDOps, filter) \
0N/A do { \
0N/A if ((oglSDOps)->textureFilter != (filter)) { \
0N/A OGLSD_INIT_TEXTURE_FILTER(oglSDOps, filter); \
0N/A } \
0N/A } while (0)
0N/A
0N/A/**
0N/A * Convenience macros for setting the texture wrap mode for a given target.
0N/A * The texture wrap mode should be reset to our default value of
0N/A * GL_CLAMP_TO_EDGE by calling OGLSD_RESET_TEXTURE_WRAP() when a texture
0N/A * is first created. If another mode is needed (e.g. GL_REPEAT in the case
0N/A * of TexturePaint acceleration), one can call the OGLSD_UPDATE_TEXTURE_WRAP()
0N/A * macro to easily set up the new wrap mode. However, it is important to
0N/A * restore the wrap mode back to its default value (by calling the
0N/A * OGLSD_RESET_TEXTURE_WRAP() macro) when the operation is finished.
0N/A */
0N/A#define OGLSD_UPDATE_TEXTURE_WRAP(target, wrap) \
0N/A do { \
0N/A j2d_glTexParameteri((target), GL_TEXTURE_WRAP_S, (wrap)); \
0N/A j2d_glTexParameteri((target), GL_TEXTURE_WRAP_T, (wrap)); \
0N/A } while (0)
0N/A
0N/A#define OGLSD_RESET_TEXTURE_WRAP(target) \
0N/A OGLSD_UPDATE_TEXTURE_WRAP(target, GL_CLAMP_TO_EDGE)
0N/A
0N/A/**
0N/A * Exported methods.
0N/A */
0N/Ajint OGLSD_Lock(JNIEnv *env,
0N/A SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo,
0N/A jint lockflags);
0N/Avoid OGLSD_GetRasInfo(JNIEnv *env,
0N/A SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo);
0N/Avoid OGLSD_Unlock(JNIEnv *env,
0N/A SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo);
0N/Avoid OGLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops);
4632N/Avoid OGLSD_Delete(JNIEnv *env, OGLSDOps *oglsdo);
0N/Ajint OGLSD_NextPowerOfTwo(jint val, jint max);
0N/Ajboolean OGLSD_InitFBObject(GLuint *fbobjectID, GLuint *depthID,
0N/A GLuint textureID, GLenum textureTarget,
0N/A jint textureWidth, jint textureHeight);
0N/A
0N/A#endif /* OGLSurfaceData_h_Included */