public abstract class

RenderQueue

extends Object
java.lang.Object
   ↳ sun.java2d.pipe.RenderQueue
Known Direct Subclasses

Class Overview

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(); } }

Summary

Fields
protected RenderBuffer buf The underlying buffer for this queue.
protected Set refSet A Set containing hard references to Objects that must stay alive until the queue has been completely flushed.
Protected Constructors
RenderQueue()
Public Methods
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.
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.
final void ensureCapacity(int opsize)
Ensures that there will be enough room on the underlying buffer for the following operation.
final void ensureCapacityAndAlignment(int opsize, int first8ByteValueOffset)
Convenience method that is equivalent to calling ensureCapacity() followed by ensureAlignment().
abstract void flushAndInvokeNow(Runnable task)
Immediately processes each operation currently pending on the buffer, and then invokes the provided task.
void flushNow(int position)
Updates the current position of the underlying buffer, and then flushes the queue immediately.
abstract void flushNow()
Immediately processes each operation currently pending on the buffer.
final RenderBuffer getBuffer()
Returns the encapsulated RenderBuffer object.
final void lock()
Locks the queue for read/write access.
final boolean tryLock()
Attempts to lock the queue.
final void unlock()
Unlocks the queue.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected RenderBuffer buf

The underlying buffer for this queue.

protected Set refSet

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

Protected Constructors

protected RenderQueue ()

Public Methods

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.

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 offset (in bytes) from the current position to the first 8-byte value used in the following operation

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 size (in bytes) of the following operation

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 size (in bytes) of the following operation
first8ByteValueOffset offset (in bytes) from the current position to the first 8-byte value used in the following operation

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.

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.

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.

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. If successful, this method returns true, indicating that the caller is responsible for calling unlock; otherwise this method returns false.

public final void unlock ()

Unlocks the queue.