src/macosx/classes/sun/lwawt/LWWindowPeer.java
Print this page
@@ -35,10 +35,11 @@
import sun.awt.*;
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
extends LWContainerPeer<Window, JComponent>
implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
@@ -107,10 +108,12 @@
private static LWWindowPeer grabbingWindow;
private volatile boolean skipNextFocusChange;
+ private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
+
/**
* Current modal blocker or null.
*
* Synchronization: peerTreeLock.
*/
@@ -167,20 +170,25 @@
}
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);
}
setOpaque(getTarget().isOpaque());
updateInsets(platformWindow.getInsets());
if (getSurfaceData() == null) {
- replaceSurfaceData();
+ replaceSurfaceData(false);
}
}
// Just a helper method
public PlatformWindow getPlatformWindow() {
@@ -292,11 +300,11 @@
// unsupported, and 1 corresponds to a SingleBufferStrategy which
// doesn't depend on the peer. Screen is considered as a separate
// "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());
}
}
@@ -432,23 +440,36 @@
@Override
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() {
+ return !isOpaque() || isShaped();
+ }
+
+ @Override
+ final void applyShapeImpl(final Region shape) {
+ super.applyShapeImpl(shape);
+ updateOpaque();
}
@Override
public void repositionSecurityWarning() {
throw new RuntimeException("not implemented");
@@ -550,11 +571,11 @@
// back buffer here unconditionally, so some flickering may appear.
// A possible solution is to split postPaintEvent() into two parts,
// and override that part which is only called after if
// createPaintEvent() returned non-null value and flush the buffer
// from the overridden method
- flushOnscreenGraphics();
+ //flushOnscreenGraphics();
repaintPeer(new Rectangle(x, y, w, h));
}
/**
* Called by the delegate when this window is moved/resized by user.
@@ -595,14 +616,21 @@
handleResize(w, h,true);
}
}
private void clearBackground(final int w, final int h) {
- final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
+ final Graphics2D g = (Graphics2D) getOnscreenGraphics(getForeground(),
+ getBackground(),
getFont());
if (g != null) {
try {
+ if (isTranslucent()) {
+ g.setBackground(nonOpaqueBackground);
+ g.clearRect(0, 0, w, h);
+ }
+ SG2DConstraint((SunGraphics2D) g, getRegion());
+ g.setBackground(getBackground());
g.clearRect(0, 0, w, h);
} finally {
g.dispose();
}
}
@@ -906,54 +934,30 @@
AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
}
});
}
- /**
- * 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.
*/
public SurfaceData getSurfaceData() {
synchronized (surfaceDataLock) {
return surfaceData;
}
}
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();
// TODO: volatile image
// VolatileImage oldBB = backBuffer;
@@ -962,28 +966,32 @@
backBufferCaps = newBackBufferCaps;
final Rectangle size = getSize();
if (getSurfaceData() != null && oldData != getSurfaceData()) {
clearBackground(size.width, size.height);
}
+
+ if (blit) {
blitSurfaceData(oldData, getSurfaceData());
+ }
if (oldData != null && oldData != getSurfaceData()) {
// TODO: drop oldData for D3D/WGL pipelines
// This can only happen when this peer is being created
oldData.flush();
}
// TODO: volatile image
- // backBuffer = (VolatileImage)delegate.createBackBuffer();
+ //backBuffer = (VolatileImage)delegate.createBackBuffer();
+ if (oldBB != null) {
backBuffer = (BufferedImage) platformWindow.createBackBuffer();
if (backBuffer != null) {
- Graphics g = backBuffer.getGraphics();
+ Graphics2D g = (Graphics2D) backBuffer.getGraphics();
try {
Rectangle r = getBounds();
- g.setColor(getForeground());
- ((Graphics2D) g).setBackground(getBackground());
+ g.setBackground(nonOpaqueBackground);
g.clearRect(0, 0, r.width, r.height);
+ SG2DConstraint((SunGraphics2D) g, getRegion());
if (oldBB != null) {
// Draw the old back buffer to the new one
g.drawImage(oldBB, 0, 0, null);
oldBB.flush();
}
@@ -991,10 +999,11 @@
g.dispose();
}
}
}
}
+ }
private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
//TODO blit. proof-of-concept
if (src != dst && src != null && dst != null
&& !(dst instanceof NullSurfaceData)