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

public abstract Class RenderQueue

extends Object
Class Inheritance
Known Direct Subclasses
sun.java2d.opengl.OGLRenderQueue
Imports
java.util.HashSet, .Set, sun.awt.SunToolkit

The RenderQueue class encapsulates a RenderBuffer on which rendering operations are enqueued. Note that the RenderQueue lock must be acquired before performing any operations on the queue (e.g. enqueuing an operation or flushing the queue). A sample usage scenario follows: public void drawSomething(...) { rq.lock(); try { ctx.validate(...); rq.ensureCapacity(4); rq.getBuffer().putInt(DRAW_SOMETHING); ... } finally { rq.unlock(); } } If you are enqueuing an operation that involves 8-byte parameters (i.e. long or double values), it is imperative that you ensure proper alignment of the underlying RenderBuffer. This can be accomplished simply by providing an offset to the first 8-byte parameter in your operation to the ensureCapacityAndAlignment() method. For example: public void drawStuff(...) { rq.lock(); try { RenderBuffer buf = rq.getBuffer(); ctx.validate(...); // 28 total bytes in the operation, 12 bytes to the first long rq.ensureCapacityAndAlignment(28, 12); buf.putInt(DRAW_STUFF); buf.putInt(x).putInt(y); buf.putLong(addr1); buf.putLong(addr2); } finally { rq.unlock(); } }

Field Summary

Modifier and TypeField and Description
protected RenderBuffer
buf

The underlying buffer for this queue.

private static final int
BUFFER_SIZE

The size of the underlying buffer, in bytes.

protected Set<Object>
refSet

A Set containing hard references to Objects that must stay alive until the queue has been completely flushed.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public final void
addReference(Object ref)

Adds the given Object to the set of hard references, which will prevent that Object from being disposed until the queue has been flushed completely.

public final void
ensureAlignment(int
offset (in bytes) from the current position to the first 8-byte value used in the following operation
first8ByteValueOffset
)

Inserts a 4-byte NOOP token when necessary to ensure that all 8-byte parameters for the following operation are added to the underlying buffer with an 8-byte memory alignment.

public final void
ensureCapacity(int
size (in bytes) of the following operation
opsize
)

Ensures that there will be enough room on the underlying buffer for the following operation.

public final void
ensureCapacityAndAlignment(int
size (in bytes) of the following operation
opsize
,
int
offset (in bytes) from the current position to the first 8-byte value used in the following operation
first8ByteValueOffset
)

Convenience method that is equivalent to calling ensureCapacity() followed by ensureAlignment().

public abstract void
flushAndInvokeNow(Runnable task)

Immediately processes each operation currently pending on the buffer, and then invokes the provided task.

public abstract void
flushNow()

Immediately processes each operation currently pending on the buffer.

public void
flushNow(int position)

Updates the current position of the underlying buffer, and then flushes the queue immediately.

public final RenderBuffer
getBuffer()

Returns the encapsulated RenderBuffer object.

public final void
lock()

Locks the queue for read/write access.

public final boolean
tryLock()

Attempts to lock the queue.

public final void
unlock()

Unlocks the queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
protected RenderBuffer buf

The underlying buffer for this queue.

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE

The size of the underlying buffer, in bytes.

refSetback to summary
protected Set<Object> refSet

A Set containing hard references to Objects that must stay alive until the queue has been completely flushed.

Constructor Detail

RenderQueueback to summary
protected RenderQueue()

Method Detail

addReferenceback to summary
public final void addReference(Object ref)

Adds the given Object to the set of hard references, which will prevent that Object from being disposed until the queue has been flushed completely. This is useful in cases where some enqueued data could become invalid if the reference Object were garbage collected before the queue could be processed. (For example, keeping a hard reference to a FontStrike will prevent any enqueued glyph images associated with that strike from becoming invalid before the queue is flushed.) The reference set will be cleared immediately after the queue is flushed each time.

ensureAlignmentback to summary
public final void ensureAlignment(int first8ByteValueOffset)

Inserts a 4-byte NOOP token when necessary to ensure that all 8-byte parameters for the following operation are added to the underlying buffer with an 8-byte memory alignment.

Parameters
first8ByteValueOffset:int

offset (in bytes) from the current position to the first 8-byte value used in the following operation

ensureCapacityback to summary
public final void ensureCapacity(int opsize)

Ensures that there will be enough room on the underlying buffer for the following operation. If the operation will not fit given the remaining space, the buffer will be flushed immediately, leaving an empty buffer for the impending operation.

Parameters
opsize:int

size (in bytes) of the following operation

ensureCapacityAndAlignmentback to summary
public final void ensureCapacityAndAlignment(int opsize, int first8ByteValueOffset)

Convenience method that is equivalent to calling ensureCapacity() followed by ensureAlignment(). The ensureCapacity() call allows for an extra 4 bytes of space in case the ensureAlignment() method needs to insert a NOOP token on the buffer.

Parameters
opsize:int

size (in bytes) of the following operation

first8ByteValueOffset:int

offset (in bytes) from the current position to the first 8-byte value used in the following operation

flushAndInvokeNowback to summary
public abstract void flushAndInvokeNow(Runnable task)

Immediately processes each operation currently pending on the buffer, and then invokes the provided task. This method will block until the entire buffer has been flushed and the provided task has been executed. The queue lock must be acquired before calling this method.

flushNowback to summary
public abstract void flushNow()

Immediately processes each operation currently pending on the buffer. This method will block until the entire buffer has been flushed. The queue lock must be acquired before calling this method.

flushNowback to summary
public void flushNow(int position)

Updates the current position of the underlying buffer, and then flushes the queue immediately. This method is useful when native code has added data to the queue and needs to flush immediately.

getBufferback to summary
public final RenderBuffer getBuffer()

Returns the encapsulated RenderBuffer object.

lockback to summary
public final void lock()

Locks the queue for read/write access.

tryLockback to summary
public final boolean tryLock()

Attempts to lock the queue. If successful, this method returns true, indicating that the caller is responsible for calling unlock; otherwise this method returns false.

unlockback to summary
public final void unlock()

Unlocks the queue.