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
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 #ifndef XAWT
69 extern struct MComponentPeerIDs mComponentPeerIDs;
70 #endif
71 extern int J2DXErrHandler(Display *display, XErrorEvent *xerr);
72 extern AwtGraphicsConfigDataPtr
73 getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
74 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
75
76 static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
77 X11SDOps *xsdo);
78 static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
79 X11SDOps *xsdo);
80 static void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
81 static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
82 SurfaceDataBounds *bounds,
83 jint lockFlags);
84
85 extern jfieldID validID;
86
87 static int nativeByteOrder;
88 static jboolean dgaAvailable = JNI_FALSE;
89 static jboolean useDGAWithPixmaps = JNI_FALSE;
90 static jclass xorCompClass;
91
534
535 #ifndef HEADLESS
536
537 #ifdef MITSHM
538
539 void X11SD_DropSharedSegment(XShmSegmentInfo *shminfo)
540 {
541 if (shminfo != NULL) {
542 XShmDetach(awt_display, shminfo);
543 shmdt(shminfo->shmaddr);
544 /* REMIND: we don't need shmctl(shminfo->shmid, IPC_RMID, 0); here. */
545 /* Check X11SD_CreateSharedImage() for the explanation */
546 }
547 }
548
549 XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
550 jint width, jint height)
551 {
552 XImage *img = NULL;
553 XShmSegmentInfo *shminfo;
554
555 shminfo = malloc(sizeof(XShmSegmentInfo));
556 if (shminfo == NULL) {
557 return NULL;
558 }
559 memset(shminfo, 0, sizeof(XShmSegmentInfo));
560
561 img = XShmCreateImage(awt_display, xsdo->configData->awt_visInfo.visual,
562 xsdo->depth, ZPixmap, NULL, shminfo,
563 width, height);
564 if (img == NULL) {
565 free((void *)shminfo);
566 return NULL;
567 }
568 shminfo->shmid =
569 shmget(IPC_PRIVATE, height * img->bytes_per_line,
570 IPC_CREAT|mitShmPermissionMask);
571 if (shminfo->shmid < 0) {
572 J2dRlsTraceLn1(J2D_TRACE_ERROR,
573 "X11SD_SetupSharedSegment shmget has failed: %s",
574 strerror(errno));
575 free((void *)shminfo);
576 XDestroyImage(img);
577 return NULL;
578 }
579
580 shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
581 if (shminfo->shmaddr == ((char *) -1)) {
582 shmctl(shminfo->shmid, IPC_RMID, 0);
583 J2dRlsTraceLn1(J2D_TRACE_ERROR,
584 "X11SD_SetupSharedSegment shmat has failed: %s",
585 strerror(errno));
586 free((void *)shminfo);
587 XDestroyImage(img);
588 return NULL;
589 }
590
591 shminfo->readOnly = False;
592
593 resetXShmAttachFailed();
594 EXEC_WITH_XERROR_HANDLER(J2DXErrHandler,
595 XShmAttach(awt_display, shminfo));
596
597 /*
598 * Once the XSync round trip has finished then we
599 * can get rid of the id so that this segment does not stick
600 * around after we go away, holding system resources.
601 */
602 shmctl(shminfo->shmid, IPC_RMID, 0);
603
604 if (isXShmAttachFailed() == JNI_TRUE) {
605 J2dRlsTraceLn1(J2D_TRACE_ERROR,
606 "X11SD_SetupSharedSegment XShmAttach has failed: %s",
607 strerror(errno));
608 shmdt(shminfo->shmaddr);
609 free((void *)shminfo);
610 XDestroyImage(img);
611 return NULL;
612 }
613
614 img->data = shminfo->shmaddr;
615 img->obdata = (char *)shminfo;
616
617 return img;
618 }
619
620 XImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
621 jint maxWidth, jint maxHeight, jboolean readBits)
622 {
623 XImage * retImage = NULL;
624 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
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 #ifndef XAWT
69 extern struct MComponentPeerIDs mComponentPeerIDs;
70 #endif
71 extern AwtGraphicsConfigDataPtr
72 getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
73 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
74
75 static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
76 X11SDOps *xsdo);
77 static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
78 X11SDOps *xsdo);
79 static void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
80 static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
81 SurfaceDataBounds *bounds,
82 jint lockFlags);
83
84 extern jfieldID validID;
85
86 static int nativeByteOrder;
87 static jboolean dgaAvailable = JNI_FALSE;
88 static jboolean useDGAWithPixmaps = JNI_FALSE;
89 static jclass xorCompClass;
90
533
534 #ifndef HEADLESS
535
536 #ifdef MITSHM
537
538 void X11SD_DropSharedSegment(XShmSegmentInfo *shminfo)
539 {
540 if (shminfo != NULL) {
541 XShmDetach(awt_display, shminfo);
542 shmdt(shminfo->shmaddr);
543 /* REMIND: we don't need shmctl(shminfo->shmid, IPC_RMID, 0); here. */
544 /* Check X11SD_CreateSharedImage() for the explanation */
545 }
546 }
547
548 XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
549 jint width, jint height)
550 {
551 XImage *img = NULL;
552 XShmSegmentInfo *shminfo;
553 JNIEnv* env;
554 jboolean xShmAttachResult;
555
556 shminfo = malloc(sizeof(XShmSegmentInfo));
557 if (shminfo == NULL) {
558 return NULL;
559 }
560 memset(shminfo, 0, sizeof(XShmSegmentInfo));
561
562 img = XShmCreateImage(awt_display, xsdo->configData->awt_visInfo.visual,
563 xsdo->depth, ZPixmap, NULL, shminfo,
564 width, height);
565 if (img == NULL) {
566 free((void *)shminfo);
567 return NULL;
568 }
569 shminfo->shmid =
570 shmget(IPC_PRIVATE, height * img->bytes_per_line,
571 IPC_CREAT|mitShmPermissionMask);
572 if (shminfo->shmid < 0) {
573 J2dRlsTraceLn1(J2D_TRACE_ERROR,
574 "X11SD_SetupSharedSegment shmget has failed: %s",
575 strerror(errno));
576 free((void *)shminfo);
577 XDestroyImage(img);
578 return NULL;
579 }
580
581 shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
582 if (shminfo->shmaddr == ((char *) -1)) {
583 shmctl(shminfo->shmid, IPC_RMID, 0);
584 J2dRlsTraceLn1(J2D_TRACE_ERROR,
585 "X11SD_SetupSharedSegment shmat has failed: %s",
586 strerror(errno));
587 free((void *)shminfo);
588 XDestroyImage(img);
589 return NULL;
590 }
591
592 shminfo->readOnly = False;
593
594 env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2);
595 xShmAttachResult = TryXShmAttach(env, awt_display, shminfo);
596
597 /*
598 * Once the XSync round trip has finished then we
599 * can get rid of the id so that this segment does not stick
600 * around after we go away, holding system resources.
601 */
602 shmctl(shminfo->shmid, IPC_RMID, 0);
603
604 if (xShmAttachResult == JNI_FALSE) {
605 J2dRlsTraceLn1(J2D_TRACE_ERROR,
606 "X11SD_SetupSharedSegment XShmAttach has failed: %s",
607 strerror(errno));
608 shmdt(shminfo->shmaddr);
609 free((void *)shminfo);
610 XDestroyImage(img);
611 return NULL;
612 }
613
614 img->data = shminfo->shmaddr;
615 img->obdata = (char *)shminfo;
616
617 return img;
618 }
619
620 XImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
621 jint maxWidth, jint maxHeight, jboolean readBits)
622 {
623 XImage * retImage = NULL;
624 if (cachedXImage != NULL &&
|