1/*
2 * Copyright (c) 2000, 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
23 * questions.
24 */
25
26#include "SurfaceData.h"
27
28#include "awt_p.h"
29#include "awt_GraphicsEnv.h"
30
31#ifdef HEADLESS
32#include "GLXGraphicsConfig.h"
33#endif
34
35#include <X11/extensions/Xrender.h>
36
37/**
38 * This include file contains support declarations for loops using the
39 * X11 extended SurfaceData interface to talk to an X11 drawable from
40 * native code.
41 */
42
43#ifdef HEADLESS
44#define X11SDOps void
45#else /* HEADLESS */
46typedef struct _X11SDOps X11SDOps;
47
48/*
49 * This function returns an X11 Drawable which transparent pixels
50 * (if there are any) were set to the specified color.
51 *
52 * The env parameter should be the JNIEnv of the surrounding JNI context.
53 *
54 * The xsdo parameter should be a pointer to the ops object upon which
55 * this function is being invoked.
56 *
57 * The pixel parameter should be a color to which the transparent
58 * pixels of the image should be se set to.
59 */
60typedef Drawable GetPixmapBgFunc(JNIEnv *env,
61 X11SDOps *xsdo,
62 jint pixel);
63
64/*
65 * This function releases the lock set by GetPixmapBg
66 * function of the indicated X11SDOps structure.
67 *
68 * The env parameter should be the JNIEnv of the surrounding JNI context.
69 *
70 * The ops parameter should be a pointer to the ops object upon which
71 * this function is being invoked.
72 */
73typedef void ReleasePixmapBgFunc(JNIEnv *env,
74 X11SDOps *xsdo);
75
76
77#ifdef MITSHM
78typedef struct {
79 XShmSegmentInfo *shmSegInfo; /* Shared Memory Segment Info */
80 jint bytesPerLine; /* needed for ShMem lock */
81 jboolean xRequestSent; /* true if x request is sent w/o XSync */
82 jint pmSize;
83
84 jboolean usingShmPixmap;
85 Drawable pixmap;
86 Drawable shmPixmap;
87 jint numBltsSinceRead;
88 jint pixelsReadSinceBlt;
89 jint pixelsReadThreshold;
90 jint numBltsThreshold;
91} ShmPixmapData;
92#endif /* MITSHM */
93
94struct _X11SDOps {
95 SurfaceDataOps sdOps;
96 GetPixmapBgFunc *GetPixmapWithBg;
97 ReleasePixmapBgFunc *ReleasePixmapWithBg;
98 jboolean invalid;
99 jboolean isPixmap;
100 jobject peer;
101 Drawable drawable;
102 GC javaGC; /* used for Java-level GC validation */
103 GC cachedGC; /* cached for use in X11SD_Unlock() */
104 jint depth;
105 jint pixelmask;
106 AwtGraphicsConfigData *configData;
107 ColorData *cData;
108 Pixmap bitmask;
109 jint bgPixel; /* bg pixel for the pixmap */
110 jboolean isBgInitialized; /* whether the bg pixel is valid */
111 jint pmWidth; /* width, height of the */
112 jint pmHeight; /* pixmap */
113 Picture xrPic;
114#ifdef MITSHM
115 ShmPixmapData shmPMData; /* data for switching between shm/nonshm pixmaps*/
116#endif /* MITSHM */
117};
118
119#define X11SD_LOCK_UNLOCKED 0 /* surface is not locked */
120#define X11SD_LOCK_BY_NULL 1 /* surface locked for NOP */
121#define X11SD_LOCK_BY_XIMAGE 2 /* surface locked by Get/PutImage */
122#define X11SD_LOCK_BY_SHMEM 4 /* surface locked by ShMemExt */
123
124#ifdef MITSHM
125XImage * X11SD_GetSharedImage (X11SDOps *xsdo,
126 jint width, jint height,
127 jint maxWidth, jint maxHeight,
128 jboolean readBits);
129XImage * X11SD_CreateSharedImage (X11SDOps *xsdo, jint width, jint height);
130Drawable X11SD_CreateSharedPixmap (X11SDOps *xsdo);
131void X11SD_DropSharedSegment (XShmSegmentInfo *shminfo);
132void X11SD_PuntPixmap (X11SDOps *xsdo, jint width, jint height);
133void X11SD_UnPuntPixmap (X11SDOps *xsdo);
134jboolean X11SD_CachedXImageFits (jint width, jint height,
135 jint maxWidth, jint maxHeight,
136 jint depth, jboolean readBits);
137XImage * X11SD_GetCachedXImage (jint width, jint height, jboolean readBits);
138#endif /* MITSHM */
139jint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo);
140void X11SD_DisposeOrCacheXImage (XImage * image);
141void X11SD_DisposeXImage(XImage * image);
142void X11SD_DirectRenderNotify(JNIEnv *env, X11SDOps *xsdo);
143#endif /* !HEADLESS */
144
145jboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps);
146jboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable);
147
148/*
149 * This function returns a pointer to a native X11SDOps structure
150 * for accessing the indicated X11 SurfaceData Java object. It
151 * verifies that the indicated SurfaceData object is an instance
152 * of X11SurfaceData before returning and will return NULL if the
153 * wrong SurfaceData object is being accessed. This function will
154 * throw the appropriate Java exception if it returns NULL so that
155 * the caller can simply return.
156 *
157 * Note to callers:
158 * This function uses JNI methods so it is important that the
159 * caller not have any outstanding GetPrimitiveArrayCritical or
160 * GetStringCritical locks which have not been released.
161 *
162 * The caller may continue to use JNI methods after this method
163 * is called since this function will not leave any outstanding
164 * JNI Critical locks unreleased.
165 */
166JNIEXPORT X11SDOps * JNICALL
167X11SurfaceData_GetOps(JNIEnv *env, jobject sData);
168