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

Print this page




 563         final boolean moved;
 564         final boolean resized;
 565         final boolean invalid = updateInsets(platformWindow.getInsets());
 566         synchronized (getStateLock()) {
 567             moved = (x != sysX) || (y != sysY);
 568             resized = (w != sysW) || (h != sysH);
 569             sysX = x;
 570             sysY = y;
 571             sysW = w;
 572             sysH = h;
 573         }
 574 
 575         // Check if anything changed
 576         if (!moved && !resized && !invalid) {
 577             return;
 578         }
 579         // First, update peer's bounds
 580         setBounds(x, y, w, h, SET_BOUNDS, false, false);
 581 
 582         // Second, update the graphics config and surface data
 583         checkIfOnNewScreen();
 584         if (resized) {
 585             replaceSurfaceData();
 586             flushOnscreenGraphics();
 587         }
 588 
 589         // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
 590         if (moved || invalid) {
 591             handleMove(x, y, true);
 592         }
 593         if (resized || invalid) {
 594             handleResize(w, h, true);
 595             repaintPeer();
 596         }
 597     }
 598 
 599     private void clearBackground(final int w, final int h) {
 600         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 601                                                getFont());
 602         if (g != null) {
 603             try {
 604                 if (g instanceof Graphics2D) {
 605                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 606                 }
 607                 if (isTranslucent()) {
 608                     g.setColor(nonOpaqueBackground);
 609                     g.fillRect(0, 0, w, h);
 610                 }
 611                 if (!isTextured()) {
 612                     if (g instanceof SunGraphics2D) {
 613                         SG2DConstraint((SunGraphics2D) g, getRegion());
 614                     }
 615                     g.setColor(getBackground());
 616                     g.fillRect(0, 0, w, h);
 617                 }
 618             } finally {
 619                 g.dispose();
 620             }
 621         }
 622     }
 623 
 624     public void notifyUpdateCursor() {
 625         getLWToolkit().getCursorManager().updateCursorLater(this);
 626     }
 627 
 628     public void notifyActivation(boolean activation, LWWindowPeer opposite) {
 629         Window oppositeWindow = (opposite == null)? null : opposite.getTarget();
 630         changeFocusedWindow(activation, oppositeWindow);
 631     }
 632 
 633     // MouseDown in non-client area


 905             }
 906         }
 907         // Should never happen if gc is a screen device config
 908         return 0;
 909     }
 910 
 911     /*
 912      * This method is called when window's graphics config is changed from
 913      * the app code (e.g. when the window is made non-opaque) or when
 914      * the window is moved to another screen by user.
 915      *
 916      * Returns true if the graphics config has been changed, false otherwise.
 917      */
 918     private boolean setGraphicsConfig(GraphicsConfiguration gc) {
 919         synchronized (getStateLock()) {
 920             if (graphicsConfig == gc) {
 921                 return false;
 922             }
 923             // If window's graphics config is changed from the app code, the
 924             // config correspond to the same device as before; when the window
 925             // is moved by user, graphicsDevice is updated in checkIfOnNewScreen().
 926             // In either case, there's nothing to do with screenOn here
 927             graphicsConfig = gc;
 928         }
 929         // SurfaceData is replaced later in updateGraphicsData()
 930         return true;
 931     }
 932 
 933     private void checkIfOnNewScreen() {



 934         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 935         synchronized (getStateLock()) {
 936             if (graphicsDevice == newGraphicsDevice) {
 937                 return;
 938             }
 939             graphicsDevice = newGraphicsDevice;
 940         }
 941 
 942         // TODO: DisplayChangedListener stuff
 943         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 944 
 945         if (!setGraphicsConfig(newGC)) return;
 946 
 947         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 948             public void run() {
 949                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 950             }
 951         });

 952     }
 953 
 954     /*
 955      * May be called by delegate to provide SD to Java2D code.
 956      */
 957     public SurfaceData getSurfaceData() {
 958         synchronized (surfaceDataLock) {
 959             return surfaceData;
 960         }
 961     }
 962 
 963     private void replaceSurfaceData() {
 964         replaceSurfaceData(true);
 965     }
 966 
 967     private void replaceSurfaceData(final boolean blit) {
 968         synchronized (surfaceDataLock) {
 969             final SurfaceData oldData = getSurfaceData();
 970             surfaceData = platformWindow.replaceSurfaceData();
 971             final Rectangle size = getSize();
 972             if (getSurfaceData() != null && oldData != getSurfaceData()) {
 973                 clearBackground(size.width, size.height);
 974             }
 975 
 976             if (blit) {
 977                 blitSurfaceData(oldData, getSurfaceData());
 978             }
 979 
 980             if (oldData != null && oldData != getSurfaceData()) {
 981                 // TODO: drop oldData for D3D/WGL pipelines
 982                 // This can only happen when this peer is being created
 983                 oldData.flush();
 984             }
 985         }

 986     }
 987 
 988     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
 989         //TODO blit. proof-of-concept
 990         if (src != dst && src != null && dst != null
 991             && !(dst instanceof NullSurfaceData)
 992             && !(src instanceof NullSurfaceData)
 993             && src.getSurfaceType().equals(dst.getSurfaceType())) {
 994             final Rectangle size = getSize();

 995             final Blit blit = Blit.locate(src.getSurfaceType(),
 996                                           CompositeType.Src,
 997                                           dst.getSurfaceType());
 998             if (blit != null) {
 999                 blit.Blit(src, dst, AlphaComposite.Src,
1000                           getRegion(), 0, 0, 0, 0, size.width, size.height);
1001             }
1002         }
1003     }
1004 
1005     /**
1006      * Request the window insets from the delegate and compares it with the
1007      * current one. This method is mostly called by the delegate, e.g. when the
1008      * window state is changed and insets should be recalculated.
1009      * <p/>
1010      * This method may be called on the toolkit thread.
1011      */
1012     public final boolean updateInsets(final Insets newInsets) {
1013         synchronized (getStateLock()) {
1014             if (insets.equals(newInsets)) {
1015                 return false;
1016             }
1017             insets = newInsets;
1018         }
1019         return true;
1020     }




 563         final boolean moved;
 564         final boolean resized;
 565         final boolean invalid = updateInsets(platformWindow.getInsets());
 566         synchronized (getStateLock()) {
 567             moved = (x != sysX) || (y != sysY);
 568             resized = (w != sysW) || (h != sysH);
 569             sysX = x;
 570             sysY = y;
 571             sysW = w;
 572             sysH = h;
 573         }
 574 
 575         // Check if anything changed
 576         if (!moved && !resized && !invalid) {
 577             return;
 578         }
 579         // First, update peer's bounds
 580         setBounds(x, y, w, h, SET_BOUNDS, false, false);
 581 
 582         // Second, update the graphics config and surface data
 583         final boolean isNewDevice = updateGraphicsDevice();
 584         if (resized || isNewDevice) {
 585             replaceSurfaceData();

 586         }
 587 
 588         // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
 589         if (moved || invalid) {
 590             handleMove(x, y, true);
 591         }
 592         if (resized || invalid || isNewDevice) {
 593             handleResize(w, h, true);
 594             repaintPeer();
 595         }
 596     }
 597 
 598     private void clearBackground(final int w, final int h) {
 599         final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
 600                                                getFont());
 601         if (g != null) {
 602             try {
 603                 if (g instanceof Graphics2D) {
 604                     ((Graphics2D) g).setComposite(AlphaComposite.Src);
 605                 }
 606                 if (isTranslucent()) {
 607                     g.setColor(nonOpaqueBackground);
 608                     g.fillRect(0, 0, w, h);
 609                 }
 610                 if (!isTextured()) {
 611                     if (g instanceof SunGraphics2D) {
 612                         ((SunGraphics2D) g).constrain(0, 0, w, h, getRegion());
 613                     }
 614                     g.setColor(getBackground());
 615                     g.fillRect(0, 0, w, h);
 616                 }
 617             } finally {
 618                 g.dispose();
 619             }
 620         }
 621     }
 622 
 623     public void notifyUpdateCursor() {
 624         getLWToolkit().getCursorManager().updateCursorLater(this);
 625     }
 626 
 627     public void notifyActivation(boolean activation, LWWindowPeer opposite) {
 628         Window oppositeWindow = (opposite == null)? null : opposite.getTarget();
 629         changeFocusedWindow(activation, oppositeWindow);
 630     }
 631 
 632     // MouseDown in non-client area


 904             }
 905         }
 906         // Should never happen if gc is a screen device config
 907         return 0;
 908     }
 909 
 910     /*
 911      * This method is called when window's graphics config is changed from
 912      * the app code (e.g. when the window is made non-opaque) or when
 913      * the window is moved to another screen by user.
 914      *
 915      * Returns true if the graphics config has been changed, false otherwise.
 916      */
 917     private boolean setGraphicsConfig(GraphicsConfiguration gc) {
 918         synchronized (getStateLock()) {
 919             if (graphicsConfig == gc) {
 920                 return false;
 921             }
 922             // If window's graphics config is changed from the app code, the
 923             // config correspond to the same device as before; when the window
 924             // is moved by user, graphicsDevice is updated in notifyReshape().
 925             // In either case, there's nothing to do with screenOn here
 926             graphicsConfig = gc;
 927         }
 928         // SurfaceData is replaced later in updateGraphicsData()
 929         return true;
 930     }
 931 
 932     /**
 933      * Returns true if the GraphicsDevice has been changed, false otherwise.
 934      */
 935     public boolean updateGraphicsDevice() {
 936         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 937         synchronized (getStateLock()) {
 938             if (graphicsDevice == newGraphicsDevice) {
 939                 return false;
 940             }
 941             graphicsDevice = newGraphicsDevice;
 942         }
 943 
 944         // TODO: DisplayChangedListener stuff
 945         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 946 
 947         if (!setGraphicsConfig(newGC)) return false;
 948 
 949         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 950             public void run() {
 951                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 952             }
 953         });
 954         return true;
 955     }
 956 
 957     /*
 958      * May be called by delegate to provide SD to Java2D code.
 959      */
 960     public SurfaceData getSurfaceData() {
 961         synchronized (surfaceDataLock) {
 962             return surfaceData;
 963         }
 964     }
 965 
 966     private void replaceSurfaceData() {
 967         replaceSurfaceData(true);
 968     }
 969 
 970     private void replaceSurfaceData(final boolean blit) {
 971         synchronized (surfaceDataLock) {
 972             final SurfaceData oldData = getSurfaceData();
 973             surfaceData = platformWindow.replaceSurfaceData();
 974             final Rectangle size = getSize();
 975             if (getSurfaceData() != null && oldData != getSurfaceData()) {
 976                 clearBackground(size.width, size.height);
 977             }
 978 
 979             if (blit) {
 980                 blitSurfaceData(oldData, getSurfaceData());
 981             }
 982 
 983             if (oldData != null && oldData != getSurfaceData()) {
 984                 // TODO: drop oldData for D3D/WGL pipelines
 985                 // This can only happen when this peer is being created
 986                 oldData.flush();
 987             }
 988         }
 989         flushOnscreenGraphics();
 990     }
 991 
 992     private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
 993         //TODO blit. proof-of-concept
 994         if (src != dst && src != null && dst != null
 995             && !(dst instanceof NullSurfaceData)
 996             && !(src instanceof NullSurfaceData)
 997             && src.getSurfaceType().equals(dst.getSurfaceType())
 998             && src.getDefaultScale() == dst.getDefaultScale()) {
 999             final Rectangle size = src.getBounds();
1000             final Blit blit = Blit.locate(src.getSurfaceType(),
1001                                           CompositeType.Src,
1002                                           dst.getSurfaceType());
1003             if (blit != null) {
1004                 blit.Blit(src, dst, AlphaComposite.Src, null, 0, 0, 0, 0,
1005                           size.width, size.height);
1006             }
1007         }
1008     }
1009 
1010     /**
1011      * Request the window insets from the delegate and compares it with the
1012      * current one. This method is mostly called by the delegate, e.g. when the
1013      * window state is changed and insets should be recalculated.
1014      * <p/>
1015      * This method may be called on the toolkit thread.
1016      */
1017     public final boolean updateInsets(final Insets newInsets) {
1018         synchronized (getStateLock()) {
1019             if (insets.equals(newInsets)) {
1020                 return false;
1021             }
1022             insets = newInsets;
1023         }
1024         return true;
1025     }