/*
* 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.
*/
/**
* This class describes an OpenGL "surface", that is, a region of pixels
* managed via OpenGL. An OGLSurfaceData can be tagged with one of three
* different SurfaceType objects for the purpose of registering loops, etc.
* This diagram shows the hierarchy of OGL SurfaceTypes:
*
* Any
* / \
* OpenGLSurface OpenGLTexture
* |
* OpenGLSurfaceRTT
*
* OpenGLSurface
* This kind of surface can be rendered to using OpenGL APIs. It is also
* possible to copy an OpenGLSurface to another OpenGLSurface (or to itself).
* This is typically accomplished by calling MakeContextCurrent(dstSD, srcSD)
* and then calling glCopyPixels() (although there are other techniques to
* achieve the same goal).
*
* OpenGLTexture
* This kind of surface cannot be rendered to using OpenGL (in the same sense
* as in OpenGLSurface). However, it is possible to upload a region of pixels
* to an OpenGLTexture object via glTexSubImage2D(). One can also copy a
* surface of type OpenGLTexture to an OpenGLSurface by binding the texture
* to a quad and then rendering it to the destination surface (this process
* is known as "texture mapping").
*
* OpenGLSurfaceRTT
* This kind of surface can be thought of as a sort of hybrid between
* OpenGLSurface and OpenGLTexture, in that one can render to this kind of
* surface as if it were of type OpenGLSurface, but the process of copying
* this kind of surface to another is more like an OpenGLTexture. (Note that
* "RTT" stands for "render-to-texture".)
*
* In addition to these SurfaceType variants, we have also defined some
* constants that describe in more detail the type of underlying OpenGL
* surface. This table helps explain the relationships between those
* "type" constants and their corresponding SurfaceType:
*
* OGL Type Corresponding SurfaceType
* -------- -------------------------
* WINDOW OpenGLSurface
* PBUFFER OpenGLSurface
* TEXTURE OpenGLTexture
* FLIP_BACKBUFFER OpenGLSurface
* FBOBJECT OpenGLSurfaceRTT
*/
implements AccelSurface {
/**
* OGL-specific surface types
*
* @see sun.java2d.pipe.hw.AccelSurface
*/
/**
* Pixel formats
*/
/**
* SurfaceTypes
*/
"OpenGL Surface (render-to-texture)";
/** This will be true if the fbobject system property has been enabled. */
private static boolean isFBObjectEnabled;
/** This will be true if the lcdshader system property has been enabled.*/
private static boolean isLCDShaderEnabled;
/** This will be true if the biopshader system property has been enabled.*/
private static boolean isBIOpShaderEnabled;
/** This will be true if the gradshader system property has been enabled.*/
private static boolean isGradShaderEnabled;
protected int type;
// these fields are set from the native code when the surface is
// initialized
boolean isOpaque, boolean texNonPow2,
boolean texRect,
boolean isOpaque, boolean texNonPow2,
boolean texRect,
boolean isOpaque,
static {
if (!GraphicsEnvironment.isHeadless()) {
// fbobject currently enabled by default; use "false" to disable
"sun.java2d.opengl.fbobject"));
// lcdshader currently enabled by default; use "false" to disable
"sun.java2d.opengl.lcdshader"));
// biopshader currently enabled by default; use "false" to disable
"sun.java2d.opengl.biopshader"));
// gradshader currently enabled by default; use "false" to disable
"sun.java2d.opengl.gradshader"));
oglImagePipe = new OGLDrawImage();
if (GraphicsPrimitive.tracingEnabled()) {
//The wrapped oglRenderPipe will wrap the AA pipe as well...
//oglAAPgramPipe = oglRenderPipe.traceWrap();
}
1.0, 0.25, true);
}
}
{
this.graphicsConfig = gc;
}
}
/**
* Returns the appropriate SurfaceType corresponding to the given OpenGL
* surface type constant (e.g. TEXTURE -> OpenGLTexture).
*/
switch (oglType) {
case TEXTURE:
return OpenGLTexture;
case FBOBJECT:
return OpenGLSurfaceRTT;
case PBUFFER:
default:
return OpenGLSurface;
}
}
/**
* Note: This should only be called from the QFT under the AWT lock.
* This method is kept separate from the initSurface() method below just
* to keep the code a bit cleaner.
*/
boolean success = false;
switch (type) {
case PBUFFER:
break;
case TEXTURE:
break;
case FBOBJECT:
break;
case FLIP_BACKBUFFER:
break;
default:
break;
}
if (!success) {
throw new OutOfMemoryError("can't create offscreen surface");
}
}
/**
* Initializes the appropriate OpenGL offscreen surface based on the value
* of the type parameter. If the surface creation fails for any reason,
* an OutOfMemoryError will be thrown.
*/
try {
switch (type) {
case TEXTURE:
case PBUFFER:
case FBOBJECT:
// need to make sure the context is current before
// creating the texture (or pbuffer, or fbobject)
break;
default:
break;
}
public void run() {
}
});
} finally {
}
}
/**
* Returns the OGLContext for the GraphicsConfig associated with this
* surface.
*/
return graphicsConfig.getContext();
}
/**
* Returns the OGLGraphicsConfig associated with this surface.
*/
return graphicsConfig;
}
/**
* Returns one of the surface type constants defined above.
*/
public final int getType() {
return type;
}
/**
* If this surface is backed by a texture object, returns the target
* for that texture (either GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB).
* Otherwise, this method will return zero.
*/
public final int getTextureTarget() {
return getTextureTarget(getNativeOps());
}
/**
* If this surface is backed by a texture object, returns the texture ID
* for that texture.
* Otherwise, this method will return zero.
*/
public final int getTextureID() {
return getTextureID(getNativeOps());
}
/**
* Returns native resource of specified {@code resType} associated with
* this surface.
*
* Specifically, for {@code OGLSurfaceData} this method returns the
* the following:
* <pre>
* TEXTURE - texture id
* </pre>
*
* Note: the resource returned by this method is only valid on the rendering
* thread.
*
* @return native resource of specified type or 0L if
* such resource doesn't exist or can not be retrieved.
* @see sun.java2d.pipe.hw.AccelSurface#getNativeResource
*/
return getTextureID();
}
return 0L;
}
throw new InternalError("not implemented yet");
}
/**
* For now, we can only render LCD text if:
* - the fragment shader extension is available, and
* - blending is disabled, and
* - the source color is opaque
* - and the destination is opaque
*
* Eventually, we could enhance the native OGL text rendering code
* and remove the above restrictions, but that would require significantly
* more code just to support a few uncommon cases.
*/
return
}
boolean validated = false;
// OGLTextRenderer handles both AA and non-AA text, but
// only works with the following modes:
// (Note: For LCD text we only enter this code path if
// canRenderLCDText() has already validated that the mode is
// CompositeType.SrcNoEa (opaque color), which will be subsumed
// by the CompositeType.SrcNoEa (any color) test below.)
if (/* CompositeType.SrcNoEa (any color) */
/* CompositeType.SrcOver (any color) */
AlphaComposite.SRC_OVER)) ||
/* CompositeType.Xor (any color) */
{
} else {
// do this to initialize textpipe correctly; we will attempt
// to override the non-text pipes below
super.validatePipe(sg2d);
validated = true;
}
}
}
// custom paints handled by super.validatePipe() below
}
} else {
{
if (!validated) {
super.validatePipe(sg2d);
validated = true;
}
1.0/8.0, 0.499,
false);
// install the solid pipes when AA and XOR are both enabled
}
}
// other cases handled by super.validatePipe() below
}
} else {
}
// Note that we use the transforming pipe here because it
// will examine the shape and possibly perform an optimized
// operation if it can be simplified. The simplifications
// will be valid for all STROKE and TRANSFORM types.
} else {
if (!validated) {
super.validatePipe(sg2d);
}
}
// install the text pipe based on our earlier decision
// always override the image pipe with the specialized OGL pipe
}
/*
* We can only accelerate non-Color MaskFill operations if
* all of the following conditions hold true:
* - there is an implementation for the given paintState
* - the current Paint can be accelerated for this destination
* - multitexturing is available (since we need to modulate
* the alpha mask texture with the paint texture)
*
* In all other cases, we return null, in which case the
* validation code will choose a more general software-based loop.
*/
{
return null;
}
}
return super.getMaskFill(sg2d);
}
{
{
return true;
}
return false;
}
public void flush() {
invalidate();
try {
// make sure we have a current context before
// disposing the native resources (e.g. texture object)
// this call is expected to complete synchronously, so flush now
} finally {
}
}
/**
* Disposes the native resources associated with the given OGLSurfaceData
* (referenced by the pData parameter). This method is invoked from
* the native Dispose() method from the Disposer thread when the
* Java-level OGLSurfaceData object is about to go away. Note that we
* also pass a reference to the native GLX/WGLGraphicsConfigInfo
* (pConfigInfo) for the purposes of making a context current.
*/
try {
// make sure we have a current context before
// disposing the native resources (e.g. texture object)
// this call is expected to complete synchronously, so flush now
} finally {
}
}
try {
} finally {
}
}
/**
* Returns true if OpenGL textures can have non-power-of-two dimensions
* when using the basic GL_TEXTURE_2D target.
*/
boolean isTexNonPow2Available() {
}
/**
* Returns true if OpenGL textures can have non-power-of-two dimensions
* when using the GL_TEXTURE_RECTANGLE_ARB target (only available when the
* GL_ARB_texture_rectangle extension is present).
*/
boolean isTexRectAvailable() {
}
try {
} finally {
}
}
/**
* Returns true if the surface is an on-screen window surface or
* a FBO texture attached to an on-screen CALayer.
*
* Needed by Mac OS X port.
*/
boolean isOnScreen() {
}
}