< prev index next >
src/java.desktop/share/classes/sun/java2d/pipe/BufferedContext.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 36,45 ****
--- 36,47 ----
import sun.java2d.loops.XORComposite;
import static sun.java2d.pipe.BufferedOpCodes.*;
import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN;
import java.lang.annotation.Native;
+ import java.lang.ref.Reference;
+ import java.lang.ref.WeakReference;
/**
* 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
*** 85,99 ****
* check to see if the BufferedContext passed to that method is the same
* as the one we've cached here.
*/
protected static BufferedContext currentContext;
! private AccelSurface validatedSrcData;
! private AccelSurface validatedDstData;
! private Region validatedClip;
! private Composite validatedComp;
! private Paint validatedPaint;
// renamed from isValidatedPaintAColor as part of a work around for 6764257
private boolean isValidatedPaintJustAColor;
private int validatedRGB;
private int validatedFlags;
private boolean xformInUse;
--- 87,101 ----
* check to see if the BufferedContext passed to that method is the same
* as the one we've cached here.
*/
protected static BufferedContext currentContext;
! private Reference<AccelSurface> validSrcDataRef = new WeakReference<>(null);
! private Reference<AccelSurface> validDstDataRef = new WeakReference<>(null);
! private Reference<Region> validClipRef = new WeakReference<>(null);
! private Reference<Composite> validCompRef = new WeakReference<>(null);
! private Reference<Paint> validPaintRef = new WeakReference<>(null);
// renamed from isValidatedPaintAColor as part of a work around for 6764257
private boolean isValidatedPaintJustAColor;
private int validatedRGB;
private int validatedFlags;
private boolean xformInUse;
*** 125,136 ****
AffineTransform xform,
Paint paint, SunGraphics2D sg2d,
int flags)
{
// assert rq.lock.isHeldByCurrentThread();
! BufferedContext d3dc = dstData.getContext();
! d3dc.validate(srcData, dstData,
clip, comp, xform, paint, sg2d, flags);
}
/**
* Fetches the BufferedContextassociated with the surface
--- 127,138 ----
AffineTransform xform,
Paint paint, SunGraphics2D sg2d,
int flags)
{
// assert rq.lock.isHeldByCurrentThread();
! BufferedContext context = dstData.getContext();
! context.validate(srcData, dstData,
clip, comp, xform, paint, sg2d, flags);
}
/**
* Fetches the BufferedContextassociated with the surface
*** 198,214 ****
} else {
validatedRGB = newRGB;
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) {
--- 200,218 ----
} else {
validatedRGB = newRGB;
updatePaint = true;
isValidatedPaintJustAColor = true;
}
! } else if (validPaintRef.get() != 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;
}
+ final AccelSurface validatedSrcData = validSrcDataRef.get();
+ final AccelSurface validatedDstData = validDstDataRef.get();
if ((currentContext != this) ||
(srcData != validatedSrcData) ||
(dstData != validatedDstData))
{
if (dstData != validatedDstData) {
*** 226,240 ****
// update the current source and destination surfaces
setSurfaces(srcData, dstData);
currentContext = this;
! validatedSrcData = srcData;
! validatedDstData = dstData;
}
// validate clip
if ((clip != validatedClip) || updateClip) {
if (clip != null) {
if (updateClip ||
validatedClip == null ||
!(validatedClip.isRectangular() && clip.isRectangular()) ||
--- 230,245 ----
// update the current source and destination surfaces
setSurfaces(srcData, dstData);
currentContext = this;
! validSrcDataRef = new WeakReference<>(srcData);
! validDstDataRef = new WeakReference<>(dstData);
}
// validate clip
+ final Region validatedClip = validClipRef.get();
if ((clip != validatedClip) || updateClip) {
if (clip != null) {
if (updateClip ||
validatedClip == null ||
!(validatedClip.isRectangular() && clip.isRectangular()) ||
*** 246,271 ****
setClip(clip);
}
} else {
resetClip();
}
! validatedClip = clip;
}
// 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)
! if ((comp != validatedComp) || (flags != validatedFlags)) {
if (comp != null) {
setComposite(comp, flags);
} else {
resetComposite();
}
// the paint state is dependent on the composite state, so make
// sure we update the color below
updatePaint = true;
! validatedComp = comp;
validatedFlags = flags;
}
// validate transform
boolean txChanged = false;
--- 251,276 ----
setClip(clip);
}
} else {
resetClip();
}
! validClipRef = new WeakReference<>(clip);
}
// 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)
! if ((comp != validCompRef.get()) || (flags != validatedFlags)) {
if (comp != null) {
setComposite(comp, flags);
} else {
resetComposite();
}
// the paint state is dependent on the composite state, so make
// sure we update the color below
updatePaint = true;
! validCompRef = new WeakReference<>(comp);
validatedFlags = flags;
}
// validate transform
boolean txChanged = false;
*** 295,305 ****
if (paint != null) {
BufferedPaints.setPaint(rq, sg2d, paint, flags);
} else {
BufferedPaints.resetPaint(rq);
}
! validatedPaint = paint;
}
// mark dstData dirty
// REMIND: is this really needed now? we do it in SunGraphics2D..
dstData.markDirty();
--- 300,310 ----
if (paint != null) {
BufferedPaints.setPaint(rq, sg2d, paint, flags);
} else {
BufferedPaints.resetPaint(rq);
}
! validPaintRef = new WeakReference<>(paint);
}
// mark dstData dirty
// REMIND: is this really needed now? we do it in SunGraphics2D..
dstData.markDirty();
*** 313,325 ****
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
! public void invalidateSurfaces() {
! validatedSrcData = null;
! validatedDstData = null;
}
private void setSurfaces(AccelSurface srcData,
AccelSurface dstData)
{
--- 318,330 ----
* Note: must be called while the RenderQueue lock is held.
*
* @see RenderQueue#lock
* @see RenderQueue#unlock
*/
! private void invalidateSurfaces() {
! validSrcDataRef.clear();
! validDstDataRef.clear();
}
private void setSurfaces(AccelSurface srcData,
AccelSurface dstData)
{
*** 432,444 ****
resetTransform();
resetComposite();
resetClip();
BufferedPaints.resetPaint(rq);
invalidateSurfaces();
! validatedComp = null;
! validatedClip = null;
! validatedPaint = null;
isValidatedPaintJustAColor = false;
xformInUse = false;
}
/**
--- 437,449 ----
resetTransform();
resetComposite();
resetClip();
BufferedPaints.resetPaint(rq);
invalidateSurfaces();
! validCompRef.clear();
! validClipRef.clear();
! validPaintRef.clear();
isValidatedPaintJustAColor = false;
xformInUse = false;
}
/**
< prev index next >