1 /*
2 * Copyright (c) 1999, 2011, 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
48 * This file contains support code for loops using the SurfaceData
49 * interface to talk to an X11 drawable from native code.
50 */
51
52 typedef struct _X11RIPrivate {
53 jint lockType;
54 jint lockFlags;
55 XImage *img;
56 int x, y;
57 } X11RIPrivate;
58
59 #define MAX(a,b) ((a) > (b) ? (a) : (b))
60 #define MIN(a,b) ((a) < (b) ? (a) : (b))
61
62 static LockFunc X11SD_Lock;
63 static GetRasInfoFunc X11SD_GetRasInfo;
64 static UnlockFunc X11SD_Unlock;
65 static DisposeFunc X11SD_Dispose;
66 static GetPixmapBgFunc X11SD_GetPixmapWithBg;
67 static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
68 extern int J2DXErrHandler(Display *display, XErrorEvent *xerr);
69 extern AwtGraphicsConfigDataPtr
70 getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
71 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
72
73 static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
74 X11SDOps *xsdo);
75 static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
76 X11SDOps *xsdo);
77 static void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
78 static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
79 SurfaceDataBounds *bounds,
80 jint lockFlags);
81
82 extern jfieldID validID;
83
84 static int nativeByteOrder;
85 static jboolean dgaAvailable = JNI_FALSE;
86 static jboolean useDGAWithPixmaps = JNI_FALSE;
87 static jclass xorCompClass;
88
542 "X11SD_SetupSharedSegment shmget has failed: %s",
543 strerror(errno));
544 free((void *)shminfo);
545 XDestroyImage(img);
546 return NULL;
547 }
548
549 shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
550 if (shminfo->shmaddr == ((char *) -1)) {
551 shmctl(shminfo->shmid, IPC_RMID, 0);
552 J2dRlsTraceLn1(J2D_TRACE_ERROR,
553 "X11SD_SetupSharedSegment shmat has failed: %s",
554 strerror(errno));
555 free((void *)shminfo);
556 XDestroyImage(img);
557 return NULL;
558 }
559
560 shminfo->readOnly = False;
561
562 resetXShmAttachFailed();
563 EXEC_WITH_XERROR_HANDLER(J2DXErrHandler,
564 XShmAttach(awt_display, shminfo));
565
566 /*
567 * Once the XSync round trip has finished then we
568 * can get rid of the id so that this segment does not stick
569 * around after we go away, holding system resources.
570 */
571 shmctl(shminfo->shmid, IPC_RMID, 0);
572
573 if (isXShmAttachFailed() == JNI_TRUE) {
574 J2dRlsTraceLn1(J2D_TRACE_ERROR,
575 "X11SD_SetupSharedSegment XShmAttach has failed: %s",
576 strerror(errno));
577 shmdt(shminfo->shmaddr);
578 free((void *)shminfo);
579 XDestroyImage(img);
580 return NULL;
581 }
582
583 img->data = shminfo->shmaddr;
584 img->obdata = (char *)shminfo;
585
586 return img;
587 }
588
589 XImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
590 jint maxWidth, jint maxHeight, jboolean readBits)
591 {
592 XImage * retImage = NULL;
593 if (cachedXImage != NULL &&
|
1 /*
2 * Copyright (c) 1999, 2013, 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
48 * This file contains support code for loops using the SurfaceData
49 * interface to talk to an X11 drawable from native code.
50 */
51
52 typedef struct _X11RIPrivate {
53 jint lockType;
54 jint lockFlags;
55 XImage *img;
56 int x, y;
57 } X11RIPrivate;
58
59 #define MAX(a,b) ((a) > (b) ? (a) : (b))
60 #define MIN(a,b) ((a) < (b) ? (a) : (b))
61
62 static LockFunc X11SD_Lock;
63 static GetRasInfoFunc X11SD_GetRasInfo;
64 static UnlockFunc X11SD_Unlock;
65 static DisposeFunc X11SD_Dispose;
66 static GetPixmapBgFunc X11SD_GetPixmapWithBg;
67 static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
68 extern AwtGraphicsConfigDataPtr
69 getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
70 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
71
72 static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
73 X11SDOps *xsdo);
74 static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
75 X11SDOps *xsdo);
76 static void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
77 static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
78 SurfaceDataBounds *bounds,
79 jint lockFlags);
80
81 extern jfieldID validID;
82
83 static int nativeByteOrder;
84 static jboolean dgaAvailable = JNI_FALSE;
85 static jboolean useDGAWithPixmaps = JNI_FALSE;
86 static jclass xorCompClass;
87
541 "X11SD_SetupSharedSegment shmget has failed: %s",
542 strerror(errno));
543 free((void *)shminfo);
544 XDestroyImage(img);
545 return NULL;
546 }
547
548 shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
549 if (shminfo->shmaddr == ((char *) -1)) {
550 shmctl(shminfo->shmid, IPC_RMID, 0);
551 J2dRlsTraceLn1(J2D_TRACE_ERROR,
552 "X11SD_SetupSharedSegment shmat has failed: %s",
553 strerror(errno));
554 free((void *)shminfo);
555 XDestroyImage(img);
556 return NULL;
557 }
558
559 shminfo->readOnly = False;
560
561 JNIEnv* env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2);
562 AWT_LOCK();
563 jboolean xShmAttachResult = TryXShmAttach(env, awt_display, shminfo);
564 AWT_UNLOCK();
565 /*
566 * Once the XSync round trip has finished then we
567 * can get rid of the id so that this segment does not stick
568 * around after we go away, holding system resources.
569 */
570 shmctl(shminfo->shmid, IPC_RMID, 0);
571
572 if (xShmAttachResult == JNI_FALSE) {
573 J2dRlsTraceLn1(J2D_TRACE_ERROR,
574 "X11SD_SetupSharedSegment XShmAttach has failed: %s",
575 strerror(errno));
576 shmdt(shminfo->shmaddr);
577 free((void *)shminfo);
578 XDestroyImage(img);
579 return NULL;
580 }
581
582 img->data = shminfo->shmaddr;
583 img->obdata = (char *)shminfo;
584
585 return img;
586 }
587
588 XImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
589 jint maxWidth, jint maxHeight, jboolean readBits)
590 {
591 XImage * retImage = NULL;
592 if (cachedXImage != NULL &&
|