Print this page
Added gradle and cmake project
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformView.java
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformView.java
1 1 /*
2 2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
26 26 package sun.lwawt.macosx;
27 27
28 28 import java.awt.*;
29 29 import java.awt.geom.Rectangle2D;
30 30 import java.util.concurrent.atomic.AtomicBoolean;
31 31 import java.util.concurrent.atomic.AtomicInteger;
32 32 import java.util.concurrent.atomic.AtomicReference;
33 33
34 34 import sun.awt.CGraphicsConfig;
35 35 import sun.awt.CGraphicsEnvironment;
36 +import sun.java2d.macos.MacOSFlags;
37 +import sun.java2d.metal.MTLLayer;
38 +import sun.java2d.metal.MTLSurfaceData;
36 39 import sun.lwawt.LWWindowPeer;
37 40
38 41 import sun.java2d.SurfaceData;
39 42 import sun.java2d.opengl.CGLLayer;
40 43 import sun.java2d.opengl.CGLSurfaceData;
41 44
42 45 public class CPlatformView extends CFRetainedResource {
43 46 private native long nativeCreateView(int x, int y, int width, int height, long windowLayerPtr);
44 47 private static native void nativeSetAutoResizable(long awtView, boolean toResize);
45 48 private static native int nativeGetNSViewDisplayID(long awtView);
46 49 private static native Rectangle2D nativeGetLocationOnScreen(long awtView);
47 50 private static native boolean nativeIsViewUnderMouse(long ptr);
48 51
49 52 private LWWindowPeer peer;
50 53 private SurfaceData surfaceData;
51 - private CGLLayer windowLayer;
54 + private CFRetainedResource windowLayer;
52 55 private CPlatformResponder responder;
53 56
54 57 public CPlatformView() {
55 58 super(0, true);
56 59 }
57 60
58 61 public void initialize(LWWindowPeer peer, CPlatformResponder responder) {
59 62 initializeBase(peer, responder);
60 63
61 64 if (!LWCToolkit.getSunAwtDisableCALayers()) {
62 - this.windowLayer = createCGLayer();
65 + this.windowLayer = MacOSFlags.isMetalEnabled()? createMTLLayer() : createCGLayer();
63 66 }
64 67 setPtr(nativeCreateView(0, 0, 0, 0, getWindowLayerPtr()));
65 68 }
66 69
67 70 public CGLLayer createCGLayer() {
68 71 return new CGLLayer(peer);
69 72 }
70 73
74 + public MTLLayer createMTLLayer() {
75 + return new MTLLayer(peer);
76 + }
77 +
78 +
71 79 protected void initializeBase(LWWindowPeer peer, CPlatformResponder responder) {
72 80 this.peer = peer;
73 81 this.responder = responder;
74 82 }
75 83
76 84 public long getAWTView() {
77 85 return ptr;
78 86 }
79 87
80 88 public boolean isOpaque() {
81 89 return !peer.isTranslucent();
82 90 }
83 91
84 92 /*
85 93 * All coordinates passed to the method should be based on the origin being in the bottom-left corner (standard
86 94 * Cocoa coordinates).
87 95 */
88 96 public void setBounds(int x, int y, int width, int height) {
89 97 execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height));
90 98 }
91 99
92 100 // REMIND: CGLSurfaceData expects top-level's size
93 101 public Rectangle getBounds() {
94 102 return peer.getBounds();
95 103 }
96 104
97 105 public Object getDestination() {
98 106 return peer;
99 107 }
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
100 108
101 109 public void setToolTip(String msg) {
102 110 execute(ptr -> CWrapper.NSView.setToolTip(ptr, msg));
103 111 }
104 112
105 113 // ----------------------------------------------------------------------
106 114 // PAINTING METHODS
107 115 // ----------------------------------------------------------------------
108 116 public SurfaceData replaceSurfaceData() {
109 117 if (!LWCToolkit.getSunAwtDisableCALayers()) {
110 - surfaceData = windowLayer.replaceSurfaceData();
118 + surfaceData = (MacOSFlags.isMetalEnabled()) ?
119 + ((MTLLayer)windowLayer).replaceSurfaceData() :
120 + ((CGLLayer)windowLayer).replaceSurfaceData()
121 + ;
111 122 } else {
112 123 if (surfaceData == null) {
113 124 CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration();
114 125 surfaceData = graphicsConfig.createSurfaceData(this);
115 126 } else {
116 127 validateSurface();
117 128 }
118 129 }
119 130 return surfaceData;
120 131 }
121 132
122 133 private void validateSurface() {
123 134 if (surfaceData != null) {
124 - ((CGLSurfaceData)surfaceData).validate();
135 + if (MacOSFlags.isMetalEnabled()) {
136 + ((MTLSurfaceData) surfaceData).validate();
137 + } else {
138 + ((CGLSurfaceData) surfaceData).validate();
139 + }
125 140 }
126 141 }
127 142
128 143 public GraphicsConfiguration getGraphicsConfiguration() {
129 144 return peer.getGraphicsConfiguration();
130 145 }
131 146
132 147 public SurfaceData getSurfaceData() {
133 148 return surfaceData;
134 149 }
135 150
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
136 151 @Override
137 152 public void dispose() {
138 153 if (!LWCToolkit.getSunAwtDisableCALayers()) {
139 154 windowLayer.dispose();
140 155 }
141 156 super.dispose();
142 157 }
143 158
144 159 public long getWindowLayerPtr() {
145 160 if (!LWCToolkit.getSunAwtDisableCALayers()) {
146 - return windowLayer.getPointer();
161 + return MacOSFlags.isMetalEnabled() ?
162 + ((MTLLayer)windowLayer).getPointer() :
163 + ((CGLLayer)windowLayer).getPointer();
147 164 } else {
148 165 return 0;
149 166 }
150 167 }
151 168
152 169 public void setAutoResizable(boolean toResize) {
153 170 execute(ptr -> nativeSetAutoResizable(ptr, toResize));
154 171 }
155 172
156 173 public boolean isUnderMouse() {
157 174 AtomicBoolean ref = new AtomicBoolean();
158 175 execute(ptr -> {
159 176 ref.set(nativeIsViewUnderMouse(ptr));
160 177 });
161 178 return ref.get();
162 179 }
163 180
164 181 public GraphicsDevice getGraphicsDevice() {
165 182 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
166 183 CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
167 184 AtomicInteger ref = new AtomicInteger();
168 185 execute(ptr -> {
169 186 ref.set(nativeGetNSViewDisplayID(ptr));
170 187 });
171 188 GraphicsDevice gd = cge.getScreenDevice(ref.get());
172 189 if (gd == null) {
173 190 // this could possibly happen during device removal
174 191 // use the default screen device in this case
175 192 gd = ge.getDefaultScreenDevice();
176 193 }
177 194 return gd;
178 195 }
179 196
180 197 public Point getLocationOnScreen() {
181 198 AtomicReference<Rectangle> ref = new AtomicReference<>();
182 199 execute(ptr -> {
183 200 ref.set(nativeGetLocationOnScreen(ptr).getBounds());
184 201 });
185 202 Rectangle r = ref.get();
186 203 if (r != null) {
187 204 return new Point(r.x, r.y);
188 205 }
189 206 return new Point(0, 0);
190 207 }
191 208
192 209 // ----------------------------------------------------------------------
193 210 // NATIVE CALLBACKS
194 211 // ----------------------------------------------------------------------
195 212
196 213 /*
197 214 * The callback is called only in the embedded case when the view is
198 215 * automatically resized by the superview.
199 216 * In normal mode this method is never called.
200 217 */
201 218 private void deliverResize(int x, int y, int w, int h) {
202 219 peer.notifyReshape(x, y, w, h);
203 220 }
204 221
205 222
206 223 private void deliverMouseEvent(final NSEvent event) {
207 224 int x = event.getX();
208 225 int y = getBounds().height - event.getY();
209 226 int absX = event.getAbsX();
210 227 int absY = event.getAbsY();
211 228
212 229 if (event.getType() == CocoaConstants.NSScrollWheel) {
213 230 responder.handleScrollEvent(x, y, absX, absY, event.getModifierFlags(),
214 231 event.getScrollDeltaX(), event.getScrollDeltaY(),
215 232 event.getScrollPhase());
216 233 } else {
217 234 responder.handleMouseEvent(event.getType(), event.getModifierFlags(), event.getButtonNumber(),
218 235 event.getClickCount(), x, y,
219 236 absX, absY);
220 237 }
221 238 }
222 239
223 240 private void deliverKeyEvent(NSEvent event) {
224 241 responder.handleKeyEvent(event.getType(), event.getModifierFlags(), event.getCharacters(),
225 242 event.getCharactersIgnoringModifiers(), event.getKeyCode(), true, false);
226 243 }
227 244
228 245 /**
229 246 * Called by the native delegate in layer backed view mode or in the simple
230 247 * NSView mode. See NSView.drawRect().
231 248 */
232 249 private void deliverWindowDidExposeEvent() {
233 250 peer.notifyExpose(peer.getSize());
234 251 }
235 252 }
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX