src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;

  40 import sun.util.logging.PlatformLogger;
  41 
  42 public class LWWindowPeer
  43     extends LWContainerPeer<Window, JComponent>
  44     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  45 {
  46     public static enum PeerType {
  47         SIMPLEWINDOW,
  48         FRAME,
  49         DIALOG,
  50         EMBEDDEDFRAME
  51     }
  52 
  53     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  54 
  55     private PlatformWindow platformWindow;
  56 
  57     // Window bounds reported by the native system (as opposed to
  58     // regular bounds inherited from LWComponentPeer which are
  59     // requested by user and may haven't been applied yet because


  92     // find the component under cursor
  93     private static volatile LWComponentPeer lastMouseEventPeer = null;
  94 
  95     // Peers where all dragged/released events should come to,
  96     // depending on what mouse button is being dragged according to Cocoa
  97     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  98 
  99     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 100     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 101     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 102     private static int mouseClickButtons = 0;
 103 
 104     private volatile boolean isOpaque = true;
 105 
 106     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 107 
 108     private static LWWindowPeer grabbingWindow;
 109 
 110     private volatile boolean skipNextFocusChange;
 111 


 112     /**
 113      * Current modal blocker or null.
 114      *
 115      * Synchronization: peerTreeLock.
 116      */
 117     private LWWindowPeer blocker;
 118 
 119     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 120                         PlatformWindow platformWindow)
 121     {
 122         super(target, platformComponent);
 123         this.platformWindow = platformWindow;
 124 
 125         Window owner = target.getOwner();
 126         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 127         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 128 
 129         // The delegate.initialize() needs a non-null GC on X11.
 130         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 131         synchronized (getStateLock()) {


 152             // we should not call setForeground because it will call a repaint
 153             // which the peer may not be ready to do yet.
 154         }
 155 
 156         platformWindow.initialize(target, this, ownerDelegate);
 157     }
 158 
 159     @Override
 160     void initializeImpl() {
 161         super.initializeImpl();
 162         if (getTarget() instanceof Frame) {
 163             setTitle(((Frame) getTarget()).getTitle());
 164             setState(((Frame) getTarget()).getExtendedState());
 165         } else if (getTarget() instanceof Dialog) {
 166             setTitle(((Dialog) getTarget()).getTitle());
 167         }
 168 
 169         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 170         updateMinimumSize();
 171 





 172         final float opacity = getTarget().getOpacity();
 173         if (opacity < 1.0f) {
 174             setOpacity(opacity);
 175         }
 176 
 177         setOpaque(getTarget().isOpaque());
 178 
 179         updateInsets(platformWindow.getInsets());
 180         if (getSurfaceData() == null) {
 181             replaceSurfaceData();
 182         }
 183     }
 184 
 185     // Just a helper method
 186     public PlatformWindow getPlatformWindow() {
 187         return platformWindow;
 188     }
 189 
 190     @Override
 191     protected LWWindowPeer getWindowPeerOrSelf() {
 192         return this;
 193     }
 194 
 195     @Override
 196     protected void initializeContainerPeer() {
 197         // No-op as LWWindowPeer doesn't have any containerPeer
 198     }
 199 
 200     // ---- PEER METHODS ---- //
 201 


 263         if (bg == null) {
 264             bg = SystemColor.window;
 265         }
 266         if (f == null) {
 267             f = DEFAULT_FONT;
 268         }
 269         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 270     }
 271 
 272     @Override
 273     public void createBuffers(int numBuffers, BufferCapabilities caps)
 274         throws AWTException
 275     {
 276         try {
 277             // Assume this method is never called with numBuffers <= 1, as 0 is
 278             // unsupported, and 1 corresponds to a SingleBufferStrategy which
 279             // doesn't depend on the peer. Screen is considered as a separate
 280             // "buffer", that's why numBuffers - 1
 281             assert numBuffers > 1;
 282 
 283             replaceSurfaceData(numBuffers - 1, caps);
 284         } catch (InvalidPipeException z) {
 285             throw new AWTException(z.toString());
 286         }
 287     }
 288 
 289     @Override
 290     public final Image getBackBuffer() {
 291         synchronized (getStateLock()) {
 292             return backBuffer;
 293         }
 294     }
 295 
 296     @Override
 297     public void flip(int x1, int y1, int x2, int y2,
 298                      BufferCapabilities.FlipContents flipAction)
 299     {
 300         platformWindow.flip(x1, y1, x2, y2, flipAction);
 301     }
 302 
 303     @Override


 403             d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 404         }
 405         platformWindow.setMinimumSize(d.width, d.height);
 406     }
 407 
 408     @Override
 409     public void updateIconImages() {
 410         getPlatformWindow().updateIconImages();
 411     }
 412 
 413     @Override
 414     public void setOpacity(float opacity) {
 415         getPlatformWindow().setOpacity(opacity);
 416         repaintPeer();
 417     }
 418 
 419     @Override
 420     public final void setOpaque(final boolean isOpaque) {
 421         if (this.isOpaque != isOpaque) {
 422             this.isOpaque = isOpaque;
 423             getPlatformWindow().setOpaque(isOpaque);
 424             replaceSurfaceData();
 425             repaintPeer();
 426         }
 427     }
 428 
 429     public final boolean isOpaque() {
 430         return isOpaque;
 431     }
 432 






 433     @Override
 434     public void updateWindow() {
 435         flushOffscreenGraphics();









 436     }
 437 
 438     @Override
 439     public void repositionSecurityWarning() {
 440         throw new RuntimeException("not implemented");
 441     }
 442 
 443     // ---- FRAME PEER METHODS ---- //
 444 
 445     @Override // FramePeer and DialogPeer
 446     public void setTitle(String title) {
 447         platformWindow.setTitle(title == null ? "" : title);
 448     }
 449 
 450     @Override
 451     public void setMenuBar(MenuBar mb) {
 452          platformWindow.setMenuBar(mb);
 453     }
 454 
 455     @Override // FramePeer and DialogPeer


 582         checkIfOnNewScreen();
 583         if (resized) {
 584             replaceSurfaceData();
 585             flushOnscreenGraphics();
 586         }
 587 
 588         // Third, COMPONENT_MOVED/COMPONENT_RESIZED events
 589         if (moved) {
 590             handleMove(x, y, true);
 591         }
 592         if (resized) {
 593             handleResize(w, h,true);
 594         }
 595     }
 596 
 597     private void clearBackground(final int w, final int h) {
 598         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 599                                                getFont());
 600         if (g != null) {
 601             try {
 602                 g.clearRect(0, 0, w, h);











 603             } finally {
 604                 g.dispose();
 605             }
 606         }
 607     }
 608 
 609     public void notifyUpdateCursor() {
 610         getLWToolkit().getCursorManager().updateCursorLater(this);
 611     }
 612 
 613     public void notifyActivation(boolean activation) {
 614         changeFocusedWindow(activation);
 615     }
 616 
 617     // MouseDown in non-client area
 618     public void notifyNCMouseDown() {
 619         // Ungrab except for a click on a Dialog with the grabbing owner
 620         if (grabbingWindow != null &&
 621             grabbingWindow != getOwnerFrameDialog(this))
 622         {


 889         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 890         synchronized (getStateLock()) {
 891             if (graphicsDevice == newGraphicsDevice) {
 892                 return;
 893             }
 894             graphicsDevice = newGraphicsDevice;
 895         }
 896 
 897         // TODO: DisplayChangedListener stuff
 898         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 899 
 900         if (!setGraphicsConfig(newGC)) return;
 901 
 902         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 903             public void run() {
 904                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 905             }
 906         });
 907     }
 908 
 909     /**
 910      * This method returns a back buffer Graphics to render all the
 911      * peers to. After the peer is painted, the back buffer contents
 912      * should be flushed to the screen. All the target painting
 913      * (Component.paint() method) should be done directly to the screen.
 914      */
 915     protected final Graphics getOffscreenGraphics(Color fg, Color bg, Font f) {
 916         final Image bb = getBackBuffer();
 917         if (bb == null) {
 918             return null;
 919         }
 920         if (fg == null) {
 921             fg = SystemColor.windowText;
 922         }
 923         if (bg == null) {
 924             bg = SystemColor.window;
 925         }
 926         if (f == null) {
 927             f = DEFAULT_FONT;
 928         }
 929         final Graphics2D g = (Graphics2D) bb.getGraphics();
 930         if (g != null) {
 931             g.setColor(fg);
 932             g.setBackground(bg);
 933             g.setFont(f);
 934         }
 935         return g;
 936     }
 937 
 938     /*
 939      * May be called by delegate to provide SD to Java2D code.
 940      */
 941     public SurfaceData getSurfaceData() {
 942         synchronized (surfaceDataLock) {
 943             return surfaceData;
 944         }
 945     }
 946 
 947     private void replaceSurfaceData() {
 948         replaceSurfaceData(backBufferCount, backBufferCaps);




 949     }
 950 
 951     private void replaceSurfaceData(int newBackBufferCount,
 952                                                  BufferCapabilities newBackBufferCaps) {

 953         synchronized (surfaceDataLock) {
 954             final SurfaceData oldData = getSurfaceData();
 955             surfaceData = platformWindow.replaceSurfaceData();
 956             // TODO: volatile image
 957     //        VolatileImage oldBB = backBuffer;
 958             BufferedImage oldBB = backBuffer;
 959             backBufferCount = newBackBufferCount;
 960             backBufferCaps = newBackBufferCaps;
 961             final Rectangle size = getSize();
 962             if (getSurfaceData() != null && oldData != getSurfaceData()) {
 963                 clearBackground(size.width, size.height);
 964             }


 965             blitSurfaceData(oldData, getSurfaceData());

 966 
 967             if (oldData != null && oldData != getSurfaceData()) {
 968                 // TODO: drop oldData for D3D/WGL pipelines
 969                 // This can only happen when this peer is being created
 970                 oldData.flush();
 971             }
 972 
 973             // TODO: volatile image
 974     //        backBuffer = (VolatileImage)delegate.createBackBuffer();


 975             backBuffer = (BufferedImage) platformWindow.createBackBuffer();
 976             if (backBuffer != null) {
 977                 Graphics g = backBuffer.getGraphics();
 978                 try {
 979                     Rectangle r = getBounds();
 980                     g.setColor(getBackground());
 981                     if (g instanceof Graphics2D) {
 982                         ((Graphics2D) g).setComposite(AlphaComposite.Src);
 983                     }






 984                     g.fillRect(0, 0, r.width, r.height);
 985                     if (oldBB != null) {
 986                         // Draw the old back buffer to the new one
 987                         g.drawImage(oldBB, 0, 0, null);
 988                         oldBB.flush();
 989                     }
 990                 } finally {
 991                     g.dispose();
 992                 }
 993             }
 994         }
 995     }

 996 
 997     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
 998         //TODO blit. proof-of-concept
 999         if (src != dst && src != null && dst != null
1000             && !(dst instanceof NullSurfaceData)
1001             && !(src instanceof NullSurfaceData)
1002             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1003             final Rectangle size = getSize();
1004             final Blit blit = Blit.locate(src.getSurfaceType(),
1005                                           CompositeType.Src,
1006                                           dst.getSurfaceType());
1007             if (blit != null) {
1008                 blit.Blit(src, dst, ((Graphics2D) getGraphics()).getComposite(),
1009                           getRegion(), 0, 0, 0, 0, size.width, size.height);
1010             }
1011         }
1012     }
1013 
1014     public int getBackBufferCount() {
1015         return backBufferCount;
1016     }
1017 
1018     public BufferCapabilities getBackBufferCaps() {
1019         return backBufferCaps;
1020     }
1021 
1022     /*
1023      * Request the window insets from the delegate and compares it
1024      * with the current one. This method is mostly called by the
1025      * delegate, e.g. when the window state is changed and insets
1026      * should be recalculated.
1027      *
1028      * This method may be called on the toolkit thread.




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.image.BufferedImage;
  31 import java.awt.peer.*;
  32 import java.util.List;
  33 
  34 import javax.swing.*;
  35 
  36 import sun.awt.*;
  37 import sun.java2d.*;
  38 import sun.java2d.loops.Blit;
  39 import sun.java2d.loops.CompositeType;
  40 import sun.java2d.pipe.Region;
  41 import sun.util.logging.PlatformLogger;
  42 
  43 public class LWWindowPeer
  44     extends LWContainerPeer<Window, JComponent>
  45     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  46 {
  47     public static enum PeerType {
  48         SIMPLEWINDOW,
  49         FRAME,
  50         DIALOG,
  51         EMBEDDEDFRAME
  52     }
  53 
  54     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  55 
  56     private PlatformWindow platformWindow;
  57 
  58     // Window bounds reported by the native system (as opposed to
  59     // regular bounds inherited from LWComponentPeer which are
  60     // requested by user and may haven't been applied yet because


  93     // find the component under cursor
  94     private static volatile LWComponentPeer lastMouseEventPeer = null;
  95 
  96     // Peers where all dragged/released events should come to,
  97     // depending on what mouse button is being dragged according to Cocoa
  98     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  99 
 100     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 101     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 102     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 103     private static int mouseClickButtons = 0;
 104 
 105     private volatile boolean isOpaque = true;
 106 
 107     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 108 
 109     private static LWWindowPeer grabbingWindow;
 110 
 111     private volatile boolean skipNextFocusChange;
 112 
 113     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 114 
 115     /**
 116      * Current modal blocker or null.
 117      *
 118      * Synchronization: peerTreeLock.
 119      */
 120     private LWWindowPeer blocker;
 121 
 122     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 123                         PlatformWindow platformWindow)
 124     {
 125         super(target, platformComponent);
 126         this.platformWindow = platformWindow;
 127 
 128         Window owner = target.getOwner();
 129         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 130         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 131 
 132         // The delegate.initialize() needs a non-null GC on X11.
 133         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 134         synchronized (getStateLock()) {


 155             // we should not call setForeground because it will call a repaint
 156             // which the peer may not be ready to do yet.
 157         }
 158 
 159         platformWindow.initialize(target, this, ownerDelegate);
 160     }
 161 
 162     @Override
 163     void initializeImpl() {
 164         super.initializeImpl();
 165         if (getTarget() instanceof Frame) {
 166             setTitle(((Frame) getTarget()).getTitle());
 167             setState(((Frame) getTarget()).getExtendedState());
 168         } else if (getTarget() instanceof Dialog) {
 169             setTitle(((Dialog) getTarget()).getTitle());
 170         }
 171 
 172         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 173         updateMinimumSize();
 174 
 175         final Shape shape = getTarget().getShape();
 176         if (shape != null) {
 177             applyShape(Region.getInstance(shape, null));
 178         }
 179 
 180         final float opacity = getTarget().getOpacity();
 181         if (opacity < 1.0f) {
 182             setOpacity(opacity);
 183         }
 184 
 185         setOpaque(getTarget().isOpaque());
 186 
 187         updateInsets(platformWindow.getInsets());
 188         if (getSurfaceData() == null) {
 189             replaceSurfaceData(false);
 190         }
 191     }
 192 
 193     // Just a helper method
 194     public PlatformWindow getPlatformWindow() {
 195         return platformWindow;
 196     }
 197 
 198     @Override
 199     protected LWWindowPeer getWindowPeerOrSelf() {
 200         return this;
 201     }
 202 
 203     @Override
 204     protected void initializeContainerPeer() {
 205         // No-op as LWWindowPeer doesn't have any containerPeer
 206     }
 207 
 208     // ---- PEER METHODS ---- //
 209 


 271         if (bg == null) {
 272             bg = SystemColor.window;
 273         }
 274         if (f == null) {
 275             f = DEFAULT_FONT;
 276         }
 277         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 278     }
 279 
 280     @Override
 281     public void createBuffers(int numBuffers, BufferCapabilities caps)
 282         throws AWTException
 283     {
 284         try {
 285             // Assume this method is never called with numBuffers <= 1, as 0 is
 286             // unsupported, and 1 corresponds to a SingleBufferStrategy which
 287             // doesn't depend on the peer. Screen is considered as a separate
 288             // "buffer", that's why numBuffers - 1
 289             assert numBuffers > 1;
 290 
 291             replaceSurfaceData(numBuffers - 1, caps, false);
 292         } catch (InvalidPipeException z) {
 293             throw new AWTException(z.toString());
 294         }
 295     }
 296 
 297     @Override
 298     public final Image getBackBuffer() {
 299         synchronized (getStateLock()) {
 300             return backBuffer;
 301         }
 302     }
 303 
 304     @Override
 305     public void flip(int x1, int y1, int x2, int y2,
 306                      BufferCapabilities.FlipContents flipAction)
 307     {
 308         platformWindow.flip(x1, y1, x2, y2, flipAction);
 309     }
 310 
 311     @Override


 411             d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 412         }
 413         platformWindow.setMinimumSize(d.width, d.height);
 414     }
 415 
 416     @Override
 417     public void updateIconImages() {
 418         getPlatformWindow().updateIconImages();
 419     }
 420 
 421     @Override
 422     public void setOpacity(float opacity) {
 423         getPlatformWindow().setOpacity(opacity);
 424         repaintPeer();
 425     }
 426 
 427     @Override
 428     public final void setOpaque(final boolean isOpaque) {
 429         if (this.isOpaque != isOpaque) {
 430             this.isOpaque = isOpaque;
 431             updateOpaque();


 432         }
 433     }
 434 
 435     public final boolean isOpaque() {
 436         return isOpaque;
 437     }
 438 
 439     private void updateOpaque() {
 440         getPlatformWindow().setOpaque(!isTranslucent());
 441         replaceSurfaceData(false);
 442         repaintPeer();
 443     }
 444 
 445     @Override
 446     public void updateWindow() {
 447     }
 448 
 449     public final boolean isTranslucent() {
 450         return !isOpaque() || isShaped();
 451     }
 452 
 453     @Override
 454     final void applyShapeImpl(final Region shape) {
 455         super.applyShapeImpl(shape);
 456         updateOpaque();
 457     }
 458 
 459     @Override
 460     public void repositionSecurityWarning() {
 461         throw new RuntimeException("not implemented");
 462     }
 463 
 464     // ---- FRAME PEER METHODS ---- //
 465 
 466     @Override // FramePeer and DialogPeer
 467     public void setTitle(String title) {
 468         platformWindow.setTitle(title == null ? "" : title);
 469     }
 470 
 471     @Override
 472     public void setMenuBar(MenuBar mb) {
 473          platformWindow.setMenuBar(mb);
 474     }
 475 
 476     @Override // FramePeer and DialogPeer


 603         checkIfOnNewScreen();
 604         if (resized) {
 605             replaceSurfaceData();
 606             flushOnscreenGraphics();
 607         }
 608 
 609         // Third, COMPONENT_MOVED/COMPONENT_RESIZED events
 610         if (moved) {
 611             handleMove(x, y, true);
 612         }
 613         if (resized) {
 614             handleResize(w, h,true);
 615         }
 616     }
 617 
 618     private void clearBackground(final int w, final int h) {
 619         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 620                                                getFont());
 621         if (g != null) {
 622             try {
 623                 if (g instanceof Graphics2D) {
 624                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 625                 }
 626                 if (isTranslucent()) {
 627                     g.setColor(nonOpaqueBackground);
 628                     g.fillRect(0, 0, w, h);
 629                 }
 630                 if (g instanceof SunGraphics2D) {
 631                     SG2DConstraint((SunGraphics2D) g, getRegion());
 632                 }
 633                 g.setColor(getBackground());
 634                 g.fillRect(0, 0, w, h);
 635             } finally {
 636                 g.dispose();
 637             }
 638         }
 639     }
 640 
 641     public void notifyUpdateCursor() {
 642         getLWToolkit().getCursorManager().updateCursorLater(this);
 643     }
 644 
 645     public void notifyActivation(boolean activation) {
 646         changeFocusedWindow(activation);
 647     }
 648 
 649     // MouseDown in non-client area
 650     public void notifyNCMouseDown() {
 651         // Ungrab except for a click on a Dialog with the grabbing owner
 652         if (grabbingWindow != null &&
 653             grabbingWindow != getOwnerFrameDialog(this))
 654         {


 921         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 922         synchronized (getStateLock()) {
 923             if (graphicsDevice == newGraphicsDevice) {
 924                 return;
 925             }
 926             graphicsDevice = newGraphicsDevice;
 927         }
 928 
 929         // TODO: DisplayChangedListener stuff
 930         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 931 
 932         if (!setGraphicsConfig(newGC)) return;
 933 
 934         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 935             public void run() {
 936                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 937             }
 938         });
 939     }
 940 





























 941     /*
 942      * May be called by delegate to provide SD to Java2D code.
 943      */
 944     public SurfaceData getSurfaceData() {
 945         synchronized (surfaceDataLock) {
 946             return surfaceData;
 947         }
 948     }
 949 
 950     private void replaceSurfaceData() {
 951         replaceSurfaceData(true);
 952     }
 953 
 954     private void replaceSurfaceData(boolean blit) {
 955         replaceSurfaceData(backBufferCount, backBufferCaps, blit);
 956     }
 957 
 958     private void replaceSurfaceData(int newBackBufferCount,
 959                                     BufferCapabilities newBackBufferCaps,
 960                                     boolean blit) {
 961         synchronized (surfaceDataLock) {
 962             final SurfaceData oldData = getSurfaceData();
 963             surfaceData = platformWindow.replaceSurfaceData();
 964             // TODO: volatile image
 965     //        VolatileImage oldBB = backBuffer;
 966             BufferedImage oldBB = backBuffer;
 967             backBufferCount = newBackBufferCount;
 968             backBufferCaps = newBackBufferCaps;
 969             final Rectangle size = getSize();
 970             if (getSurfaceData() != null && oldData != getSurfaceData()) {
 971                 clearBackground(size.width, size.height);
 972             }
 973 
 974             if (blit) {
 975                 blitSurfaceData(oldData, getSurfaceData());
 976             }
 977 
 978             if (oldData != null && oldData != getSurfaceData()) {
 979                 // TODO: drop oldData for D3D/WGL pipelines
 980                 // This can only happen when this peer is being created
 981                 oldData.flush();
 982             }
 983 
 984             // TODO: volatile image
 985     //        backBuffer = (VolatileImage)delegate.createBackBuffer();
 986 
 987             if (oldBB != null) {
 988                 backBuffer = (BufferedImage) platformWindow.createBackBuffer();
 989                 if (backBuffer != null) {
 990                     Graphics g = backBuffer.getGraphics();
 991                     try {
 992                         Rectangle r = getBounds();

 993                         if (g instanceof Graphics2D) {
 994                             ((Graphics2D) g).setComposite(AlphaComposite.Src);
 995                         }
 996                         g.setColor(nonOpaqueBackground);
 997                         g.fillRect(0, 0, r.width, r.height);
 998                         if (g instanceof SunGraphics2D) {
 999                             SG2DConstraint((SunGraphics2D) g, getRegion());
1000                         }
1001                         g.setColor(getBackground());
1002                         g.fillRect(0, 0, r.width, r.height);
1003                         if (oldBB != null) {
1004                             // Draw the old back buffer to the new one
1005                             g.drawImage(oldBB, 0, 0, null);
1006                             oldBB.flush();
1007                         }
1008                     } finally {
1009                         g.dispose();
1010                     }
1011                 }
1012             }
1013         }
1014     }
1015 
1016     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
1017         //TODO blit. proof-of-concept
1018         if (src != dst && src != null && dst != null
1019             && !(dst instanceof NullSurfaceData)
1020             && !(src instanceof NullSurfaceData)
1021             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1022             final Rectangle size = getSize();
1023             final Blit blit = Blit.locate(src.getSurfaceType(),
1024                                           CompositeType.Src,
1025                                           dst.getSurfaceType());
1026             if (blit != null) {
1027                 blit.Blit(src, dst, AlphaComposite.Src,
1028                           getRegion(), 0, 0, 0, 0, size.width, size.height);
1029             }
1030         }
1031     }
1032 
1033     public int getBackBufferCount() {
1034         return backBufferCount;
1035     }
1036 
1037     public BufferCapabilities getBackBufferCaps() {
1038         return backBufferCaps;
1039     }
1040 
1041     /*
1042      * Request the window insets from the delegate and compares it
1043      * with the current one. This method is mostly called by the
1044      * delegate, e.g. when the window state is changed and insets
1045      * should be recalculated.
1046      *
1047      * This method may be called on the toolkit thread.