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.metal.MetalRenderQueue;
82 import sun.java2d.pipe.Region;
83 import sun.util.logging.PlatformLogger;
84
85 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
86 implements ComponentPeer, DropTargetPeer
87 {
88 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
89
90 /**
91 * State lock is to be used for modifications to this peer's fields (e.g.
92 * bounds, background, font, etc.) It should be the last lock in the lock
93 * chain
94 */
95 private final Object stateLock = new Object();
96
97 /**
98 * The lock to operate with the peers hierarchy. AWT tree lock is not used
99 * as there are many peers related ops to be done on the toolkit thread, and
100 * we don't want to depend on a public lock on this thread
101 */
102 private static final Object peerTreeLock = new Object();
1418 return false;
1419 }
1420
1421 /**
1422 * Paints the peer. Delegate the actual painting to Swing components.
1423 */
1424 protected final void paintPeer(final Graphics g) {
1425 final D delegate = getDelegate();
1426 if (delegate != null) {
1427 if (!SwingUtilities.isEventDispatchThread()) {
1428 throw new InternalError("Painting must be done on EDT");
1429 }
1430 synchronized (getDelegateLock()) {
1431 // JComponent.print() is guaranteed to not affect the double buffer
1432 getDelegate().print(g);
1433 }
1434 }
1435 }
1436
1437 protected static final void flushOnscreenGraphics(){
1438
1439 // Check for metal
1440 boolean isMetal = false;
1441 String str = System.getProperty("sun.java2d.metal");
1442
1443 if (str != null) {
1444 //System.out.println("Property : sun.java2d.metal=" + str);
1445 if (str.equals("true")) {
1446 isMetal = true;
1447 }
1448 }
1449
1450 if (isMetal) {
1451 final MetalRenderQueue rq = MetalRenderQueue.getInstance();
1452 rq.lock();
1453 try {
1454 rq.flushNow();
1455 } finally {
1456 rq.unlock();
1457 }
1458 } else {
1459
1460 final OGLRenderQueue rq = OGLRenderQueue.getInstance();
1461 rq.lock();
1462 try {
1463 rq.flushNow();
1464 } finally {
1465 rq.unlock();
1466 }
1467 }
1468 }
1469
1470
1471 /**
1472 * Used by ContainerPeer to skip all the paint events during layout.
1473 *
1474 * @param isLayouting layouting state.
1475 */
1476 protected final void setLayouting(final boolean isLayouting) {
1477 this.isLayouting = isLayouting;
1478 }
1479
1480 /**
1481 * Returns layouting state. Used by ComponentPeer to skip all the paint
1482 * events during layout.
1483 *
1484 * @return true during layout, false otherwise.
1485 */
1486 private boolean isLayouting() {
1487 return isLayouting;
1488 }
1489 }
|
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.
1462 *
1463 * @return true during layout, false otherwise.
1464 */
1465 private boolean isLayouting() {
1466 return isLayouting;
1467 }
1468 }
|