--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu Jun 28 14:05:06 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java Wed Jul 04 14:38:14 2012 +0400
@@ -37,6 +37,7 @@
import sun.java2d.*;
import sun.java2d.loops.Blit;
import sun.java2d.loops.CompositeType;
+import sun.java2d.pipe.Region;
import sun.util.logging.PlatformLogger;
public class LWWindowPeer
@@ -109,6 +110,8 @@
private volatile boolean skipNextFocusChange;
+ private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
+
/**
* Current modal blocker or null.
*
@@ -169,6 +172,11 @@
setAlwaysOnTop(getTarget().isAlwaysOnTop());
updateMinimumSize();
+ final Shape shape = getTarget().getShape();
+ if (shape != null) {
+ applyShape(Region.getInstance(shape, null));
+ }
+
final float opacity = getTarget().getOpacity();
if (opacity < 1.0f) {
setOpacity(opacity);
@@ -178,7 +186,7 @@
updateInsets(platformWindow.getInsets());
if (getSurfaceData() == null) {
- replaceSurfaceData();
+ replaceSurfaceData(false);
}
}
@@ -280,7 +288,7 @@
// "buffer", that's why numBuffers - 1
assert numBuffers > 1;
- replaceSurfaceData(numBuffers - 1, caps);
+ replaceSurfaceData(numBuffers - 1, caps, false);
} catch (InvalidPipeException z) {
throw new AWTException(z.toString());
}
@@ -420,19 +428,30 @@
public final void setOpaque(final boolean isOpaque) {
if (this.isOpaque != isOpaque) {
this.isOpaque = isOpaque;
- getPlatformWindow().setOpaque(isOpaque);
- replaceSurfaceData();
- repaintPeer();
+ updateOpaque();
}
}
- public final boolean isOpaque() {
- return isOpaque;
+ private void updateOpaque() {
+ getPlatformWindow().setOpaque(!isTranslucent());
+ replaceSurfaceData(false);
+ repaintPeer();
}
@Override
public void updateWindow() {
- flushOffscreenGraphics();
+ }
+
+ public final boolean isTranslucent() {
+ synchronized (getStateLock()) {
+ return !isOpaque || isShaped();
+ }
+ }
+
+ @Override
+ final void applyShapeImpl(final Region shape) {
+ super.applyShapeImpl(shape);
+ updateOpaque();
}
@Override
@@ -587,7 +606,18 @@
getFont());
if (g != null) {
try {
- g.clearRect(0, 0, w, h);
+ if (g instanceof Graphics2D) {
+ ((Graphics2D) g).setComposite(AlphaComposite.Src);
+ }
+ if (isTranslucent()) {
+ g.setColor(nonOpaqueBackground);
+ g.fillRect(0, 0, w, h);
+ }
+ if (g instanceof SunGraphics2D) {
+ SG2DConstraint((SunGraphics2D) g, getRegion());
+ }
+ g.setColor(getBackground());
+ g.fillRect(0, 0, w, h);
} finally {
g.dispose();
}
@@ -894,35 +924,6 @@
});
}
- /**
- * This method returns a back buffer Graphics to render all the
- * peers to. After the peer is painted, the back buffer contents
- * should be flushed to the screen. All the target painting
- * (Component.paint() method) should be done directly to the screen.
- */
- protected final Graphics getOffscreenGraphics(Color fg, Color bg, Font f) {
- final Image bb = getBackBuffer();
- if (bb == null) {
- return null;
- }
- if (fg == null) {
- fg = SystemColor.windowText;
- }
- if (bg == null) {
- bg = SystemColor.window;
- }
- if (f == null) {
- f = DEFAULT_FONT;
- }
- final Graphics2D g = (Graphics2D) bb.getGraphics();
- if (g != null) {
- g.setColor(fg);
- g.setBackground(bg);
- g.setFont(f);
- }
- return g;
- }
-
/*
* May be called by delegate to provide SD to Java2D code.
*/
@@ -933,11 +934,16 @@
}
private void replaceSurfaceData() {
- replaceSurfaceData(backBufferCount, backBufferCaps);
+ replaceSurfaceData(true);
+ }
+
+ private void replaceSurfaceData(boolean blit) {
+ replaceSurfaceData(backBufferCount, backBufferCaps, blit);
}
private void replaceSurfaceData(int newBackBufferCount,
- BufferCapabilities newBackBufferCaps) {
+ BufferCapabilities newBackBufferCaps,
+ boolean blit) {
synchronized (surfaceDataLock) {
final SurfaceData oldData = getSurfaceData();
surfaceData = platformWindow.replaceSurfaceData();
@@ -950,7 +956,10 @@
if (getSurfaceData() != null && oldData != getSurfaceData()) {
clearBackground(size.width, size.height);
}
- blitSurfaceData(oldData, getSurfaceData());
+
+ if (blit) {
+ blitSurfaceData(oldData, getSurfaceData());
+ }
if (oldData != null && oldData != getSurfaceData()) {
// TODO: drop oldData for D3D/WGL pipelines
@@ -965,10 +974,15 @@
Graphics g = backBuffer.getGraphics();
try {
Rectangle r = getBounds();
- g.setColor(getBackground());
if (g instanceof Graphics2D) {
((Graphics2D) g).setComposite(AlphaComposite.Src);
}
+ g.setColor(nonOpaqueBackground);
+ g.fillRect(0, 0, r.width, r.height);
+ if (g instanceof SunGraphics2D) {
+ SG2DConstraint((SunGraphics2D) g, getRegion());
+ }
+ g.setColor(getBackground());
g.fillRect(0, 0, r.width, r.height);
if (oldBB != null) {
// Draw the old back buffer to the new one
@@ -993,7 +1007,7 @@
CompositeType.Src,
dst.getSurfaceType());
if (blit != null) {
- blit.Blit(src, dst, ((Graphics2D) getGraphics()).getComposite(),
+ blit.Blit(src, dst, AlphaComposite.Src,
getRegion(), 0, 0, 0, 0, size.width, size.height);
}
}