< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java

Print this page
rev 54883 : JDK-8220154 Improve java2d rendering performance on macOS by using Metal framework


  60 import java.awt.peer.ContainerPeer;
  61 import java.awt.peer.KeyboardFocusManagerPeer;
  62 import java.lang.reflect.Field;
  63 import java.security.AccessController;
  64 import java.security.PrivilegedAction;
  65 import java.util.concurrent.atomic.AtomicBoolean;
  66 
  67 import javax.swing.JComponent;
  68 import javax.swing.RepaintManager;
  69 import javax.swing.SwingUtilities;
  70 
  71 import com.sun.java.swing.SwingUtilities3;
  72 import sun.awt.AWTAccessor;
  73 import sun.awt.PaintEventDispatcher;
  74 import sun.awt.RepaintArea;
  75 import sun.awt.SunToolkit;
  76 import sun.awt.event.IgnorePaintEvent;
  77 import sun.awt.image.SunVolatileImage;
  78 import sun.awt.image.ToolkitImage;
  79 import sun.java2d.SunGraphics2D;


  80 import sun.java2d.opengl.OGLRenderQueue;
  81 import sun.java2d.pipe.Region;

  82 import sun.util.logging.PlatformLogger;
  83 
  84 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
  85     implements ComponentPeer, DropTargetPeer
  86 {
  87     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
  88 
  89     /**
  90      * State lock is to be used for modifications to this peer's fields (e.g.
  91      * bounds, background, font, etc.) It should be the last lock in the lock
  92      * chain
  93      */
  94     private final Object stateLock = new Object();
  95 
  96     /**
  97      * The lock to operate with the peers hierarchy. AWT tree lock is not used
  98      * as there are many peers related ops to be done on the toolkit thread, and
  99      * we don't want to depend on a public lock on this thread
 100      */
 101     private static final Object peerTreeLock = new Object();


1417         return false;
1418     }
1419 
1420     /**
1421      * Paints the peer. Delegate the actual painting to Swing components.
1422      */
1423     protected final void paintPeer(final Graphics g) {
1424         final D delegate = getDelegate();
1425         if (delegate != null) {
1426             if (!SwingUtilities.isEventDispatchThread()) {
1427                 throw new InternalError("Painting must be done on EDT");
1428             }
1429             synchronized (getDelegateLock()) {
1430                 // JComponent.print() is guaranteed to not affect the double buffer
1431                 getDelegate().print(g);
1432             }
1433         }
1434     }
1435 
1436     protected static final void flushOnscreenGraphics(){
1437         final OGLRenderQueue rq = OGLRenderQueue.getInstance();

1438         rq.lock();
1439         try {
1440             rq.flushNow();
1441         } finally {
1442             rq.unlock();
1443         }
1444     }
1445 
1446     /**
1447      * Used by ContainerPeer to skip all the paint events during layout.
1448      *
1449      * @param isLayouting layouting state.
1450      */
1451     protected final void setLayouting(final boolean isLayouting) {
1452         this.isLayouting = isLayouting;
1453     }
1454 
1455     /**
1456      * Returns layouting state. Used by ComponentPeer to skip all the paint
1457      * events during layout.


  60 import java.awt.peer.ContainerPeer;
  61 import java.awt.peer.KeyboardFocusManagerPeer;
  62 import java.lang.reflect.Field;
  63 import java.security.AccessController;
  64 import java.security.PrivilegedAction;
  65 import java.util.concurrent.atomic.AtomicBoolean;
  66 
  67 import javax.swing.JComponent;
  68 import javax.swing.RepaintManager;
  69 import javax.swing.SwingUtilities;
  70 
  71 import com.sun.java.swing.SwingUtilities3;
  72 import sun.awt.AWTAccessor;
  73 import sun.awt.PaintEventDispatcher;
  74 import sun.awt.RepaintArea;
  75 import sun.awt.SunToolkit;
  76 import sun.awt.event.IgnorePaintEvent;
  77 import sun.awt.image.SunVolatileImage;
  78 import sun.awt.image.ToolkitImage;
  79 import sun.java2d.SunGraphics2D;
  80 import sun.java2d.macos.MacOSFlags;
  81 import sun.java2d.metal.MTLRenderQueue;
  82 import sun.java2d.opengl.OGLRenderQueue;
  83 import sun.java2d.pipe.Region;
  84 import sun.java2d.pipe.RenderQueue;
  85 import sun.util.logging.PlatformLogger;
  86 
  87 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
  88     implements ComponentPeer, DropTargetPeer
  89 {
  90     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
  91 
  92     /**
  93      * State lock is to be used for modifications to this peer's fields (e.g.
  94      * bounds, background, font, etc.) It should be the last lock in the lock
  95      * chain
  96      */
  97     private final Object stateLock = new Object();
  98 
  99     /**
 100      * The lock to operate with the peers hierarchy. AWT tree lock is not used
 101      * as there are many peers related ops to be done on the toolkit thread, and
 102      * we don't want to depend on a public lock on this thread
 103      */
 104     private static final Object peerTreeLock = new Object();


1420         return false;
1421     }
1422 
1423     /**
1424      * Paints the peer. Delegate the actual painting to Swing components.
1425      */
1426     protected final void paintPeer(final Graphics g) {
1427         final D delegate = getDelegate();
1428         if (delegate != null) {
1429             if (!SwingUtilities.isEventDispatchThread()) {
1430                 throw new InternalError("Painting must be done on EDT");
1431             }
1432             synchronized (getDelegateLock()) {
1433                 // JComponent.print() is guaranteed to not affect the double buffer
1434                 getDelegate().print(g);
1435             }
1436         }
1437     }
1438 
1439     protected static final void flushOnscreenGraphics(){
1440         RenderQueue rq = MacOSFlags.isMetalEnabled() ?
1441                 MTLRenderQueue.getInstance() : OGLRenderQueue.getInstance();
1442         rq.lock();
1443         try {
1444             rq.flushNow();
1445         } finally {
1446             rq.unlock();
1447         }
1448     }
1449 
1450     /**
1451      * Used by ContainerPeer to skip all the paint events during layout.
1452      *
1453      * @param isLayouting layouting state.
1454      */
1455     protected final void setLayouting(final boolean isLayouting) {
1456         this.isLayouting = isLayouting;
1457     }
1458 
1459     /**
1460      * Returns layouting state. Used by ComponentPeer to skip all the paint
1461      * events during layout.
< prev index next >