0N/A/*
6447N/A * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include "X11SurfaceData.h"
0N/A#include "GraphicsPrimitiveMgr.h"
0N/A#include "Region.h"
0N/A#include "Trace.h"
0N/A
0N/A/* Needed to define intptr_t */
0N/A#include "gdefs.h"
0N/A
0N/A#include "jni_util.h"
4632N/A#include "jvm_md.h"
0N/A#include "awt_Component.h"
0N/A#include "awt_GraphicsEnv.h"
0N/A
0N/A#include <dlfcn.h>
0N/A
0N/A#ifndef HEADLESS
0N/Astatic JDgaLibInfo DgaLibInfoStub;
0N/Astatic JDgaLibInfo theJDgaInfo;
0N/Astatic JDgaLibInfo *pJDgaInfo = &DgaLibInfoStub;
0N/A
0N/A
0N/A/**
0N/A * This file contains support code for loops using the SurfaceData
0N/A * interface to talk to an X11 drawable from native code.
0N/A */
0N/A
0N/Atypedef struct _X11RIPrivate {
0N/A jint lockType;
0N/A jint lockFlags;
0N/A XImage *img;
0N/A int x, y;
0N/A} X11RIPrivate;
0N/A
0N/A#define MAX(a,b) ((a) > (b) ? (a) : (b))
0N/A#define MIN(a,b) ((a) < (b) ? (a) : (b))
0N/A
0N/Astatic LockFunc X11SD_Lock;
0N/Astatic GetRasInfoFunc X11SD_GetRasInfo;
0N/Astatic UnlockFunc X11SD_Unlock;
0N/Astatic DisposeFunc X11SD_Dispose;
0N/Astatic GetPixmapBgFunc X11SD_GetPixmapWithBg;
0N/Astatic ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
0N/A#ifndef XAWT
0N/Aextern struct MComponentPeerIDs mComponentPeerIDs;
0N/A#endif
0N/Aextern AwtGraphicsConfigDataPtr
0N/A getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
0N/Aextern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
2370N/A
0N/Astatic int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
0N/A X11SDOps *xsdo);
0N/Astatic int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
0N/A X11SDOps *xsdo);
0N/Astatic void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
0N/Astatic XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
0N/A SurfaceDataBounds *bounds,
0N/A jint lockFlags);
0N/A
0N/Aextern jfieldID validID;
0N/A
0N/Astatic int nativeByteOrder;
0N/Astatic jboolean dgaAvailable = JNI_FALSE;
0N/Astatic jboolean useDGAWithPixmaps = JNI_FALSE;
0N/Astatic jclass xorCompClass;
0N/A
0N/Ajint useMitShmExt = CANT_USE_MITSHM;
0N/Ajint useMitShmPixmaps = CANT_USE_MITSHM;
0N/Ajint forceSharedPixmaps = JNI_FALSE;
6251N/Aint mitShmPermissionMask = MITSHM_PERM_OWNER;
0N/A
0N/A/* Cached shared image, one for all surface datas. */
0N/Astatic XImage * cachedXImage;
0N/A
0N/A#endif /* !HEADLESS */
0N/A
2370N/Ajboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps)
2370N/A{
2370N/A#ifndef HEADLESS
2370N/A union {
2370N/A char c[4];
2370N/A int i;
2370N/A } endian;
2370N/A
2370N/A endian.i = 0xff000000;
2370N/A nativeByteOrder = (endian.c[0]) ? MSBFirst : LSBFirst;
2370N/A
2370N/A dgaAvailable = JNI_FALSE;
2370N/A
2370N/A cachedXImage = NULL;
2370N/A
2370N/A if (sizeof(X11RIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
2370N/A JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
2370N/A return JNI_FALSE;
2370N/A }
2370N/A
2370N/A#ifdef MITSHM
2370N/A if (getenv("NO_AWT_MITSHM") == NULL &&
2370N/A getenv("NO_J2D_MITSHM") == NULL) {
2370N/A char * force;
6251N/A char * permission = getenv("J2D_MITSHM_PERMISSION");
6251N/A if (permission != NULL) {
6251N/A if (strcmp(permission, "common") == 0) {
6251N/A mitShmPermissionMask = MITSHM_PERM_COMMON;
6251N/A }
6251N/A }
6251N/A
2370N/A TryInitMITShm(env, &useMitShmExt, &useMitShmPixmaps);
2370N/A
2370N/A if(allowShmPixmaps) {
2370N/A useMitShmPixmaps = (useMitShmPixmaps == CAN_USE_MITSHM);
2370N/A force = getenv("J2D_PIXMAPS");
2370N/A if (force != NULL) {
2370N/A if (useMitShmPixmaps && (strcmp(force, "shared") == 0)) {
2370N/A forceSharedPixmaps = JNI_TRUE;
2370N/A } else if (strcmp(force, "server") == 0) {
2370N/A useMitShmPixmaps = JNI_FALSE;
2370N/A }
2370N/A }
2370N/A }else {
2370N/A useMitShmPixmaps = JNI_FALSE;
2370N/A }
2370N/A }
2370N/A
2370N/A return JNI_TRUE;
2370N/A#endif /* MITSHM */
2370N/A
2370N/A#endif /* !HEADLESS */
2370N/A}
2370N/A
2370N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: initIDs
0N/A * Signature: (Ljava/lang/Class;Z)V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_initIDs(JNIEnv *env, jclass xsd,
0N/A jclass XORComp, jboolean tryDGA)
0N/A{
0N/A#ifndef HEADLESS
2370N/A if(XShared_initIDs(env, JNI_TRUE))
2370N/A {
0N/A void *lib = 0;
0N/A
0N/A xorCompClass = (*env)->NewGlobalRef(env, XORComp);
0N/A
0N/A if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
0N/A /* we use RTLD_NOW because of bug 4032715 */
4632N/A lib = dlopen(JNI_LIB_NAME("sunwjdga"), RTLD_NOW);
0N/A }
2370N/A
0N/A if (lib != NULL) {
0N/A JDgaStatus ret = JDGA_FAILED;
0N/A void *sym = dlsym(lib, "JDgaLibInit");
0N/A if (sym != NULL) {
0N/A theJDgaInfo.display = awt_display;
0N/A AWT_LOCK();
0N/A ret = (*(JDgaLibInitFunc *)sym)(env, &theJDgaInfo);
0N/A AWT_UNLOCK();
0N/A }
0N/A if (ret == JDGA_SUCCESS) {
0N/A pJDgaInfo = &theJDgaInfo;
0N/A dgaAvailable = JNI_TRUE;
0N/A useDGAWithPixmaps = (getenv("USE_DGA_PIXMAPS") != NULL);
0N/A } else {
0N/A dlclose(lib);
0N/A lib = NULL;
0N/A }
0N/A }
2370N/A }
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: isDrawableValid
0N/A * Signature: ()Z
0N/A */
0N/AJNIEXPORT jboolean JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_isDrawableValid(JNIEnv *env, jobject this)
0N/A{
0N/A jboolean ret = JNI_FALSE;
0N/A
0N/A#ifndef HEADLESS
0N/A X11SDOps *xsdo = X11SurfaceData_GetOps(env, this);
0N/A
0N/A AWT_LOCK();
0N/A if (xsdo->drawable != 0 || X11SD_InitWindow(env, xsdo) == SD_SUCCESS) {
0N/A ret = JNI_TRUE;
0N/A }
0N/A AWT_UNLOCK();
0N/A#endif /* !HEADLESS */
0N/A
0N/A return ret;
0N/A}
0N/A
0N/A/*
2370N/A * Class: sun_java2d_x11_X11SurfaceData
2370N/A * Method: isShmPMAvailable
2370N/A * Signature: ()Z
2370N/A */
2370N/AJNIEXPORT jboolean JNICALL
2370N/AJava_sun_java2d_x11_X11SurfaceData_isShmPMAvailable(JNIEnv *env, jobject this)
2370N/A{
2370N/A#if defined(HEADLESS) || !defined(MITSHM)
2370N/A return JNI_FALSE;
2370N/A#else
2370N/A return useMitShmPixmaps;
2370N/A#endif /* HEADLESS, MITSHM */
2370N/A}
2370N/A
2370N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: isDgaAvailable
0N/A * Signature: ()Z
0N/A */
0N/AJNIEXPORT jboolean JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_isDgaAvailable(JNIEnv *env, jobject this)
0N/A{
0N/A#if defined(HEADLESS) || defined(__linux__)
0N/A return JNI_FALSE;
0N/A#else
0N/A return dgaAvailable;
0N/A#endif /* HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: initOps
0N/A * Signature: (Ljava/lang/Object;I)V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_initOps(JNIEnv *env, jobject xsd,
0N/A jobject peer,
0N/A jobject graphicsConfig, jint depth)
0N/A{
0N/A#ifndef HEADLESS
0N/A X11SDOps *xsdo = (X11SDOps*)SurfaceData_InitOps(env, xsd, sizeof(X11SDOps));
2514N/A if (xsdo == NULL) {
2514N/A JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
2514N/A return;
2514N/A }
0N/A xsdo->sdOps.Lock = X11SD_Lock;
0N/A xsdo->sdOps.GetRasInfo = X11SD_GetRasInfo;
0N/A xsdo->sdOps.Unlock = X11SD_Unlock;
0N/A xsdo->sdOps.Dispose = X11SD_Dispose;
0N/A xsdo->GetPixmapWithBg = X11SD_GetPixmapWithBg;
0N/A xsdo->ReleasePixmapWithBg = X11SD_ReleasePixmapWithBg;
0N/A#ifndef XAWT
0N/A if (peer != NULL) {
0N/A struct ComponentData *cdata;
0N/A cdata = (struct ComponentData *)
0N/A JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData);
0N/A if (cdata == NULL) {
0N/A JNU_ThrowNullPointerException(env, "Component data missing");
0N/A return;
0N/A }
0N/A if (cdata->widget == NULL) {
0N/A JNU_ThrowInternalError(env, "Widget is NULL in initOps");
0N/A return;
0N/A }
0N/A xsdo->widget = cdata->widget;
0N/A } else {
0N/A xsdo->widget = NULL;
0N/A }
0N/A#else
0N/A xsdo->widget = NULL;
0N/A if (peer != NULL) {
0N/A xsdo->drawable = JNU_CallMethodByName(env, NULL, peer, "getWindow", "()J").j;
0N/A } else {
0N/A xsdo->drawable = 0;
0N/A }
0N/A#endif
0N/A xsdo->depth = depth;
0N/A xsdo->dgaAvailable = dgaAvailable;
0N/A xsdo->isPixmap = JNI_FALSE;
0N/A xsdo->bitmask = 0;
0N/A xsdo->bgPixel = 0;
0N/A xsdo->isBgInitialized = JNI_FALSE;
0N/A#ifdef MITSHM
0N/A xsdo->shmPMData.shmSegInfo = NULL;
0N/A xsdo->shmPMData.xRequestSent = JNI_FALSE;
0N/A xsdo->shmPMData.pmSize = 0;
0N/A xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
0N/A xsdo->shmPMData.pixmap = 0;
0N/A xsdo->shmPMData.shmPixmap = 0;
0N/A xsdo->shmPMData.numBltsSinceRead = 0;
0N/A xsdo->shmPMData.pixelsReadSinceBlt = 0;
0N/A xsdo->shmPMData.numBltsThreshold = 2;
0N/A#endif /* MITSHM */
0N/A
0N/A xsdo->configData = (AwtGraphicsConfigDataPtr)
0N/A JNU_GetLongFieldAsPtr(env,
0N/A graphicsConfig,
0N/A x11GraphicsConfigIDs.aData);
0N/A if (xsdo->configData == NULL) {
0N/A JNU_ThrowNullPointerException(env,
0N/A "Native GraphicsConfig data block missing");
0N/A return;
0N/A }
0N/A if (depth > 12) {
0N/A xsdo->pixelmask = (xsdo->configData->awt_visInfo.red_mask |
0N/A xsdo->configData->awt_visInfo.green_mask |
0N/A xsdo->configData->awt_visInfo.blue_mask);
0N/A } else if (depth == 12) {
0N/A xsdo->pixelmask = 0xfff;
0N/A } else {
0N/A xsdo->pixelmask = 0xff;
0N/A }
2370N/A
2370N/A xsdo->xrPic = None;
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: flushNativeSurface
0N/A * Signature: ()V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_flushNativeSurface(JNIEnv *env, jobject xsd)
0N/A{
0N/A#ifndef HEADLESS
0N/A SurfaceDataOps *ops = SurfaceData_GetOps(env, xsd);
0N/A
0N/A if (ops != NULL) {
0N/A X11SD_Dispose(env, ops);
0N/A }
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A
0N/AJNIEXPORT X11SDOps * JNICALL
0N/AX11SurfaceData_GetOps(JNIEnv *env, jobject sData)
0N/A{
0N/A#ifdef HEADLESS
0N/A return NULL;
0N/A#else
0N/A SurfaceDataOps *ops = SurfaceData_GetOps(env, sData);
0N/A if (ops != NULL && ops->Lock != X11SD_Lock) {
0N/A SurfaceData_ThrowInvalidPipeException(env, "not an X11 SurfaceData");
0N/A ops = NULL;
0N/A }
0N/A return (X11SDOps *) ops;
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Method for disposing X11SD-specific data
0N/A */
0N/Astatic void
0N/AX11SD_Dispose(JNIEnv *env, SurfaceDataOps *ops)
0N/A{
0N/A#ifndef HEADLESS
0N/A /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
0N/A X11SDOps * xsdo = (X11SDOps*)ops;
0N/A
0N/A AWT_LOCK();
0N/A
0N/A xsdo->invalid = JNI_TRUE;
3610N/A
3610N/A if (xsdo->xrPic != None) {
3610N/A XRenderFreePicture(awt_display, xsdo->xrPic);
3610N/A xsdo->xrPic = None;
3610N/A }
3610N/A
0N/A if (xsdo->isPixmap == JNI_TRUE && xsdo->drawable != 0) {
0N/A#ifdef MITSHM
0N/A if (xsdo->shmPMData.shmSegInfo != NULL) {
0N/A X11SD_DropSharedSegment(xsdo->shmPMData.shmSegInfo);
0N/A xsdo->shmPMData.shmSegInfo = NULL;
0N/A }
0N/A if (xsdo->shmPMData.pixmap) {
0N/A XFreePixmap(awt_display, xsdo->shmPMData.pixmap);
0N/A xsdo->shmPMData.pixmap = 0;
0N/A }
0N/A if (xsdo->shmPMData.shmPixmap) {
0N/A XFreePixmap(awt_display, xsdo->shmPMData.shmPixmap);
0N/A xsdo->shmPMData.shmPixmap = 0;
0N/A }
0N/A#else
0N/A XFreePixmap(awt_display, xsdo->drawable);
0N/A#endif /* MITSHM */
0N/A xsdo->drawable = 0;
0N/A }
0N/A if (xsdo->bitmask != 0) {
0N/A XFreePixmap(awt_display, xsdo->bitmask);
0N/A xsdo->bitmask = 0;
0N/A }
0N/A if (xsdo->javaGC != NULL) {
0N/A XFreeGC(awt_display, xsdo->javaGC);
0N/A xsdo->javaGC = NULL;
0N/A }
0N/A if (xsdo->cachedGC != NULL) {
0N/A XFreeGC(awt_display, xsdo->cachedGC);
0N/A xsdo->cachedGC = NULL;
0N/A }
2370N/A
2370N/A if(xsdo->xrPic != None) {
2370N/A XRenderFreePicture(awt_display, xsdo->xrPic);
2370N/A }
2370N/A
0N/A AWT_UNLOCK();
0N/A#endif /* !HEADLESS */
0N/A}
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: setInvalid
0N/A * Signature: ()V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_setInvalid(JNIEnv *env, jobject xsd)
0N/A{
0N/A#ifndef HEADLESS
0N/A X11SDOps *xsdo = (X11SDOps *) SurfaceData_GetOps(env, xsd);
0N/A
0N/A if (xsdo != NULL) {
0N/A xsdo->invalid = JNI_TRUE;
0N/A }
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
2370N/A
2370N/Ajboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable)
2370N/A{
2370N/A#ifndef HEADLESS
2370N/A
2370N/A if (drawable != (jlong)0) {
2370N/A /* Double-buffering */
2370N/A xsdo->drawable = drawable;
2370N/A xsdo->isPixmap = JNI_FALSE;
2370N/A } else {
2370N/A xsdo->isPixmap = JNI_TRUE;
2370N/A /* REMIND: workaround for bug 4420220 on pgx32 boards:
2370N/A don't use DGA with pixmaps unless USE_DGA_PIXMAPS is set.
2370N/A */
2370N/A xsdo->dgaAvailable = useDGAWithPixmaps;
2370N/A
2370N/A xsdo->pmWidth = width;
2370N/A xsdo->pmHeight = height;
2370N/A
2370N/A#ifdef MITSHM
2370N/A xsdo->shmPMData.pmSize = width * height * depth;
2370N/A xsdo->shmPMData.pixelsReadThreshold = width * height / 8;
2370N/A if (forceSharedPixmaps) {
2370N/A AWT_LOCK();
2370N/A xsdo->drawable = X11SD_CreateSharedPixmap(xsdo);
2370N/A AWT_UNLOCK();
2370N/A if (xsdo->drawable) {
2370N/A xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
2370N/A xsdo->shmPMData.shmPixmap = xsdo->drawable;
2370N/A return JNI_TRUE;
2370N/A }
2370N/A }
2370N/A#endif /* MITSHM */
2370N/A
2370N/A AWT_LOCK();
2370N/A xsdo->drawable =
2370N/A XCreatePixmap(awt_display,
2370N/A RootWindow(awt_display,
2370N/A xsdo->configData->awt_visInfo.screen),
2370N/A width, height, depth);
2370N/A AWT_UNLOCK();
2370N/A#ifdef MITSHM
2370N/A xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
2370N/A xsdo->shmPMData.pixmap = xsdo->drawable;
2370N/A#endif /* MITSHM */
2370N/A }
2370N/A if (xsdo->drawable == 0) {
2370N/A JNU_ThrowOutOfMemoryError(env,
2370N/A "Can't create offscreen surface");
2370N/A return JNI_FALSE;
2370N/A }
2370N/A
2370N/A return JNI_TRUE;
2370N/A#endif /* !HEADLESS */
2370N/A}
2370N/A
2370N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: initSurface
0N/A * Signature: ()V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_initSurface(JNIEnv *env, jclass xsd,
0N/A jint depth,
0N/A jint width, jint height,
0N/A jlong drawable)
0N/A{
0N/A#ifndef HEADLESS
0N/A X11SDOps *xsdo = X11SurfaceData_GetOps(env, xsd);
0N/A if (xsdo == NULL) {
0N/A return;
0N/A }
0N/A
0N/A if (xsdo->configData->awt_cmap == (Colormap)NULL) {
0N/A awtJNI_CreateColorData(env, xsdo->configData, 1);
0N/A }
0N/A /* color_data will be initialized in awtJNI_CreateColorData for
0N/A 8-bit visuals */
0N/A xsdo->cData = xsdo->configData->color_data;
0N/A
2370N/A XShared_initSurface(env, xsdo, depth, width, height, drawable);
2370N/A xsdo->xrPic = NULL;
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A#ifndef HEADLESS
0N/A
0N/A#ifdef MITSHM
0N/A
0N/Avoid X11SD_DropSharedSegment(XShmSegmentInfo *shminfo)
0N/A{
0N/A if (shminfo != NULL) {
0N/A XShmDetach(awt_display, shminfo);
0N/A shmdt(shminfo->shmaddr);
0N/A/* REMIND: we don't need shmctl(shminfo->shmid, IPC_RMID, 0); here. */
0N/A/* Check X11SD_CreateSharedImage() for the explanation */
0N/A }
0N/A}
0N/A
0N/AXImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
0N/A jint width, jint height)
0N/A{
0N/A XImage *img = NULL;
0N/A XShmSegmentInfo *shminfo;
6447N/A JNIEnv* env;
6447N/A jboolean xShmAttachResult;
0N/A
0N/A shminfo = malloc(sizeof(XShmSegmentInfo));
0N/A if (shminfo == NULL) {
0N/A return NULL;
0N/A }
0N/A memset(shminfo, 0, sizeof(XShmSegmentInfo));
0N/A
0N/A img = XShmCreateImage(awt_display, xsdo->configData->awt_visInfo.visual,
0N/A xsdo->depth, ZPixmap, NULL, shminfo,
0N/A width, height);
0N/A if (img == NULL) {
0N/A free((void *)shminfo);
0N/A return NULL;
0N/A }
0N/A shminfo->shmid =
6251N/A shmget(IPC_PRIVATE, height * img->bytes_per_line,
6251N/A IPC_CREAT|mitShmPermissionMask);
0N/A if (shminfo->shmid < 0) {
0N/A J2dRlsTraceLn1(J2D_TRACE_ERROR,
0N/A "X11SD_SetupSharedSegment shmget has failed: %s",
0N/A strerror(errno));
5471N/A free((void *)shminfo);
5471N/A XDestroyImage(img);
0N/A return NULL;
0N/A }
0N/A
0N/A shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
0N/A if (shminfo->shmaddr == ((char *) -1)) {
0N/A shmctl(shminfo->shmid, IPC_RMID, 0);
0N/A J2dRlsTraceLn1(J2D_TRACE_ERROR,
0N/A "X11SD_SetupSharedSegment shmat has failed: %s",
0N/A strerror(errno));
5471N/A free((void *)shminfo);
5471N/A XDestroyImage(img);
0N/A return NULL;
0N/A }
0N/A
0N/A shminfo->readOnly = False;
0N/A
6447N/A env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2);
6447N/A xShmAttachResult = TryXShmAttach(env, awt_display, shminfo);
0N/A
0N/A /*
0N/A * Once the XSync round trip has finished then we
0N/A * can get rid of the id so that this segment does not stick
0N/A * around after we go away, holding system resources.
0N/A */
0N/A shmctl(shminfo->shmid, IPC_RMID, 0);
0N/A
6447N/A if (xShmAttachResult == JNI_FALSE) {
0N/A J2dRlsTraceLn1(J2D_TRACE_ERROR,
0N/A "X11SD_SetupSharedSegment XShmAttach has failed: %s",
0N/A strerror(errno));
5471N/A shmdt(shminfo->shmaddr);
5471N/A free((void *)shminfo);
5471N/A XDestroyImage(img);
0N/A return NULL;
0N/A }
0N/A
0N/A img->data = shminfo->shmaddr;
0N/A img->obdata = (char *)shminfo;
0N/A
0N/A return img;
0N/A}
0N/A
0N/AXImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
3539N/A jint maxWidth, jint maxHeight, jboolean readBits)
0N/A{
0N/A XImage * retImage = NULL;
0N/A if (cachedXImage != NULL &&
3539N/A X11SD_CachedXImageFits(width, height, maxWidth, maxHeight,
3539N/A xsdo->depth, readBits)) {
3539N/A /* sync so previous data gets flushed */
3539N/A XSync(awt_display, False);
3539N/A retImage = cachedXImage;
3539N/A cachedXImage = (XImage *)NULL;
0N/A } else if (width * height * xsdo->depth > 0x10000) {
0N/A retImage = X11SD_CreateSharedImage(xsdo, width, height);
0N/A }
0N/A return retImage;
0N/A}
0N/A
0N/ADrawable X11SD_CreateSharedPixmap(X11SDOps *xsdo)
0N/A{
0N/A XShmSegmentInfo *shminfo;
0N/A XImage *img = NULL;
0N/A Drawable pixmap;
0N/A int scan;
0N/A int width = xsdo->pmWidth;
0N/A int height = xsdo->pmHeight;
0N/A
0N/A if (xsdo->shmPMData.pmSize < 0x10000) {
0N/A /* only use shared mem pixmaps for relatively big images */
0N/A return 0;
0N/A }
0N/A
0N/A /* need to create shared(!) image to get bytes_per_line */
0N/A img = X11SD_CreateSharedImage(xsdo, width, height);
0N/A if (img == NULL) {
0N/A return 0;
0N/A }
0N/A scan = img->bytes_per_line;
0N/A shminfo = (XShmSegmentInfo*)img->obdata;
0N/A XFree(img);
0N/A
0N/A pixmap =
0N/A XShmCreatePixmap(awt_display,
0N/A RootWindow(awt_display,
0N/A xsdo->configData->awt_visInfo.screen),
0N/A shminfo->shmaddr, shminfo,
0N/A width, height, xsdo->depth);
0N/A if (pixmap == 0) {
0N/A X11SD_DropSharedSegment(shminfo);
0N/A return 0;
0N/A }
0N/A
0N/A xsdo->shmPMData.shmSegInfo = shminfo;
0N/A xsdo->shmPMData.bytesPerLine = scan;
0N/A return pixmap;
0N/A}
0N/A
0N/Avoid X11SD_PuntPixmap(X11SDOps *xsdo, jint width, jint height)
0N/A{
0N/A
0N/A if (useMitShmPixmaps != CAN_USE_MITSHM || forceSharedPixmaps) {
0N/A return;
0N/A }
0N/A
0N/A /* we wouldn't be here if it's a shared pixmap, so no check
0N/A * for !usingShmPixmap.
0N/A */
0N/A
0N/A xsdo->shmPMData.numBltsSinceRead = 0;
0N/A
0N/A xsdo->shmPMData.pixelsReadSinceBlt += width * height;
0N/A if (xsdo->shmPMData.pixelsReadSinceBlt >
0N/A xsdo->shmPMData.pixelsReadThreshold) {
0N/A if (!xsdo->shmPMData.shmPixmap) {
0N/A xsdo->shmPMData.shmPixmap =
0N/A X11SD_CreateSharedPixmap(xsdo);
0N/A }
0N/A if (xsdo->shmPMData.shmPixmap) {
0N/A GC xgc = XCreateGC(awt_display, xsdo->shmPMData.shmPixmap, 0L, NULL);
0N/A if (xgc != NULL) {
0N/A xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
0N/A xsdo->drawable = xsdo->shmPMData.shmPixmap;
0N/A XCopyArea(awt_display,
0N/A xsdo->shmPMData.pixmap, xsdo->drawable, xgc,
0N/A 0, 0, xsdo->pmWidth, xsdo->pmHeight, 0, 0);
0N/A XSync(awt_display, False);
0N/A xsdo->shmPMData.xRequestSent = JNI_FALSE;
0N/A XFreeGC(awt_display, xgc);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid X11SD_UnPuntPixmap(X11SDOps *xsdo)
0N/A{
0N/A if (useMitShmPixmaps != CAN_USE_MITSHM || forceSharedPixmaps) {
0N/A return;
0N/A }
0N/A xsdo->shmPMData.pixelsReadSinceBlt = 0;
0N/A if (xsdo->shmPMData.numBltsSinceRead >=
0N/A xsdo->shmPMData.numBltsThreshold)
0N/A {
0N/A if (xsdo->shmPMData.usingShmPixmap) {
0N/A if (!xsdo->shmPMData.pixmap) {
0N/A xsdo->shmPMData.pixmap =
0N/A XCreatePixmap(awt_display,
0N/A RootWindow(awt_display,
0N/A xsdo->configData->awt_visInfo.screen),
0N/A xsdo->pmWidth, xsdo->pmHeight, xsdo->depth);
0N/A }
0N/A if (xsdo->shmPMData.pixmap) {
0N/A GC xgc = XCreateGC(awt_display, xsdo->shmPMData.pixmap, 0L, NULL);
0N/A if (xgc != NULL) {
0N/A xsdo->drawable = xsdo->shmPMData.pixmap;
0N/A XCopyArea(awt_display,
0N/A xsdo->shmPMData.shmPixmap, xsdo->drawable, xgc,
0N/A 0, 0, xsdo->pmWidth, xsdo->pmHeight, 0, 0);
0N/A XSync(awt_display, False);
0N/A XFreeGC(awt_display, xgc);
0N/A xsdo->shmPMData.xRequestSent = JNI_FALSE;
0N/A xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
0N/A xsdo->shmPMData.numBltsThreshold *= 2;
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A xsdo->shmPMData.numBltsSinceRead++;
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Determines if the cached image can be used for current operation.
0N/A * If the image is to be used to be read into by XShmGetImage,
0N/A * it must be close enough to avoid excessive reading from the screen;
0N/A * otherwise it should just be at least the size requested.
0N/A */
3539N/Ajboolean X11SD_CachedXImageFits(jint width, jint height, jint maxWidth,
3539N/A jint maxHeight, jint depth, jboolean readBits)
0N/A{
0N/A /* we assume here that the cached image exists */
0N/A jint imgWidth = cachedXImage->width;
0N/A jint imgHeight = cachedXImage->height;
0N/A
0N/A if (imgWidth < width || imgHeight < height || depth != cachedXImage->depth) {
0N/A /* doesn't fit if any of the cached image dimensions is smaller
0N/A or the depths are different */
0N/A return JNI_FALSE;
0N/A }
0N/A
0N/A if (!readBits) {
0N/A /* Not reading from this image, so any image at least of the
0N/A size requested will do */
0N/A return JNI_TRUE;
0N/A }
0N/A
3539N/A if ((imgWidth < width + 64) && (imgHeight < height + 64)
3539N/A && imgWidth <= maxWidth && imgHeight <= maxHeight)
3539N/A {
0N/A /* Cached image's width/height shouldn't be more than 64 pixels
0N/A * larger than requested, because the region in XShmGetImage
0N/A * can't be specified and we don't want to read too much.
3539N/A * Furthermore it has to be smaller than maxWidth/Height
3539N/A * so drawables are not read out of bounds.
0N/A */
0N/A return JNI_TRUE;
0N/A }
0N/A
0N/A return JNI_FALSE;
0N/A}
0N/A#endif /* MITSHM */
0N/A
2370N/Ajint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo)
0N/A{
0N/A if (xsdo->isPixmap == JNI_TRUE) {
0N/A return SD_FAILURE;
0N/A }
0N/A#ifndef XAWT
0N/A if (!XtIsRealized(xsdo->widget)) {
0N/A J2dTraceLn(J2D_TRACE_WARNING, "X11SD_InitWindow: widget is unrealized");
0N/A /* AWT_UNLOCK(); unlock it in caller */
0N/A return SD_FAILURE;
0N/A }
0N/A xsdo->drawable = XtWindow(xsdo->widget);
0N/A#endif
0N/A xsdo->cData = xsdo->configData->color_data;
0N/A
0N/A return SD_SUCCESS;
0N/A}
0N/A
0N/Astatic jint X11SD_Lock(JNIEnv *env,
0N/A SurfaceDataOps *ops,
0N/A SurfaceDataRasInfo *pRasInfo,
0N/A jint lockflags)
0N/A{
0N/A X11SDOps *xsdo = (X11SDOps *) ops;
0N/A X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
0N/A int ret = SD_SUCCESS;
0N/A
0N/A AWT_LOCK();
0N/A
0N/A if (xsdo->invalid) {
0N/A AWT_UNLOCK();
0N/A SurfaceData_ThrowInvalidPipeException(env, "bounds changed");
0N/A return SD_FAILURE;
0N/A }
0N/A#ifdef XAWT
0N/A xsdo->cData = xsdo->configData->color_data;
0N/A#endif
0N/A if (xsdo->drawable == 0 && X11SD_InitWindow(env, xsdo) == SD_FAILURE) {
0N/A AWT_UNLOCK();
0N/A return SD_FAILURE;
0N/A }
0N/A if ((lockflags & SD_LOCK_LUT) != 0 &&
0N/A (xsdo->cData == NULL ||
0N/A xsdo->cData->awt_icmLUT == NULL))
0N/A {
0N/A AWT_UNLOCK();
0N/A JNU_ThrowNullPointerException(env, "colormap lookup table");
0N/A return SD_FAILURE;
0N/A }
0N/A if ((lockflags & SD_LOCK_INVCOLOR) != 0 &&
0N/A (xsdo->cData == NULL ||
0N/A xsdo->cData->img_clr_tbl == NULL ||
0N/A xsdo->cData->img_oda_red == NULL ||
0N/A xsdo->cData->img_oda_green == NULL ||
0N/A xsdo->cData->img_oda_blue == NULL))
0N/A {
0N/A AWT_UNLOCK();
0N/A JNU_ThrowNullPointerException(env, "inverse colormap lookup table");
0N/A return SD_FAILURE;
0N/A }
0N/A if ((lockflags & SD_LOCK_INVGRAY) != 0 &&
0N/A (xsdo->cData == NULL ||
0N/A xsdo->cData->pGrayInverseLutData == NULL))
0N/A {
0N/A AWT_UNLOCK();
0N/A JNU_ThrowNullPointerException(env, "inverse gray lookup table");
0N/A return SD_FAILURE;
0N/A }
0N/A if (xsdo->dgaAvailable && (lockflags & (SD_LOCK_RD_WR))) {
0N/A int dgaret;
0N/A
0N/A dgaret = (*pJDgaInfo->pGetLock)(env, awt_display, &xsdo->dgaDev,
0N/A xsdo->drawable, &xsdo->surfInfo,
0N/A pRasInfo->bounds.x1,
0N/A pRasInfo->bounds.y1,
0N/A pRasInfo->bounds.x2,
0N/A pRasInfo->bounds.y2);
0N/A if (dgaret == JDGA_SUCCESS) {
0N/A int wx = xsdo->surfInfo.window.lox;
0N/A int wy = xsdo->surfInfo.window.loy;
0N/A pRasInfo->bounds.x1 = xsdo->surfInfo.visible.lox - wx;
0N/A pRasInfo->bounds.y1 = xsdo->surfInfo.visible.loy - wy;
0N/A pRasInfo->bounds.x2 = xsdo->surfInfo.visible.hix - wx;
0N/A pRasInfo->bounds.y2 = xsdo->surfInfo.visible.hiy - wy;
0N/A xpriv->lockType = X11SD_LOCK_BY_DGA;
0N/A xpriv->lockFlags = lockflags;
0N/A return SD_SUCCESS;
0N/A } else if (dgaret == JDGA_UNAVAILABLE) {
0N/A xsdo->dgaAvailable = JNI_FALSE;
0N/A }
0N/A }
0N/A if (lockflags & SD_LOCK_RD_WR) {
0N/A if (lockflags & SD_LOCK_FASTEST) {
0N/A ret = SD_SLOWLOCK;
0N/A }
0N/A xpriv->lockType = X11SD_LOCK_BY_XIMAGE;
0N/A if (xsdo->isPixmap) {
0N/A#ifdef MITSHM
0N/A if (xsdo->shmPMData.usingShmPixmap) {
0N/A xpriv->lockType = X11SD_LOCK_BY_SHMEM;
0N/A }
0N/A#endif /* MITSHM */
0N/A if (pRasInfo->bounds.x1 < 0) {
0N/A pRasInfo->bounds.x1 = 0;
0N/A }
0N/A if (pRasInfo->bounds.y1 < 0) {
0N/A pRasInfo->bounds.y1 = 0;
0N/A }
0N/A if (pRasInfo->bounds.x2 > xsdo->pmWidth) {
0N/A pRasInfo->bounds.x2 = xsdo->pmWidth;
0N/A }
0N/A if (pRasInfo->bounds.y2 > xsdo->pmHeight) {
0N/A pRasInfo->bounds.y2 = xsdo->pmHeight;
0N/A }
0N/A }
0N/A } else {
0N/A /* They didn't lock for anything - we won't give them anything */
0N/A xpriv->lockType = X11SD_LOCK_BY_NULL;
0N/A }
0N/A xpriv->lockFlags = lockflags;
0N/A xpriv->img = NULL;
0N/A
0N/A return ret;
0N/A /* AWT_UNLOCK() called in Unlock */
0N/A}
0N/A
0N/Astatic void X11SD_GetRasInfo(JNIEnv *env,
0N/A SurfaceDataOps *ops,
0N/A SurfaceDataRasInfo *pRasInfo)
0N/A{
0N/A X11SDOps *xsdo = (X11SDOps *) ops;
0N/A X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
0N/A jint lockFlags = xpriv->lockFlags;
0N/A jint depth = xsdo->depth;
0N/A int mult = xsdo->configData->pixelStride;
0N/A
0N/A if (xsdo->dgaAvailable &&
0N/A xpriv->lockType == X11SD_LOCK_BY_XIMAGE &&
0N/A (lockFlags & SD_LOCK_FASTEST))
0N/A {
0N/A /* Try one more time to use DGA (now with smaller bounds)... */
0N/A int dgaret;
0N/A
0N/A dgaret = (*pJDgaInfo->pGetLock)(env, awt_display, &xsdo->dgaDev,
0N/A xsdo->drawable, &xsdo->surfInfo,
0N/A pRasInfo->bounds.x1,
0N/A pRasInfo->bounds.y1,
0N/A pRasInfo->bounds.x2,
0N/A pRasInfo->bounds.y2);
0N/A if (dgaret == JDGA_SUCCESS) {
0N/A int wx = xsdo->surfInfo.window.lox;
0N/A int wy = xsdo->surfInfo.window.loy;
0N/A pRasInfo->bounds.x1 = xsdo->surfInfo.visible.lox - wx;
0N/A pRasInfo->bounds.y1 = xsdo->surfInfo.visible.loy - wy;
0N/A pRasInfo->bounds.x2 = xsdo->surfInfo.visible.hix - wx;
0N/A pRasInfo->bounds.y2 = xsdo->surfInfo.visible.hiy - wy;
0N/A xpriv->lockType = X11SD_LOCK_BY_DGA;
0N/A } else if (dgaret == JDGA_UNAVAILABLE) {
0N/A xsdo->dgaAvailable = JNI_FALSE;
0N/A }
0N/A }
0N/A
0N/A if (xpriv->lockType == X11SD_LOCK_BY_DGA) {
0N/A int scan = xsdo->surfInfo.surfaceScan;
0N/A int wx = xsdo->surfInfo.window.lox;
0N/A int wy = xsdo->surfInfo.window.loy;
0N/A pRasInfo->rasBase =
0N/A (void *)(((uintptr_t) xsdo->surfInfo.basePtr) + (scan*wy + wx) * mult);
0N/A pRasInfo->pixelStride = mult;
0N/A pRasInfo->pixelBitOffset = 0;
0N/A pRasInfo->scanStride = scan * mult;
0N/A#ifdef MITSHM
0N/A } else if (xpriv->lockType == X11SD_LOCK_BY_SHMEM) {
0N/A if (xsdo->shmPMData.xRequestSent == JNI_TRUE) {
0N/A /* need to sync before using shared mem pixmap
0N/A if any x calls were issued for this pixmap */
0N/A XSync(awt_display, False);
0N/A xsdo->shmPMData.xRequestSent = JNI_FALSE;
0N/A }
0N/A xpriv->x = pRasInfo->bounds.x1;
0N/A xpriv->y = pRasInfo->bounds.y1;
0N/A pRasInfo->rasBase = xsdo->shmPMData.shmSegInfo->shmaddr;
0N/A pRasInfo->pixelStride = mult;
0N/A pRasInfo->pixelBitOffset = 0;
0N/A pRasInfo->scanStride = xsdo->shmPMData.bytesPerLine;
0N/A#endif /* MITSHM */
0N/A } else if (xpriv->lockType == X11SD_LOCK_BY_XIMAGE) {
0N/A int x, y, w, h;
0N/A x = pRasInfo->bounds.x1;
0N/A y = pRasInfo->bounds.y1;
0N/A w = pRasInfo->bounds.x2 - x;
0N/A h = pRasInfo->bounds.y2 - y;
0N/A
0N/A xpriv->img = X11SD_GetImage(env, xsdo, &pRasInfo->bounds, lockFlags);
0N/A if (xpriv->img) {
0N/A int scan = xpriv->img->bytes_per_line;
0N/A xpriv->x = x;
0N/A xpriv->y = y;
0N/A pRasInfo->rasBase = xpriv->img->data - x * mult - y * scan;
0N/A pRasInfo->pixelStride = mult;
0N/A pRasInfo->pixelBitOffset = 0;
0N/A pRasInfo->scanStride = scan;
0N/A } else {
0N/A pRasInfo->rasBase = NULL;
0N/A pRasInfo->pixelStride = 0;
0N/A pRasInfo->pixelBitOffset = 0;
0N/A pRasInfo->scanStride = 0;
0N/A }
0N/A } else {
0N/A /* They didn't lock for anything - we won't give them anything */
0N/A pRasInfo->rasBase = NULL;
0N/A pRasInfo->pixelStride = 0;
0N/A pRasInfo->pixelBitOffset = 0;
0N/A pRasInfo->scanStride = 0;
0N/A }
0N/A if (lockFlags & SD_LOCK_LUT) {
0N/A pRasInfo->lutBase = (jint *) xsdo->cData->awt_icmLUT;
0N/A pRasInfo->lutSize = xsdo->cData->awt_numICMcolors;
0N/A } else {
0N/A pRasInfo->lutBase = NULL;
0N/A pRasInfo->lutSize = 0;
0N/A }
0N/A if (lockFlags & SD_LOCK_INVCOLOR) {
0N/A pRasInfo->invColorTable = xsdo->cData->img_clr_tbl;
0N/A pRasInfo->redErrTable = xsdo->cData->img_oda_red;
0N/A pRasInfo->grnErrTable = xsdo->cData->img_oda_green;
0N/A pRasInfo->bluErrTable = xsdo->cData->img_oda_blue;
0N/A } else {
0N/A pRasInfo->invColorTable = NULL;
0N/A pRasInfo->redErrTable = NULL;
0N/A pRasInfo->grnErrTable = NULL;
0N/A pRasInfo->bluErrTable = NULL;
0N/A }
0N/A if (lockFlags & SD_LOCK_INVGRAY) {
0N/A pRasInfo->invGrayTable = xsdo->cData->pGrayInverseLutData;
0N/A } else {
0N/A pRasInfo->invGrayTable = NULL;
0N/A }
0N/A}
0N/A
0N/Astatic void X11SD_Unlock(JNIEnv *env,
0N/A SurfaceDataOps *ops,
0N/A SurfaceDataRasInfo *pRasInfo)
0N/A{
0N/A X11SDOps *xsdo = (X11SDOps *) ops;
0N/A X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
0N/A
0N/A if (xpriv->lockType == X11SD_LOCK_BY_DGA) {
0N/A (*pJDgaInfo->pReleaseLock)(env, xsdo->dgaDev, xsdo->drawable);
0N/A } else if (xpriv->lockType == X11SD_LOCK_BY_XIMAGE &&
0N/A xpriv->img != NULL)
0N/A {
0N/A if (xpriv->lockFlags & SD_LOCK_WRITE) {
0N/A int x = xpriv->x;
0N/A int y = xpriv->y;
0N/A int w = pRasInfo->bounds.x2 - x;
0N/A int h = pRasInfo->bounds.y2 - y;
0N/A Drawable drawable = xsdo->drawable;
0N/A GC xgc = xsdo->cachedGC;
0N/A if (xgc == NULL) {
0N/A xsdo->cachedGC = xgc =
0N/A XCreateGC(awt_display, drawable, 0L, NULL);
0N/A }
0N/A
0N/A if (xpriv->img->byte_order != nativeByteOrder) {
0N/A /* switching bytes back in 24 and 32 bpp cases. */
0N/A /* For 16 bit XLib will switch for us. */
0N/A if (xsdo->depth > 16) {
0N/A X11SD_SwapBytes(xsdo, xpriv->img, xsdo->depth,
0N/A xsdo->configData->awtImage->wsImageFormat.bits_per_pixel);
0N/A }
0N/A }
0N/A
0N/A#ifdef MITSHM
0N/A if (xpriv->img->obdata != NULL) {
0N/A XShmPutImage(awt_display, drawable, xgc,
0N/A xpriv->img, 0, 0, x, y, w, h, False);
0N/A XFlush(awt_display);
0N/A } else {
0N/A XPutImage(awt_display, drawable, xgc,
0N/A xpriv->img, 0, 0, x, y, w, h);
0N/A }
0N/A if (xsdo->shmPMData.usingShmPixmap) {
0N/A xsdo->shmPMData.xRequestSent = JNI_TRUE;
0N/A }
0N/A#else
0N/A XPutImage(awt_display, drawable, xgc,
0N/A xpriv->img, 0, 0, x, y, w, h);
0N/A#endif /* MITSHM */
0N/A
0N/A (*pJDgaInfo->pXRequestSent)(env, xsdo->dgaDev, drawable);
0N/A }
0N/A X11SD_DisposeOrCacheXImage(xpriv->img);
0N/A xpriv->img = (XImage *)NULL;
0N/A }
0N/A /* the background pixel is not valid anymore */
0N/A if (xpriv->lockFlags & SD_LOCK_WRITE) {
0N/A xsdo->isBgInitialized = JNI_FALSE;
0N/A }
0N/A xpriv->lockType = X11SD_LOCK_UNLOCKED;
0N/A AWT_UNLOCK();
0N/A}
0N/A
0N/Astatic int
0N/AX11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
0N/A X11SDOps *xsdo)
0N/A{
0N/A Position x1=0, y1=0, x2=0, y2=0;
0N/A int tmpx, tmpy;
0N/A Window tmpchild;
0N/A
0N/A#ifndef XAWT
0N/A Widget w = xsdo->widget;
0N/A
0N/A x1 = y1 = 0;
0N/A for (; w != NULL && ! XtIsShell(w); w = w->core.parent) {
0N/A x1 += w->core.x + w->core.border_width;
0N/A y1 += w->core.y + w->core.border_width;
0N/A }
0N/A if (w == NULL) {
0N/A return FALSE;
0N/A }
0N/A
0N/A /*
0N/A * REMIND: We should not be offsetting here by border_width
0N/A * but for some unknown reason if we do not do that the
0N/A * results will be off exactly by border_width. We were unable
0N/A * to find cause of this.
0N/A */
0N/A (void) XTranslateCoordinates(XtDisplay(w), XtWindow(w),
0N/A RootWindowOfScreen(XtScreen(w)),
0N/A (int) w->core.border_width,
0N/A (int) w->core.border_width,
0N/A &tmpx, &tmpy, &tmpchild);
0N/A#else
0N/A Window window = (Window)(xsdo->drawable); /* is always a Window */
0N/A XWindowAttributes winAttr;
0N/A
0N/A Status status = XGetWindowAttributes(awt_display, window, &winAttr);
0N/A if (status == 0) {
0N/A /* Failure, X window no longer valid. */
0N/A return FALSE;
0N/A }
0N/A if (!XTranslateCoordinates(awt_display, window,
0N/A RootWindowOfScreen(winAttr.screen),
0N/A 0, 0, &tmpx, &tmpy, &tmpchild)) {
0N/A return FALSE;
0N/A }
0N/A#endif
0N/A
0N/A x1 = -(x1 + tmpx);
0N/A y1 = -(y1 + tmpy);
0N/A
0N/A x2 = x1 + DisplayWidth(awt_display, xsdo->configData->awt_visInfo.screen);
0N/A y2 = y1 + DisplayHeight(awt_display, xsdo->configData->awt_visInfo.screen);
0N/A
0N/A x1 = MAX(bounds->x1, x1);
0N/A y1 = MAX(bounds->y1, y1);
0N/A x2 = MIN(bounds->x2, x2);
0N/A y2 = MIN(bounds->y2, y2);
0N/A if ((x1 >= x2) || (y1 >= y2)) {
0N/A return FALSE;
0N/A }
0N/A b->x1 = x1;
0N/A b->y1 = y1;
0N/A b->x2 = x2;
0N/A b->y2 = y2;
0N/A
0N/A return TRUE;
0N/A}
0N/A
0N/A/*
0N/A * x1, y1, x2, y2 - our rectangle in the coord system of
0N/A * the widget
0N/A * px1, xy1, px2, py2 - current parent rect coords in the
0N/A * same system
0N/A */
0N/Astatic int
0N/AX11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds, X11SDOps *xsdo)
0N/A{
0N/A#ifndef XAWT
0N/A int x1, y1, x2, y2, px1, py1, px2, py2, child_x, child_y;
0N/A Widget current_widget, child_widget;
0N/A
0N/A XWindowAttributes attr;
0N/A Window ignore_root, current_window, *ignore_children;
0N/A unsigned int pborder, ignore_uint;
0N/A
0N/A x1 = bounds->x1;
0N/A y1 = bounds->y1;
0N/A x2 = bounds->x2;
0N/A y2 = bounds->y2;
0N/A
0N/A px1 = py1 = 0;
0N/A
0N/A child_widget = xsdo->widget;
0N/A current_widget = XtParent(xsdo->widget);
0N/A while (current_widget != NULL && !XtIsShell(current_widget)) {
0N/A px1 = px1 - (child_widget->core.x + child_widget->core.border_width);
0N/A py1 = py1 - (child_widget->core.y + child_widget->core.border_width);
0N/A px2 = px1 + current_widget->core.width;
0N/A py2 = py1 + current_widget->core.height;
0N/A x1 = MAX(x1, px1);
0N/A y1 = MAX(y1, py1);
0N/A x2 = MIN(x2, px2);
0N/A y2 = MIN(y2, py2);
0N/A if ((x1 >= x2) || (y1 >= y2)) {
0N/A return FALSE;
0N/A }
0N/A
0N/A child_widget = current_widget;
0N/A current_widget = current_widget->core.parent;
0N/A }
0N/A
0N/A if (current_widget == NULL) {
0N/A XQueryTree(awt_display,
0N/A XtWindow(child_widget),
0N/A &ignore_root,
0N/A &current_window,
0N/A &ignore_children,
0N/A &ignore_uint);
0N/A XFree(ignore_children);
0N/A } else {
0N/A current_window = XtWindow(current_widget);
0N/A }
0N/A
0N/A child_x = child_widget->core.x + child_widget->core.border_width;
0N/A child_y = child_widget->core.y + child_widget->core.border_width;
0N/A while (current_window != 0) {
0N/A px1 = px1 - child_x;
0N/A py1 = py1 - child_y;
0N/A if (!XGetGeometry(awt_display, current_window, &ignore_root,
0N/A &child_x, &child_y,
0N/A (unsigned int *)&px2, (unsigned int *)&py2,
0N/A &pborder, &ignore_uint)) {
0N/A return FALSE;
0N/A }
0N/A child_x += pborder;
0N/A child_y += pborder;
0N/A px2 += px1;
0N/A py2 += py1;
0N/A
0N/A x1 = MAX(x1, px1);
0N/A y1 = MAX(y1, py1);
0N/A x2 = MIN(x2, px2);
0N/A y2 = MIN(y2, py2);
0N/A if ((x1 >= x2) || (y1 >= y2)) {
0N/A return FALSE;
0N/A }
0N/A XQueryTree(awt_display,
0N/A current_window,
0N/A &ignore_root,
0N/A &current_window,
0N/A &ignore_children,
0N/A &ignore_uint);
0N/A XFree(ignore_children);
0N/A }
0N/A
0N/A b->x1 = x1;
0N/A b->y1 = y1;
0N/A b->x2 = x2;
0N/A b->y2 = y2;
0N/A#endif
0N/A return TRUE;
0N/A}
0N/A
0N/Astatic void
0N/AX11SD_SwapBytes(X11SDOps *xsdo, XImage * img, int depth, int bpp) {
0N/A int lengthInBytes = img->height * img->bytes_per_line;
0N/A int i;
0N/A
0N/A switch (depth) {
0N/A case 12:
0N/A case 15:
0N/A case 16:
0N/A {
0N/A /* AB -> BA */
0N/A unsigned short *d = (unsigned short *)img->data;
0N/A unsigned short t;
0N/A for (i = 0; i < lengthInBytes/2; i++) {
0N/A t = *d;
0N/A *d++ = (t >> 8) | (t << 8);
0N/A }
0N/A img->byte_order = nativeByteOrder;
0N/A img->bitmap_bit_order = nativeByteOrder;
0N/A break;
0N/A }
0N/A case 24:
0N/A {
0N/A /* ABC -> CBA */
0N/A if (bpp == 24) {
0N/A // 4517321: Only swap if we have a "real" ThreeByteBgr
0N/A // visual (denoted by a red_mask of 0xff). Due to ambiguity
0N/A // in the X11 spec, it appears that the swap is not required
0N/A // on Linux configurations that use 24 bits per pixel (denoted
0N/A // by a red_mask of 0xff0000).
0N/A if (xsdo->configData->awt_visInfo.red_mask == 0xff) {
0N/A int scan = img->bytes_per_line;
0N/A unsigned char *d = (unsigned char *) img->data;
0N/A unsigned char *d1;
0N/A unsigned int t;
0N/A int j;
0N/A
0N/A for (i = 0; i < img->height; i++, d += scan) {
0N/A d1 = d;
0N/A for (j = 0; j < img->width; j++, d1 += 3) {
0N/A /* not obvious opt from XLib src */
0N/A t = d1[0]; d1[0] = d1[2]; d1[2] = t;
0N/A }
0N/A }
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A /* FALL THROUGH for 32-bit case */
0N/A case 32:
0N/A {
0N/A /* ABCD -> DCBA */
0N/A unsigned int *d = (unsigned int *) img->data;
0N/A unsigned int t;
0N/A for (i = 0; i < lengthInBytes/4; i++) {
0N/A t = *d;
0N/A *d++ = ((t >> 24) |
0N/A ((t >> 8) & 0xff00) |
0N/A ((t & 0xff00) << 8) |
0N/A (t << 24));
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A}
0N/A
0N/Astatic XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
0N/A SurfaceDataBounds *bounds,
0N/A jint lockFlags)
0N/A{
3539N/A int x, y, w, h, maxWidth, maxHeight;
0N/A int scan;
0N/A XImage * img = NULL;
0N/A Drawable drawable;
0N/A int depth = xsdo->depth;
0N/A int mult = xsdo->configData->pixelStride;
0N/A int pad = (mult == 3) ? 32 : mult * 8; // pad must be 8, 16, or 32
0N/A jboolean readBits = lockFlags & SD_LOCK_NEED_PIXELS;
0N/A
0N/A x = bounds->x1;
0N/A y = bounds->y1;
0N/A w = bounds->x2 - x;
0N/A h = bounds->y2 - y;
0N/A
0N/A#ifdef MITSHM
0N/A if (useMitShmExt == CAN_USE_MITSHM) {
3539N/A if (xsdo->isPixmap) {
3539N/A if (readBits) {
3539N/A X11SD_PuntPixmap(xsdo, w, h);
3539N/A }
3539N/A maxWidth = xsdo->pmWidth;
3539N/A maxHeight = xsdo->pmHeight;
3539N/A } else {
3539N/A XWindowAttributes winAttr;
3539N/A if (XGetWindowAttributes(awt_display,
3539N/A (Window) xsdo->drawable, &winAttr) != 0) {
3539N/A maxWidth = winAttr.width;
3539N/A maxHeight = winAttr.height;
3539N/A } else {
3539N/A /* XGWA failed which isn't a good thing. Defaulting to using
3539N/A * x,y means that after the subtraction of these we will use
3539N/A * w=0, h=0 which is a reasonable default on such a failure.
3539N/A */
3539N/A maxWidth = x;
3539N/A maxHeight = y;
3539N/A }
0N/A }
3539N/A maxWidth -= x;
3539N/A maxHeight -= y;
3539N/A
3539N/A img = X11SD_GetSharedImage(xsdo, w, h, maxWidth, maxHeight, readBits);
0N/A }
0N/A#endif /* MITSHM */
0N/A drawable = xsdo->drawable;
0N/A
0N/A if (readBits) {
0N/A#ifdef MITSHM
0N/A if (img != NULL) {
0N/A if (!XShmGetImage(awt_display, drawable, img, x, y, -1)) {
0N/A X11SD_DisposeOrCacheXImage(img);
0N/A img = NULL;
0N/A }
0N/A }
0N/A if (img == NULL) {
0N/A img = XGetImage(awt_display, drawable, x, y, w, h, -1, ZPixmap);
0N/A if (img != NULL) {
0N/A img->obdata = NULL;
0N/A }
0N/A }
0N/A#else
0N/A img = XGetImage(awt_display, drawable, x, y, w, h, -1, ZPixmap);
0N/A#endif /* MITSHM */
0N/A if (img == NULL) {
0N/A SurfaceDataBounds temp;
0N/A img = XCreateImage(awt_display,
0N/A xsdo->configData->awt_visInfo.visual,
0N/A depth, ZPixmap, 0, NULL, w, h, pad, 0);
0N/A if (img == NULL) {
0N/A return NULL;
0N/A }
0N/A
0N/A scan = img->bytes_per_line;
0N/A img->data = malloc(h * scan);
0N/A if (img->data == NULL) {
0N/A XFree(img);
0N/A return NULL;
0N/A }
0N/A
0N/A if (xsdo->isPixmap == JNI_FALSE &&
0N/A X11SD_ClipToRoot(&temp, bounds, xsdo)) {
0N/A
0N/A XImage * temp_image;
0N/A temp_image = XGetImage(awt_display, drawable,
0N/A temp.x1, temp.y1,
0N/A temp.x2 - temp.x1,
0N/A temp.y2 - temp.y1,
0N/A -1, ZPixmap);
0N/A if (temp_image == NULL) {
0N/A XGrabServer(awt_display);
0N/A if (X11SD_FindClip(&temp, bounds, xsdo)) {
0N/A temp_image =
0N/A XGetImage(awt_display, drawable,
0N/A temp.x1, temp.y1,
0N/A temp.x2 - temp.x1,
0N/A temp.y2 - temp.y1,
0N/A -1, ZPixmap);
0N/A }
0N/A XUngrabServer(awt_display);
0N/A /* Workaround for bug 5039226 */
0N/A XSync(awt_display, False);
0N/A }
0N/A if (temp_image != NULL) {
0N/A int temp_scan, bytes_to_copy;
0N/A char * img_addr, * temp_addr;
0N/A int i;
0N/A
0N/A img_addr = img->data +
0N/A (temp.y1 - y) * scan + (temp.x1 - x) * mult;
0N/A temp_scan = temp_image->bytes_per_line;
0N/A temp_addr = temp_image->data;
0N/A bytes_to_copy = (temp.x2 - temp.x1) * mult;
0N/A for (i = temp.y1; i < temp.y2; i++) {
0N/A memcpy(img_addr, temp_addr, bytes_to_copy);
0N/A img_addr += scan;
0N/A temp_addr += temp_scan;
0N/A }
0N/A XDestroyImage(temp_image);
0N/A }
0N/A }
0N/A img->obdata = NULL;
0N/A }
0N/A if (depth > 8 && img->byte_order != nativeByteOrder) {
0N/A X11SD_SwapBytes(xsdo, img, depth,
0N/A xsdo->configData->awtImage->wsImageFormat.bits_per_pixel);
0N/A }
0N/A } else {
0N/A /*
0N/A * REMIND: This might be better to move to the Lock function
0N/A * to avoid lengthy I/O pauses inside what may be a critical
0N/A * section. This will be more critical when SD_LOCK_READ is
0N/A * implemented. Another solution is to cache the pixels
0N/A * to avoid reading for every operation.
0N/A */
0N/A if (img == NULL) {
0N/A img = XCreateImage(awt_display,
0N/A xsdo->configData->awt_visInfo.visual,
0N/A depth, ZPixmap, 0, NULL, w, h, pad, 0);
0N/A if (img == NULL) {
0N/A return NULL;
0N/A }
0N/A
0N/A img->data = malloc(h * img->bytes_per_line);
0N/A if (img->data == NULL) {
0N/A XFree(img);
0N/A return NULL;
0N/A }
0N/A
0N/A img->obdata = NULL;
0N/A
0N/A if (img->byte_order != nativeByteOrder &&
0N/A (depth == 15 || depth == 16 || depth == 12)) {
0N/A /* bytes will be swapped by XLib. */
0N/A img->byte_order = nativeByteOrder;
0N/A img->bitmap_bit_order = nativeByteOrder;
0N/A }
0N/A }
0N/A }
0N/A return img;
0N/A}
0N/A
0N/Avoid X11SD_DisposeOrCacheXImage(XImage * image) {
0N/A /* REMIND: might want to check if the new image worth caching. */
0N/A /* Cache only shared images. Passed image is assumed to be non-null. */
0N/A if (image->obdata != NULL) {
0N/A if (cachedXImage != NULL) {
0N/A X11SD_DisposeXImage(cachedXImage);
0N/A }
0N/A cachedXImage = image;
0N/A } else {
0N/A X11SD_DisposeXImage(image);
0N/A }
0N/A}
0N/A
0N/Avoid X11SD_DisposeXImage(XImage * image) {
0N/A if (image != NULL) {
0N/A#ifdef MITSHM
0N/A if (image->obdata != NULL) {
0N/A X11SD_DropSharedSegment((XShmSegmentInfo*)image->obdata);
5471N/A image->obdata = NULL;
0N/A }
0N/A#endif /* MITSHM */
5471N/A XDestroyImage(image);
0N/A }
0N/A}
0N/A
0N/Astatic JDgaStatus
0N/A GetLockStub(JNIEnv *env, Display *display, void **dgaDev,
0N/A Drawable d, JDgaSurfaceInfo *pSurface,
0N/A jint lox, jint loy, jint hix, jint hiy)
0N/A{
0N/A return JDGA_UNAVAILABLE;
0N/A}
0N/A
0N/Astatic JDgaStatus
0N/A ReleaseLockStub(JNIEnv *env, void *dgaDev, Drawable d)
0N/A{
0N/A return JDGA_FAILED;
0N/A}
0N/A
0N/Astatic void
0N/A XRequestSentStub(JNIEnv *env, void *dgaDev, Drawable d)
0N/A{
0N/A}
0N/A
0N/Astatic void
0N/A LibDisposeStub(JNIEnv *env)
0N/A{
0N/A}
0N/A
0N/Astatic JDgaLibInfo DgaLibInfoStub = {
0N/A NULL,
0N/A GetLockStub,
0N/A ReleaseLockStub,
0N/A XRequestSentStub,
0N/A LibDisposeStub,
0N/A};
0N/A
0N/Avoid X11SD_LibDispose(JNIEnv *env) {
0N/A AWT_LOCK();
0N/A if (pJDgaInfo != NULL) {
0N/A pJDgaInfo->pLibDispose(env);
0N/A pJDgaInfo = &DgaLibInfoStub;
0N/A }
0N/A AWT_UNLOCK();
0N/A}
0N/A
0N/Avoid
0N/AX11SD_DirectRenderNotify(JNIEnv *env, X11SDOps *xsdo)
0N/A{
0N/A#ifdef MITSHM
0N/A if (xsdo->shmPMData.usingShmPixmap) {
0N/A xsdo->shmPMData.xRequestSent = JNI_TRUE;
0N/A }
0N/A#endif /* MITSHM */
0N/A (*pJDgaInfo->pXRequestSent)(env, xsdo->dgaDev, xsdo->drawable);
0N/A awt_output_flush();
0N/A}
0N/A
0N/A/*
0N/A * Sets transparent pixels in the pixmap to
0N/A * the specified solid background color and returns it.
0N/A * Doesn't update source pixmap unless the color of the
0N/A * transparent pixels is different from the specified color.
0N/A *
0N/A * Note: The AWT lock must be held by the current thread
0N/A * while calling into this method.
0N/A */
0N/Astatic Drawable
0N/AX11SD_GetPixmapWithBg(JNIEnv *env, X11SDOps *xsdo, jint pixel)
0N/A{
0N/A /* assert AWT_CHECK_HAVE_LOCK(); */
0N/A
0N/A if (xsdo->invalid) {
0N/A AWT_UNLOCK();
0N/A SurfaceData_ThrowInvalidPipeException(env, "bounds changed");
0N/A return 0;
0N/A }
0N/A
0N/A /* the image doesn't have transparency, just return it */
0N/A if (xsdo->bitmask == 0) {
0N/A /* don't need to unlock here, the caller will unlock through
0N/A the release call */
0N/A return xsdo->drawable;
0N/A }
0N/A
0N/A /* Check if current color of the transparent pixels is different
0N/A from the specified one */
0N/A if (xsdo->isBgInitialized == JNI_FALSE || xsdo->bgPixel != pixel) {
0N/A GC srcGC;
0N/A GC bmGC;
0N/A
0N/A if (xsdo->drawable == 0) {
0N/A AWT_UNLOCK();
0N/A return 0;
0N/A }
0N/A
0N/A bmGC = XCreateGC(awt_display, xsdo->bitmask, 0, NULL);
0N/A if (bmGC == NULL) {
0N/A AWT_UNLOCK();
0N/A return 0;
0N/A }
0N/A
0N/A /* invert the bitmask */
0N/A XSetFunction(awt_display, bmGC, GXxor);
0N/A XSetForeground(awt_display, bmGC, 1);
0N/A XFillRectangle(awt_display, xsdo->bitmask, bmGC,
0N/A 0, 0, xsdo->pmWidth, xsdo->pmHeight);
0N/A
0N/A srcGC = XCreateGC(awt_display, xsdo->drawable, 0L, NULL);
0N/A if (srcGC == NULL) {
0N/A XFreeGC(awt_display, bmGC);
0N/A AWT_UNLOCK();
0N/A return 0;
0N/A }
0N/A
0N/A /* set transparent pixels in the source pm to the bg color */
0N/A XSetClipMask(awt_display, srcGC, xsdo->bitmask);
0N/A XSetForeground(awt_display, srcGC, pixel);
0N/A XFillRectangle(awt_display, xsdo->drawable, srcGC,
0N/A 0, 0, xsdo->pmWidth, xsdo->pmHeight);
0N/A
0N/A /* invert the mask back */
0N/A XFillRectangle(awt_display, xsdo->bitmask, bmGC,
0N/A 0, 0, xsdo->pmWidth, xsdo->pmHeight);
0N/A
0N/A XFreeGC(awt_display, bmGC);
0N/A XFreeGC(awt_display, srcGC);
0N/A xsdo->bgPixel = pixel;
0N/A xsdo->isBgInitialized = JNI_TRUE;
0N/A }
0N/A
0N/A return xsdo->drawable;
0N/A}
0N/A
0N/Astatic void
0N/AX11SD_ReleasePixmapWithBg(JNIEnv *env, X11SDOps *xsdo)
0N/A{
0N/A#ifdef MITSHM
0N/A if (xsdo->shmPMData.usingShmPixmap) {
0N/A xsdo->shmPMData.xRequestSent = JNI_TRUE;
0N/A }
0N/A#endif /* MITSHM */
0N/A}
0N/A
0N/A#endif /* !HEADLESS */
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XCreateGC
0N/A * Signature: (I)J
0N/A */
0N/AJNIEXPORT jlong JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_XCreateGC
0N/A (JNIEnv *env, jclass xsd, jlong pXSData)
0N/A{
0N/A jlong ret;
0N/A
0N/A#ifndef HEADLESS
0N/A X11SDOps *xsdo;
0N/A
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XCreateGC");
0N/A
0N/A xsdo = (X11SDOps *) pXSData;
0N/A if (xsdo == NULL) {
0N/A return 0L;
0N/A }
0N/A
0N/A xsdo->javaGC = XCreateGC(awt_display, xsdo->drawable, 0, NULL);
0N/A ret = (jlong) xsdo->javaGC;
0N/A#else /* !HEADLESS */
0N/A ret = 0L;
0N/A#endif /* !HEADLESS */
0N/A
0N/A return ret;
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XResetClip
0N/A * Signature: (JIIIILsun/java2d/pipe/Region;)V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_XResetClip
0N/A (JNIEnv *env, jclass xsd, jlong xgc)
0N/A{
0N/A#ifndef HEADLESS
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XResetClip");
0N/A XSetClipMask(awt_display, (GC) xgc, None);
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XSetClip
0N/A * Signature: (JIIIILsun/java2d/pipe/Region;)V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_XSetClip
0N/A (JNIEnv *env, jclass xsd, jlong xgc,
0N/A jint x1, jint y1, jint x2, jint y2,
0N/A jobject complexclip)
0N/A{
0N/A#ifndef HEADLESS
0N/A int numrects;
0N/A XRectangle rects[256];
0N/A XRectangle *pRect = rects;
0N/A
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetClip");
0N/A
0N/A numrects = RegionToYXBandedRectangles(env,
0N/A x1, y1, x2, y2, complexclip,
0N/A &pRect, 256);
0N/A
0N/A XSetClipRectangles(awt_display, (GC) xgc, 0, 0, pRect, numrects, YXBanded);
0N/A
0N/A if (pRect != rects) {
0N/A free(pRect);
0N/A }
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XSetCopyMode
0N/A * Signature: (J)V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_XSetCopyMode
0N/A (JNIEnv *env, jclass xsd, jlong xgc)
0N/A{
0N/A#ifndef HEADLESS
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetCopyMode");
0N/A XSetFunction(awt_display, (GC) xgc, GXcopy);
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XSetXorMode
0N/A * Signature: (J)V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_XSetXorMode
0N/A (JNIEnv *env, jclass xr, jlong xgc)
0N/A{
0N/A#ifndef HEADLESS
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetXorMode");
0N/A XSetFunction(awt_display, (GC) xgc, GXxor);
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XSetForeground
0N/A * Signature: (JI)V
0N/A */
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_x11_X11SurfaceData_XSetForeground
0N/A (JNIEnv *env, jclass xsd, jlong xgc, jint pixel)
0N/A{
0N/A#ifndef HEADLESS
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetForeground");
0N/A XSetForeground(awt_display, (GC) xgc, pixel);
0N/A#endif /* !HEADLESS */
0N/A}
0N/A
0N/A/*
0N/A * Class: sun_java2d_x11_X11SurfaceData
0N/A * Method: XSetGraphicsExposures
0N/A * Signature: (JZ)V
0N/A */
0N/AJNIEXPORT void JNICALL
2370N/AJava_sun_java2d_x11_XSurfaceData_XSetGraphicsExposures
0N/A (JNIEnv *env, jclass xsd, jlong xgc, jboolean needExposures)
0N/A{
0N/A#ifndef HEADLESS
0N/A J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetGraphicsExposures");
0N/A XSetGraphicsExposures(awt_display, (GC) xgc, needExposures ? True : False);
0N/A#endif /* !HEADLESS */
0N/A}