blob: b3e52ee7790f911d7c82fb93fc72c3b08a1af18a [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997-2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#include "awt_p.h"
27#include "awt.h"
28#include "color.h"
29#include <java_awt_DisplayMode.h>
30#include <sun_awt_X11GraphicsEnvironment.h>
31#include <sun_awt_X11GraphicsDevice.h>
32#include <sun_awt_X11GraphicsConfig.h>
33#ifndef HEADLESS
34#include <X11/extensions/Xdbe.h>
35#include <X11/XKBlib.h>
36#include "Xrandr.h"
37#include "GLXGraphicsConfig.h"
38#endif /* !HEADLESS */
39
40#include <jni.h>
41#include <jni_util.h>
42#include <jvm.h>
43#include <jlong.h>
44
45#include <stdlib.h>
46
47#include "awt_GraphicsEnv.h"
48#include "awt_Window.h"
49#include "awt_util.h"
50#include "gdefs.h"
51#include <dlfcn.h>
52#include "Trace.h"
53
54#ifdef NETSCAPE
55#include <signal.h>
56extern int awt_init_xt;
57#endif
58
59#ifndef HEADLESS
60
61int awt_numScreens; /* Xinerama-aware number of screens */
62
63AwtScreenDataPtr x11Screens;
64
65/*
66 * Set in initDisplay() to indicate whether we should attempt to initialize
67 * GLX for the default configuration.
68 */
69static jboolean glxRequested = JNI_FALSE;
70
71#endif /* !HEADLESS */
72
73#ifdef HEADLESS
74#define Display void
75#endif /* HEADLESS */
76
77Display *awt_display;
78
79jclass tkClass = NULL;
80jmethodID awtLockMID = NULL;
81jmethodID awtUnlockMID = NULL;
82jmethodID awtWaitMID = NULL;
83jmethodID awtNotifyMID = NULL;
84jmethodID awtNotifyAllMID = NULL;
85jboolean awtLockInited = JNI_FALSE;
86
87/** Convenience macro for loading the lock-related method IDs. */
88#define GET_STATIC_METHOD(klass, method_id, method_name, method_sig) \
89 do { \
90 method_id = (*env)->GetStaticMethodID(env, klass, \
91 method_name, method_sig); \
92 if (method_id == NULL) return NULL; \
93 } while (0)
94
95struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
96struct X11GraphicsDeviceIDs x11GraphicsDeviceIDs;
97extern struct WindowIDs mWindowIDs;
98extern struct MWindowPeerIDs mWindowPeerIDs;
99
100#ifndef HEADLESS
101int awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata);
102#endif /* HEADLESS */
103
104static char *x11GraphicsConfigClassName = "sun/awt/X11GraphicsConfig";
105
106/* AWT and Xinerama
107 *
108 * As of fix 4356756, AWT is Xinerama-aware. X11GraphicsDevices are created for
109 * each screen of a Xinerama setup, though X11 itself still only sees a single
110 * display.
111 * In many places where we talk to X11, a xinawareScreen variable is used to
112 * pass the correct Display value, depending on the circumstances (a single
113 * X display, multiple X displays, or a single X display with multiple
114 * Xinerama screens).
115 *
116 * Solaris and Linux differ in the functions used to access Xinerama-related
117 * data. This is in part because at this time, the X consortium has not
118 * finalized the "official" Xinerama API. Once this spec is available, and
119 * both OSes are conformant, one code base should be sufficient for Xinerama
120 * operation on both OSes. Until then, some of the Xinerama-related code
121 * is ifdef'd appropriately. -bchristi, 7/12/01
122 */
123
124#define MAXFRAMEBUFFERS 16
125#ifdef __linux__
126typedef struct {
127 int screen_number;
128 short x_org;
129 short y_org;
130 short width;
131 short height;
132} XineramaScreenInfo;
133
134typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
135
136#else /* SOLARIS */
137typedef Status XineramaGetInfoFunc(Display* display, int screen_number,
138 XRectangle* framebuffer_rects, unsigned char* framebuffer_hints,
139 int* num_framebuffers);
140typedef Status XineramaGetCenterHintFunc(Display* display, int screen_number,
141 int* x, int* y);
142
143XineramaGetCenterHintFunc* XineramaSolarisCenterFunc = NULL;
144#endif
145
146Bool usingXinerama = False;
147XRectangle fbrects[MAXFRAMEBUFFERS];
148
149JNIEXPORT void JNICALL
150Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls)
151{
152 x11GraphicsConfigIDs.aData = NULL;
153 x11GraphicsConfigIDs.bitsPerPixel = NULL;
154 x11GraphicsConfigIDs.screen = NULL;
155
156 x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J");
157 x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I");
158 x11GraphicsConfigIDs.screen = (*env)->GetFieldID (env, cls, "screen", "Lsun/awt/X11GraphicsDevice;");
159
160 if (x11GraphicsConfigIDs.aData == NULL ||
161 x11GraphicsConfigIDs.bitsPerPixel == NULL ||
162 x11GraphicsConfigIDs.screen == NULL) {
163
164 JNU_ThrowNoSuchFieldError(env, "Can't find a field");
165 return;
166 }
167}
168
169JNIEXPORT void JNICALL
170Java_sun_awt_X11GraphicsDevice_initIDs (JNIEnv *env, jclass cls)
171{
172 x11GraphicsDeviceIDs.screen = NULL;
173 x11GraphicsDeviceIDs.screen = (*env)->GetFieldID (env, cls, "screen", "I");
174 DASSERT(x11GraphicsDeviceIDs.screen);
175}
176
177#ifndef HEADLESS
178/*
179 * error handlers
180 */
181
182int
183xerror_handler(Display * disp, XErrorEvent * err)
184{
185/* #ifdef DEBUG */
186 char msg[128];
187 char buf[128];
188 char *ev = getenv("NOISY_AWT");
189
190 if (!ev || !ev[0])
191 return 0;
192 XGetErrorText(disp, err->error_code, msg, sizeof(msg));
193 jio_fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid, err->serial);
194 jio_snprintf(buf, sizeof(buf), "%d", err->request_code);
195 XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
196 jio_fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
197 if (err->request_code > 128) {
198 jio_fprintf(stderr, "Minor opcode %d\n", err->minor_code);
199 }
200 if (awtLockInited) {
201 /*SignalError(lockedee->lastpc, lockedee, "fp/ade/gui/GUIException", msg); */
202 }
203 if (strcasecmp(ev, "abort") == 0) {
204 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
205
206 (*env)->FatalError(env, "xerror_handler abort");
207 }
208/* #endif */
209 return 0;
210}
211
212static int
213xioerror_handler(Display * disp)
214{
215 if (awtLockInited) {
216 if (errno == EPIPE) {
217 jio_fprintf(stderr, "X connection to %s host broken (explicit kill or server shutdown)\n", XDisplayName(NULL));
218 }
219 /*SignalError(lockedee->lastpc, lockedee, "fp/ade/gui/GUIException", "I/O error"); */
220 }
221 return 0;
222}
223
224static AwtGraphicsConfigDataPtr
225findWithTemplate(XVisualInfo *vinfo,
226 long mask)
227{
228
229 XVisualInfo *visualList;
230 XColor color;
231 AwtGraphicsConfigDataPtr defaultConfig;
232 int visualsMatched, i;
233
234 visualList = XGetVisualInfo(awt_display,
235 mask, vinfo, &visualsMatched);
236 if (visualList) {
237 defaultConfig = ZALLOC(_AwtGraphicsConfigData);
238 for (i = 0; i < visualsMatched; i++) {
239 memcpy(&defaultConfig->awt_visInfo, &visualList[i], sizeof(XVisualInfo));
240 defaultConfig->awt_depth = visualList[i].depth;
241
242 /* we can't use awtJNI_CreateColorData here, because it'll pull,
243 SystemColor, which in turn will cause toolkit to be reinitialized */
244 if (awtCreateX11Colormap(defaultConfig)) {
245 /* Allocate white and black pixels for this visual */
246 color.flags = DoRed | DoGreen | DoBlue;
247 color.red = color.green = color.blue = 0x0000;
248 XAllocColor(awt_display, defaultConfig->awt_cmap, &color);
249 x11Screens[visualList[i].screen].blackpixel = color.pixel;
250 color.flags = DoRed | DoGreen | DoBlue;
251 color.red = color.green = color.blue = 0xffff;
252 XAllocColor(awt_display, defaultConfig->awt_cmap, &color);
253 x11Screens[visualList[i].screen].whitepixel = color.pixel;
254
255 XFree(visualList);
256 return defaultConfig;
257 }
258 }
259 XFree(visualList);
260 free((void *)defaultConfig);
261 }
262 return NULL;
263}
264
265/* default config is based on X11 screen. All Xinerama screens of that X11
266 screen will have the same default config */
267/* Need more notes about which fields of the structure are based on the X
268 screen, and which are based on the Xinerama screen */
269static AwtGraphicsConfigDataPtr
270makeDefaultConfig(JNIEnv *env, int screen) {
271
272 AwtGraphicsConfigDataPtr defaultConfig;
273 int xinawareScreen = 0;
274 VisualID forcedVisualID, defaultVisualID;
275 char *forcedVisualStr;
276 XVisualInfo vinfo;
277 long mask;
278
279 xinawareScreen = usingXinerama ? 0 : screen;
280 defaultVisualID =
281 XVisualIDFromVisual(DefaultVisual(awt_display, xinawareScreen));
282
283 memset(&vinfo, 0, sizeof(XVisualInfo));
284 vinfo.screen = xinawareScreen;
285
286 if ((forcedVisualStr = getenv("FORCEDEFVIS"))) {
287 mask = VisualIDMask | VisualScreenMask;
288 if (sscanf(forcedVisualStr, "%x", &forcedVisualID) > 0 &&
289 forcedVisualID > 0)
290 {
291 vinfo.visualid = forcedVisualID;
292 } else {
293 vinfo.visualid = defaultVisualID;
294 }
295 } else {
296 VisualID bestGLXVisualID;
297 if (glxRequested &&
298 (bestGLXVisualID = GLXGC_FindBestVisual(env, xinawareScreen)) > 0)
299 {
300 /* we've found the best visual for use with GLX, so use it */
301 vinfo.visualid = bestGLXVisualID;
302 mask = VisualIDMask | VisualScreenMask;
303 } else {
304 /* otherwise, continue looking for the best X11 visual */
305 vinfo.depth = 24;
306 vinfo.class = TrueColor;
307 mask = VisualDepthMask | VisualScreenMask | VisualClassMask;
308 }
309 }
310
311 /* try the best, or forced visual */
312 defaultConfig = findWithTemplate(&vinfo, mask);
313 if (defaultConfig) {
314 return defaultConfig;
315 }
316
317 /* try the default visual */
318 vinfo.visualid = defaultVisualID;
319 mask = VisualIDMask | VisualScreenMask;
320 defaultConfig = findWithTemplate(&vinfo, mask);
321 if (defaultConfig) {
322 return defaultConfig;
323 }
324
325 /* try any TrueColor */
326 vinfo.class = TrueColor;
327 mask = VisualScreenMask | VisualClassMask;
328 defaultConfig = findWithTemplate(&vinfo, mask);
329 if (defaultConfig) {
330 return defaultConfig;
331 }
332
333 /* try 8-bit PseudoColor */
334 vinfo.depth = 8;
335 vinfo.class = PseudoColor;
336 mask = VisualDepthMask | VisualScreenMask | VisualClassMask;
337 defaultConfig = findWithTemplate(&vinfo, mask);
338 if (defaultConfig) {
339 return defaultConfig;
340 }
341
342 /* try any 8-bit */
343 vinfo.depth = 8;
344 mask = VisualDepthMask | VisualScreenMask;
345 defaultConfig = findWithTemplate(&vinfo, mask);
346 if (defaultConfig) {
347 return defaultConfig;
348 }
349
350 /* we tried everything, give up */
351 JNU_ThrowInternalError(env, "Can't find supported visual");
352 XCloseDisplay(awt_display);
353 awt_display = NULL;
354 return NULL;
355}
356
357static void
358getAllConfigs (JNIEnv *env, int screen, AwtScreenDataPtr screenDataPtr) {
359
360 int i;
361 int n8p=0, n12p=0, n8s=0, n8gs=0, n8sg=0, n1sg=0, nTrue=0;
362 int nConfig;
363 XVisualInfo *pVI8p, *pVI12p, *pVI8s, *pVITrue, *pVI8gs,
364 *pVI8sg, *pVI1sg = NULL, viTmp;
365 AwtGraphicsConfigDataPtr *graphicsConfigs;
366 AwtGraphicsConfigDataPtr defaultConfig;
367 int ind;
368 char errmsg[128];
369 int xinawareScreen;
370
371 if (usingXinerama) {
372 xinawareScreen = 0;
373 }
374 else {
375 xinawareScreen = screen;
376 }
377
378 AWT_LOCK ();
379
380 viTmp.screen = xinawareScreen;
381
382 viTmp.depth = 8;
383 viTmp.class = PseudoColor;
384 viTmp.colormap_size = 256;
385 pVI8p = XGetVisualInfo (awt_display,
386 VisualDepthMask | VisualClassMask |
387 VisualColormapSizeMask | VisualScreenMask,
388 &viTmp, &n8p);
389
390 viTmp.depth = 12;
391 viTmp.class = PseudoColor;
392 viTmp.colormap_size = 4096;
393 pVI12p = XGetVisualInfo (awt_display,
394 VisualDepthMask | VisualClassMask |
395 VisualColormapSizeMask | VisualScreenMask,
396 &viTmp, &n12p);
397
398 viTmp.class = TrueColor;
399 pVITrue = XGetVisualInfo (awt_display,
400 VisualClassMask |
401 VisualScreenMask,
402 &viTmp, &nTrue);
403
404 viTmp.depth = 8;
405 viTmp.class = StaticColor;
406 pVI8s = XGetVisualInfo (awt_display, VisualDepthMask | VisualClassMask |
407 VisualScreenMask, &viTmp, &n8s);
408
409 viTmp.depth = 8;
410 viTmp.class = GrayScale;
411 viTmp.colormap_size = 256;
412 pVI8gs = XGetVisualInfo (awt_display,
413 VisualDepthMask | VisualClassMask |
414 VisualColormapSizeMask | VisualScreenMask,
415 &viTmp, &n8gs);
416 viTmp.depth = 8;
417 viTmp.class = StaticGray;
418 viTmp.colormap_size = 256;
419 pVI8sg = XGetVisualInfo (awt_display,
420 VisualDepthMask | VisualClassMask |
421 VisualColormapSizeMask | VisualScreenMask,
422 &viTmp, &n8sg);
423
424/* REMIND.. remove when we have support for the color classes below */
425/* viTmp.depth = 1; */
426/* viTmp.class = StaticGray; */
427/* pVI1sg = XGetVisualInfo (awt_display, VisualDepthMask | VisualClassMask, */
428/* viTmp, &n1sg); */
429
430 nConfig = n8p + n12p + n8s + n8gs + n8sg + n1sg + nTrue + 1;
431 graphicsConfigs = (AwtGraphicsConfigDataPtr *)
432 calloc(nConfig, sizeof(AwtGraphicsConfigDataPtr));
433 if (graphicsConfigs == NULL) {
434 JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2),
435 NULL);
436 AWT_UNLOCK();
437 return;
438 }
439
440 if (screenDataPtr->defaultConfig == NULL) {
441 /*
442 * After a display change event, the default config field will have
443 * been reset, so we need to recreate the default config here.
444 */
445 screenDataPtr->defaultConfig = makeDefaultConfig(env, screen);
446 }
447
448 defaultConfig = screenDataPtr->defaultConfig;
449 graphicsConfigs[0] = defaultConfig;
450 nConfig = 1; /* reserve index 0 for default config */
451
452 for (i = 0; i < nTrue; i++) {
453 if (XVisualIDFromVisual(pVITrue[i].visual) ==
454 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) ||
455 pVITrue[i].depth == 12) {
456 /* Skip the non-supported 12-bit TrueColor visual */
457 continue;
458 } else {
459 ind = nConfig++;
460 }
461 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
462 graphicsConfigs [ind]->awt_depth = pVITrue [i].depth;
463 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i],
464 sizeof (XVisualInfo));
465 }
466
467 for (i = 0; i < n8p; i++) {
468 if (XVisualIDFromVisual(pVI8p[i].visual) ==
469 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
470 continue;
471 } else {
472 ind = nConfig++;
473 }
474 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
475 graphicsConfigs [ind]->awt_depth = pVI8p [i].depth;
476 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8p [i],
477 sizeof (XVisualInfo));
478 }
479
480 for (i = 0; i < n12p; i++) {
481 if (XVisualIDFromVisual(pVI12p[i].visual) ==
482 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
483 continue;
484 } else {
485 ind = nConfig++;
486 }
487 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
488 graphicsConfigs [ind]->awt_depth = pVI12p [i].depth;
489 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI12p [i],
490 sizeof (XVisualInfo));
491 }
492
493 for (i = 0; i < n8s; i++) {
494 if (XVisualIDFromVisual(pVI8s[i].visual) ==
495 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
496 continue;
497 } else {
498 ind = nConfig++;
499 }
500 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
501 graphicsConfigs [ind]->awt_depth = pVI8s [i].depth;
502 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8s [i],
503 sizeof (XVisualInfo));
504 }
505
506 for (i = 0; i < n8gs; i++) {
507 if (XVisualIDFromVisual(pVI8gs[i].visual) ==
508 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
509 continue;
510 } else {
511 ind = nConfig++;
512 }
513 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
514 graphicsConfigs [ind]->awt_depth = pVI8gs [i].depth;
515 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8gs [i],
516 sizeof (XVisualInfo));
517 }
518
519 for (i = 0; i < n8sg; i++) {
520 if (XVisualIDFromVisual(pVI8sg[i].visual) ==
521 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
522 continue;
523 } else {
524 ind = nConfig++;
525 }
526 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
527 graphicsConfigs [ind]->awt_depth = pVI8sg [i].depth;
528 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8sg [i],
529 sizeof (XVisualInfo));
530 }
531
532 for (i = 0; i < n1sg; i++) {
533 if (XVisualIDFromVisual(pVI1sg[i].visual) ==
534 XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
535 continue;
536 } else {
537 ind = nConfig++;
538 }
539 graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
540 graphicsConfigs [ind]->awt_depth = pVI1sg [i].depth;
541 memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI1sg [i],
542 sizeof (XVisualInfo));
543 }
544
545 if (n8p != 0)
546 XFree (pVI8p);
547 if (n12p != 0)
548 XFree (pVI12p);
549 if (n8s != 0)
550 XFree (pVI8s);
551 if (n8gs != 0)
552 XFree (pVI8gs);
553 if (n8sg != 0)
554 XFree (pVI8sg);
555 if (n1sg != 0)
556 XFree (pVI1sg);
557
558 screenDataPtr->numConfigs = nConfig;
559 screenDataPtr->configs = graphicsConfigs;
560
561 AWT_UNLOCK ();
562}
563
564/*
565 * Determing if this top-level has been moved onto another Xinerama screen.
566 * Called from awt_TopLevel.c
567 *
568 * ASSUME: wdata != null
569 */
570#ifndef HEADLESS
571void checkNewXineramaScreen(JNIEnv* env, jobject peer, struct FrameData* wdata,
572 int32_t newX, int32_t newY,
573 int32_t newWidth, int32_t newHeight) {
574 int i;
575 int amt;
576 int totAmt = 0;
577 int largestAmt = 0;
578 int largestAmtScr = 0;
579
580 int horiz;
581 int vert;
582
583 if (!usingXinerama) { return; }
584
585 totAmt = newWidth * newHeight;
586
587 /* assert that peer implements WindowPeer */
588 DASSERT(JNU_IsInstanceOfByName(env, peer, "java/awt/peer/WindowPeer"));
589
590 DTRACE_PRINTLN4("checkNewXineramaScreen() x=%i y=%i w=%i h=%i\n",newX, newY, newWidth, newHeight);
591
592 /* decide which screen we're on
593 * if we're spanning, figure out which screen we're most on
594 */
595 for (i = 0; i < awt_numScreens; i++) {
596 if (INTERSECTS(newX, newX + newWidth, newY, newY + newHeight,
597 fbrects[i].x, fbrects[i].x + fbrects[i].width,
598 fbrects[i].y, fbrects[i].y + fbrects[i].height)) {
599
600 /* calc how much of window is on this screen */
601 horiz = MIN(newX + newWidth, fbrects[i].x + fbrects[i].width) -
602 MAX(newX, fbrects[i].x);
603 vert = MIN(newY + newHeight, fbrects[i].y + fbrects[i].height) -
604 MAX(newY, fbrects[i].y);
605 DASSERT(horiz > 0);
606 DASSERT(vert > 0);
607
608 amt = horiz * vert;
609 if (amt == totAmt) {
610 /* completely on this screen - done! */
611 largestAmtScr = i;
612 break;
613 }
614 if (amt > largestAmt) {
615 largestAmt = amt;
616 largestAmtScr = i;
617 }
618 }
619 }
620
621#ifndef XAWT
622 /* check if we're on a new screen */
623 if (largestAmtScr != wdata->screenNum) {
624 wdata->screenNum = largestAmtScr;
625 /* update peer, target Comp */
626 (*env)->CallVoidMethod(env, peer,
627 mWindowPeerIDs.draggedToScreenMID, largestAmtScr);
628 }
629#endif /* XAWT */
630}
631#endif /* HEADLESS */
632
633#ifndef HEADLESS
634#ifdef __linux__
635static void xinerama_init_linux()
636{
637 void* libHandle = 0;
638 char* XineramaLibName= "libXinerama.so.1";
639 int32_t locNumScr = 0;
640 XineramaScreenInfo *xinInfo;
641 char* XineramaQueryScreensName = "XineramaQueryScreens";
642 XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
643
644 /* load library */
645 libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
646 if (libHandle != 0) {
647 XineramaQueryScreens = (XineramaQueryScreensFunc*)
648 dlsym(libHandle, XineramaQueryScreensName);
649
650 if (XineramaQueryScreens != NULL) {
651 DTRACE_PRINTLN("calling XineramaQueryScreens func on Linux");
652 xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
653 if (xinInfo != NULL) {
654 int32_t idx;
655 DTRACE_PRINTLN("Enabling Xinerama support");
656 usingXinerama = True;
657 /* set global number of screens */
658 DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
659 awt_numScreens = locNumScr;
660
661 /* stuff values into fbrects */
662 for (idx = 0; idx < awt_numScreens; idx++) {
663 DASSERT(xinInfo[idx].screen_number == idx);
664
665 fbrects[idx].width = xinInfo[idx].width;
666 fbrects[idx].height = xinInfo[idx].height;
667 fbrects[idx].x = xinInfo[idx].x_org;
668 fbrects[idx].y = xinInfo[idx].y_org;
669 }
670 } else {
671 DTRACE_PRINTLN("calling XineramaQueryScreens didn't work");
672 }
673 } else {
674 DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
675 }
676 dlclose(libHandle);
677 } else {
678 DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
679 }
680}
681#endif
682#ifndef __linux__ /* Solaris */
683static void xinerama_init_solaris()
684{
685 void* libHandle = 0;
686 char* XineramaLibName= "libXext.so";
687 unsigned char fbhints[MAXFRAMEBUFFERS];
688 int32_t locNumScr = 0;
689 /* load and run XineramaGetInfo */
690 char* XineramaGetInfoName = "XineramaGetInfo";
691 char* XineramaGetCenterHintName = "XineramaGetCenterHint";
692 XineramaGetInfoFunc* XineramaSolarisFunc = NULL;
693
694 /* load library */
695 libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
696 if (libHandle != 0) {
697 XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName);
698 XineramaSolarisCenterFunc =
699 (XineramaGetCenterHintFunc*)dlsym(libHandle, XineramaGetCenterHintName);
700
701 if (XineramaSolarisFunc != NULL) {
702 DTRACE_PRINTLN("calling XineramaGetInfo func on Solaris");
703 if ((*XineramaSolarisFunc)(awt_display, 0, &fbrects[0],
704 &fbhints[0], &locNumScr) != 0)
705 {
706 DTRACE_PRINTLN("Enabling Xinerama support");
707 usingXinerama = True;
708 /* set global number of screens */
709 DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
710 awt_numScreens = locNumScr;
711 } else {
712 DTRACE_PRINTLN("calling XineramaGetInfo didn't work");
713 }
714 } else {
715 DTRACE_PRINTLN("couldn't load XineramaGetInfo symbol");
716 }
717 dlclose(libHandle);
718 } else {
719 DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
720 }
721}
722#endif
723
724/*
725 * Checks if Xinerama is running and perform Xinerama-related
726 * platform dependent initialization.
727 */
728static void xineramaInit(void) {
729 char* XinExtName = "XINERAMA";
730 int32_t major_opcode, first_event, first_error;
731 Bool gotXinExt = False;
732
733 gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
734 &first_event, &first_error);
735
736 if (!gotXinExt) {
737 DTRACE_PRINTLN("Xinerama extension is not available");
738 return;
739 }
740
741 DTRACE_PRINTLN("Xinerama extension is available");
742#ifdef __linux__
743 xinerama_init_linux();
744#else /* Solaris */
745 xinerama_init_solaris();
746#endif /* __linux__ */
747}
748#endif /* HEADLESS */
749
750Display *
751awt_init_Display(JNIEnv *env, jobject this)
752{
753 jclass klass;
754 Display *dpy;
755 char errmsg[128];
756 int i;
757#ifdef NETSCAPE
758 sigset_t alarm_set, oldset;
759#endif
760
761 if (awt_display) {
762 return awt_display;
763 }
764
765#ifdef NETSCAPE
766 /* Disable interrupts during XtOpenDisplay to avoid bugs in unix os select
767 code: some unix systems don't implement SA_RESTART properly and
768 because of this, select returns with EINTR. Most implementations of
769 gethostbyname don't cope with EINTR properly and as a result we get
770 stuck (forever) in the gethostbyname code
771 */
772 sigemptyset(&alarm_set);
773 sigaddset(&alarm_set, SIGALRM);
774 sigprocmask(SIG_BLOCK, &alarm_set, &oldset);
775#endif
776
777 /* Load AWT lock-related methods in SunToolkit */
778 klass = (*env)->FindClass(env, "sun/awt/SunToolkit");
779 if (klass == NULL) return NULL;
780 GET_STATIC_METHOD(klass, awtLockMID, "awtLock", "()V");
781 GET_STATIC_METHOD(klass, awtUnlockMID, "awtUnlock", "()V");
782 GET_STATIC_METHOD(klass, awtWaitMID, "awtLockWait", "(J)V");
783 GET_STATIC_METHOD(klass, awtNotifyMID, "awtLockNotify", "()V");
784 GET_STATIC_METHOD(klass, awtNotifyAllMID, "awtLockNotifyAll", "()V");
785 tkClass = (*env)->NewGlobalRef(env, klass);
786 awtLockInited = JNI_TRUE;
787
788 if (getenv("_AWT_IGNORE_XKB") != NULL &&
789 strlen(getenv("_AWT_IGNORE_XKB")) > 0) {
790 if (XkbIgnoreExtension(True)) {
791 printf("Ignoring XKB.\n");
792 }
793 }
794
795 dpy = awt_display = XOpenDisplay(NULL);
796#ifdef NETSCAPE
797 sigprocmask(SIG_SETMASK, &oldset, NULL);
798#endif
799 if (!dpy) {
800 jio_snprintf(errmsg,
801 sizeof(errmsg),
802 "Can't connect to X11 window server using '%s' as the value of the DISPLAY variable.",
803 (getenv("DISPLAY") == NULL) ? ":0.0" : getenv("DISPLAY"));
804 JNU_ThrowInternalError(env, errmsg);
805 return NULL;
806 }
807
808 XSetErrorHandler(xerror_handler);
809 XSetIOErrorHandler(xioerror_handler);
810
811 /* set awt_numScreens, and whether or not we're using Xinerama */
812 xineramaInit();
813
814 if (!usingXinerama) {
815 awt_numScreens = XScreenCount(awt_display);
816 }
817
818 DTRACE_PRINTLN1("allocating %i screens\n", awt_numScreens);
819 /* Allocate screen data structure array */
820 x11Screens = calloc(awt_numScreens, sizeof(AwtScreenData));
821 if (x11Screens == NULL) {
822 JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2),
823 NULL);
824 return NULL;
825 }
826
827 for (i = 0; i < awt_numScreens; i++) {
828 if (usingXinerama) {
829 /* All Xinerama screens use the same X11 root for now */
830 x11Screens[i].root = RootWindow(awt_display, 0);
831 }
832 else {
833 x11Screens[i].root = RootWindow(awt_display, i);
834 }
835 x11Screens[i].defaultConfig = makeDefaultConfig(env, i);
836 }
837
838 return dpy;
839}
840#endif /* !HEADLESS */
841
842/*
843 * Class: sun_awt_X11GraphicsEnvironment
844 * Method: getDefaultScreenNum
845 * Signature: ()I
846 */
847JNIEXPORT jint JNICALL
848Java_sun_awt_X11GraphicsEnvironment_getDefaultScreenNum(
849JNIEnv *env, jobject this)
850{
851#ifdef HEADLESS
852 return (jint)0;
853#else
854 return DefaultScreen(awt_display);
855#endif /* !HEADLESS */
856}
857
858#ifndef HEADLESS
859static void ensureConfigsInited(JNIEnv* env, int screen) {
860 if (x11Screens[screen].numConfigs == 0) {
861 if (env == NULL) {
862 env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
863 }
864 getAllConfigs (env, screen, &(x11Screens[screen]));
865 }
866}
867#endif
868
869#ifdef HEADLESS
870void* getDefaultConfig(int screen) {
871 return NULL;
872}
873#else
874AwtGraphicsConfigDataPtr
875getDefaultConfig(int screen) {
876 ensureConfigsInited(NULL, screen);
877 return x11Screens[screen].defaultConfig;
878}
879
880AwtScreenDataPtr
881getScreenData(int screen) {
882 return &(x11Screens[screen]);
883}
884#endif /* !HEADLESS */
885
886/*
887 * Class: sun_awt_X11GraphicsEnvironment
888 * Method: initDisplay
889 * Signature: (Z)V
890 */
891JNIEXPORT void JNICALL
892Java_sun_awt_X11GraphicsEnvironment_initDisplay(JNIEnv *env, jobject this,
893 jboolean glxReq)
894{
895#ifndef HEADLESS
896 glxRequested = glxReq;
897 (void) awt_init_Display(env, this);
898#endif /* !HEADLESS */
899}
900
901/*
902 * Class: sun_awt_X11GraphicsEnvironment
903 * Method: initGLX
904 * Signature: ()Z
905 */
906JNIEXPORT jboolean JNICALL
907Java_sun_awt_X11GraphicsEnvironment_initGLX(JNIEnv *env, jclass x11ge)
908{
909#ifndef HEADLESS
910 jboolean glxAvailable;
911
912 AWT_LOCK();
913 glxAvailable = GLXGC_IsGLXAvailable();
914 AWT_UNLOCK();
915
916 return glxAvailable;
917#else
918 return JNI_FALSE;
919#endif /* !HEADLESS */
920}
921
922/*
923 * Class: sun_awt_X11GraphicsEnvironment
924 * Method: getNumScreens
925 * Signature: ()I
926 */
927JNIEXPORT jint JNICALL
928Java_sun_awt_X11GraphicsEnvironment_getNumScreens(JNIEnv *env, jobject this)
929{
930#ifdef HEADLESS
931 return (jint)0;
932#else
933 return awt_numScreens;
934#endif /* !HEADLESS */
935}
936
937/*
938 * Class: sun_awt_X11GraphicsDevice
939 * Method: getDisplay
940 * Signature: ()J
941 */
942JNIEXPORT jlong JNICALL
943Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this)
944{
945#ifdef HEADLESS
946 return NULL;
947#else
948 return ptr_to_jlong(awt_display);
949#endif /* !HEADLESS */
950}
951
952#ifdef MITSHM
953
954static jint canUseShmExt = UNSET_MITSHM;
955static jint canUseShmExtPixmaps = UNSET_MITSHM;
956static jboolean xshmAttachFailed = JNI_FALSE;
957
958int J2DXErrHandler(Display *display, XErrorEvent *xerr) {
959 int ret = 0;
960 if (xerr->minor_code == X_ShmAttach) {
961 xshmAttachFailed = JNI_TRUE;
962 } else {
963 ret = (*xerror_saved_handler)(display, xerr);
964 }
965 return ret;
966}
967jboolean isXShmAttachFailed() {
968 return xshmAttachFailed;
969}
970void resetXShmAttachFailed() {
971 xshmAttachFailed = JNI_FALSE;
972}
973
974void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
975 XShmSegmentInfo shminfo;
976 int XShmMajor, XShmMinor;
977 int a, b, c;
978
979 AWT_LOCK();
980 if (canUseShmExt != UNSET_MITSHM) {
981 *shmExt = canUseShmExt;
982 *shmPixmaps = canUseShmExtPixmaps;
983 AWT_UNLOCK();
984 return;
985 }
986
987 *shmExt = canUseShmExt = CANT_USE_MITSHM;
988 *shmPixmaps = canUseShmExtPixmaps = CANT_USE_MITSHM;
989
990 /**
991 * XShmQueryExtension returns False in remote server case.
992 * Unfortunately it also returns True in ssh case, so
993 * we need to test that we can actually do XShmAttach.
994 */
995 if (XShmQueryExtension(awt_display)) {
996 shminfo.shmid = shmget(IPC_PRIVATE, 0x10000, IPC_CREAT|0777);
997 if (shminfo.shmid < 0) {
998 AWT_UNLOCK();
999 J2dRlsTraceLn1(J2D_TRACE_ERROR,
1000 "TryInitMITShm: shmget has failed: %s",
1001 strerror(errno));
1002 return;
1003 }
1004 shminfo.shmaddr = (char *) shmat(shminfo.shmid, 0, 0);
1005 if (shminfo.shmaddr == ((char *) -1)) {
1006 shmctl(shminfo.shmid, IPC_RMID, 0);
1007 AWT_UNLOCK();
1008 J2dRlsTraceLn1(J2D_TRACE_ERROR,
1009 "TryInitMITShm: shmat has failed: %s",
1010 strerror(errno));
1011 return;
1012 }
1013 shminfo.readOnly = True;
1014
1015 resetXShmAttachFailed();
1016 /**
1017 * The J2DXErrHandler handler will set xshmAttachFailed
1018 * to JNI_TRUE if any Shm error has occured.
1019 */
1020 EXEC_WITH_XERROR_HANDLER(J2DXErrHandler,
1021 XShmAttach(awt_display, &shminfo));
1022
1023 /**
1024 * Get rid of the id now to reduce chances of leaking
1025 * system resources.
1026 */
1027 shmctl(shminfo.shmid, IPC_RMID, 0);
1028
1029 if (isXShmAttachFailed() == JNI_FALSE) {
1030 canUseShmExt = CAN_USE_MITSHM;
1031 /* check if we can use shared pixmaps */
1032 XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
1033 (Bool*)&canUseShmExtPixmaps);
1034 canUseShmExtPixmaps = canUseShmExtPixmaps &&
1035 (XShmPixmapFormat(awt_display) == ZPixmap);
1036 XShmDetach(awt_display, &shminfo);
1037 }
1038 shmdt(shminfo.shmaddr);
1039 *shmExt = canUseShmExt;
1040 *shmPixmaps = canUseShmExtPixmaps;
1041 }
1042 AWT_UNLOCK();
1043}
1044#endif /* MITSHM */
1045
1046/*
1047 * Class: sun_awt_X11GraphicsEnvironment
1048 * Method: checkShmExt
1049 * Signature: ()I
1050 */
1051JNIEXPORT jint JNICALL
1052Java_sun_awt_X11GraphicsEnvironment_checkShmExt(JNIEnv *env, jobject this)
1053{
1054
1055 int shmExt = NOEXT_MITSHM, shmPixmaps;
1056#ifdef MITSHM
1057 TryInitMITShm(env, &shmExt, &shmPixmaps);
1058#endif
1059 return shmExt;
1060}
1061
1062/*
1063 * Class: sun_awt_X11GraphicsEnvironment
1064 * Method: getDisplayString
1065 * Signature: ()Ljava/lang/String
1066 */
1067JNIEXPORT jstring JNICALL
1068Java_sun_awt_X11GraphicsEnvironment_getDisplayString
1069 (JNIEnv *env, jobject this)
1070{
1071#ifdef HEADLESS
1072 return (jstring)NULL;
1073#else
1074 return (*env)->NewStringUTF(env, DisplayString(awt_display));
1075#endif /* HEADLESS */
1076}
1077
1078
1079/*
1080 * Class: sun_awt_X11GraphicsDevice
1081 * Method: getNumConfigs
1082 * Signature: ()I
1083 */
1084JNIEXPORT jint JNICALL
1085Java_sun_awt_X11GraphicsDevice_getNumConfigs(
1086JNIEnv *env, jobject this, jint screen)
1087{
1088#ifdef HEADLESS
1089 return (jint)0;
1090#else
1091 ensureConfigsInited(env, screen);
1092 return x11Screens[screen].numConfigs;
1093#endif /* !HEADLESS */
1094}
1095
1096/*
1097 * Class: sun_awt_X11GraphicsDevice
1098 * Method: getConfigVisualId
1099 * Signature: (I)I
1100 */
1101JNIEXPORT jint JNICALL
1102Java_sun_awt_X11GraphicsDevice_getConfigVisualId(
1103JNIEnv *env, jobject this, jint index, jint screen)
1104{
1105#ifdef HEADLESS
1106 return (jint)0;
1107#else
1108 int visNum;
1109
1110 ensureConfigsInited(env, screen);
1111 if (index == 0) {
1112 return ((jint)x11Screens[screen].defaultConfig->awt_visInfo.visualid);
1113 } else {
1114 return ((jint)x11Screens[screen].configs[index]->awt_visInfo.visualid);
1115 }
1116#endif /* !HEADLESS */
1117}
1118
1119/*
1120 * Class: sun_awt_X11GraphicsDevice
1121 * Method: getConfigDepth
1122 * Signature: (I)I
1123 */
1124JNIEXPORT jint JNICALL
1125Java_sun_awt_X11GraphicsDevice_getConfigDepth(
1126JNIEnv *env, jobject this, jint index, jint screen)
1127{
1128#ifdef HEADLESS
1129 return (jint)0;
1130#else
1131 int visNum;
1132
1133 ensureConfigsInited(env, screen);
1134 if (index == 0) {
1135 return ((jint)x11Screens[screen].defaultConfig->awt_visInfo.depth);
1136 } else {
1137 return ((jint)x11Screens[screen].configs[index]->awt_visInfo.depth);
1138 }
1139#endif /* !HEADLESS */
1140}
1141
1142/*
1143 * Class: sun_awt_X11GraphicsDevice
1144 * Method: getConfigColormap
1145 * Signature: (I)I
1146 */
1147JNIEXPORT jint JNICALL
1148Java_sun_awt_X11GraphicsDevice_getConfigColormap(
1149JNIEnv *env, jobject this, jint index, jint screen)
1150{
1151#ifdef HEADLESS
1152 return (jint)0;
1153#else
1154 int visNum;
1155
1156 ensureConfigsInited(env, screen);
1157 if (index == 0) {
1158 return ((jint)x11Screens[screen].defaultConfig->awt_cmap);
1159 } else {
1160 return ((jint)x11Screens[screen].configs[index]->awt_cmap);
1161 }
1162#endif /* !HEADLESS */
1163}
1164
1165/*
1166 * Class: sun_awt_X11GraphicsDevice
1167 * Method: resetNativeData
1168 * Signature: (I)V
1169 */
1170JNIEXPORT void JNICALL
1171Java_sun_awt_X11GraphicsDevice_resetNativeData
1172 (JNIEnv *env, jclass x11gd, jint screen)
1173{
1174#ifndef HEADLESS
1175 /*
1176 * Reset references to the various configs; the actual native config data
1177 * will be free'd later by the Disposer mechanism when the Java-level
1178 * X11GraphicsConfig objects go away. By setting these values to NULL,
1179 * we ensure that they will be reinitialized as necessary (for example,
1180 * see the getNumConfigs() method).
1181 */
1182 if (x11Screens[screen].configs) {
1183 free(x11Screens[screen].configs);
1184 x11Screens[screen].configs = NULL;
1185 }
1186 x11Screens[screen].defaultConfig = NULL;
1187 x11Screens[screen].numConfigs = 0;
1188#endif /* !HEADLESS */
1189}
1190
1191/*
1192 * Class: sun_awt_X11GraphicsConfig
1193 * Method: dispose
1194 * Signature: (J)V
1195 */
1196JNIEXPORT void JNICALL
1197Java_sun_awt_X11GraphicsConfig_dispose
1198 (JNIEnv *env, jclass x11gc, jlong configData)
1199{
1200#ifndef HEADLESS
1201 AwtGraphicsConfigDataPtr aData = (AwtGraphicsConfigDataPtr)
1202 jlong_to_ptr(configData);
1203
1204 if (aData == NULL) {
1205 return;
1206 }
1207
1208 AWT_LOCK();
1209 if (aData->awt_cmap) {
1210 XFreeColormap(awt_display, aData->awt_cmap);
1211 }
1212 if (aData->awtImage) {
1213 free(aData->awtImage);
1214 }
1215 if (aData->monoImage) {
1216 XFree(aData->monoImage);
1217 }
1218 if (aData->monoPixmap) {
1219 XFreePixmap(awt_display, aData->monoPixmap);
1220 }
1221 if (aData->monoPixmapGC) {
1222 XFreeGC(awt_display, aData->monoPixmapGC);
1223 }
1224 if (aData->color_data) {
1225 free(aData->color_data);
1226 }
1227 AWT_UNLOCK();
1228
1229 if (aData->glxInfo) {
1230 /*
1231 * The native GLXGraphicsConfig data needs to be disposed separately
1232 * on the OGL queue flushing thread (should not be called while
1233 * the AWT lock is held).
1234 */
1235 JNU_CallStaticMethodByName(env, NULL,
1236 "sun/java2d/opengl/OGLRenderQueue",
1237 "disposeGraphicsConfig", "(J)V",
1238 ptr_to_jlong(aData->glxInfo));
1239 }
1240
1241 free(aData);
1242#endif /* !HEADLESS */
1243}
1244
1245/*
1246 * Class: sun_awt_X11GraphicsConfig
1247 * Method: getXResolution
1248 * Signature: ()I
1249 */
1250JNIEXPORT jdouble JNICALL
1251Java_sun_awt_X11GraphicsConfig_getXResolution(
1252JNIEnv *env, jobject this, jint screen)
1253{
1254#ifdef HEADLESS
1255 return (jdouble)0;
1256#else
1257 return ((DisplayWidth(awt_display, screen) * 25.4) /
1258 DisplayWidthMM(awt_display, screen));
1259#endif /* !HEADLESS */
1260}
1261
1262/*
1263 * Class: sun_awt_X11GraphicsConfig
1264 * Method: getYResolution
1265 * Signature: ()I
1266 */
1267JNIEXPORT jdouble JNICALL
1268Java_sun_awt_X11GraphicsConfig_getYResolution(
1269JNIEnv *env, jobject this, jint screen)
1270{
1271#ifdef HEADLESS
1272 return (jdouble)0;
1273#else
1274 return ((DisplayHeight(awt_display, screen) * 25.4) /
1275 DisplayHeightMM(awt_display, screen));
1276#endif /* !HEADLESS */
1277}
1278
1279
1280/*
1281 * Class: sun_awt_X11GraphicsConfig
1282 * Method: getNumColors
1283 * Signature: ()I
1284 */
1285JNIEXPORT jint JNICALL
1286Java_sun_awt_X11GraphicsConfig_getNumColors(
1287JNIEnv *env, jobject this)
1288{
1289#ifdef HEADLESS
1290 return (jint)0;
1291#else
1292 AwtGraphicsConfigData *adata;
1293
1294 adata = (AwtGraphicsConfigData *) JNU_GetLongFieldAsPtr(env, this,
1295 x11GraphicsConfigIDs.aData);
1296
1297 return adata->awt_num_colors;
1298#endif /* !HEADLESS */
1299}
1300
1301/*
1302 * Class: sun_awt_X11GraphicsConfig
1303 * Method: init
1304 * Signature: (I)V
1305 */
1306JNIEXPORT void JNICALL
1307Java_sun_awt_X11GraphicsConfig_init(
1308JNIEnv *env, jobject this, jint visualNum, jint screen)
1309{
1310#ifndef HEADLESS
1311 AwtGraphicsConfigData *adata = NULL;
1312 AwtScreenData asd = x11Screens[screen];
1313 int i, n;
1314 int depth;
1315 XImage * tempImage;
1316
1317 /* If haven't gotten all of the configs yet, do it now. */
1318 if (asd.numConfigs == 0) {
1319 getAllConfigs (env, screen, &asd);
1320 }
1321
1322 /* Check the graphicsConfig for this visual */
1323 for (i = 0; i < asd.numConfigs; i++) {
1324 AwtGraphicsConfigDataPtr agcPtr = asd.configs[i];
1325 if ((jint)agcPtr->awt_visInfo.visualid == visualNum) {
1326 adata = agcPtr;
1327 break;
1328 }
1329 }
1330
1331 /* If didn't find the visual, throw an exception... */
1332 if (adata == (AwtGraphicsConfigData *) NULL) {
1333 JNU_ThrowIllegalArgumentException(env, "Unknown Visual Specified");
1334 return;
1335 }
1336
1337 /* adata->awt_cmap initialization has been deferred to
1338 * makeColorModel call
1339 */
1340
1341 JNU_SetLongFieldFromPtr(env, this, x11GraphicsConfigIDs.aData, adata);
1342
1343 depth = adata->awt_visInfo.depth;
1344 tempImage = XCreateImage(awt_display,
1345 adata->awt_visInfo.visual,
1346 depth, ZPixmap, 0, NULL, 1, 1, 32, 0);
1347 adata->pixelStride = (tempImage->bits_per_pixel + 7) / 8;
1348 (*env)->SetIntField(env, this, x11GraphicsConfigIDs.bitsPerPixel,
1349 (jint)tempImage->bits_per_pixel);
1350 XDestroyImage(tempImage);
1351#endif /* !HEADLESS */
1352}
1353
1354
1355
1356/*
1357 * Class: sun_awt_X11GraphicsConfig
1358 * Method: makeColorModel
1359 * Signature: ()Ljava/awt/image/ColorModel
1360 */
1361JNIEXPORT jobject JNICALL
1362Java_sun_awt_X11GraphicsConfig_makeColorModel(
1363JNIEnv *env, jobject this)
1364{
1365#ifdef HEADLESS
1366 return NULL;
1367#else
1368 AwtGraphicsConfigData *adata;
1369 jobject colorModel;
1370
1371 /*
1372 * If awt is not locked yet, return null since the toolkit is not
1373 * initialized yet.
1374 */
1375 if (!awtLockInited) {
1376 return NULL;
1377 }
1378
1379 AWT_LOCK ();
1380
1381 adata = (AwtGraphicsConfigData *) JNU_GetLongFieldAsPtr(env, this,
1382 x11GraphicsConfigIDs.aData);
1383
1384 /* If colormap entry of adata is NULL, need to create it now */
1385 if (adata->awt_cmap == (Colormap) NULL) {
1386 awtJNI_CreateColorData (env, adata, 1);
1387 }
1388
1389 /* Make Color Model object for this GraphicsConfiguration */
1390 colorModel = awtJNI_GetColorModel (env, adata);
1391
1392 AWT_UNLOCK ();
1393
1394 return colorModel;
1395#endif /* !HEADLESS */
1396}
1397
1398
1399/*
1400 * Class: sun_awt_X11GraphicsConfig
1401 * Method: getBounds
1402 * Signature: ()Ljava/awt/Rectangle
1403 */
1404JNIEXPORT jobject JNICALL
1405Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen)
1406{
1407#ifdef HEADLESS
1408 return NULL;
1409#else
1410 jclass clazz;
1411 jmethodID mid;
1412 jobject bounds = NULL;
1413 AwtGraphicsConfigDataPtr adata;
1414
1415 adata = (AwtGraphicsConfigDataPtr)
1416 JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
1417
1418 clazz = (*env)->FindClass(env, "java/awt/Rectangle");
1419 mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
1420 if (mid != NULL) {
1421 if (usingXinerama) {
1422 bounds = (*env)->NewObject(env, clazz, mid, fbrects[screen].x,
1423 fbrects[screen].y,
1424 fbrects[screen].width,
1425 fbrects[screen].height);
1426 }
1427 else {
1428 bounds = (*env)->NewObject(env, clazz, mid, 0, 0,
1429 DisplayWidth(awt_display,
1430 adata->awt_visInfo.screen),
1431 DisplayHeight(awt_display,
1432 adata->awt_visInfo.screen));
1433 }
1434
1435 if ((*env)->ExceptionOccurred(env)) {
1436 return NULL;
1437 }
1438 }
1439 return bounds;
1440#endif /* !HEADLESS */
1441}
1442
1443/*
1444 * Class: sun_awt_X11GraphicsConfig
1445 * Method: createBackBuffer
1446 * Signature: (JI)J
1447 */
1448JNIEXPORT jlong JNICALL
1449Java_sun_awt_X11GraphicsConfig_createBackBuffer
1450 (JNIEnv *env, jobject this, jlong window, jint swapAction)
1451{
1452 int32_t v1, v2;
1453 XdbeBackBuffer ret = (unsigned long) 0;
1454 Window w = (Window)window;
1455 AWT_LOCK();
1456 if (!XdbeQueryExtension(awt_display, &v1, &v2)) {
1457 JNU_ThrowByName(env, "java/lang/Exception",
1458 "Could not query double-buffer extension");
1459 AWT_UNLOCK();
1460 return (jlong)0;
1461 }
1462 ret = XdbeAllocateBackBufferName(awt_display, w,
1463 (XdbeSwapAction)swapAction);
1464 AWT_FLUSH_UNLOCK();
1465 return (jlong)ret;
1466}
1467
1468/*
1469 * Class: sun_awt_X11GraphicsConfig
1470 * Method: destroyBackBuffer
1471 * Signature: (J)V
1472 */
1473JNIEXPORT void JNICALL
1474Java_sun_awt_X11GraphicsConfig_destroyBackBuffer
1475 (JNIEnv *env, jobject this, jlong backBuffer)
1476{
1477 AWT_LOCK();
1478 XdbeDeallocateBackBufferName(awt_display, (XdbeBackBuffer)backBuffer);
1479 AWT_FLUSH_UNLOCK();
1480}
1481
1482/*
1483 * Class: sun_awt_X11GraphicsConfig
1484 * Method: swapBuffers
1485 * Signature: (JI)V
1486 */
1487JNIEXPORT void JNICALL
1488Java_sun_awt_X11GraphicsConfig_swapBuffers
1489 (JNIEnv *env, jobject this,
1490 jlong window, jint swapAction)
1491{
1492 XdbeSwapInfo swapInfo;
1493
1494 AWT_LOCK();
1495
1496 XdbeBeginIdiom(awt_display);
1497 swapInfo.swap_window = (Window)window;
1498 swapInfo.swap_action = (XdbeSwapAction)swapAction;
1499 if (!XdbeSwapBuffers(awt_display, &swapInfo, 1)) {
1500 JNU_ThrowInternalError(env, "Could not swap buffers");
1501 }
1502 XdbeEndIdiom(awt_display);
1503
1504 AWT_FLUSH_UNLOCK();
1505}
1506
1507/*
1508 * Class: sun_awt_X11GraphicsDevice
1509 * Method: isDBESupported
1510 * Signature: ()Z
1511 */
1512JNIEXPORT jboolean JNICALL
1513Java_sun_awt_X11GraphicsDevice_isDBESupported(JNIEnv *env, jobject this)
1514{
1515#ifdef HEADLESS
1516 return JNI_FALSE;
1517#else
1518 int opcode = 0, firstEvent = 0, firstError = 0;
1519 jboolean ret;
1520
1521 AWT_LOCK();
1522 ret = (jboolean)XQueryExtension(awt_display, "DOUBLE-BUFFER",
1523 &opcode, &firstEvent, &firstError);
1524 AWT_FLUSH_UNLOCK();
1525 return ret;
1526#endif /* !HEADLESS */
1527}
1528
1529/*
1530 * Class: sun_awt_X11GraphicsDevice
1531 * Method: getDoubleBufferVisuals
1532 * Signature: (I)V
1533 */
1534JNIEXPORT void JNICALL
1535Java_sun_awt_X11GraphicsDevice_getDoubleBufferVisuals(JNIEnv *env,
1536 jobject this, jint screen)
1537{
1538#ifndef HEADLESS
1539 jclass clazz;
1540 jmethodID midAddVisual;
1541 Window rootWindow;
1542 int i, n = 1;
1543 XdbeScreenVisualInfo* visScreenInfo;
1544 int xinawareScreen;
1545
1546 if (usingXinerama) {
1547 xinawareScreen = 0;
1548 }
1549 else {
1550 xinawareScreen = screen;
1551 }
1552
1553 clazz = (*env)->GetObjectClass(env, this);
1554 midAddVisual = (*env)->GetMethodID(env, clazz, "addDoubleBufferVisual",
1555 "(I)V");
1556
1557 AWT_LOCK();
1558 rootWindow = RootWindow(awt_display, xinawareScreen);
1559 visScreenInfo = XdbeGetVisualInfo(awt_display, &rootWindow, &n);
1560 if (visScreenInfo == NULL) {
1561 JNU_ThrowInternalError(env, "Could not get visual info");
1562 AWT_UNLOCK();
1563 return;
1564 }
1565 AWT_FLUSH_UNLOCK();
1566 for (i = 0; i < visScreenInfo->count; i++) {
1567 XdbeVisualInfo* visInfo = visScreenInfo->visinfo;
1568 (*env)->CallVoidMethod(env, this, midAddVisual, (visInfo[i]).visual);
1569 }
1570#endif /* !HEADLESS */
1571}
1572
1573/*
1574 * Class: sun_awt_X11GraphicsEnvironment
1575 * Method: pRunningXinerama
1576 * Signature: ()Z
1577 */
1578JNIEXPORT jboolean JNICALL
1579Java_sun_awt_X11GraphicsEnvironment_pRunningXinerama(JNIEnv *env,
1580 jobject this)
1581{
1582#ifdef HEADLESS
1583 return false;
1584#else
1585 return usingXinerama;
1586#endif /* HEADLESS */
1587}
1588
1589/*
1590 * Can return NULL.
1591 *
1592 * Class: sun_awt_X11GraphicsEnvironment
1593 * Method: getXineramaCenterPoint
1594 * Signature: ()Ljava/awt/Point
1595 */
1596JNIEXPORT jobject JNICALL
1597Java_sun_awt_X11GraphicsEnvironment_getXineramaCenterPoint(JNIEnv *env,
1598 jobject this)
1599{
1600 jobject point = NULL;
1601#ifndef HEADLESS /* return NULL in HEADLESS, Linux */
1602#ifndef __linux__
1603 int x,y;
1604
1605 AWT_LOCK();
1606 DASSERT(usingXinerama);
1607 if (XineramaSolarisCenterFunc != NULL) {
1608 (XineramaSolarisCenterFunc)(awt_display, 0, &x, &y);
1609 point = JNU_NewObjectByName(env, "java/awt/Point","(II)V", x, y);
1610 DASSERT(point);
1611 } else {
1612 DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
1613 }
1614 AWT_FLUSH_UNLOCK();
1615#endif /* __linux __ */
1616#endif /* HEADLESS */
1617 return point;
1618}
1619
1620
1621/**
1622 * Begin DisplayMode/FullScreen support
1623 */
1624
1625#ifndef HEADLESS
1626
1627#define BIT_DEPTH_MULTI java_awt_DisplayMode_BIT_DEPTH_MULTI
1628
1629typedef XRRScreenConfiguration*
1630 (*XRRGetScreenInfoType)(Display *dpy, Drawable root);
1631typedef void
1632 (*XRRFreeScreenConfigInfoType)(XRRScreenConfiguration *config);
1633typedef short*
1634 (*XRRConfigRatesType)(XRRScreenConfiguration *config,
1635 int sizeID, int *nrates);
1636typedef short
1637 (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config);
1638typedef XRRScreenSize*
1639 (*XRRConfigSizesType)(XRRScreenConfiguration *config,
1640 int *nsizes);
1641typedef SizeID
1642 (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config,
1643 Rotation *rotation);
1644typedef Status
1645 (*XRRSetScreenConfigAndRateType)(Display *dpy,
1646 XRRScreenConfiguration *config,
1647 Drawable draw,
1648 int size_index,
1649 Rotation rotation,
1650 short rate,
1651 Time timestamp);
1652
1653static XRRGetScreenInfoType awt_XRRGetScreenInfo;
1654static XRRFreeScreenConfigInfoType awt_XRRFreeScreenConfigInfo;
1655static XRRConfigRatesType awt_XRRConfigRates;
1656static XRRConfigCurrentRateType awt_XRRConfigCurrentRate;
1657static XRRConfigSizesType awt_XRRConfigSizes;
1658static XRRConfigCurrentConfigurationType awt_XRRConfigCurrentConfiguration;
1659static XRRSetScreenConfigAndRateType awt_XRRSetScreenConfigAndRate;
1660
1661#define LOAD_XRANDR_FUNC(f) \
1662 do { \
1663 awt_##f = (f##Type)dlsym(pLibRandR, #f); \
1664 if (awt_##f == NULL) { \
1665 J2dRlsTraceLn1(J2D_TRACE_ERROR, \
1666 "X11GD_InitXrandrFuncs: Could not load %s", #f); \
1667 dlclose(pLibRandR); \
1668 return JNI_FALSE; \
1669 } \
1670 } while (0)
1671
1672static jboolean
1673X11GD_InitXrandrFuncs(JNIEnv *env)
1674{
1675 void *pLibRandR = dlopen("libXrandr.so.2", RTLD_LAZY | RTLD_LOCAL);
1676 if (pLibRandR == NULL) {
1677 J2dRlsTraceLn(J2D_TRACE_ERROR,
1678 "X11GD_InitXrandrFuncs: Could not open libXrandr.so.2");
1679 return JNI_FALSE;
1680 }
1681
1682 LOAD_XRANDR_FUNC(XRRGetScreenInfo);
1683 LOAD_XRANDR_FUNC(XRRFreeScreenConfigInfo);
1684 LOAD_XRANDR_FUNC(XRRConfigRates);
1685 LOAD_XRANDR_FUNC(XRRConfigCurrentRate);
1686 LOAD_XRANDR_FUNC(XRRConfigSizes);
1687 LOAD_XRANDR_FUNC(XRRConfigCurrentConfiguration);
1688 LOAD_XRANDR_FUNC(XRRSetScreenConfigAndRate);
1689
1690 return JNI_TRUE;
1691}
1692
1693static jobject
1694X11GD_CreateDisplayMode(JNIEnv *env, jint width, jint height,
1695 jint bitDepth, jint refreshRate)
1696{
1697 jclass displayModeClass;
1698 jmethodID cid;
1699
1700 displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
1701 if (JNU_IsNull(env, displayModeClass)) {
1702 JNU_ThrowInternalError(env,
1703 "Could not get display mode class");
1704 return NULL;
1705 }
1706
1707 cid = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
1708 if (cid == NULL) {
1709 JNU_ThrowInternalError(env,
1710 "Could not get display mode constructor");
1711 return NULL;
1712 }
1713
1714 return (*env)->NewObject(env, displayModeClass, cid,
1715 width, height, bitDepth, refreshRate);
1716}
1717
1718static void
1719X11GD_AddDisplayMode(JNIEnv *env, jobject arrayList,
1720 jint width, jint height,
1721 jint bitDepth, jint refreshRate)
1722{
1723 jobject displayMode = X11GD_CreateDisplayMode(env, width, height,
1724 bitDepth, refreshRate);
1725 if (!JNU_IsNull(env, displayMode)) {
1726 jclass arrayListClass;
1727 jmethodID mid;
1728 arrayListClass = (*env)->GetObjectClass(env, arrayList);
1729 if (JNU_IsNull(env, arrayListClass)) {
1730 JNU_ThrowInternalError(env,
1731 "Could not get class java.util.ArrayList");
1732 return;
1733 }
1734 mid = (*env)->GetMethodID(env, arrayListClass, "add",
1735 "(Ljava/lang/Object;)Z");
1736 if (mid == NULL) {
1737 JNU_ThrowInternalError(env,
1738 "Could not get method java.util.ArrayList.add()");
1739 return;
1740 }
1741 (*env)->CallObjectMethod(env, arrayList, mid, displayMode);
1742 (*env)->DeleteLocalRef(env, displayMode);
1743 }
1744}
1745
1746static void
1747X11GD_SetFullscreenMode(Window win, jboolean enabled)
1748{
1749 Atom wmState = XInternAtom(awt_display, "_NET_WM_STATE", False);
1750 Atom wmStateFs = XInternAtom(awt_display,
1751 "_NET_WM_STATE_FULLSCREEN", False);
1752 Window root, parent, *children = NULL;
1753 unsigned int numchildren;
1754 XEvent event;
1755 Status status;
1756
1757 if (wmState == None || wmStateFs == None) {
1758 return;
1759 }
1760
1761 /*
1762 * Note: the Window passed to this method is typically the "content
1763 * window" of the top-level, but we need the actual shell window for
1764 * the purposes of constructing the XEvent. Therefore, we walk up the
1765 * window hierarchy here to find the true top-level.
1766 */
1767 do {
1768 if (!XQueryTree(awt_display, win,
1769 &root, &parent,
1770 &children, &numchildren))
1771 {
1772 return;
1773 }
1774
1775 if (children != NULL) {
1776 XFree(children);
1777 }
1778
1779 if (parent == root) {
1780 break;
1781 }
1782
1783 win = parent;
1784 } while (root != parent);
1785
1786 memset(&event, 0, sizeof(event));
1787 event.xclient.type = ClientMessage;
1788 event.xclient.message_type = wmState;
1789 event.xclient.display = awt_display;
1790 event.xclient.window = win;
1791 event.xclient.format = 32;
1792 event.xclient.data.l[0] = enabled ? 1 : 0; // 1==add, 0==remove
1793 event.xclient.data.l[1] = wmStateFs;
1794
1795 XSendEvent(awt_display, root, False,
1796 SubstructureRedirectMask | SubstructureNotifyMask,
1797 &event);
1798 XSync(awt_display, False);
1799}
1800#endif /* !HEADLESS */
1801
1802/*
1803 * Class: sun_awt_X11GraphicsDevice
1804 * Method: initXrandrExtension
1805 * Signature: ()Z
1806 */
1807JNIEXPORT jboolean JNICALL
1808Java_sun_awt_X11GraphicsDevice_initXrandrExtension
1809 (JNIEnv *env, jclass x11gd)
1810{
1811#ifdef HEADLESS
1812 return JNI_FALSE;
1813#else
1814 int opcode = 0, firstEvent = 0, firstError = 0;
1815 jboolean ret;
1816
1817 if (usingXinerama) {
1818 /*
1819 * REMIND: we'll just punt if Xinerama is enabled; we can remove this
1820 * restriction in the future if we find Xinerama and XRandR playing
1821 * well together...
1822 */
1823 return JNI_FALSE;
1824 }
1825
1826 AWT_LOCK();
1827 ret = (jboolean)XQueryExtension(awt_display, "RANDR",
1828 &opcode, &firstEvent, &firstError);
1829 if (ret) {
1830 ret = X11GD_InitXrandrFuncs(env);
1831 }
1832 AWT_FLUSH_UNLOCK();
1833
1834 return ret;
1835#endif /* HEADLESS */
1836}
1837
1838/*
1839 * Class: sun_awt_X11GraphicsDevice
1840 * Method: getCurrentDisplayMode
1841 * Signature: (I)Ljava/awt/DisplayMode;
1842 */
1843JNIEXPORT jobject JNICALL
1844Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode
1845 (JNIEnv* env, jclass x11gd, jint screen)
1846{
1847#ifdef HEADLESS
1848 return NULL;
1849#else
1850 XRRScreenConfiguration *config;
1851 jobject displayMode = NULL;
1852
1853 AWT_LOCK();
1854
1855 config = awt_XRRGetScreenInfo(awt_display,
1856 RootWindow(awt_display, screen));
1857 if (config != NULL) {
1858 Rotation rotation;
1859 short curRate;
1860 SizeID curSizeIndex;
1861 XRRScreenSize *sizes;
1862 int nsizes;
1863
1864 curSizeIndex = awt_XRRConfigCurrentConfiguration(config, &rotation);
1865 sizes = awt_XRRConfigSizes(config, &nsizes);
1866 curRate = awt_XRRConfigCurrentRate(config);
1867
1868 if ((sizes != NULL) &&
1869 (curSizeIndex < nsizes) &&
1870 (curRate > 0))
1871 {
1872 XRRScreenSize curSize = sizes[curSizeIndex];
1873 displayMode = X11GD_CreateDisplayMode(env,
1874 curSize.width,
1875 curSize.height,
1876 BIT_DEPTH_MULTI,
1877 curRate);
1878 }
1879
1880 awt_XRRFreeScreenConfigInfo(config);
1881 }
1882
1883 AWT_FLUSH_UNLOCK();
1884
1885 return displayMode;
1886#endif /* HEADLESS */
1887}
1888
1889/*
1890 * Class: sun_awt_X11GraphicsDevice
1891 * Method: enumDisplayModes
1892 * Signature: (ILjava/util/ArrayList;)V
1893 */
1894JNIEXPORT void JNICALL
1895Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1896 (JNIEnv* env, jclass x11gd,
1897 jint screen, jobject arrayList)
1898{
1899#ifndef HEADLESS
1900 XRRScreenConfiguration *config;
1901
1902 AWT_LOCK();
1903
1904 config = awt_XRRGetScreenInfo(awt_display,
1905 RootWindow(awt_display, screen));
1906 if (config != NULL) {
1907 int nsizes, i, j;
1908 XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
1909
1910 if (sizes != NULL) {
1911 for (i = 0; i < nsizes; i++) {
1912 int nrates;
1913 XRRScreenSize size = sizes[i];
1914 short *rates = awt_XRRConfigRates(config, i, &nrates);
1915
1916 for (j = 0; j < nrates; j++) {
1917 X11GD_AddDisplayMode(env, arrayList,
1918 size.width,
1919 size.height,
1920 BIT_DEPTH_MULTI,
1921 rates[j]);
1922 }
1923 }
1924 }
1925
1926 awt_XRRFreeScreenConfigInfo(config);
1927 }
1928
1929 AWT_FLUSH_UNLOCK();
1930#endif /* !HEADLESS */
1931}
1932
1933/*
1934 * Class: sun_awt_X11GraphicsDevice
1935 * Method: configDisplayMode
1936 * Signature: (IIII)V
1937 */
1938JNIEXPORT void JNICALL
1939Java_sun_awt_X11GraphicsDevice_configDisplayMode
1940 (JNIEnv* env, jclass x11gd,
1941 jint screen, jint width, jint height, jint refreshRate)
1942{
1943#ifndef HEADLESS
1944 jboolean success = JNI_FALSE;
1945 XRRScreenConfiguration *config;
1946 Drawable root;
1947
1948 AWT_LOCK();
1949
1950 root = RootWindow(awt_display, screen);
1951 config = awt_XRRGetScreenInfo(awt_display, root);
1952 if (config != NULL) {
1953 jboolean foundConfig = JNI_FALSE;
1954 int chosenSizeIndex = -1;
1955 short chosenRate = -1;
1956 int nsizes;
1957 XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
1958
1959 if (sizes != NULL) {
1960 int i, j;
1961
1962 /* find the size index that matches the requested dimensions */
1963 for (i = 0; i < nsizes; i++) {
1964 XRRScreenSize size = sizes[i];
1965
1966 if ((size.width == width) && (size.height == height)) {
1967 /* we've found our size index... */
1968 int nrates;
1969 short *rates = awt_XRRConfigRates(config, i, &nrates);
1970
1971 /* now find rate that matches requested refresh rate */
1972 for (j = 0; j < nrates; j++) {
1973 if (rates[j] == refreshRate) {
1974 /* we've found our rate; break out of the loop */
1975 chosenSizeIndex = i;
1976 chosenRate = rates[j];
1977 foundConfig = JNI_TRUE;
1978 break;
1979 }
1980 }
1981
1982 break;
1983 }
1984 }
1985 }
1986
1987 if (foundConfig) {
1988 Status status =
1989 awt_XRRSetScreenConfigAndRate(awt_display, config, root,
1990 chosenSizeIndex,
1991 RR_Rotate_0,
1992 chosenRate,
1993 CurrentTime);
1994
1995 /* issue XSync to ensure immediate mode change */
1996 XSync(awt_display, False);
1997
1998 if (status == RRSetConfigSuccess) {
1999 success = JNI_TRUE;
2000 }
2001 }
2002
2003 awt_XRRFreeScreenConfigInfo(config);
2004 }
2005
2006 AWT_FLUSH_UNLOCK();
2007
2008 if (!success) {
2009 JNU_ThrowInternalError(env, "Could not set display mode");
2010 }
2011#endif /* !HEADLESS */
2012}
2013
2014/*
2015 * Class: sun_awt_X11GraphicsDevice
2016 * Method: enterFullScreenExclusive
2017 * Signature: (J)V
2018 */
2019JNIEXPORT void JNICALL
2020Java_sun_awt_X11GraphicsDevice_enterFullScreenExclusive
2021 (JNIEnv* env, jclass x11gd,
2022 jlong window)
2023{
2024#ifndef HEADLESS
2025 Window win = (Window)window;
2026
2027 AWT_LOCK();
2028 XSync(awt_display, False); /* ensures window is visible first */
2029 X11GD_SetFullscreenMode(win, JNI_TRUE);
2030 AWT_UNLOCK();
2031#endif /* !HEADLESS */
2032}
2033
2034/*
2035 * Class: sun_awt_X11GraphicsDevice
2036 * Method: exitFullScreenExclusive
2037 * Signature: (J)V
2038 */
2039JNIEXPORT void JNICALL
2040Java_sun_awt_X11GraphicsDevice_exitFullScreenExclusive
2041 (JNIEnv* env, jclass x11gd,
2042 jlong window)
2043{
2044#ifndef HEADLESS
2045 Window win = (Window)window;
2046
2047 AWT_LOCK();
2048 X11GD_SetFullscreenMode(win, JNI_FALSE);
2049 AWT_UNLOCK();
2050#endif /* !HEADLESS */
2051}
2052
2053/**
2054 * End DisplayMode/FullScreen support
2055 */