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

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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,


  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
  61     // of asynchronous requests to the windowing system)
  62     private int sysX;
  63     private int sysY;
  64     private int sysW;
  65     private int sysH;
  66 
  67     private static final int MINIMUM_WIDTH = 1;
  68     private static final int MINIMUM_HEIGHT = 1;
  69 
  70     private Insets insets = new Insets(0, 0, 0, 0);
  71 
  72     private GraphicsDevice graphicsDevice;
  73     private GraphicsConfiguration graphicsConfig;
  74 
  75     private SurfaceData surfaceData;
  76     private final Object surfaceDataLock = new Object();
  77 
  78     private int backBufferCount;
  79     private BufferCapabilities backBufferCaps;
  80 
  81     // The back buffer is used for two purposes:
  82     // 1. To render all the lightweight peers
  83     // 2. To provide user with a BufferStrategy
  84     // Need to check if a single back buffer can be used for both
  85 // TODO: VolatileImage
  86 //    private VolatileImage backBuffer;
  87     private volatile BufferedImage backBuffer;
  88 
  89     private volatile int windowState = Frame.NORMAL;
  90 
  91     // check that the mouse is over the window
  92     private volatile boolean isMouseOver = false;
  93 
  94     // A peer where the last mouse event came to. Used by cursor manager to
  95     // find the component under cursor
  96     private static volatile LWComponentPeer lastCommonMouseEventPeer = null;
  97 
  98     // A peer where the last mouse event came to. Used to generate
  99     // MOUSE_ENTERED/EXITED notifications
 100     private volatile LWComponentPeer lastMouseEventPeer;
 101 
 102     // Peers where all dragged/released events should come to,
 103     // depending on what mouse button is being dragged according to Cocoa
 104     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
 105 
 106     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 107     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 108     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button


 210 
 211     @Override
 212     protected void initializeContainerPeer() {
 213         // No-op as LWWindowPeer doesn't have any containerPeer
 214     }
 215 
 216     // ---- PEER METHODS ---- //
 217 
 218     @Override
 219     protected void disposeImpl() {
 220         SurfaceData oldData = getSurfaceData();
 221         synchronized (surfaceDataLock){
 222             surfaceData = null;
 223         }
 224         if (oldData != null) {
 225             oldData.invalidate();
 226         }
 227         if (isGrabbing()) {
 228             ungrab();
 229         }
 230         destroyBuffers();
 231         platformWindow.dispose();
 232         super.disposeImpl();
 233     }
 234 
 235     @Override
 236     protected void setVisibleImpl(final boolean visible) {
 237         super.setVisibleImpl(visible);
 238         // TODO: update graphicsConfig, see 4868278
 239         platformWindow.setVisible(visible);
 240         if (isSimpleWindow()) {
 241             KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 242 
 243             if (visible) {
 244                 if (!getTarget().isAutoRequestFocus()) {
 245                     return;
 246                 } else {
 247                     requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 248                 }
 249             // Focus the owner in case this window is focused.
 250             } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
 251                 // Transfer focus to the owner.
 252                 LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
 253                 if (owner != null) {
 254                     owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 255                 }
 256             }
 257         }
 258     }
 259 
 260     @Override
 261     public GraphicsConfiguration getGraphicsConfiguration() {

 262         return graphicsConfig;
 263     }

 264 
 265     @Override
 266     public boolean updateGraphicsData(GraphicsConfiguration gc) {
 267         setGraphicsConfig(gc);
 268         return false;
 269     }
 270 
 271     protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
 272         if (getSurfaceData() == null) {
 273             return null;
 274         }
 275         if (fg == null) {
 276             fg = SystemColor.windowText;
 277         }
 278         if (bg == null) {
 279             bg = SystemColor.window;
 280         }
 281         if (f == null) {
 282             f = DEFAULT_FONT;
 283         }
 284         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 285     }
 286 
 287     @Override
 288     public void createBuffers(int numBuffers, BufferCapabilities caps)
 289         throws AWTException
 290     {
 291         try {
 292             // Assume this method is never called with numBuffers <= 1, as 0 is
 293             // unsupported, and 1 corresponds to a SingleBufferStrategy which
 294             // doesn't depend on the peer. Screen is considered as a separate
 295             // "buffer", that's why numBuffers - 1
 296             assert numBuffers > 1;
 297 
 298             replaceSurfaceData(numBuffers - 1, caps, false);
 299         } catch (InvalidPipeException z) {
 300             throw new AWTException(z.toString());
 301         }
 302     }
 303 
 304     @Override
 305     public final Image getBackBuffer() {
 306         synchronized (getStateLock()) {
 307             return backBuffer;
 308         }
 309     }
 310 
 311     @Override
 312     public void flip(int x1, int y1, int x2, int y2,
 313                      BufferCapabilities.FlipContents flipAction)
 314     {
 315         platformWindow.flip(x1, y1, x2, y2, flipAction);
 316     }
 317 
 318     @Override
 319     public final void destroyBuffers() {
 320         final Image oldBB = getBackBuffer();
 321         synchronized (getStateLock()) {
 322             backBuffer = null;
 323         }
 324         if (oldBB != null) {
 325             oldBB.flush();
 326         }
 327     }
 328 
 329     @Override
 330     public void setBounds(int x, int y, int w, int h, int op) {
 331         if ((op & SET_CLIENT_SIZE) != 0) {
 332             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
 333             // instead of pulling 'insets' field up to LWComponentPeer
 334             // no need to add insets since Window's notion of width and height includes insets.
 335             op &= ~SET_CLIENT_SIZE;
 336             op |= SET_SIZE;
 337         }
 338 
 339         if (w < MINIMUM_WIDTH) {
 340             w = MINIMUM_WIDTH;
 341         }
 342         if (h < MINIMUM_HEIGHT) {
 343             h = MINIMUM_HEIGHT;
 344         }
 345 
 346         if (graphicsConfig instanceof TextureSizeConstraining) {
 347             final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
 348             final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
 349 
 350             if (w > maxW) {
 351                 w = maxW;
 352             }
 353             if (h > maxH) {
 354                 h = maxH;
 355             }
 356         }
 357 
 358         // Don't post ComponentMoved/Resized and Paint events
 359         // until we've got a notification from the delegate
 360         setBounds(x, y, w, h, op, false, false);
 361         // Get updated bounds, so we don't have to handle 'op' here manually
 362         Rectangle r = getBounds();
 363         platformWindow.setBounds(r.x, r.y, r.width, r.height);
 364     }
 365 
 366     @Override
 367     public Point getLocationOnScreen() {
 368         return platformWindow.getLocationOnScreen();
 369     }
 370 
 371     /**
 372      * Overridden from LWContainerPeer to return the correct insets.
 373      * Insets are queried from the delegate and are kept up to date by
 374      * requiering when needed (i.e. when the window geometry is changed).
 375      */
 376     @Override


 414     @Override
 415     public void setModalBlocked(Dialog blocker, boolean blocked) {
 416         synchronized (getPeerTreeLock()) {
 417             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
 418         }
 419 
 420         platformWindow.setModalBlocked(blocked);
 421     }
 422 
 423     @Override
 424     public void updateMinimumSize() {
 425         final Dimension min;
 426         if (getTarget().isMinimumSizeSet()) {
 427             min = getTarget().getMinimumSize();
 428             min.width = Math.max(min.width, MINIMUM_WIDTH);
 429             min.height = Math.max(min.height, MINIMUM_HEIGHT);
 430         } else {
 431             min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 432         }
 433 
 434         final int maxW, maxH;
 435         if (graphicsConfig instanceof TextureSizeConstraining) {
 436             maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
 437             maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
 438         } else {
 439             maxW = maxH = Integer.MAX_VALUE;
 440         }
 441 
 442         final Dimension max;
 443         if (getTarget().isMaximumSizeSet()) {
 444             max = getTarget().getMaximumSize();
 445             max.width = Math.min(max.width, maxW);
 446             max.height = Math.min(max.height, maxH);
 447         } else {
 448             max = new Dimension(maxW, maxH);

 449         }
 450 
 451         platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
 452     }
 453 
 454     @Override
 455     public void updateIconImages() {
 456         getPlatformWindow().updateIconImages();
 457     }
 458 
 459     @Override
 460     public void setOpacity(float opacity) {
 461         getPlatformWindow().setOpacity(opacity);
 462         repaintPeer();
 463     }
 464 
 465     @Override
 466     public final void setOpaque(final boolean isOpaque) {
 467         if (this.isOpaque != isOpaque) {
 468             this.isOpaque = isOpaque;


 997         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 998             public void run() {
 999                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
1000             }
1001         });
1002     }
1003 
1004     /*
1005      * May be called by delegate to provide SD to Java2D code.
1006      */
1007     public SurfaceData getSurfaceData() {
1008         synchronized (surfaceDataLock) {
1009             return surfaceData;
1010         }
1011     }
1012 
1013     private void replaceSurfaceData() {
1014         replaceSurfaceData(true);
1015     }
1016 
1017     private void replaceSurfaceData(boolean blit) {
1018         replaceSurfaceData(backBufferCount, backBufferCaps, blit);
1019     }
1020 
1021     private void replaceSurfaceData(int newBackBufferCount,
1022                                     BufferCapabilities newBackBufferCaps,
1023                                     boolean blit) {
1024         synchronized (surfaceDataLock) {
1025             final SurfaceData oldData = getSurfaceData();
1026             surfaceData = platformWindow.replaceSurfaceData();
1027             // TODO: volatile image
1028     //        VolatileImage oldBB = backBuffer;
1029             BufferedImage oldBB = backBuffer;
1030             backBufferCount = newBackBufferCount;
1031             backBufferCaps = newBackBufferCaps;
1032             final Rectangle size = getSize();
1033             if (getSurfaceData() != null && oldData != getSurfaceData()) {
1034                 clearBackground(size.width, size.height);
1035             }
1036 
1037             if (blit) {
1038                 blitSurfaceData(oldData, getSurfaceData());
1039             }
1040 
1041             if (oldData != null && oldData != getSurfaceData()) {
1042                 // TODO: drop oldData for D3D/WGL pipelines
1043                 // This can only happen when this peer is being created
1044                 oldData.flush();
1045             }
1046 
1047             // TODO: volatile image
1048     //        backBuffer = (VolatileImage)delegate.createBackBuffer();
1049             backBuffer = (BufferedImage) platformWindow.createBackBuffer();
1050             if (backBuffer != null) {
1051                 Graphics g = backBuffer.getGraphics();
1052                 try {
1053                     Rectangle r = getBounds();
1054                     if (g instanceof Graphics2D) {
1055                         ((Graphics2D) g).setComposite(AlphaComposite.Src);
1056                     }
1057                     g.setColor(nonOpaqueBackground);
1058                     g.fillRect(0, 0, r.width, r.height);
1059                     if (g instanceof SunGraphics2D) {
1060                         SG2DConstraint((SunGraphics2D) g, getRegion());
1061                     }
1062                     if (!isTextured()) {
1063                         g.setColor(getBackground());
1064                         g.fillRect(0, 0, r.width, r.height);
1065                     }
1066                     if (oldBB != null) {
1067                         // Draw the old back buffer to the new one
1068                         g.drawImage(oldBB, 0, 0, null);
1069                         oldBB.flush();
1070                     }
1071                 } finally {
1072                     g.dispose();
1073                 }
1074             }
1075         }
1076     }
1077 
1078     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
1079         //TODO blit. proof-of-concept
1080         if (src != dst && src != null && dst != null
1081             && !(dst instanceof NullSurfaceData)
1082             && !(src instanceof NullSurfaceData)
1083             && src.getSurfaceType().equals(dst.getSurfaceType())) {
1084             final Rectangle size = getSize();
1085             final Blit blit = Blit.locate(src.getSurfaceType(),
1086                                           CompositeType.Src,
1087                                           dst.getSurfaceType());
1088             if (blit != null) {
1089                 blit.Blit(src, dst, AlphaComposite.Src,
1090                           getRegion(), 0, 0, 0, 0, size.width, size.height);
1091             }
1092         }
1093     }
1094 
1095     public int getBackBufferCount() {
1096         return backBufferCount;
1097     }
1098 
1099     public BufferCapabilities getBackBufferCaps() {
1100         return backBufferCaps;
1101     }
1102 
1103     /*
1104      * Request the window insets from the delegate and compares it
1105      * with the current one. This method is mostly called by the
1106      * delegate, e.g. when the window state is changed and insets
1107      * should be recalculated.
1108      *
1109      * This method may be called on the toolkit thread.
1110      */
1111     public boolean updateInsets(Insets newInsets) {
1112         boolean changed = false;
1113         synchronized (getStateLock()) {
1114             changed = (insets.equals(newInsets));
1115             insets = newInsets;
1116         }
1117 
1118         if (changed) {
1119             replaceSurfaceData();
1120             repaintPeer();




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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.peer.*;
  31 import java.util.List;
  32 
  33 import javax.swing.*;
  34 
  35 import sun.awt.*;
  36 import sun.java2d.*;
  37 import sun.java2d.loops.Blit;
  38 import sun.java2d.loops.CompositeType;
  39 import sun.java2d.pipe.Region;
  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,


  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
  60     // of asynchronous requests to the windowing system)
  61     private int sysX;
  62     private int sysY;
  63     private int sysW;
  64     private int sysH;
  65 
  66     private static final int MINIMUM_WIDTH = 1;
  67     private static final int MINIMUM_HEIGHT = 1;
  68 
  69     private Insets insets = new Insets(0, 0, 0, 0);
  70 
  71     private GraphicsDevice graphicsDevice;
  72     private GraphicsConfiguration graphicsConfig;
  73 
  74     private SurfaceData surfaceData;
  75     private final Object surfaceDataLock = new Object();
  76 











  77     private volatile int windowState = Frame.NORMAL;
  78 
  79     // check that the mouse is over the window
  80     private volatile boolean isMouseOver = false;
  81 
  82     // A peer where the last mouse event came to. Used by cursor manager to
  83     // find the component under cursor
  84     private static volatile LWComponentPeer lastCommonMouseEventPeer = null;
  85 
  86     // A peer where the last mouse event came to. Used to generate
  87     // MOUSE_ENTERED/EXITED notifications
  88     private volatile LWComponentPeer lastMouseEventPeer;
  89 
  90     // Peers where all dragged/released events should come to,
  91     // depending on what mouse button is being dragged according to Cocoa
  92     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  93 
  94     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
  95     // on MOUSE_RELEASE. Click events are only generated if there were no drag
  96     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button


 198 
 199     @Override
 200     protected void initializeContainerPeer() {
 201         // No-op as LWWindowPeer doesn't have any containerPeer
 202     }
 203 
 204     // ---- PEER METHODS ---- //
 205 
 206     @Override
 207     protected void disposeImpl() {
 208         SurfaceData oldData = getSurfaceData();
 209         synchronized (surfaceDataLock){
 210             surfaceData = null;
 211         }
 212         if (oldData != null) {
 213             oldData.invalidate();
 214         }
 215         if (isGrabbing()) {
 216             ungrab();
 217         }

 218         platformWindow.dispose();
 219         super.disposeImpl();
 220     }
 221 
 222     @Override
 223     protected void setVisibleImpl(final boolean visible) {
 224         super.setVisibleImpl(visible);
 225         // TODO: update graphicsConfig, see 4868278
 226         platformWindow.setVisible(visible);
 227         if (isSimpleWindow()) {
 228             KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 229 
 230             if (visible) {
 231                 if (!getTarget().isAutoRequestFocus()) {
 232                     return;
 233                 } else {
 234                     requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 235                 }
 236             // Focus the owner in case this window is focused.
 237             } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
 238                 // Transfer focus to the owner.
 239                 LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
 240                 if (owner != null) {
 241                     owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
 242                 }
 243             }
 244         }
 245     }
 246 
 247     @Override
 248     public final GraphicsConfiguration getGraphicsConfiguration() {
 249         synchronized (getStateLock()) {
 250             return graphicsConfig;
 251         }
 252     }
 253 
 254     @Override
 255     public boolean updateGraphicsData(GraphicsConfiguration gc) {
 256         setGraphicsConfig(gc);
 257         return false;
 258     }
 259 
 260     protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
 261         if (getSurfaceData() == null) {
 262             return null;
 263         }
 264         if (fg == null) {
 265             fg = SystemColor.windowText;
 266         }
 267         if (bg == null) {
 268             bg = SystemColor.window;
 269         }
 270         if (f == null) {
 271             f = DEFAULT_FONT;
 272         }
 273         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 274     }
 275 
 276     @Override










































 277     public void setBounds(int x, int y, int w, int h, int op) {
 278         if ((op & SET_CLIENT_SIZE) != 0) {
 279             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
 280             // instead of pulling 'insets' field up to LWComponentPeer
 281             // no need to add insets since Window's notion of width and height includes insets.
 282             op &= ~SET_CLIENT_SIZE;
 283             op |= SET_SIZE;
 284         }
 285 
 286         if (w < MINIMUM_WIDTH) {
 287             w = MINIMUM_WIDTH;
 288         }
 289         if (h < MINIMUM_HEIGHT) {
 290             h = MINIMUM_HEIGHT;
 291         }
 292 
 293         final int maxW = getLWGC().getMaxTextureWidth();
 294         final int maxH = getLWGC().getMaxTextureHeight();

 295 
 296         if (w > maxW) {
 297             w = maxW;
 298         }
 299         if (h > maxH) {
 300             h = maxH;
 301         }

 302 
 303         // Don't post ComponentMoved/Resized and Paint events
 304         // until we've got a notification from the delegate
 305         setBounds(x, y, w, h, op, false, false);
 306         // Get updated bounds, so we don't have to handle 'op' here manually
 307         Rectangle r = getBounds();
 308         platformWindow.setBounds(r.x, r.y, r.width, r.height);
 309     }
 310 
 311     @Override
 312     public Point getLocationOnScreen() {
 313         return platformWindow.getLocationOnScreen();
 314     }
 315 
 316     /**
 317      * Overridden from LWContainerPeer to return the correct insets.
 318      * Insets are queried from the delegate and are kept up to date by
 319      * requiering when needed (i.e. when the window geometry is changed).
 320      */
 321     @Override


 359     @Override
 360     public void setModalBlocked(Dialog blocker, boolean blocked) {
 361         synchronized (getPeerTreeLock()) {
 362             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
 363         }
 364 
 365         platformWindow.setModalBlocked(blocked);
 366     }
 367 
 368     @Override
 369     public void updateMinimumSize() {
 370         final Dimension min;
 371         if (getTarget().isMinimumSizeSet()) {
 372             min = getTarget().getMinimumSize();
 373             min.width = Math.max(min.width, MINIMUM_WIDTH);
 374             min.height = Math.max(min.height, MINIMUM_HEIGHT);
 375         } else {
 376             min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 377         }
 378 








 379         final Dimension max;
 380         if (getTarget().isMaximumSizeSet()) {
 381             max = getTarget().getMaximumSize();
 382             max.width = Math.min(max.width, getLWGC().getMaxTextureWidth());
 383             max.height = Math.min(max.height, getLWGC().getMaxTextureHeight());
 384         } else {
 385             max = new Dimension(getLWGC().getMaxTextureWidth(),
 386                                 getLWGC().getMaxTextureHeight());
 387         }
 388 
 389         platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
 390     }
 391 
 392     @Override
 393     public void updateIconImages() {
 394         getPlatformWindow().updateIconImages();
 395     }
 396 
 397     @Override
 398     public void setOpacity(float opacity) {
 399         getPlatformWindow().setOpacity(opacity);
 400         repaintPeer();
 401     }
 402 
 403     @Override
 404     public final void setOpaque(final boolean isOpaque) {
 405         if (this.isOpaque != isOpaque) {
 406             this.isOpaque = isOpaque;


 935         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 936             public void run() {
 937                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 938             }
 939         });
 940     }
 941 
 942     /*
 943      * May be called by delegate to provide SD to Java2D code.
 944      */
 945     public SurfaceData getSurfaceData() {
 946         synchronized (surfaceDataLock) {
 947             return surfaceData;
 948         }
 949     }
 950 
 951     private void replaceSurfaceData() {
 952         replaceSurfaceData(true);
 953     }
 954 
 955     private void replaceSurfaceData(final boolean blit) {






 956         synchronized (surfaceDataLock) {
 957             final SurfaceData oldData = getSurfaceData();
 958             surfaceData = platformWindow.replaceSurfaceData();





 959             final Rectangle size = getSize();
 960             if (getSurfaceData() != null && oldData != getSurfaceData()) {
 961                 clearBackground(size.width, size.height);
 962             }
 963 
 964             if (blit) {
 965                 blitSurfaceData(oldData, getSurfaceData());
 966             }
 967 
 968             if (oldData != null && oldData != getSurfaceData()) {
 969                 // TODO: drop oldData for D3D/WGL pipelines
 970                 // This can only happen when this peer is being created
 971                 oldData.flush();
 972             }





























 973         }
 974     }
 975 
 976     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
 977         //TODO blit. proof-of-concept
 978         if (src != dst && src != null && dst != null
 979             && !(dst instanceof NullSurfaceData)
 980             && !(src instanceof NullSurfaceData)
 981             && src.getSurfaceType().equals(dst.getSurfaceType())) {
 982             final Rectangle size = getSize();
 983             final Blit blit = Blit.locate(src.getSurfaceType(),
 984                                           CompositeType.Src,
 985                                           dst.getSurfaceType());
 986             if (blit != null) {
 987                 blit.Blit(src, dst, AlphaComposite.Src,
 988                           getRegion(), 0, 0, 0, 0, size.width, size.height);
 989             }
 990         }








 991     }
 992 
 993     /*
 994      * Request the window insets from the delegate and compares it
 995      * with the current one. This method is mostly called by the
 996      * delegate, e.g. when the window state is changed and insets
 997      * should be recalculated.
 998      *
 999      * This method may be called on the toolkit thread.
1000      */
1001     public boolean updateInsets(Insets newInsets) {
1002         boolean changed = false;
1003         synchronized (getStateLock()) {
1004             changed = (insets.equals(newInsets));
1005             insets = newInsets;
1006         }
1007 
1008         if (changed) {
1009             replaceSurfaceData();
1010             repaintPeer();