APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.javafx.tk.quantum

pack-priv final Class PaintCollector

extends Object
implements CompletionListener
Class Inheritance
All Implemented Interfaces
com.sun.javafx.tk.CompletionListener
Imports
java.util.ArrayList, .Collections, .Comparator, .List, java.util.concurrent.CountDownLatch, com.sun.javafx.PlatformUtil, com.sun.glass.ui.Application, .Window, com.sun.javafx.tk.CompletionListener, .RenderJob, com.sun.javafx.logging.PulseLogger

Manages the collection and rendering of dirty scenes. This class has methods which may be called from one of several threads, depending on the method. Assertions have been added to each method to verify whether the calling thread is the expected thread.

Field Summary

Modifier and TypeField and Description
private volatile CountDownLatch
allWorkCompletedLatch

Keeps track of the number of scenes which still need to be processed.

private static volatile PaintCollector
private static final Comparator<GlassScene>
DIRTY_SCENE_SORTER

Sorts the dirty scenes such that asynchronous scenes come first

private final List<GlassScene>
dirtyScenes

Contains a list of all of the dirty scenes.

private volatile boolean
hasDirty

Indicates whether this PaintCollector has any dirty scenes that need to be processed.

private volatile boolean
needsHint

Indicates whether we should attempt to wait for vsync at the conclusion of rendering all scenes.

private final QuantumToolkit
toolkit

A reference to the toolkit.

Constructor Summary

AccessConstructor and Description
private
PaintCollector(QuantumToolkit
The QuantumToolkit instance.
qt
)

Singleton constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
addDirtyScene(GlassScene
The scene which is dirty. This must not be null.
scene
)

Adds a dirty scene to the PaintCollector for subsequent processing.

pack-priv static PaintCollector
public void
done(RenderJob job)

Implements com.sun.javafx.tk.CompletionListener.done.

This object is a CompletionListener is registered with every GlassScene, such that when the repaint has completed, this method is called.

pack-priv static PaintCollector
pack-priv final CompletionListener

Returns:

The CompletionListener. Will never be null.
getRendered
()

Gets the CompletionListener which must be notified when a GlassScene has completed rendering.

pack-priv final boolean

Returns:

Whether there are any dirty scenes that need to be rendered.
hasDirty
()

Gets whether there are any dirty scenes that need to be rendered.

pack-priv final void
liveRepaintRenderJob(final ViewScene scene)

Run a full pulse and repaint before returning.

pack-priv final void
removeDirtyScene(GlassScene
The scene which is no longer dirty. Must not be null.
scene
)

Removes a scene from the dirtyScene list.

pack-priv final void
renderAll()

Called by QuantumToolkit during a pulse to render whatever dirty scenes we have.

private final void
setDirty(boolean value)

pack-priv void
waitForRenderingToComplete()

Called by renderAll to wait for rendering to complete before continuing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allWorkCompletedLatchback to summary
private volatile CountDownLatch allWorkCompletedLatch

Keeps track of the number of scenes which still need to be processed. In the renderAll method, we will await on this latch until all currently pending scenes are completed. Once they are all completed, we will create a new CountDownLatch initialized to the size of the number of scenes to be processed, and then process each scene in turn (or rather, cause them to render on the render thread). As each scene completes, the CompletionListener will be invoked which will decrement the allWorkCompletedLatch.

collectorback to summary
private static volatile PaintCollector collector
DIRTY_SCENE_SORTERback to summary
private static final Comparator<GlassScene> DIRTY_SCENE_SORTER

Sorts the dirty scenes such that asynchronous scenes come first

dirtyScenesback to summary
private final List<GlassScene> dirtyScenes

Contains a list of all of the dirty scenes. This list is populated only from the FX Thread in consequence of a call to addDirtyScene, or cleared from the FX Thread in consequence of a call to renderAll or removeDirtyScene. It is only ever accessed (both read and write!) from the FX thread.

hasDirtyback to summary
private volatile boolean hasDirty

Indicates whether this PaintCollector has any dirty scenes that need to be processed. This is used by the QuantumToolkit to detect in the postPulse() method whether there are dirty scenes. If there are, then the postPulse will potentially post a new pulse event. Updated from the FX Thread, but may be read from any thread.

needsHintback to summary
private volatile boolean needsHint

Indicates whether we should attempt to wait for vsync at the conclusion of rendering all scenes. This is set in the renderAll method if there are any synchronous scenes. If true, then after the last scene is processed we will indicate to the Toolkit that it should exercise the vsync block, and let it decide whether to actually do so or not (based on flags, or what OS we're on, etc).

This field will be set from the FX thread and read from the Render thread, hence it is volatile.

toolkitback to summary
private final QuantumToolkit toolkit

A reference to the toolkit. This is supplied in the constructor. Although a Toolkit.getToolkit() call and cast to QuantumToolkit could be used, it is somewhat cleaner to simply supply these parameters in the constructor and not reach out to static state.

Constructor Detail

PaintCollectorback to summary
private PaintCollector(QuantumToolkit qt)

Singleton constructor.

Parameters
qt:QuantumToolkit

The QuantumToolkit instance.

Method Detail

addDirtySceneback to summary
pack-priv final void addDirtyScene(GlassScene scene)

Adds a dirty scene to the PaintCollector for subsequent processing. This method simply makes the PaintCollector aware of this new scene and ensure it gets processed on the next call to renderAll. The next QuantumToolkit Glass timer generated pulse or PaintCollector rendering vsync hinted pulse will process these dirty scenes.

This method must only be called on the FX Thread

Parameters
scene:GlassScene

The scene which is dirty. This must not be null.

createInstanceback to summary
pack-priv static PaintCollector createInstance(QuantumToolkit toolkit)
doneback to summary
public void done(RenderJob job)

Implements com.sun.javafx.tk.CompletionListener.done.

This object is a CompletionListener is registered with every GlassScene, such that when the repaint has completed, this method is called. This method will decrement the count on the allWorkCompletedLatch.

Annotations
@Override
getInstanceback to summary
pack-priv static PaintCollector getInstance()
getRenderedback to summary
pack-priv final CompletionListener getRendered()

Gets the CompletionListener which must be notified when a GlassScene has completed rendering.

Returns:CompletionListener

The CompletionListener. Will never be null.

hasDirtyback to summary
pack-priv final boolean hasDirty()

Gets whether there are any dirty scenes that need to be rendered. If true, then a subsequent pulse event and renderAll call is required.

Returns:boolean

Whether there are any dirty scenes that need to be rendered.

liveRepaintRenderJobback to summary
pack-priv final void liveRepaintRenderJob(final ViewScene scene)

Run a full pulse and repaint before returning.

removeDirtySceneback to summary
pack-priv final void removeDirtyScene(GlassScene scene)

Removes a scene from the dirtyScene list. If the given scene was previously added with a call to addDirtyScene, it will be removed. Potentially this means that after this call the PaintCollector will no longer have any dirty scenes and will no longer require a repaint.

This method is typically called when a scene is removed from a stage, or when visible becomes false.

This method must only be called on the FX Thread

Parameters
scene:GlassScene

The scene which is no longer dirty. Must not be null.

renderAllback to summary
pack-priv final void renderAll()

Called by QuantumToolkit during a pulse to render whatever dirty scenes we have. This method is only called on the FX thread.

setDirtyback to summary
private final void setDirty(boolean value)
waitForRenderingToCompleteback to summary
pack-priv void waitForRenderingToComplete()

Called by renderAll to wait for rendering to complete before continuing.