public class QueuedPixelSource extends java.lang.Object implements PixelSource
PixelSource interface which
manages Pixels objects in the state of being consumed (uploaded
to the screen usually), in flight in the queue of upload requests, and
idle waiting to be reused for temporary storage for future uploads.
All Pixels objects currently saved for reuse will all be the
same dimensions and scale which are tracked by calling the
validate() method.
At most we will need 3 sets of pixels:
One may be "in use", a hard reference stored in beingConsumed
Another may be "in the queue", hard ref stored in enqueued
A third may be needed to prepare new pixels while those two are in
transit.
If the third is filled with pixels and enqueued while the previously
mentioned two are still in their stages of use, then it will replace
the second object as the "enqueued" reference and the previously
enqueued object will then become itself the "third unused" reference.
If everything happens in lock step we will often have only one
set of pixels. If the consumer/displayer gets slightly or occasionally
behind we might end up with two sets of pixels in play. Only when things
get really bad with multiple deliveries enqueued during the processing
of a single earlier delivery will we end up with three sets of
Pixels objects in play.
| Modifier and Type | Field and Description |
|---|---|
private Pixels |
beingConsumed |
private Pixels |
enqueued |
private java.util.List<java.lang.ref.WeakReference<Pixels>> |
saved |
private boolean |
useDirectBuffers |
| Constructor and Description |
|---|
QueuedPixelSource(boolean useDirectBuffers) |
| Modifier and Type | Method and Description |
|---|---|
void |
doneWithPixels(Pixels used)
Indicates that the specified non-null
Pixels object which was
obtained from PixelSource.getLatestPixels() is done being processed and
can be reused for future pixel deliveries if needed. |
void |
enqueuePixels(Pixels pixels)
Place the indicated
Pixels object into the enqueued state,
replacing any other objects that are currently enqueued but not yet
being used by the consumer. |
Pixels |
getLatestPixels()
Gets the next "latest" set of
Pixels to be processed or displayed. |
Pixels |
getUnusedPixels(int w,
int h,
float scale)
Return an unused Pixels with the indicated dimensions and scale.
|
void |
skipLatestPixels()
A one step method for skipping a pixel delivery object in the case
where the consumer is not ready to process any pixels.
|
private boolean |
usesSameBuffer(Pixels p1,
Pixels p2) |
private volatile Pixels beingConsumed
private volatile Pixels enqueued
private final java.util.List<java.lang.ref.WeakReference<Pixels>> saved
private final boolean useDirectBuffers
public Pixels getLatestPixels()
PixelSourcePixels to be processed or displayed.
This method is called by the consumer of Pixels objects.
The return value may be null if the delivery request was obsoleted
or superceded while in transit between the threads.
The caller should call
doneWithPixels()
if and only if the return value was non-null.getLatestPixels in interface PixelSourcepublic void doneWithPixels(Pixels used)
PixelSourcePixels object which was
obtained from PixelSource.getLatestPixels() is done being processed and
can be reused for future pixel deliveries if needed.
This method should be called by the consumer if and only if the call to
getLatestPixels() returned a non-null object.doneWithPixels in interface PixelSourceused - a non-null Pixels object previously obtained from
getLatestPixels()public void skipLatestPixels()
PixelSourcedoneWithPixels(getLatestPixels()).skipLatestPixels in interface PixelSourcepublic Pixels getUnusedPixels(int w, int h, float scale)
Pixels object.
Or it may be a brand new object.w - the width of the desired Pixels objecth - the height of the desired Pixels objectscale - the scale of the desired Pixels objectPixels objectpublic void enqueuePixels(Pixels pixels)
Pixels object into the enqueued state,
replacing any other objects that are currently enqueued but not yet
being used by the consumer.pixels - the Pixels object to be enqueued