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 "X11SurfaceData.h"
27 #include <jni.h>
28 #include <math.h>
29 #include "Region.h"
30 #include "fontscalerdefs.h"
31
32 #include <X11/extensions/Xrender.h>
33
34 /* On Solaris 10 updates 8, 9, the render.h file defines these
35 * protocol values but does not define the structs in Xrender.h.
36 * Thus in order to get these always defined on Solaris 10
37 * we will undefine the symbols if we have determined via the
38 * makefiles that Xrender.h is lacking the structs. This will
39 * trigger providing our own definitions as on earlier updates.
40 * We could assume that *all* Solaris 10 update versions will lack the updated
41 * Xrender.h and do this based solely on O/S being any 5.10 version, but this
42 * could still change and we'd be broken again as we'd be re-defining them.
43 */
44 #ifdef SOLARIS10_NO_XRENDER_STRUCTS
45 #undef X_RenderCreateLinearGradient
46 #undef X_RenderCreateRadialGradient
47 #endif
48
49 #ifndef X_RenderCreateLinearGradient
50 typedef struct _XLinearGradient {
51 XPointFixed p1;
52 XPointFixed p2;
53 } XLinearGradient;
114
115 /*
116 * X protocol uses (u_int16)length to specify the length in 4 bytes quantities
117 * of the whole request. Both XRenderFillRectangles() and XFillRectangles()
118 * have provisions to fragment into several requests if the number of rectangles
119 * plus the current x request does not fit into 65535*4 bytes. While
120 * XRenderCreateLinearGradient() and XRenderCreateRadialGradient() have
121 * provisions to gracefully degrade if the resulting request would exceed
122 * 65535*4 bytes.
123 *
124 * Below, we define a cap of 65535*4 bytes for the maximum X request payload
125 * allowed for Non-(XRenderFillRectangles() or XFillRectangles()) API calls,
126 * just to be conservative. This is offset by the size of our maximum x*Req
127 * type in this compilation unit, which is xRenderCreateRadiaGradientReq.
128 *
129 * Note that sizeof(xRenderCreateRadiaGradientReq) = 36
130 */
131 #define MAX_PAYLOAD (262140u - 36u)
132 #define MAXUINT (0xffffffffu)
133
134 static jboolean IsXRenderAvailable(jboolean verbose) {
135
136 void *xrenderlib;
137
138 int major_opcode, first_event, first_error;
139 jboolean available = JNI_TRUE;
140
141 if (!XQueryExtension(awt_display, "RENDER",
142 &major_opcode, &first_event, &first_error)) {
143 return JNI_FALSE;
144 }
145
146 #ifdef __solaris__
147 xrenderlib = dlopen("libXrender.so",RTLD_GLOBAL|RTLD_LAZY);
148 if (xrenderlib != NULL) {
149
150 XRenderCreateLinearGradientFunc =
151 (XRenderCreateLinearGradientFuncType)
152 dlsym(xrenderlib, "XRenderCreateLinearGradient");
153
154 XRenderCreateRadialGradientFunc =
236 }
237 }
238 }
239 break;
240 }
241 }
242 fclose(fp);
243 }
244 }
245 }
246 }
247 if (verbose && !versionInfoIsFound) {
248 printf("WARNING: The version of libXrender.so cannot be detected.\n,"
249 "The pipe line will be enabled, but note that versions less than 0.9.3\n"
250 "may cause hangs and crashes\n"
251 "\tSee the release notes for more details.\n");
252 fflush(stdout);
253 }
254 #endif
255
256 return available;
257 }
258 /*
259 * Class: sun_awt_X11GraphicsEnvironment
260 * Method: initGLX
261 * Signature: ()Z
262 */
263 JNIEXPORT jboolean JNICALL
264 Java_sun_awt_X11GraphicsEnvironment_initXRender
265 (JNIEnv *env, jclass x11ge, jboolean verbose)
266 {
267 #ifndef HEADLESS
268 static jboolean xrenderAvailable = JNI_FALSE;
269 static jboolean firstTime = JNI_TRUE;
270
271 if (firstTime) {
272 #ifdef DISABLE_XRENDER_BY_DEFAULT
273 if (verbose == JNI_FALSE) {
274 xrenderAvailable = JNI_FALSE;
275 firstTime = JNI_FALSE;
276 return xrenderAvailable;
277 }
278 #endif
279 AWT_LOCK();
280 xrenderAvailable = IsXRenderAvailable(verbose);
281 AWT_UNLOCK();
282 firstTime = JNI_FALSE;
283 }
284 return xrenderAvailable;
285 #else
286 return JNI_FALSE;
287 #endif /* !HEADLESS */
288 }
289
290
291 JNIEXPORT void JNICALL
292 Java_sun_java2d_xr_XRBackendNative_initIDs(JNIEnv *env, jclass cls) {
293 char *maskData;
294 XImage* defaultImg;
295 jfieldID maskImgID;
296 jlong fmt8;
297 jlong fmt32;
298
299 jfieldID a8ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_A8", "J");
300 jfieldID argb32ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_ARGB32", "J");
|
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 "X11SurfaceData.h"
27 #include <jni.h>
28 #include <math.h>
29 #include "Region.h"
30 #include "fontscalerdefs.h"
31
32 #include <X11/extensions/Xrender.h>
33
34 #ifdef __linux__
35 #include <sys/utsname.h>
36 #endif
37
38 /* On Solaris 10 updates 8, 9, the render.h file defines these
39 * protocol values but does not define the structs in Xrender.h.
40 * Thus in order to get these always defined on Solaris 10
41 * we will undefine the symbols if we have determined via the
42 * makefiles that Xrender.h is lacking the structs. This will
43 * trigger providing our own definitions as on earlier updates.
44 * We could assume that *all* Solaris 10 update versions will lack the updated
45 * Xrender.h and do this based solely on O/S being any 5.10 version, but this
46 * could still change and we'd be broken again as we'd be re-defining them.
47 */
48 #ifdef SOLARIS10_NO_XRENDER_STRUCTS
49 #undef X_RenderCreateLinearGradient
50 #undef X_RenderCreateRadialGradient
51 #endif
52
53 #ifndef X_RenderCreateLinearGradient
54 typedef struct _XLinearGradient {
55 XPointFixed p1;
56 XPointFixed p2;
57 } XLinearGradient;
118
119 /*
120 * X protocol uses (u_int16)length to specify the length in 4 bytes quantities
121 * of the whole request. Both XRenderFillRectangles() and XFillRectangles()
122 * have provisions to fragment into several requests if the number of rectangles
123 * plus the current x request does not fit into 65535*4 bytes. While
124 * XRenderCreateLinearGradient() and XRenderCreateRadialGradient() have
125 * provisions to gracefully degrade if the resulting request would exceed
126 * 65535*4 bytes.
127 *
128 * Below, we define a cap of 65535*4 bytes for the maximum X request payload
129 * allowed for Non-(XRenderFillRectangles() or XFillRectangles()) API calls,
130 * just to be conservative. This is offset by the size of our maximum x*Req
131 * type in this compilation unit, which is xRenderCreateRadiaGradientReq.
132 *
133 * Note that sizeof(xRenderCreateRadiaGradientReq) = 36
134 */
135 #define MAX_PAYLOAD (262140u - 36u)
136 #define MAXUINT (0xffffffffu)
137
138 static jboolean IsXRenderAvailable(jboolean verbose, jboolean ignoreLinuxVersion) {
139
140 void *xrenderlib;
141
142 int major_opcode, first_event, first_error;
143 jboolean available = JNI_TRUE;
144
145 if (!XQueryExtension(awt_display, "RENDER",
146 &major_opcode, &first_event, &first_error)) {
147 return JNI_FALSE;
148 }
149
150 #ifdef __solaris__
151 xrenderlib = dlopen("libXrender.so",RTLD_GLOBAL|RTLD_LAZY);
152 if (xrenderlib != NULL) {
153
154 XRenderCreateLinearGradientFunc =
155 (XRenderCreateLinearGradientFuncType)
156 dlsym(xrenderlib, "XRenderCreateLinearGradient");
157
158 XRenderCreateRadialGradientFunc =
240 }
241 }
242 }
243 break;
244 }
245 }
246 fclose(fp);
247 }
248 }
249 }
250 }
251 if (verbose && !versionInfoIsFound) {
252 printf("WARNING: The version of libXrender.so cannot be detected.\n,"
253 "The pipe line will be enabled, but note that versions less than 0.9.3\n"
254 "may cause hangs and crashes\n"
255 "\tSee the release notes for more details.\n");
256 fflush(stdout);
257 }
258 #endif
259
260 #ifdef __linux__
261 /*
262 * Check for Linux >= 3.5 (Ubuntu 12.04.02 LTS) to avoid hitting
263 * https://bugs.freedesktop.org/show_bug.cgi?id=48045
264 */
265 struct utsname utsbuf;
266 if(uname(&utsbuf) >= 0) {
267 int major, minor, revision;
268 if(sscanf(utsbuf.release, "%i.%i.%i", &major, &minor, &revision) == 3) {
269 if(major <= 3 && minor < 5) {
270 if(!ignoreLinuxVersion) {
271 available = JNI_FALSE;
272 }
273 else if(verbose) {
274 printf("WARNING: Linux < 3.5 detected.\n"
275 "The pipeline will be enabled, but graphical "
276 "artifacts can occur with old graphic drivers.\n"
277 "See the release notes for more details.\n");
278 fflush(stdout);
279 }
280 }
281 }
282 }
283 #endif // __linux__
284
285 return available;
286 }
287 /*
288 * Class: sun_awt_X11GraphicsEnvironment
289 * Method: initGLX
290 * Signature: ()Z
291 */
292 JNIEXPORT jboolean JNICALL
293 Java_sun_awt_X11GraphicsEnvironment_initXRender
294 (JNIEnv *env, jclass x11ge, jboolean verbose, jboolean ignoreLinuxVersion)
295 {
296 #ifndef HEADLESS
297 static jboolean xrenderAvailable = JNI_FALSE;
298 static jboolean firstTime = JNI_TRUE;
299
300 if (firstTime) {
301 #ifdef DISABLE_XRENDER_BY_DEFAULT
302 if (verbose == JNI_FALSE) {
303 xrenderAvailable = JNI_FALSE;
304 firstTime = JNI_FALSE;
305 return xrenderAvailable;
306 }
307 #endif
308 AWT_LOCK();
309 xrenderAvailable = IsXRenderAvailable(verbose, ignoreLinuxVersion);
310 AWT_UNLOCK();
311 firstTime = JNI_FALSE;
312 }
313 return xrenderAvailable;
314 #else
315 return JNI_FALSE;
316 #endif /* !HEADLESS */
317 }
318
319
320 JNIEXPORT void JNICALL
321 Java_sun_java2d_xr_XRBackendNative_initIDs(JNIEnv *env, jclass cls) {
322 char *maskData;
323 XImage* defaultImg;
324 jfieldID maskImgID;
325 jlong fmt8;
326 jlong fmt32;
327
328 jfieldID a8ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_A8", "J");
329 jfieldID argb32ID = (*env)->GetStaticFieldID(env, cls, "FMTPTR_ARGB32", "J");
|