APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.java2d

public abstract Class SurfaceDataProxy

extends Object
implements DisplayChangedListener, FlushableCacheData
Class Inheritance
All Implemented Interfaces
sun.awt.image.SurfaceManager.FlushableCacheData, sun.awt.DisplayChangedListener, java.util.EventListener
Known Direct Subclasses
sun.java2d.opengl.OGLSurfaceDataProxy, sun.java2d.x11.X11SurfaceDataProxy, sun.java2d.xr.XRSurfaceDataProxy
Imports
java.awt.Color, .Rectangle, .AlphaComposite, .GraphicsEnvironment, sun.awt.DisplayChangedListener, sun.java2d.StateTrackable.State, sun.java2d.loops.CompositeType, .SurfaceType, .Blit, .BlitBg, sun.awt.image.SurfaceManager

The proxy class encapsulates the logic for managing alternate SurfaceData representations of a primary SurfaceData. The main class will handle tracking the state changes of the primary SurfaceData and updating the associated SurfaceData proxy variants.

Subclasses have 2 main responsibilities:

If necessary, a subclass may also override the updateSurfaceData method to transfer the pixels to the accelerated surface. By default the parent class will transfer the pixels using a standard Blit operation between the two SurfaceData objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private SurfaceData
private StateTracker
private static boolean
private static int
private int
private StateTracker
private int
public static SurfaceDataProxy
UNCACHED

This instance is for cases where a caching implementation determines that a particular source image will never need to be cached - either the source SurfaceData was of an incompatible type, or it was in an UNTRACKABLE state or some other factor is discovered that permanently prevents acceleration or caching.

private boolean

Constructor Summary

AccessConstructor and Description
public
SurfaceDataProxy()

Create a SurfaceData proxy manager that attempts to create and cache a variant copy of the source SurfaceData after the default threshold number of attempts to copy from the STABLE source.

public
SurfaceDataProxy(int threshold)

Create a SurfaceData proxy manager that attempts to create and cache a variant copy of the source SurfaceData after the specified threshold number of attempts to copy from the STABLE source.

Method Summary

Modifier and TypeMethod and Description
protected void
activateDisplayListener()

This method should be called from subclasses which create cached SurfaceData objects that depend on the current properties of the display.

public void
displayChanged()

Implements sun.awt.DisplayChangedListener.displayChanged.

Invoked when the display mode has changed.

public boolean
flush(boolean deaccelerated)

Implements sun.awt.image.SurfaceManager.FlushableCacheData.flush.

Flush all cached resources as per the FlushableCacheData interface.

public synchronized void
flush()

Actively flushes (drops and invalidates) the cached surface so that it can be reclaimed quickly.

public StateTracker
getRetryTracker(SurfaceData srcData)

If the subclass is unable to validate or create a cached SurfaceData then this method will be used to get a StateTracker object that will indicate when to attempt to validate the surface again.

public void
invalidate()

Sets the valid state to false so that the next time this proxy is fetched to generate a replacement SurfaceData, the code in SurfaceData knows to replace the proxy first.

public boolean
isAccelerated()

Returns true iff this SurfaceData proxy is still valid and if it has a currently cached replacement that is also valid and current.

public static boolean
public abstract boolean
isSupportedOperation(SurfaceData srcData, int txtype, CompositeType comp, Color bgColor)

Determine if an alternate form for the srcData is needed and appropriate from the given operational parameters.

public boolean
isValid()

Returns true iff this SurfaceData proxy is still the best way to control caching of the given source on the given destination.

public void
paletteChanged()

Implements sun.awt.DisplayChangedListener.paletteChanged.

Invoked when the palette has changed.

public SurfaceData
replaceData(SurfaceData srcData, int txtype, CompositeType comp, Color bgColor)

This method attempts to replace the srcData with a cached version.

public void
updateSurfaceData(SurfaceData srcData, SurfaceData dstData, int w, int h)

This is the default implementation for updating the cached SurfaceData from the source (primary) SurfaceData.

public void
updateSurfaceDataBg(SurfaceData srcData, SurfaceData dstData, int w, int h, Color bgColor)

This is an alternate implementation for updating the cached SurfaceData from the source (primary) SurfaceData using a background color for transparent pixels.

public abstract SurfaceData
validateSurfaceData(SurfaceData srcData, SurfaceData cachedData, int w, int h)

Construct an alternate form of the given SurfaceData.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedSDback to summary
private SurfaceData cachedSD
cacheTrackerback to summary
private StateTracker cacheTracker
cachingAllowedback to summary
private static boolean cachingAllowed
defaultThresholdback to summary
private static int defaultThreshold
numtriesback to summary
private int numtries
srcTrackerback to summary
private StateTracker srcTracker
thresholdback to summary
private int threshold
UNCACHEDback to summary
public static SurfaceDataProxy UNCACHED

This instance is for cases where a caching implementation determines that a particular source image will never need to be cached - either the source SurfaceData was of an incompatible type, or it was in an UNTRACKABLE state or some other factor is discovered that permanently prevents acceleration or caching. This class optimally implements NOP variants of all necessary methods to avoid caching with a minimum of fuss.

validback to summary
private boolean valid

Constructor Detail

SurfaceDataProxyback to summary
public SurfaceDataProxy()

Create a SurfaceData proxy manager that attempts to create and cache a variant copy of the source SurfaceData after the default threshold number of attempts to copy from the STABLE source.

SurfaceDataProxyback to summary
public SurfaceDataProxy(int threshold)

Create a SurfaceData proxy manager that attempts to create and cache a variant copy of the source SurfaceData after the specified threshold number of attempts to copy from the STABLE source.

Method Detail

activateDisplayListenerback to summary
protected void activateDisplayListener()

This method should be called from subclasses which create cached SurfaceData objects that depend on the current properties of the display.

displayChangedback to summary
public void displayChanged()

Implements sun.awt.DisplayChangedListener.displayChanged.

Invoked when the display mode has changed. This method will invalidate and drop the internal cachedSD object.

flushback to summary
public boolean flush(boolean deaccelerated)

Implements sun.awt.image.SurfaceManager.FlushableCacheData.flush.

Flush all cached resources as per the FlushableCacheData interface. The deaccelerated parameter indicates if the flush is happening because the associated surface is no longer being accelerated (for instance the acceleration priority is set below the threshold needed for acceleration). Returns a boolean that indicates if the cached object is no longer needed and should be removed from the cache.

flushback to summary
public synchronized void flush()

Actively flushes (drops and invalidates) the cached surface so that it can be reclaimed quickly.

getRetryTrackerback to summary
public StateTracker getRetryTracker(SurfaceData srcData)

If the subclass is unable to validate or create a cached SurfaceData then this method will be used to get a StateTracker object that will indicate when to attempt to validate the surface again. Subclasses may return trackers which count down an ever increasing threshold to provide hysteresis on creating surfaces during low memory conditions. The default implementation just waits another "threshold" number of accesses before trying again.

invalidateback to summary
public void invalidate()

Sets the valid state to false so that the next time this proxy is fetched to generate a replacement SurfaceData, the code in SurfaceData knows to replace the proxy first.

isAcceleratedback to summary
public boolean isAccelerated()

Returns true iff this SurfaceData proxy is still valid and if it has a currently cached replacement that is also valid and current.

isCachingAllowedback to summary
public static boolean isCachingAllowed()
isSupportedOperationback to summary
public abstract boolean isSupportedOperation(SurfaceData srcData, int txtype, CompositeType comp, Color bgColor)

Determine if an alternate form for the srcData is needed and appropriate from the given operational parameters.

isValidback to summary
public boolean isValid()

Returns true iff this SurfaceData proxy is still the best way to control caching of the given source on the given destination.

paletteChangedback to summary
public void paletteChanged()

Implements sun.awt.DisplayChangedListener.paletteChanged.

Invoked when the palette has changed.

replaceDataback to summary
public SurfaceData replaceData(SurfaceData srcData, int txtype, CompositeType comp, Color bgColor)

This method attempts to replace the srcData with a cached version. It relies on the subclass to determine if the cached version will be useful given the operational parameters. This method checks any preexisting cached copy for being "up to date" and tries to update it if it is stale or non-existent and the appropriate number of accesses have occurred since it last was stale.

An outline of the process is as follows:

  1. Check the operational parameters (txtype, comp, bgColor) to make sure that the operation is supported. Return the original SurfaceData if the operation cannot be accelerated.
  2. Check the tracker for the source surface to see if it has remained stable since it was last cached. Update the state variables to cause both a threshold countdown and an update of the cached copy if it is not. (Setting cacheTracker to NEVER_CURRENT effectively marks it as "needing to be updated".)
  3. Check the tracker for the cached copy to see if is still valid and up to date. Note that the cacheTracker may be non-current if either something happened to the cached copy (eg. surfaceLost) or if the source was out of date and the cacheTracker was set to NEVER_CURRENT to force an update. Decrement the countdown and copy the source to the cache as necessary and then update the variables to show that the cached copy is stable.
updateSurfaceDataback to summary
public void updateSurfaceData(SurfaceData srcData, SurfaceData dstData, int w, int h)

This is the default implementation for updating the cached SurfaceData from the source (primary) SurfaceData. A simple Blit is used to copy the pixels from the source to the destination SurfaceData. A subclass can override this implementation if a more complex operation is required to update its cached copies.

updateSurfaceDataBgback to summary
public void updateSurfaceDataBg(SurfaceData srcData, SurfaceData dstData, int w, int h, Color bgColor)

This is an alternate implementation for updating the cached SurfaceData from the source (primary) SurfaceData using a background color for transparent pixels. A simple BlitBg is used to copy the pixels from the source to the destination SurfaceData with the specified bgColor. A subclass can override the normal updateSurfaceData method and call this implementation instead if it wants to use color keying for bitmask images.

validateSurfaceDataback to summary
public abstract SurfaceData validateSurfaceData(SurfaceData srcData, SurfaceData cachedData, int w, int h)

Construct an alternate form of the given SurfaceData. The contents of the returned SurfaceData may be undefined since the calling code will take care of updating the contents with a subsequent call to updateSurfaceData.

If the method returns null then there was a problem with allocating the accelerated surface. The getRetryTracker() method will be called to track when to attempt another revalidation.

sun.java2d back to summary

public Class SurfaceDataProxy.CountdownTracker

extends Object
implements StateTracker
Class Inheritance
All Implemented Interfaces
sun.java2d.StateTracker

Field Summary

Modifier and TypeField and Description
private int

Constructor Summary

AccessConstructor and Description
public
CountdownTracker(int threshold)

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean
isCurrent()

Implements sun.java2d.StateTracker.isCurrent.

Returns true iff the contents of the complex data of the associated StateTrackable object have not changed since the time that this StateTracker was returned from its getStateTracker() method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countdownback to summary
private int countdown

Constructor Detail

CountdownTrackerback to summary
public CountdownTracker(int threshold)

Method Detail

isCurrentback to summary
public synchronized boolean isCurrent()

Implements sun.java2d.StateTracker.isCurrent.

Doc from sun.java2d.StateTracker.isCurrent.

Returns true iff the contents of the complex data of the associated StateTrackable object have not changed since the time that this StateTracker was returned from its getStateTracker() method.