/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef HEADLESS
#include <stdlib.h>
#include <string.h>
#include "sun_java2d_SunGraphics2D.h"
#include "jlong.h"
#include "jni_util.h"
#include "OGLContext.h"
#include "OGLRenderQueue.h"
#include "OGLSurfaceData.h"
#include "GraphicsPrimitiveMgr.h"
#include "Region.h"
/**
* The following methods are implemented in the windowing system (i.e. GLX
* and WGL) source files.
*/
/**
* This table contains the standard blending rules (or Porter-Duff compositing
* factors) used in glBlendFunc(), indexed by the rule constants from the
* AlphaComposite class.
*/
};
/** Evaluates to "front" or "back", depending on the value of buf. */
/**
* Initializes the viewport and projection matrix, effectively positioning
* the origin at the top-left corner of the surface. This allows Java 2D
* coordinates to be passed directly to OpenGL, which is typically based on
* a bottom-right coordinate system. This method also sets the appropriate
* read and draw buffers.
*/
static void
{
"OGLContext_SetViewport: w=%d h=%d read=%s draw=%s",
// set the viewport and projection matrix
// set the active read and draw buffers
// set the color mask to enable alpha channel only when necessary
}
/**
* Initializes the alpha channel of the current surface so that it contains
* fully opaque alpha values.
*/
static void
{
// it is possible for the scissor test to be enabled at this point;
// if it is, disable it temporarily since it can affect the glClear() op
if (scissorEnabled) {
}
// set the color mask so that we only affect the alpha channel
// clear the color buffer so that the alpha channel is fully opaque
// restore the color mask (as it was set in OGLContext_SetViewport())
// re-enable scissor test, only if it was enabled earlier
if (scissorEnabled) {
}
}
/**
* Fetches the OGLContext associated with the given destination surface,
* makes the context current for those surfaces, updates the destination
* viewport, and then returns a pointer to the OGLContext.
*/
{
"OGLContext_SetSurfaces: ops are null");
return NULL;
}
"OGLContext_SetSurfaces: texture cannot be used as destination");
return NULL;
}
// initialize the surface as an OGLSD_WINDOW
"OGLContext_SetSurfaces: could not init OGL window");
return NULL;
}
}
// make the context current
"OGLContext_SetSurfaces: could not make context current");
return NULL;
}
// update the viewport
// perform additional one-time initialization, if necessary
// in this case we are treating the destination as opaque, but
// to do so, first we need to ensure that the alpha channel
// is filled with fully opaque values (see 6319663)
}
}
return oglc;
}
/**
* Resets the current clip state (disables both scissor and depth tests).
*/
void
{
}
/**
* Sets the OpenGL scissor bounds to the provided rectangular clip bounds.
*/
void
{
"OGLContext_SetRectClip: x=%d y=%d w=%d h=%d",
// use an empty scissor rectangle when the region is empty
width = 0;
height = 0;
}
// the scissor rectangle is specified using the lower-left
// origin of the clip region (in the framebuffer's coordinate
// space), so we must account for the x/y offsets of the
// destination surface
}
/**
* Sets up a complex (shape) clip using the OpenGL depth buffer. This
* method prepares the depth buffer so that the clip Region spans can
* be "rendered" into it. The depth buffer is first cleared, then the
* depth func is setup so that when we render the clip spans,
* nothing is rendered into the color buffer, but for each pixel that would
* be rendered, a non-zero value is placed into that location in the depth
* buffer. With depth test enabled, pixels will only be rendered into the
* color buffer if the corresponding value at that (x,y) location in the
* depth buffer differs from the incoming depth value.
*/
void
{
// enable depth test and clear depth buffer so that depth values are at
// their maximum; also set the depth func to GL_ALWAYS so that the
// depth values of the clip spans are forced into the depth buffer
j2d_glClearDepth(1.0);
// disable writes into the color buffer while we set up the clip
// save current transform
// use identity transform plus slight translation in the z-axis when
// setting the clip spans; this will push the clip spans (which would
// normally be at z=0) to the z=1 plane to give them some depth
}
/**
* Finishes setting up the shape clip by resetting the depth func
* so that future rendering operations will once again be written into the
* color buffer (while respecting the clip set up in the depth buffer).
*/
void
{
// restore transform
// re-enable writes into the color buffer
// enable the depth test so that only fragments within the clip region
// (i.e. those fragments whose z-values are >= the values currently
// stored in the depth buffer) are rendered
}
/**
* Initializes the OpenGL state responsible for applying extra alpha. This
* step is only necessary for any operation that uses glDrawPixels() or
* glCopyPixels() with a non-1.0f extra alpha value. Since the source is
* always premultiplied, we apply the extra alpha value to both alpha and
* color components using GL_*_SCALE.
*/
void
{
}
/**
* Resets all OpenGL compositing state (disables blending and logic
* operations).
*/
void
{
// disable blending and XOR mode
}
// set state to default values
}
/**
* Initializes the OpenGL blending state. XOR mode is disabled and the
* appropriate blend functions are setup based on the AlphaComposite rule
* constant.
*/
void
{
"OGLContext_SetAlphaComposite: flags=%d", flags);
// disable XOR mode
}
// we can safely disable blending when:
// - comp is SrcNoEa or SrcOverNoEa, and
// - the source is opaque
// (turning off blending can have a large positive impact on
// performance)
(extraAlpha == 1.0f) &&
(flags & OGLC_SRC_IS_OPAQUE))
{
" disabling alpha comp: rule=%d ea=1.0 src=opq", rule);
} else {
}
// update state
}
/**
* Initializes the OpenGL logic op state to XOR mode. Blending is disabled
* before enabling logic op mode. The XOR pixel value will be applied
* later in the OGLContext_SetColor() method.
*/
void
{
"OGLContext_SetXorComposite: xorPixel=%08x", xorPixel);
// disable blending mode
}
// enable XOR mode
// set up the alpha test so that we discard transparent fragments (this
// is primarily useful for rendering text in XOR mode)
// update state
}
/**
* Resets the OpenGL transform state back to the identity matrix.
*/
void
{
}
/**
* Initializes the OpenGL transform state by setting the modelview transform
* using the given matrix parameters.
*
* REMIND: it may be worthwhile to add serial id to AffineTransform, so we
* could do a quick check to see if the xform has changed since
* last time... a simple object compare won't suffice...
*/
void
{
}
// copy values from AffineTransform object into native matrix array
}
/**
* Creates a 2D texture of the given format and dimensions and returns the
* texture object identifier. This method is typically used to create a
* temporary texture for intermediate work, such as in the
* OGLContext_InitBlitTileTexture() method below.
*/
{
// save pixel store parameters (since this method could be invoked after
// the caller has already set up its pixel store parameters)
// set pixel store parameters to default values
// restore pixel store parameters
return texID;
}
/**
* Initializes a small texture tile for use with tiled blit operations (see
* OGLBlitLoops.c and OGLMaskBlit.c for usage examples). The texture ID for
* the tile is stored in the given OGLContext. The tile is initially filled
* with garbage values, but the tile is updated as needed (via
* glTexSubImage2D()) with real RGBA values used in tiled blit situations.
* The internal format for the texture is GL_RGBA8, which should be sufficient
* for storing system memory surfaces of any known format (see PixelFormats
* for a list of compatible surface formats).
*/
{
return JNI_TRUE;
}
/**
* Destroys the OpenGL resources associated with the given OGLContext.
* It is required that the native context associated with the OGLContext
* be made current prior to calling this method.
*/
void
{
}
if (oglc->blitTextureID != 0) {
}
}
/**
* Returns JNI_TRUE if the given extension name is available for the current
* GraphicsConfig; JNI_FALSE otherwise. An extension is considered available
* if its identifier string is found amongst the space-delimited GL_EXTENSIONS
* string.
*
* Adapted from the OpenGL Red Book, pg. 506.
*/
{
char *p = (char *)extString;
char *end;
"OGLContext_IsExtensionAvailable: extension string is null");
return JNI_FALSE;
}
while (p < end) {
break;
}
p += (n + 1);
}
"OGLContext_IsExtensionAvailable: %s=%s",
return ret;
}
/**
* Returns JNI_TRUE only if all of the following conditions are met:
* - the GL_EXT_framebuffer_object extension is available
* - FBO support has been enabled via the system property
* - we can successfully create an FBO with depth capabilities
*/
static jboolean
const char *extString)
{
// first see if the fbobject extension is available
"GL_EXT_framebuffer_object"))
{
return JNI_FALSE;
}
// next see if the fbobject system property has been enabled
"isFBObjectEnabled", "Z").z;
if (!isFBObjectEnabled) {
"OGLContext_IsFBObjectExtensionAvailable: disabled via flag");
return JNI_FALSE;
}
// finally, create a dummy fbobject with depth capabilities to see
// (first we initialize a color texture object that will be used to
// construct the dummy fbobject)
// initialize framebuffer object using color texture created above
{
"OGLContext_IsFBObjectExtensionAvailable: fbobject unsupported");
return JNI_FALSE;
}
// delete the temporary resources
"OGLContext_IsFBObjectExtensionAvailable: fbobject supported");
return JNI_TRUE;
}
/**
* Returns JNI_TRUE only if all of the following conditions are met:
* - the GL_ARB_fragment_shader extension is available
* - the LCD text shader codepath has been enabled via the system property
* - the hardware supports the minimum number of texture units
*/
static jboolean
{
// first see if the fragment shader extension is available
if (!fragShaderAvailable) {
return JNI_FALSE;
}
// next see if the lcdshader system property has been enabled
"isLCDShaderEnabled", "Z").z;
if (!isLCDShaderEnabled) {
"OGLContext_IsLCDShaderSupportAvailable: disabled via flag");
return JNI_FALSE;
}
// finally, check to see if the hardware supports the required number
// of texture units
if (maxTexUnits < 4) {
"OGLContext_IsLCDShaderSupportAvailable: not enough tex units (%d)",
}
"OGLContext_IsLCDShaderSupportAvailable: LCD text shader supported");
return JNI_TRUE;
}
/**
* Returns JNI_TRUE only if all of the following conditions are met:
* - the GL_ARB_fragment_shader extension is available
* - the BufferedImageOp shader codepath has been enabled via the
* system property
*/
static jboolean
{
// first see if the fragment shader extension is available
if (!fragShaderAvailable) {
return JNI_FALSE;
}
// next see if the biopshader system property has been enabled
"isBIOpShaderEnabled", "Z").z;
if (!isBIOpShaderEnabled) {
"OGLContext_IsBIOpShaderSupportAvailable: disabled via flag");
return JNI_FALSE;
}
/*
* Note: In theory we should probably do some other checks here, like
* linking a sample shader to see if the hardware truly supports our
* shader programs. However, our current BufferedImageOp shaders were
* designed to support first-generation shader-level hardware, so the
* assumption is that if our shaders work on those GPUs, then they'll
* work on newer ones as well. Also, linking a fragment program can
* cost valuable CPU cycles, which is another reason to avoid these
* checks at startup.
*/
"OGLContext_IsBIOpShaderSupportAvailable: BufferedImageOp shader supported");
return JNI_TRUE;
}
/**
* Returns JNI_TRUE only if all of the following conditions are met:
* - the GL_ARB_fragment_shader extension is available
* - the Linear/RadialGradientPaint shader codepath has been enabled via the
* system property
*/
static jboolean
{
// first see if the fragment shader extension is available
if (!fragShaderAvailable) {
return JNI_FALSE;
}
// next see if the gradshader system property has been enabled
"isGradShaderEnabled", "Z").z;
if (!isGradShaderEnabled) {
"OGLContext_IsGradShaderSupportAvailable: disabled via flag");
return JNI_FALSE;
}
"OGLContext_IsGradShaderSupportAvailable: Linear/RadialGradientPaint shader supported");
return JNI_TRUE;
}
/**
* Checks for the presence of the optional extensions used by
* the Java 2D OpenGL pipeline. The given caps bitfield is updated
* to reflect the availability of these extensions.
*/
void
{
const char *e = (char *)j2d_glGetString(GL_EXTENSIONS);
OGLContext_IsExtensionAvailable(e, "GL_ARB_fragment_shader");
*caps |= CAPS_TEXNONSQUARE;
if (OGLContext_IsExtensionAvailable(e, "GL_ARB_multitexture")) {
*caps |= CAPS_MULTITEXTURE;
}
if (OGLContext_IsExtensionAvailable(e, "GL_ARB_texture_non_power_of_two")){
*caps |= CAPS_TEXNONPOW2;
}
// 6656574: Use of the GL_ARB_texture_rectangle extension by Java 2D
// complicates any third-party libraries that try to interact with
// the OGL pipeline (and we've run into driver bugs in the past related
// to this extension), so for now we will disable its use by default (unless
// forced). We will still make use of the GL_ARB_texture_non_power_of_two
// extension when available, which is the better choice going forward
// anyway.
if (OGLContext_IsExtensionAvailable(e, "GL_ARB_texture_rectangle") &&
{
*caps |= CAPS_EXT_TEXRECT;
}
if (OGLContext_IsFBObjectExtensionAvailable(env, e)) {
*caps |= CAPS_EXT_FBOBJECT;
}
}
}
}
if (OGLContext_IsExtensionAvailable(e, "GL_NV_fragment_program")) {
// this is an Nvidia board, at least PS 2.0, but we can't
// use the "max instructions" heuristic since GeForce FX
// boards report 1024 even though they're only PS 2.0,
// so we'll check the following, which does imply PS 3.0
if (OGLContext_IsExtensionAvailable(e, "GL_NV_fragment_program2")) {
}
} else {
// for all other boards, we look at the "max instructions"
// count reported by the GL_ARB_fragment_program extension
// as a heuristic for detecting PS 3.0 compatible hardware
if (OGLContext_IsExtensionAvailable(e, "GL_ARB_fragment_program")) {
if (instr > 512) {
}
}
}
// stuff vendor descriptor in the upper bits of the caps
}
// REMIND: new in 7 - check if needs fixing
}
}
/**
* Returns JNI_TRUE if the given GL_VERSION string meets the minimum
* requirements (>= 1.2); JNI_FALSE otherwise.
*/
{
if (versionstr == NULL) {
"OGLContext_IsVersionSupported: version string is null");
return JNI_FALSE;
}
// note that this check allows for OpenGL 2.x
(versionstr[0] >= '2'));
}
/**
* Compiles and links the given fragment shader program. If
* successful, this function returns a handle to the newly created shader
* program; otherwise returns 0.
*/
{
int infoLogLength = 0;
// create the shader object and compile the shader source code
&success);
// print the compiler messages, if necessary
if (infoLogLength > 1) {
"OGLContext_CreateFragmentProgram: compiler msg (%d):\n%s",
}
if (!success) {
"OGLContext_CreateFragmentProgram: error compiling shader");
return 0;
}
// create the program object and attach it to the shader
// it is now safe to delete the shader object
// link the program
&success);
// print the linker messages, if necessary
if (infoLogLength > 1) {
"OGLContext_CreateFragmentProgram: linker msg (%d):\n%s",
}
if (!success) {
"OGLContext_CreateFragmentProgram: error linking shader");
return 0;
}
return fragmentProgram;
}
/*
* Class: sun_java2d_opengl_OGLContext
* Method: getOGLIdString
*/
{
char *pAdapterId;
int len;
vendor = "Unknown Vendor";
}
renderer = "Unknown Renderer";
}
version = "unknown version";
}
// 'vendor renderer (version)0'
if (pAdapterId != NULL) {
}
return ret;
}
#endif /* !HEADLESS */