author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 44752 | jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m@97a2817b5a9b |
child 57196 | a95707a39ff5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
44752 | 2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
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 |
#import "AWTSurfaceLayers.h" |
|
27 |
#import "ThreadUtilities.h" |
|
28 |
#import "LWCToolkit.h" |
|
29 |
||
30 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
17411
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
31 |
#import <QuartzCore/CATransaction.h> |
12047 | 32 |
|
33 |
@implementation AWTSurfaceLayers |
|
34 |
||
35 |
@synthesize windowLayer; |
|
36 |
||
37 |
- (id) initWithWindowLayer:(CALayer *)aWindowLayer { |
|
38 |
self = [super init]; |
|
39 |
if (self == nil) return self; |
|
40 |
||
44752 | 41 |
self.windowLayer = aWindowLayer; |
12047 | 42 |
|
43 |
return self; |
|
44 |
} |
|
45 |
||
44752 | 46 |
- (void) dealloc { |
47 |
self.windowLayer = nil; |
|
48 |
[super dealloc]; |
|
49 |
} |
|
12047 | 50 |
|
51 |
- (CALayer *) layer { |
|
52 |
return layer; |
|
53 |
} |
|
54 |
||
55 |
- (void) setLayer:(CALayer *)newLayer { |
|
56 |
if (layer != newLayer) { |
|
57 |
if (layer != nil || newLayer == nil) { |
|
58 |
[layer removeFromSuperlayer]; |
|
59 |
[layer release]; |
|
60 |
} |
|
61 |
||
62 |
if (newLayer != nil) { |
|
63 |
layer = [newLayer retain]; |
|
64 |
// REMIND: window layer -> container layer |
|
65 |
[windowLayer addSublayer: layer]; |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
// Updates back buffer size of the layer if it's an OpenGL layer |
|
71 |
// including all OpenGL sublayers |
|
72 |
+ (void) repaintLayersRecursively:(CALayer*)aLayer { |
|
73 |
if ([aLayer isKindOfClass:[CAOpenGLLayer class]]) { |
|
74 |
[aLayer setNeedsDisplay]; |
|
75 |
} |
|
76 |
for(CALayer *child in aLayer.sublayers) { |
|
77 |
[AWTSurfaceLayers repaintLayersRecursively: child]; |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
- (void) setBounds:(CGRect)rect { |
|
82 |
// translates values to the coordinate system of the "root" layer |
|
17411
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
83 |
rect.origin.y = windowLayer.bounds.size.height - rect.origin.y - rect.size.height; |
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
84 |
[CATransaction begin]; |
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
85 |
[CATransaction setDisableActions:YES]; |
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
86 |
layer.frame = rect; |
6a6136a94ebb
8013841: [macosx] Animations not disabled for CALayers used via JAWT
serb
parents:
15322
diff
changeset
|
87 |
[CATransaction commit]; |
12047 | 88 |
[AWTSurfaceLayers repaintLayersRecursively:layer]; |
89 |
} |
|
90 |
||
91 |
@end |
|
92 |
||
93 |
/* |
|
94 |
* Class: sun_lwawt_macosx_CPlatformComponent |
|
95 |
* Method: nativeCreateLayer |
|
96 |
* Signature: ()J |
|
97 |
*/ |
|
98 |
JNIEXPORT jlong JNICALL |
|
99 |
Java_sun_lwawt_macosx_CPlatformComponent_nativeCreateComponent |
|
100 |
(JNIEnv *env, jobject obj, jlong windowLayerPtr) |
|
101 |
{ |
|
102 |
__block AWTSurfaceLayers *surfaceLayers = nil; |
|
103 |
||
104 |
JNF_COCOA_ENTER(env); |
|
105 |
||
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
106 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
107 |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
108 |
CALayer *windowLayer = jlong_to_ptr(windowLayerPtr); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
109 |
surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer]; |
12047 | 110 |
}]; |
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
111 |
|
12047 | 112 |
JNF_COCOA_EXIT(env); |
113 |
||
114 |
return ptr_to_jlong(surfaceLayers); |
|
115 |
} |
|
116 |
||
117 |
/* |
|
118 |
* Class: sun_lwawt_macosx_CPlatformComponent |
|
119 |
* Method: nativeSetBounds |
|
120 |
* Signature: (JIIII)V |
|
121 |
*/ |
|
122 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds |
|
123 |
(JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height) |
|
124 |
{ |
|
125 |
JNF_COCOA_ENTER(env); |
|
126 |
||
127 |
AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr); |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
128 |
|
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
129 |
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){ |
12047 | 130 |
|
131 |
CGRect rect = CGRectMake(x, y, width, height); |
|
132 |
[surfaceLayers setBounds: rect]; |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13544
diff
changeset
|
133 |
}]; |
12047 | 134 |
|
135 |
JNF_COCOA_EXIT(env); |
|
136 |
} |