jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
changeset 13233 4d45f7ebc0d7
parent 13143 31c70a66a053
child 13544 bd136eb2a932
equal deleted inserted replaced
13147:eada40c7d74d 13233:4d45f7ebc0d7
   422         return false;
   422         return false;
   423     }
   423     }
   424 
   424 
   425     @Override
   425     @Override
   426     public final Graphics getGraphics() {
   426     public final Graphics getGraphics() {
   427         Graphics g = getWindowPeerOrSelf().isOpaque() ? getOnscreenGraphics()
   427         final Graphics g = getOnscreenGraphics();
   428                                                       : getOffscreenGraphics();
       
   429         if (g != null) {
   428         if (g != null) {
   430             synchronized (getPeerTreeLock()){
   429             synchronized (getPeerTreeLock()){
   431                 applyConstrain(g);
   430                 applyConstrain(g);
   432             }
   431             }
   433         }
   432         }
   441      */
   440      */
   442     public final Graphics getOnscreenGraphics() {
   441     public final Graphics getOnscreenGraphics() {
   443         final LWWindowPeer wp = getWindowPeerOrSelf();
   442         final LWWindowPeer wp = getWindowPeerOrSelf();
   444         return wp.getOnscreenGraphics(getForeground(), getBackground(),
   443         return wp.getOnscreenGraphics(getForeground(), getBackground(),
   445                                       getFont());
   444                                       getFont());
   446     }
   445 
   447 
       
   448     public final Graphics getOffscreenGraphics() {
       
   449         final LWWindowPeer wp = getWindowPeerOrSelf();
       
   450 
       
   451         return wp.getOffscreenGraphics(getForeground(), getBackground(),
       
   452                                        getFont());
       
   453     }
   446     }
   454 
   447 
   455     private void applyConstrain(final Graphics g) {
   448     private void applyConstrain(final Graphics g) {
   456         final SunGraphics2D sg2d = (SunGraphics2D) g;
   449         final SunGraphics2D sg2d = (SunGraphics2D) g;
   457         final Rectangle constr = localToWindow(getSize());
   450         final Rectangle constr = localToWindow(getSize());
   461         //sg2d.constrain(getVisibleRegion());
   454         //sg2d.constrain(getVisibleRegion());
   462         SG2DConstraint(sg2d, getVisibleRegion());
   455         SG2DConstraint(sg2d, getVisibleRegion());
   463     }
   456     }
   464 
   457 
   465     //TODO Move this method to SG2D?
   458     //TODO Move this method to SG2D?
   466     private void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
   459     void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
   467         sg2d.constrainX = sg2d.transX;
   460         sg2d.constrainX = sg2d.transX;
   468         sg2d.constrainY = sg2d.transY;
   461         sg2d.constrainY = sg2d.transY;
   469 
   462 
   470         Region c = sg2d.constrainClip;
   463         Region c = sg2d.constrainClip;
   471         if ((sg2d.constrainX | sg2d.constrainY) != 0) {
   464         if ((sg2d.constrainX | sg2d.constrainY) != 0) {
   708         // Borrow the metrics from the top-level window
   701         // Borrow the metrics from the top-level window
   709 //        return getWindowPeer().getFontMetrics(f);
   702 //        return getWindowPeer().getFontMetrics(f);
   710         // Obtain the metrics from the offscreen window where this peer is
   703         // Obtain the metrics from the offscreen window where this peer is
   711         // mostly drawn to.
   704         // mostly drawn to.
   712         // TODO: check for "use platform metrics" settings
   705         // TODO: check for "use platform metrics" settings
   713         Graphics g = getWindowPeer().getOffscreenGraphics();
   706         Graphics g = getWindowPeer().getGraphics();
   714         try {
   707         try {
   715             if (g != null) {
   708             if (g != null) {
   716                 return g.getFontMetrics(f);
   709                 return g.getFontMetrics(f);
   717             } else {
   710             } else {
   718                 synchronized (getDelegateLock()) {
   711                 synchronized (getDelegateLock()) {
  1009     }
  1002     }
  1010 
  1003 
  1011     @Override
  1004     @Override
  1012     public final void applyShape(final Region shape) {
  1005     public final void applyShape(final Region shape) {
  1013         synchronized (getStateLock()) {
  1006         synchronized (getStateLock()) {
  1014             region = shape;
  1007             if (region == shape || (region != null && region.equals(shape))) {
       
  1008                 return;
       
  1009             }
       
  1010         }
       
  1011         applyShapeImpl(shape);
       
  1012     }
       
  1013 
       
  1014     void applyShapeImpl(final Region shape) {
       
  1015         synchronized (getStateLock()) {
       
  1016             if (shape != null) {
       
  1017                 region = Region.WHOLE_REGION.getIntersection(shape);
       
  1018             } else {
       
  1019                 region = null;
       
  1020             }
  1015         }
  1021         }
  1016         repaintParent(getBounds());
  1022         repaintParent(getBounds());
  1017     }
  1023     }
  1018 
  1024 
  1019     protected final Region getRegion() {
  1025     protected final Region getRegion() {
  1020         synchronized (getStateLock()) {
  1026         synchronized (getStateLock()) {
  1021             return region == null ? Region.getInstance(getSize()) : region;
  1027             return isShaped() ? region : Region.getInstance(getSize());
       
  1028         }
       
  1029     }
       
  1030 
       
  1031     public boolean isShaped() {
       
  1032         synchronized (getStateLock()) {
       
  1033             return region != null;
  1022         }
  1034         }
  1023     }
  1035     }
  1024 
  1036 
  1025     // DropTargetPeer Method
  1037     // DropTargetPeer Method
  1026     @Override
  1038     @Override
  1384                 getDelegate().print(g);
  1396                 getDelegate().print(g);
  1385             }
  1397             }
  1386         }
  1398         }
  1387     }
  1399     }
  1388 
  1400 
  1389     // Just a helper method, thus final
       
  1390     protected final void flushOffscreenGraphics() {
       
  1391         flushOffscreenGraphics(getSize());
       
  1392     }
       
  1393 
       
  1394     protected static final void flushOnscreenGraphics(){
  1401     protected static final void flushOnscreenGraphics(){
  1395         final OGLRenderQueue rq = OGLRenderQueue.getInstance();
  1402         final OGLRenderQueue rq = OGLRenderQueue.getInstance();
  1396         rq.lock();
  1403         rq.lock();
  1397         try {
  1404         try {
  1398             rq.flushNow();
  1405             rq.flushNow();
  1399         } finally {
  1406         } finally {
  1400             rq.unlock();
  1407             rq.unlock();
  1401         }
  1408         }
  1402     }
  1409     }
  1403 
  1410 
  1404     /*
       
  1405      * Flushes the given rectangle from the back buffer to the screen.
       
  1406      */
       
  1407     protected void flushOffscreenGraphics(Rectangle r) {
       
  1408         flushOffscreenGraphics(r.x, r.y, r.width, r.height);
       
  1409     }
       
  1410 
       
  1411     private void flushOffscreenGraphics(int x, int y, int width, int height) {
       
  1412         Image bb = getWindowPeerOrSelf().getBackBuffer();
       
  1413         if (bb != null) {
       
  1414             // g is a screen Graphics from the delegate
       
  1415             final Graphics g = getOnscreenGraphics();
       
  1416 
       
  1417             if (g != null && g instanceof Graphics2D) {
       
  1418                 try {
       
  1419                     Graphics2D g2d = (Graphics2D)g;
       
  1420                     Point p = localToWindow(new Point(0, 0));
       
  1421                     Composite composite = g2d.getComposite();
       
  1422                     g2d.setComposite(AlphaComposite.Src);
       
  1423                     g.drawImage(bb, x, y, x + width, y + height, p.x + x,
       
  1424                             p.y + y, p.x + x + width, p.y + y + height,
       
  1425                             null);
       
  1426                     g2d.setComposite(composite);
       
  1427                 } finally {
       
  1428                     g.dispose();
       
  1429                 }
       
  1430             }
       
  1431         }
       
  1432     }
       
  1433 
       
  1434     /**
  1411     /**
  1435      * Used by ContainerPeer to skip all the paint events during layout.
  1412      * Used by ContainerPeer to skip all the paint events during layout.
  1436      *
  1413      *
  1437      * @param isLayouting layouting state.
  1414      * @param isLayouting layouting state.
  1438      */
  1415      */