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.macosx;
27
28 import java.awt.*;
29 import java.awt.geom.Rectangle2D;
30 import java.util.concurrent.atomic.AtomicBoolean;
31 import java.util.concurrent.atomic.AtomicInteger;
32 import java.util.concurrent.atomic.AtomicReference;
33
34 import sun.awt.CGraphicsConfig;
35 import sun.awt.CGraphicsEnvironment;
36 import sun.lwawt.LWWindowPeer;
37
38 import sun.java2d.SurfaceData;
39 import sun.java2d.opengl.CGLLayer;
40 import sun.java2d.opengl.CGLSurfaceData;
41
42 public class CPlatformView extends CFRetainedResource {
43 private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
44 private static native void nativeSetAutoResizable(long awtView, boolean toResize);
45 private static native int nativeGetNSViewDisplayID(long awtView);
46 private static native Rectangle2D nativeGetLocationOnScreen(long awtView);
47 private static native boolean nativeIsViewUnderMouse(long ptr);
48
49 private LWWindowPeer peer;
50 private SurfaceData surfaceData;
51 private CGLLayer windowLayer;
52 private CPlatformResponder responder;
53
54 public CPlatformView() {
55 super(0, true);
56 }
57
58 public void initialize(LWWindowPeer peer, CPlatformResponder responder) {
59 initializeBase(peer, responder);
60
61 if (!LWCToolkit.getSunAwtDisableCALayers()) {
62 this.windowLayer = createCGLayer();
63 }
64 setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
65 }
66
67 public CGLLayer createCGLayer() {
68 return new CGLLayer(peer);
69 }
70
71 protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) {
72 this.peer = peer;
73 this.responder = responder;
74 }
75
76 public long getAWTView() {
77 return ptr;
78 }
79
80 public boolean isOpaque() {
81 return !peer.isTranslucent();
82 }
83
84 /*
85 * All coordinates passed to the method should be based on the origin being in the bottom-left corner (standard
86 * Cocoa coordinates).
87 */
88 public void setBounds(int x, int y, int width, int height) {
89 execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height));
90 }
91
92 // REMIND: CGLSurfaceData expects top-level's size
93 public Rectangle getBounds() {
94 return peer.getBounds();
95 }
96
97 public Object getDestination() {
98 return peer;
99 }
100
101 public void setToolTip(String msg) {
102 execute(ptr -> CWrapper.NSView.setToolTip(ptr, msg));
103 }
104
105 // ----------------------------------------------------------------------
106 // PAINTING METHODS
107 // ----------------------------------------------------------------------
108 public SurfaceData replaceSurfaceData() {
109 if (!LWCToolkit.getSunAwtDisableCALayers()) {
110 surfaceData = windowLayer.replaceSurfaceData();
111 } else {
112 if (surfaceData == null) {
113 CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration();
114 surfaceData = graphicsConfig.createSurfaceData(this);
115 } else {
116 validateSurface();
117 }
118 }
119 return surfaceData;
120 }
121
122 private void validateSurface() {
123 if (surfaceData != null) {
124 ((CGLSurfaceData)surfaceData).validate();
125 }
126 }
127
128 public GraphicsConfiguration getGraphicsConfiguration() {
129 return peer.getGraphicsConfiguration();
130 }
131
132 public SurfaceData getSurfaceData() {
133 return surfaceData;
134 }
135
136 @Override
137 public void dispose() {
138 if (!LWCToolkit.getSunAwtDisableCALayers()) {
139 windowLayer.dispose();
140 }
141 super.dispose();
142 }
143
144 public long getWindowLayerPtr() {
145 if (!LWCToolkit.getSunAwtDisableCALayers()) {
146 return windowLayer.getPointer();
147 } else {
148 return 0;
149 }
150 }
151
152 public void setAutoResizable(boolean toResize) {
153 execute(ptr -> nativeSetAutoResizable(ptr, toResize));
154 }
155
156 public boolean isUnderMouse() {
157 AtomicBoolean ref = new AtomicBoolean();
158 execute(ptr -> {
159 ref.set(nativeIsViewUnderMouse(ptr));
160 });
161 return ref.get();
162 }
163
164 public GraphicsDevice getGraphicsDevice() {
165 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
166 CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
|
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.macosx;
27
28 import java.awt.*;
29 import java.awt.geom.Rectangle2D;
30 import java.util.concurrent.atomic.AtomicBoolean;
31 import java.util.concurrent.atomic.AtomicInteger;
32 import java.util.concurrent.atomic.AtomicReference;
33
34 import sun.awt.CGraphicsConfig;
35 import sun.awt.CGraphicsEnvironment;
36 import sun.java2d.macos.MacOSFlags;
37 import sun.java2d.metal.MTLLayer;
38 import sun.java2d.metal.MTLSurfaceData;
39 import sun.lwawt.LWWindowPeer;
40
41 import sun.java2d.SurfaceData;
42 import sun.java2d.opengl.CGLLayer;
43 import sun.java2d.opengl.CGLSurfaceData;
44
45 public class CPlatformView extends CFRetainedResource {
46 private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
47 private static native void nativeSetAutoResizable(long awtView, boolean toResize);
48 private static native int nativeGetNSViewDisplayID(long awtView);
49 private static native Rectangle2D nativeGetLocationOnScreen(long awtView);
50 private static native boolean nativeIsViewUnderMouse(long ptr);
51
52 private LWWindowPeer peer;
53 private SurfaceData surfaceData;
54 private CFRetainedResource windowLayer;
55 private CPlatformResponder responder;
56
57 public CPlatformView() {
58 super(0, true);
59 }
60
61 public void initialize(LWWindowPeer peer, CPlatformResponder responder) {
62 initializeBase(peer, responder);
63
64 if (!LWCToolkit.getSunAwtDisableCALayers()) {
65 this.windowLayer = MacOSFlags.isMetalEnabled()? createMTLLayer() : createCGLayer();
66 }
67 setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
68 }
69
70 public CGLLayer createCGLayer() {
71 return new CGLLayer(peer);
72 }
73
74 public MTLLayer createMTLLayer() {
75 return new MTLLayer(peer);
76 }
77
78
79 protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) {
80 this.peer = peer;
81 this.responder = responder;
82 }
83
84 public long getAWTView() {
85 return ptr;
86 }
87
88 public boolean isOpaque() {
89 return !peer.isTranslucent();
90 }
91
92 /*
93 * All coordinates passed to the method should be based on the origin being in the bottom-left corner (standard
94 * Cocoa coordinates).
95 */
96 public void setBounds(int x, int y, int width, int height) {
97 execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height));
98 }
99
100 // REMIND: CGLSurfaceData expects top-level's size
101 public Rectangle getBounds() {
102 return peer.getBounds();
103 }
104
105 public Object getDestination() {
106 return peer;
107 }
108
109 public void setToolTip(String msg) {
110 execute(ptr -> CWrapper.NSView.setToolTip(ptr, msg));
111 }
112
113 // ----------------------------------------------------------------------
114 // PAINTING METHODS
115 // ----------------------------------------------------------------------
116 public SurfaceData replaceSurfaceData() {
117 if (!LWCToolkit.getSunAwtDisableCALayers()) {
118 surfaceData = (MacOSFlags.isMetalEnabled()) ?
119 ((MTLLayer)windowLayer).replaceSurfaceData() :
120 ((CGLLayer)windowLayer).replaceSurfaceData()
121 ;
122 } else {
123 if (surfaceData == null) {
124 CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration();
125 surfaceData = graphicsConfig.createSurfaceData(this);
126 } else {
127 validateSurface();
128 }
129 }
130 return surfaceData;
131 }
132
133 private void validateSurface() {
134 if (surfaceData != null) {
135 if (MacOSFlags.isMetalEnabled()) {
136 ((MTLSurfaceData) surfaceData).validate();
137 } else {
138 ((CGLSurfaceData) surfaceData).validate();
139 }
140 }
141 }
142
143 public GraphicsConfiguration getGraphicsConfiguration() {
144 return peer.getGraphicsConfiguration();
145 }
146
147 public SurfaceData getSurfaceData() {
148 return surfaceData;
149 }
150
151 @Override
152 public void dispose() {
153 if (!LWCToolkit.getSunAwtDisableCALayers()) {
154 windowLayer.dispose();
155 }
156 super.dispose();
157 }
158
159 public long getWindowLayerPtr() {
160 if (!LWCToolkit.getSunAwtDisableCALayers()) {
161 return MacOSFlags.isMetalEnabled() ?
162 ((MTLLayer)windowLayer).getPointer() :
163 ((CGLLayer)windowLayer).getPointer();
164 } else {
165 return 0;
166 }
167 }
168
169 public void setAutoResizable(boolean toResize) {
170 execute(ptr -> nativeSetAutoResizable(ptr, toResize));
171 }
172
173 public boolean isUnderMouse() {
174 AtomicBoolean ref = new AtomicBoolean();
175 execute(ptr -> {
176 ref.set(nativeIsViewUnderMouse(ptr));
177 });
178 return ref.get();
179 }
180
181 public GraphicsDevice getGraphicsDevice() {
182 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
183 CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
|