Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c
32287 views
1
/*
2
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
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
/*
27
#ifdef HEADLESS
28
#error This file should not be included in headless library
29
#endif
30
*/
31
32
#ifdef __ANDROID__
33
# include "awt.h"
34
#endif
35
#include "awt_p.h"
36
#include "java_awt_Component.h"
37
38
#include "awt_Component.h"
39
40
#include <jni.h>
41
#include <jni_util.h>
42
#include <jawt_md.h>
43
44
#include "awt_GraphicsEnv.h"
45
46
47
// FIXME awt_TopLevel.c not found
48
#ifndef __ANDROID__
49
extern struct ComponentIDs componentIDs;
50
51
extern jfieldID windowID;
52
extern jfieldID targetID;
53
extern jfieldID graphicsConfigID;
54
extern jfieldID drawStateID;
55
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
56
#else
57
struct ComponentIDs componentIDs;
58
59
jfieldID windowID;
60
jfieldID targetID;
61
jfieldID graphicsConfigID;
62
jfieldID drawStateID;
63
struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
64
#endif
65
66
/*
67
* Lock the surface of the target component for native rendering.
68
* When finished drawing, the surface must be unlocked with
69
* Unlock(). This function returns a bitmask with one or more of the
70
* following values:
71
*
72
* JAWT_LOCK_ERROR - When an error has occurred and the surface could not
73
* be locked.
74
*
75
* JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
76
*
77
* JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
78
*
79
* JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
80
*/
81
JNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds)
82
{
83
JNIEnv* env;
84
jobject target, peer;
85
jclass componentClass;
86
jint drawState;
87
88
if (ds == NULL) {
89
#ifdef DEBUG
90
fprintf(stderr, "Drawing Surface is NULL\n");
91
#endif
92
return (jint)JAWT_LOCK_ERROR;
93
}
94
env = ds->env;
95
target = ds->target;
96
97
/* Make sure the target is a java.awt.Component */
98
componentClass = (*env)->FindClass(env, "java/awt/Component");
99
CHECK_NULL_RETURN(componentClass, (jint)JAWT_LOCK_ERROR);
100
101
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
102
#ifdef DEBUG
103
fprintf(stderr, "Target is not a component\n");
104
#endif
105
return (jint)JAWT_LOCK_ERROR;
106
}
107
108
if (!awtLockInited) {
109
return (jint)JAWT_LOCK_ERROR;
110
}
111
AWT_LOCK();
112
113
/* Get the peer of the target component */
114
peer = (*env)->GetObjectField(env, target, componentIDs.peer);
115
if (JNU_IsNull(env, peer)) {
116
#ifdef DEBUG
117
fprintf(stderr, "Component peer is NULL\n");
118
#endif
119
AWT_FLUSH_UNLOCK();
120
return (jint)JAWT_LOCK_ERROR;
121
}
122
123
drawState = (*env)->GetIntField(env, peer, drawStateID);
124
(*env)->SetIntField(env, peer, drawStateID, 0);
125
return drawState;
126
}
127
128
JNIEXPORT int32_t JNICALL
129
awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
130
{
131
JNIEnv* env;
132
jobject target, peer;
133
jclass componentClass;
134
AwtGraphicsConfigDataPtr adata;
135
int32_t result;
136
jobject gc_object;
137
if (ds == NULL) {
138
#ifdef DEBUG
139
fprintf(stderr, "Drawing Surface is NULL\n");
140
#endif
141
return (int32_t) 0;
142
}
143
144
env = ds->env;
145
target = ds->target;
146
147
/* Make sure the target is a java.awt.Component */
148
componentClass = (*env)->FindClass(env, "java/awt/Component");
149
CHECK_NULL_RETURN(componentClass, (int32_t) 0);
150
151
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
152
#ifdef DEBUG
153
fprintf(stderr, "DrawingSurface target must be a component\n");
154
#endif
155
return (int32_t) 0;
156
}
157
158
if (!awtLockInited) {
159
return (int32_t) 0;
160
}
161
162
AWT_LOCK();
163
164
/* Get the peer of the target component */
165
peer = (*env)->GetObjectField(env, target, componentIDs.peer);
166
if (JNU_IsNull(env, peer)) {
167
#ifdef DEBUG
168
fprintf(stderr, "Component peer is NULL\n");
169
#endif
170
AWT_UNLOCK();
171
return (int32_t) 0;
172
}
173
/* GraphicsConfiguration object of MComponentPeer */
174
gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);
175
176
if (gc_object != NULL) {
177
adata = (AwtGraphicsConfigDataPtr)
178
JNU_GetLongFieldAsPtr(env, gc_object,
179
x11GraphicsConfigIDs.aData);
180
} else {
181
#ifndef __ANDROID__
182
adata = getDefaultConfig(DefaultScreen(awt_display));
183
#else
184
adata = getDefaultConfig(0);
185
#endif
186
}
187
188
result = adata->AwtColorMatch(r, g, b, adata);
189
AWT_UNLOCK();
190
return result;
191
}
192
193
/*
194
* Get the drawing surface info.
195
* The value returned may be cached, but the values may change if
196
* additional calls to Lock() or Unlock() are made.
197
* Lock() must be called before this can return a valid value.
198
* Returns NULL if an error has occurred.
199
* When finished with the returned value, FreeDrawingSurfaceInfo must be
200
* called.
201
*/
202
JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
203
awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
204
{
205
JNIEnv* env;
206
jobject target, peer;
207
jclass componentClass;
208
JAWT_X11DrawingSurfaceInfo* px;
209
JAWT_DrawingSurfaceInfo* p;
210
XWindowAttributes attrs;
211
212
if (ds == NULL) {
213
#ifdef DEBUG
214
fprintf(stderr, "Drawing Surface is NULL\n");
215
#endif
216
return NULL;
217
}
218
219
env = ds->env;
220
target = ds->target;
221
222
/* Make sure the target is a java.awt.Component */
223
componentClass = (*env)->FindClass(env, "java/awt/Component");
224
CHECK_NULL_RETURN(componentClass, NULL);
225
226
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
227
#ifdef DEBUG
228
fprintf(stderr, "DrawingSurface target must be a component\n");
229
#endif
230
return NULL;
231
}
232
233
if (!awtLockInited) {
234
return NULL;
235
}
236
237
AWT_LOCK();
238
239
/* Get the peer of the target component */
240
peer = (*env)->GetObjectField(env, target, componentIDs.peer);
241
if (JNU_IsNull(env, peer)) {
242
#ifdef DEBUG
243
fprintf(stderr, "Component peer is NULL\n");
244
#endif
245
AWT_UNLOCK();
246
return NULL;
247
}
248
249
AWT_UNLOCK();
250
251
/* Allocate platform-specific data */
252
px = (JAWT_X11DrawingSurfaceInfo*)
253
malloc(sizeof(JAWT_X11DrawingSurfaceInfo));
254
255
/* Set drawable and display */
256
px->drawable = (*env)->GetLongField(env, peer, windowID);
257
/*
258
#ifdef __ANDROID__
259
Display fake_awt_display;
260
awt_display = &fake_awt_display;
261
awt_display->proto_major_version = 11;
262
awt_display->proto_minor_version = 7;
263
awt_display->vendor = "Android Xlib";
264
#endif
265
*/
266
px->display = awt_display;
267
268
/* Get window attributes to set other values */
269
#if !defined(__ANDROID__) && !defined(HEADLESS)
270
XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);
271
272
px->visualID = XVisualIDFromVisual(attrs.visual);
273
#else
274
px->visualID = TrueColor;
275
attrs.colormap = 1; // FIXME!
276
attrs.depth = 24;
277
#endif
278
279
/* Set the other values */
280
px->colormapID = attrs.colormap;
281
px->depth = attrs.depth;
282
px->GetAWTColor = awt_GetColor;
283
284
/* Allocate and initialize platform-independent data */
285
p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
286
p->platformInfo = px;
287
p->ds = ds;
288
p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
289
p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
290
p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
291
p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
292
p->clipSize = 1;
293
p->clip = &(p->bounds);
294
295
/* Return our new structure */
296
return p;
297
}
298
299
/*
300
* Free the drawing surface info.
301
*/
302
JNIEXPORT void JNICALL
303
awt_DrawingSurface_FreeDrawingSurfaceInfo(JAWT_DrawingSurfaceInfo* dsi)
304
{
305
if (dsi == NULL ) {
306
#ifdef DEBUG
307
fprintf(stderr, "Drawing Surface Info is NULL\n");
308
#endif
309
return;
310
}
311
free(dsi->platformInfo);
312
free(dsi);
313
}
314
315
/*
316
* Unlock the drawing surface of the target component for native rendering.
317
*/
318
JNIEXPORT void JNICALL awt_DrawingSurface_Unlock(JAWT_DrawingSurface* ds)
319
{
320
JNIEnv* env;
321
if (ds == NULL) {
322
#ifdef DEBUG
323
fprintf(stderr, "Drawing Surface is NULL\n");
324
#endif
325
return;
326
}
327
env = ds->env;
328
AWT_FLUSH_UNLOCK();
329
}
330
331
JNIEXPORT JAWT_DrawingSurface* JNICALL
332
awt_GetDrawingSurface(JNIEnv* env, jobject target)
333
{
334
jclass componentClass;
335
JAWT_DrawingSurface* p;
336
337
/* Make sure the target component is a java.awt.Component */
338
componentClass = (*env)->FindClass(env, "java/awt/Component");
339
CHECK_NULL_RETURN(componentClass, NULL);
340
341
if (!(*env)->IsInstanceOf(env, target, componentClass)) {
342
#ifdef DEBUG
343
fprintf(stderr,
344
"GetDrawingSurface target must be a java.awt.Component\n");
345
#endif
346
return NULL;
347
}
348
349
p = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface));
350
p->env = env;
351
p->target = (*env)->NewGlobalRef(env, target);
352
p->Lock = awt_DrawingSurface_Lock;
353
p->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo;
354
p->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo;
355
p->Unlock = awt_DrawingSurface_Unlock;
356
return p;
357
}
358
359
JNIEXPORT void JNICALL
360
awt_FreeDrawingSurface(JAWT_DrawingSurface* ds)
361
{
362
JNIEnv* env;
363
364
if (ds == NULL ) {
365
#ifdef DEBUG
366
fprintf(stderr, "Drawing Surface is NULL\n");
367
#endif
368
return;
369
}
370
env = ds->env;
371
(*env)->DeleteGlobalRef(env, ds->target);
372
free(ds);
373
}
374
375
JNIEXPORT void JNICALL
376
awt_Lock(JNIEnv* env)
377
{
378
if (awtLockInited) {
379
AWT_LOCK();
380
}
381
}
382
383
JNIEXPORT void JNICALL
384
awt_Unlock(JNIEnv* env)
385
{
386
if (awtLockInited) {
387
AWT_FLUSH_UNLOCK();
388
}
389
}
390
391
JNIEXPORT jobject JNICALL
392
awt_GetComponent(JNIEnv* env, void* platformInfo)
393
{
394
Window window = (Window)platformInfo;
395
jobject peer = NULL;
396
jobject target = NULL;
397
398
AWT_LOCK();
399
400
if (window != None) {
401
peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
402
"windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
403
if ((*env)->ExceptionCheck(env)) {
404
AWT_UNLOCK();
405
return (jobject)NULL;
406
}
407
}
408
if ((peer != NULL) &&
409
(JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
410
target = (*env)->GetObjectField(env, peer, targetID);
411
}
412
413
if (target == NULL) {
414
(*env)->ExceptionClear(env);
415
JNU_ThrowNullPointerException(env, "NullPointerException");
416
AWT_UNLOCK();
417
return (jobject)NULL;
418
}
419
420
AWT_UNLOCK();
421
422
return target;
423
}
424
425