/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Base context class for managing state in a single-threaded rendering
* environment. Each state-setting operation (e.g. SET_COLOR) is added to
* the provided RenderQueue, which will be processed at a later time by a
* single thread. Note that the RenderQueue lock must be acquired before
* calling the validate() method (or any other method in this class). See
* the RenderQueue class comments for a sample usage scenario.
*
* @see RenderQueue
*/
public abstract class BufferedContext {
/*
* The following flags help the internals of validate() determine
* the appropriate (meaning correct, or optimal) code path when
* setting up the current context. The flags can be bitwise OR'd
* together as needed.
*/
/**
* Indicates that no flags are needed; take all default code paths.
*/
/**
* Indicates that the source surface (or color value, if it is a simple
* rendering operation) is opaque (has an alpha value of 1.0). If this
* flag is present, it allows us to disable blending in certain
* situations in order to improve performance.
*/
/**
* Indicates that the operation uses an alpha mask, which may determine
* the code path that is used when setting up the current paint state.
*/
/**
* This is a reference to the most recently validated BufferedContext. If
* this value is null, it means that there is no current context. It is
* provided here so that validate() only needs to do a quick reference
* check to see if the BufferedContext passed to that method is the same
* as the one we've cached here.
*/
// renamed from isValidatedPaintAColor as part of a work around for 6764257
private boolean isValidatedPaintJustAColor;
private int validatedRGB;
private int validatedFlags;
private boolean xformInUse;
}
/**
* Fetches the BufferedContextContext associated with the dst. surface
* and validates the context using the given parameters. Most rendering
* operations will call this method first in order to set the necessary
* state before issuing rendering commands.
*
* Note: must be called while the RenderQueue lock is held.
*
* It's assumed that the type of surfaces has been checked by the Renderer
*
* @throws InvalidPipeException if either src or dest surface is not valid
* or lost
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
int flags)
{
// assert rq.lock.isHeldByCurrentThread();
}
/**
* Fetches the BufferedContextassociated with the surface
* and disables all context state settings.
*
* Note: must be called while the RenderQueue lock is held.
*
* It's assumed that the type of surfaces has been checked by the Renderer
*
* @throws InvalidPipeException if the surface is not valid
* or lost
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
// assert rt.lock.isHeldByCurrentThread();
}
/**
* Validates the given parameters against the current state for this
* context. If this context is not current, it will be made current
* for the given source and destination surfaces, and the viewport will
* be updated. Then each part of the context state (clip, composite,
* etc.) is checked against the previous value. If the value has changed
* since the last call to validate(), it will be updated accordingly.
*
* Note that the SunGraphics2D parameter is only used for the purposes
* of validating a (non-null) Paint parameter. In all other cases it
* is safe to pass a null SunGraphics2D and it will be ignored.
*
* Note: must be called while the RenderQueue lock is held.
*
* It's assumed that the type of surfaces has been checked by the Renderer
*
* @throws InvalidPipeException if either src or dest surface is not valid
* or lost
*/
{
// assert rq.lock.isHeldByCurrentThread();
boolean updateClip = false;
boolean updatePaint = false;
{
throw new InvalidPipeException("bounds changed or surface lost");
}
// REMIND: not 30-bit friendly
if (isValidatedPaintJustAColor) {
if (newRGB != validatedRGB) {
updatePaint = true;
}
} else {
updatePaint = true;
isValidatedPaintJustAColor = true;
}
} else if (validatedPaint != paint) {
updatePaint = true;
// this should be set when we are switching from paint to color
// in which case this condition will be true
isValidatedPaintJustAColor = false;
}
if ((currentContext != this) ||
(srcData != validatedSrcData) ||
(dstData != validatedDstData))
{
if (dstData != validatedDstData) {
// the clip is dependent on the destination surface, so we
// need to update it if we have a new destination surface
updateClip = true;
}
// make sure we update the color state (otherwise, it might
// not be updated if this is the first time the context
// is being validated)
updatePaint = true;
}
// update the current source and destination surfaces
currentContext = this;
}
// validate clip
if (updateClip ||
validatedClip == null ||
{
}
} else {
resetClip();
}
}
// validate composite (note that a change in the context flags
// may require us to update the composite state, even if the
// composite has not changed)
} else {
}
// the paint state is dependent on the composite state, so make
// sure we update the color below
updatePaint = true;
}
// validate transform
boolean txChanged = false;
if (xformInUse) {
xformInUse = false;
txChanged = true;
txChanged = true;
}
}
} else {
xformInUse = true;
txChanged = true;
}
// non-Color paints may require paint revalidation
if (!isValidatedPaintJustAColor && txChanged) {
updatePaint = true;
}
// validate paint
if (updatePaint) {
} else {
}
}
// mark dstData dirty
// REMIND: is this really needed now? we do it in SunGraphics2D..
}
/**
* Invalidates the surfaces associated with this context. This is
* useful when the context is no longer needed, and we want to break
* the chain caused by these surface references.
*
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
public void invalidateSurfaces() {
}
{
// assert rq.lock.isHeldByCurrentThread();
}
private void resetClip() {
// assert rq.lock.isHeldByCurrentThread();
}
// assert rq.lock.isHeldByCurrentThread();
if (clip.isRectangular()) {
} else {
// include a placeholder for the span count
int spanCount = 0;
int span[] = new int[4];
if (remainingSpans == 0) {
spanCount = 0;
}
spanCount++;
}
}
}
private void resetComposite() {
// assert rq.lock.isHeldByCurrentThread();
}
// assert rq.lock.isHeldByCurrentThread();
if (comp instanceof AlphaComposite) {
} else if (comp instanceof XORComposite) {
} else {
throw new InternalError("not yet implemented");
}
}
private void resetTransform() {
// assert rq.lock.isHeldByCurrentThread();
}
// assert rq.lock.isHeldByCurrentThread();
}
/**
* Resets this context's surfaces and all attributes.
*
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
public void invalidateContext() {
resetClip();
isValidatedPaintJustAColor = false;
xformInUse = false;
}
/**
* Returns a singleton {@code RenderQueue} object used by the rendering
* pipeline.
*
* @return a render queue
* @see RenderQueue
*/
/**
* Saves the the state of this context.
* It may reset the current context.
*
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
public abstract void saveState();
/**
* Restores the native state of this context.
* It may reset the current context.
*
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
public abstract void restoreState();
}