/*
* 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 a D3D "surface", that is, a region of pixels
* managed via D3D. An D3DSurfaceData can be tagged with one of three
* different SurfaceType objects for the purpose of registering loops, etc.
* This diagram shows the hierarchy of D3D SurfaceTypes:
*
* Any
* / \
* D3DSurface D3DTexture
* |
* D3DSurfaceRTT
*
* D3DSurface
* This kind of surface can be rendered to using D3D APIs. It is also
* possible to copy a D3DSurface to another D3DSurface (or to itself).
*
* D3DTexture
* This kind of surface cannot be rendered to using D3D (in the same sense
* as in D3DSurface). However, it is possible to upload a region of pixels
* to a D3DTexture object via Lock/UnlockRect(). One can also copy a
* surface of type D3DTexture to a D3DSurface by binding the texture
* to a quad and then rendering it to the destination surface (this process
* is known as "texture mapping").
*
* D3DSurfaceRTT
* This kind of surface can be thought of as a sort of hybrid between
* D3DSurface and D3DTexture, in that one can render to this kind of
* surface as if it were of type D3DSurface, but the process of copying
* this kind of surface to another is more like a D3DTexture. (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 D3D
* surface. This table helps explain the relationships between those
* "type" constants and their corresponding SurfaceType:
*
* D3D Type Corresponding SurfaceType
* -------- -------------------------
* RT_PLAIN D3DSurface
* TEXTURE D3DTexture
* FLIP_BACKBUFFER D3DSurface
* RT_TEXTURE D3DSurfaceRTT
*/
/**
* To be used with getNativeResource() only.
* @see #getNativeResource()
*/
/*
* Surface types.
* We use these surface types when copying from a sw surface
* to a surface or texture.
*/
/** Equals to D3DSWAPEFFECT_DISCARD */
/** Equals to D3DSWAPEFFECT_FLIP */
/** Equals to D3DSWAPEFFECT_COPY */
/*
* SurfaceTypes
*/
"D3D Surface (render-to-texture)";
// REMIND: regarding ArgbPre??
private int type;
// these fields are set from the native code when the surface is
// initialized
private int swapEffect;
private int backBuffersNum;
boolean isOpaque);
int numbuffers,
int swapEffect, int syncType);
static {
d3dImagePipe = new D3DDrawImage();
if (GraphicsPrimitive.tracingEnabled()) {
//The wrapped d3dRenderPipe will wrap the AA pipe as well...
//d3dAAPgramPipe = d3dRenderPipe.traceWrap();
}
1.0, 0.25, true);
}
int type)
{
this.offscreenImage = image;
this.backBuffersNum = numBackBuffers;
this.swapEffect = swapEffect;
// we put the surface into the "lost"
// state; it will be restored by the D3DScreenUpdateManager
// prior to rendering to it for the first time. This is done
// so that vram is not wasted for surfaces never rendered to
setSurfaceLost(true);
} else {
initSurface();
}
}
return D3DSurfaceDataProxy.
}
/**
* Creates a SurfaceData object representing the back buffer of a
* double-buffered on-screen Window.
*/
return null;
}
if (caps instanceof ExtendedBufferCapabilities) {
}
int swapEffect;
} else { // flip == FlipContents.UNDEFINED || .BACKGROUND
}
}
/**
* Returns a WINDOW type of surface - a
* swap chain which serves as an on-screen surface,
* handled by the D3DScreenUpdateManager.
*
* Note that the native surface is not initialized
* when the surface is created to avoid using excessive
* resources, and the surface is placed into the lost
* state. It will be restored prior to any rendering
* to it.
*
* @param peer peer for which the onscreen surface is to be created
* @return a D3DWindowSurfaceData (flip chain) surface
*/
return null;
}
}
/**
* Creates a SurfaceData object representing an off-screen buffer (either
* a plain surface or Texture).
*/
{
if (type == RT_TEXTURE) {
}
}
try {
type);
} catch (InvalidPipeException ipe) {
// try again - we might have ran out of vram, and rt textures
// could take up more than a plain surface, so it might succeed
if (type == RT_TEXTURE) {
// If a RT_TEXTURE was requested do not attempt to create a
// plain surface. (note that RT_TEXTURE can only be requested
// from a VI so the cast is safe)
{
}
}
}
return ret;
}
/**
* Returns the appropriate SurfaceType corresponding to the given D3D
* surface type constant (e.g. TEXTURE -> D3DTexture).
*/
switch (d3dType) {
case TEXTURE:
return D3DTexture;
case RT_TEXTURE:
return D3DSurfaceRTT;
default:
return D3DSurface;
}
}
private boolean initSurfaceNow() {
switch (type) {
case RT_PLAIN:
case TEXTURE:
case RT_TEXTURE:
// REMIND: we may want to pass the exact type to the native
// level here so that we could choose the right presentation
// interval for the frontbuffer (immediate vs v-synced)
case WINDOW:
case FLIP_BACKBUFFER:
default:
return false;
}
}
/**
* Initializes the appropriate D3D offscreen surface based on the value
* of the type parameter. If the surface creation fails for any reason,
* an OutOfMemoryError will be thrown.
*/
protected void initSurface() {
// any time we create or restore the surface, recreate the raster
synchronized (this) {
}
// REMIND: somewhere a puppy died
class Status {
boolean success = false;
};
try {
public void run() {
}
});
throw new InvalidPipeException("Error creating D3DSurface");
}
} finally {
}
}
/**
* Returns the D3DContext for the GraphicsConfig associated with this
* surface.
*/
return graphicsDevice.getContext();
}
/**
* Returns one of the surface type constants defined above.
*/
public final int getType() {
return type;
}
int pixel);
int pixel;
int type, int w, int h)
{
}
protected int getElem(final int x, final int y,
final SurfaceData sData)
{
if (sData.isSurfaceLost()) {
return 0;
}
int retPixel;
try {
public void run() {
}
});
} finally {
}
return retPixel;
}
final SurfaceData sData)
{
if (sData.isSurfaceLost()) {
return;
}
try {
public void run() {
}
});
} finally {
}
}
}
int dataType = 0;
int scanStride = width;
} else {
// 15, 16
}
// note that we have to use the surface width and height here,
// not the passed w,h
}
return wrn;
}
/**
* For now, we can only render LCD text if:
* - the pixel shaders are available, and
* - blending is disabled, and
* - the source color is opaque
* - and the destination is opaque
*/
return
}
/**
* If acceleration should no longer be used for this surface.
* This implementation flags to the manager that it should no
* longer attempt to re-create a D3DSurface.
*/
void disableAccelerationForSurface() {
if (offscreenImage != null) {
if (sm instanceof D3DVolatileSurfaceManager) {
setSurfaceLost(true);
}
}
}
boolean validated = false;
// REMIND: the D3D pipeline doesn't support XOR!, more
// fixes will be needed below. For now we disable D3D rendering
// for the surface which had any XOR rendering done to.
super.validatePipe(sg2d);
return;
}
// D3DTextRenderer 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 D3D 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() {
try {
// this call is expected to complete synchronously, so flush now
} finally {
}
}
/**
* Disposes the native resources associated with the given D3DSurfaceData
* (referenced by the pData parameter). This method is invoked from
* the native Dispose() method from the Disposer thread when the
* Java-level D3DSurfaceData object is about to go away.
*/
try {
// this call is expected to complete synchronously, so flush now
} finally {
}
}
{
// swapBuffers can be called from the toolkit thread by swing, we
// should detect this and prevent the deadlocks
if (rq.isRenderQueueThread()) {
// if we could not obtain the lock, repaint the area
// that was supposed to be swapped, and no-op this swap
public void run() {
}
});
return;
}
} else {
}
try {
} finally {
}
}
/**
* Returns destination Image associated with this SurfaceData.
*/
return offscreenImage;
}
r.x = r.y = 0;
return r;
} else {
}
}
// need to lock to make sure nativeWidth and Height are consistent
// since they are set from the render thread from the native
// level
try {
// REMIND: use xyoffsets?
} finally {
}
}
return graphicsDevice.getDefaultConfiguration();
}
return restoreContents(offscreenImage);
}
} else {
}
}
/**
* Attempts to restore the surface by initializing the native data
*/
void restoreSurface() {
initSurface();
}
return peer;
}
/**
* We need to let the surface manager know that the surface is lost so
* that for example BufferStrategy.contentsLost() returns correct result.
* Normally the status of contentsLost is set in validate(), but in some
* cases (like Swing's buffer per window) we intentionally don't call
* validate from the toolkit thread but only check for the BS status.
*/
super.setSurfaceLost(lost);
}
}
/**
* Returns a pointer to the native resource of specified {@code resType}
* associated with this surface.
*
* Specifically, for {@code D3DSurfaceData} this method returns pointers of
* the following:
* <pre>
* TEXTURE - (IDirect3DTexture9*)
* RT_TEXTURE, RT_PLAIN - (IDirect3DSurface9*)
* FLIP_BACKBUFFER - (IDirect3DSwapChain9*)
* D3D_DEVICE_RESOURCE - (IDirect3DDevice9*)
* </pre>
*
* Multiple resources may be available for some types (i.e. for render to
* texture one could retrieve both a destination surface by specifying
* RT_TEXTURE, and a texture by using TEXTURE).
*
* Note: the pointer returned by this method is only valid on the rendering
* thread.
*
* @return pointer to the 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
*/
}
/**
* Class representing an on-screen d3d surface. Since d3d can't
* render to the screen directly, it is implemented as a swap chain,
* controlled by D3DScreenUpdateManager.
*
* @see D3DScreenUpdateManager
*/
{
WINDOW);
}
/**
* {@inheritDoc}
*
* Overridden to use ScreenUpdateManager to obtain the replacement
* surface.
*
* @see sun.java2d.ScreenUpdateManager#getReplacementScreenSurface
*/
}
/**
* Returns destination Component associated with this SurfaceData.
*/
}
void disableAccelerationForSurface() {
// for on-screen surfaces we need to make sure a backup GDI surface is
// is used until a new one is set (which may happen during a resize). We
// don't want the screen update maanger to replace the surface right way
// because it causes repainting issues in Swing, so we invalidate it,
// this will prevent SUM from issuing a replaceSurfaceData call.
setSurfaceLost(true);
invalidate();
flush();
}
void restoreSurface() {
if (!peer.isAccelCapable()) {
throw new InvalidPipeException("Onscreen acceleration " +
"disabled for this surface");
}
throw new InvalidPipeException("Can't restore onscreen surface"+
" when in full-screen mode");
}
super.restoreSurface();
// if initialization was unsuccessful, an IPE will be thrown
// and the surface will remain lost
setSurfaceLost(false);
// This is to make sure the render target is reset after this
// surface is restored. The reason for this is that sometimes this
// surface can be restored from multiple threads (the screen update
// manager's thread and app's rendering thread) at the same time,
// and when that happens the second restoration will create the
// native resource which will not be set as render target because
// the BufferedContext's validate method will think that since the
// surface data object didn't change then the current render target
// is correct and no rendering will appear on the screen.
try {
} finally {
}
}
public boolean isDirty() {
return !dirtyTracker.isCurrent();
}
public void markClean() {
}
}
/**
* Updates the layered window with the contents of the surface.
*
* @param pd3dsd pointer to the D3DSDOps structure
* @param pData pointer to the AwtWindow peer data
* @param w width of the window
* @param h height of the window
* @see sun.awt.windows.TranslucentWindowPainter
*/
int w, int h);
}