jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
author alitvinov
Wed, 04 Dec 2013 12:29:18 +0400
changeset 21939 5169fd314636
parent 20425 5964c0fc5cc0
child 22600 a509464f280f
permissions -rw-r--r--
8025775: JNI warnings in TryXShmAttach Reviewed-by: art, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 15504
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1739
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1739
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1739
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1739
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1739
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "X11SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "Region.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/* Needed to define intptr_t */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "gdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "jni_util.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    35
#include "jvm_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "awt_GraphicsEnv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
static JDgaLibInfo DgaLibInfoStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
static JDgaLibInfo theJDgaInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
static JDgaLibInfo *pJDgaInfo = &DgaLibInfoStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This file contains support code for loops using the SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * interface to talk to an X11 drawable from native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
typedef struct _X11RIPrivate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    jint                lockType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jint                lockFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    XImage              *img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    int                 x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
} X11RIPrivate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#define MAX(a,b) ((a) > (b) ? (a) : (b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define MIN(a,b) ((a) < (b) ? (a) : (b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
static LockFunc X11SD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
static GetRasInfoFunc X11SD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
static UnlockFunc X11SD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
static DisposeFunc X11SD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
static GetPixmapBgFunc X11SD_GetPixmapWithBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
21939
5169fd314636 8025775: JNI warnings in TryXShmAttach
alitvinov
parents: 20425
diff changeset
    68
extern int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
extern AwtGraphicsConfigDataPtr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
    72
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                          X11SDOps *xsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                            X11SDOps *xsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static void X11SD_SwapBytes(X11SDOps *xsdo, XImage *img, int depth, int bpp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                               SurfaceDataBounds *bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                               jint lockFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
extern jfieldID validID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static int nativeByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
static jboolean dgaAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static jboolean useDGAWithPixmaps = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
static jclass xorCompClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
jint useMitShmExt = CANT_USE_MITSHM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
jint useMitShmPixmaps = CANT_USE_MITSHM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
jint forceSharedPixmaps = JNI_FALSE;
18184
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
    92
int mitShmPermissionMask = MITSHM_PERM_OWNER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* Cached shared image, one for all surface datas. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
static XImage * cachedXImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
    99
jboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps)
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   100
{
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   101
#ifndef HEADLESS
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   102
   union {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   103
        char c[4];
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   104
        int i;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   105
    } endian;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   106
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   107
    endian.i = 0xff000000;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   108
    nativeByteOrder = (endian.c[0]) ? MSBFirst : LSBFirst;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   109
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   110
    dgaAvailable = JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   111
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   112
    cachedXImage = NULL;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   113
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   114
    if (sizeof(X11RIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   115
        JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   116
        return JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   117
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   118
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   119
#ifdef MITSHM
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   120
    if (getenv("NO_AWT_MITSHM") == NULL &&
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   121
        getenv("NO_J2D_MITSHM") == NULL) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   122
        char * force;
18184
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   123
        char * permission = getenv("J2D_MITSHM_PERMISSION");
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   124
        if (permission != NULL) {
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   125
            if (strcmp(permission, "common") == 0) {
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   126
                mitShmPermissionMask = MITSHM_PERM_COMMON;
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   127
            }
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   128
        }
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   129
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   130
        TryInitMITShm(env, &useMitShmExt, &useMitShmPixmaps);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   131
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   132
        if(allowShmPixmaps) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   133
          useMitShmPixmaps = (useMitShmPixmaps == CAN_USE_MITSHM);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   134
          force = getenv("J2D_PIXMAPS");
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   135
          if (force != NULL) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   136
              if (useMitShmPixmaps && (strcmp(force, "shared") == 0)) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   137
                  forceSharedPixmaps = JNI_TRUE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   138
              } else if (strcmp(force, "server") == 0) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   139
                  useMitShmPixmaps = JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   140
              }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   141
          }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   142
        }else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   143
          useMitShmPixmaps = JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   144
        }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   145
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   146
#endif /* MITSHM */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   147
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   148
#endif /* !HEADLESS */
15504
c13b899e2b15 8005052: [parfait] #416 X11SurfaceData.c UNINITIALISED OR MISSING RETURN VALUE
jgodinez
parents: 12171
diff changeset
   149
c13b899e2b15 8005052: [parfait] #416 X11SurfaceData.c UNINITIALISED OR MISSING RETURN VALUE
jgodinez
parents: 12171
diff changeset
   150
    return JNI_TRUE;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   151
}
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   152
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   153
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Signature: (Ljava/lang/Class;Z)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
Java_sun_java2d_x11_X11SurfaceData_initIDs(JNIEnv *env, jclass xsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                           jclass XORComp, jboolean tryDGA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#ifndef HEADLESS
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   164
  if(XShared_initIDs(env, JNI_TRUE))
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   165
  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    void *lib = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    xorCompClass = (*env)->NewGlobalRef(env, XORComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /* we use RTLD_NOW because of bug 4032715 */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   172
        lib = dlopen(JNI_LIB_NAME("sunwjdga"), RTLD_NOW);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    if (lib != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        JDgaStatus ret = JDGA_FAILED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        void *sym = dlsym(lib, "JDgaLibInit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (sym != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            theJDgaInfo.display = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            ret = (*(JDgaLibInitFunc *)sym)(env, &theJDgaInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (ret == JDGA_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            pJDgaInfo = &theJDgaInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            dgaAvailable = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            useDGAWithPixmaps = (getenv("USE_DGA_PIXMAPS") != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            dlclose(lib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            lib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   193
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * Method:    isDrawableValid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
JNIEXPORT jboolean JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   203
Java_sun_java2d_x11_XSurfaceData_isDrawableValid(JNIEnv *env, jobject this)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    jboolean ret = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    X11SDOps *xsdo = X11SurfaceData_GetOps(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if (xsdo->drawable != 0 || X11SD_InitWindow(env, xsdo) == SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        ret = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
/*
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   221
 * Class: sun_java2d_x11_X11SurfaceData
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   222
 * Method: isShmPMAvailable
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   223
 * Signature: ()Z
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   224
 */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   225
JNIEXPORT jboolean JNICALL
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   226
Java_sun_java2d_x11_X11SurfaceData_isShmPMAvailable(JNIEnv *env, jobject this)
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   227
{
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   228
#if defined(HEADLESS) || !defined(MITSHM)
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   229
    return JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   230
#else
20425
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   231
    return (jboolean)useMitShmPixmaps;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   232
#endif /* HEADLESS, MITSHM */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   233
}
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   234
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   235
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * Method:    isDgaAvailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
Java_sun_java2d_x11_X11SurfaceData_isDgaAvailable(JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#if defined(HEADLESS) || defined(__linux__)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    return dgaAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
#endif /* HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * Method:    initOps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * Signature: (Ljava/lang/Object;I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   256
Java_sun_java2d_x11_XSurfaceData_initOps(JNIEnv *env, jobject xsd,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                           jobject peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                           jobject graphicsConfig, jint depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    X11SDOps *xsdo = (X11SDOps*)SurfaceData_InitOps(env, xsd, sizeof(X11SDOps));
20425
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   262
    jboolean hasException;
5938
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5580
diff changeset
   263
    if (xsdo == NULL) {
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5580
diff changeset
   264
        JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5580
diff changeset
   265
        return;
c93e51904f68 6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents: 5580
diff changeset
   266
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    xsdo->sdOps.Lock = X11SD_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    xsdo->sdOps.GetRasInfo = X11SD_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    xsdo->sdOps.Unlock = X11SD_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    xsdo->sdOps.Dispose = X11SD_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    xsdo->GetPixmapWithBg = X11SD_GetPixmapWithBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    xsdo->ReleasePixmapWithBg = X11SD_ReleasePixmapWithBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    xsdo->widget = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    if (peer != NULL) {
20425
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   275
        xsdo->drawable = JNU_CallMethodByName(env, &hasException, peer, "getWindow", "()J").j;
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   276
        if (hasException) {
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   277
            return;
5964c0fc5cc0 8025294: [parfait] JNI-related warnings from b107 for jdk.src.solaris.native.sun.java2d.x11
jchen
parents: 18253
diff changeset
   278
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        xsdo->drawable = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    xsdo->depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    xsdo->dgaAvailable = dgaAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    xsdo->isPixmap = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    xsdo->bitmask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    xsdo->bgPixel = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    xsdo->isBgInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    xsdo->shmPMData.shmSegInfo = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    xsdo->shmPMData.xRequestSent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    xsdo->shmPMData.pmSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    xsdo->shmPMData.pixmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    xsdo->shmPMData.shmPixmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    xsdo->shmPMData.numBltsSinceRead = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    xsdo->shmPMData.pixelsReadSinceBlt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    xsdo->shmPMData.numBltsThreshold = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    xsdo->configData = (AwtGraphicsConfigDataPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        JNU_GetLongFieldAsPtr(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                              graphicsConfig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                              x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (xsdo->configData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        JNU_ThrowNullPointerException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                      "Native GraphicsConfig data block missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    if (depth > 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        xsdo->pixelmask = (xsdo->configData->awt_visInfo.red_mask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                           xsdo->configData->awt_visInfo.green_mask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                           xsdo->configData->awt_visInfo.blue_mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    } else if (depth == 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        xsdo->pixelmask = 0xfff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        xsdo->pixelmask = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   318
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   319
    xsdo->xrPic = None;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * Method:    flushNativeSurface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   329
Java_sun_java2d_x11_XSurfaceData_flushNativeSurface(JNIEnv *env, jobject xsd)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    SurfaceDataOps *ops = SurfaceData_GetOps(env, xsd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    if (ops != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        X11SD_Dispose(env, ops);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
JNIEXPORT X11SDOps * JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
X11SurfaceData_GetOps(JNIEnv *env, jobject sData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    SurfaceDataOps *ops = SurfaceData_GetOps(env, sData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (ops != NULL && ops->Lock != X11SD_Lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        SurfaceData_ThrowInvalidPipeException(env, "not an X11 SurfaceData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        ops = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    return (X11SDOps *) ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * Method for disposing X11SD-specific data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
X11SD_Dispose(JNIEnv *env, SurfaceDataOps *ops)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    X11SDOps * xsdo = (X11SDOps*)ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    xsdo->invalid = JNI_TRUE;
8507
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   369
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   370
    if (xsdo->xrPic != None) {
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   371
        XRenderFreePicture(awt_display, xsdo->xrPic);
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   372
        xsdo->xrPic = None;
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   373
     }
78ea3ec4877b 6974985: Jave2Demo threw exceptions when xrender enabled in OEL5.5
ceisserer
parents: 8356
diff changeset
   374
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (xsdo->isPixmap == JNI_TRUE && xsdo->drawable != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (xsdo->shmPMData.shmSegInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            X11SD_DropSharedSegment(xsdo->shmPMData.shmSegInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            xsdo->shmPMData.shmSegInfo = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (xsdo->shmPMData.pixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            XFreePixmap(awt_display, xsdo->shmPMData.pixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            xsdo->shmPMData.pixmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (xsdo->shmPMData.shmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            XFreePixmap(awt_display, xsdo->shmPMData.shmPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            xsdo->shmPMData.shmPixmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        XFreePixmap(awt_display, xsdo->drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        xsdo->drawable = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    if (xsdo->bitmask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        XFreePixmap(awt_display, xsdo->bitmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        xsdo->bitmask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    if (xsdo->javaGC != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        XFreeGC(awt_display, xsdo->javaGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        xsdo->javaGC = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if (xsdo->cachedGC != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        XFreeGC(awt_display, xsdo->cachedGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        xsdo->cachedGC = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   406
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   407
    if(xsdo->xrPic != None) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   408
      XRenderFreePicture(awt_display, xsdo->xrPic);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   409
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   410
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
 * Method:    setInvalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   420
Java_sun_java2d_x11_XSurfaceData_setInvalid(JNIEnv *env, jobject xsd)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    X11SDOps *xsdo = (X11SDOps *) SurfaceData_GetOps(env, xsd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    if (xsdo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        xsdo->invalid = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   431
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   432
jboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable)
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   433
{
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   434
#ifndef HEADLESS
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   435
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   436
    if (drawable != (jlong)0) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   437
        /* Double-buffering */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   438
        xsdo->drawable = drawable;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   439
        xsdo->isPixmap = JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   440
    } else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   441
        xsdo->isPixmap = JNI_TRUE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   442
        /* REMIND: workaround for bug 4420220 on pgx32 boards:
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   443
           don't use DGA with pixmaps unless USE_DGA_PIXMAPS is set.
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   444
         */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   445
        xsdo->dgaAvailable = useDGAWithPixmaps;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   446
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   447
        xsdo->pmWidth = width;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   448
        xsdo->pmHeight = height;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   449
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   450
#ifdef MITSHM
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   451
        xsdo->shmPMData.pmSize = width * height * depth;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   452
        xsdo->shmPMData.pixelsReadThreshold = width * height / 8;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   453
        if (forceSharedPixmaps) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   454
            AWT_LOCK();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   455
            xsdo->drawable = X11SD_CreateSharedPixmap(xsdo);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   456
            AWT_UNLOCK();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   457
            if (xsdo->drawable) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   458
                xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   459
                xsdo->shmPMData.shmPixmap = xsdo->drawable;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   460
                return JNI_TRUE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   461
            }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   462
        }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   463
#endif /* MITSHM */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   464
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   465
        AWT_LOCK();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   466
        xsdo->drawable =
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   467
            XCreatePixmap(awt_display,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   468
                          RootWindow(awt_display,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   469
                                     xsdo->configData->awt_visInfo.screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   470
                          width, height, depth);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   471
        AWT_UNLOCK();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   472
#ifdef MITSHM
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   473
        xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   474
        xsdo->shmPMData.pixmap = xsdo->drawable;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   475
#endif /* MITSHM */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   476
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   477
    if (xsdo->drawable == 0) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   478
        JNU_ThrowOutOfMemoryError(env,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   479
                                  "Can't create offscreen surface");
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   480
        return JNI_FALSE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   481
    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   482
15504
c13b899e2b15 8005052: [parfait] #416 X11SurfaceData.c UNINITIALISED OR MISSING RETURN VALUE
jgodinez
parents: 12171
diff changeset
   483
#endif /* !HEADLESS */
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   484
    return JNI_TRUE;
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   485
}
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   486
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   487
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 * Method:    initSurface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
Java_sun_java2d_x11_X11SurfaceData_initSurface(JNIEnv *env, jclass xsd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                               jint depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                               jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                               jlong drawable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    X11SDOps *xsdo = X11SurfaceData_GetOps(env, xsd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if (xsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    if (xsdo->configData->awt_cmap == (Colormap)NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        awtJNI_CreateColorData(env, xsdo->configData, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /* color_data will be initialized in awtJNI_CreateColorData for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
       8-bit visuals */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    xsdo->cData = xsdo->configData->color_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   512
    XShared_initSurface(env, xsdo, depth, width, height, drawable);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   513
    xsdo->xrPic = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
void X11SD_DropSharedSegment(XShmSegmentInfo *shminfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    if (shminfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        XShmDetach(awt_display, shminfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        shmdt(shminfo->shmaddr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
/*      REMIND: we don't need shmctl(shminfo->shmid, IPC_RMID, 0); here. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
/*      Check X11SD_CreateSharedImage() for the explanation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                   jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    XImage *img = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    XShmSegmentInfo *shminfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    shminfo = malloc(sizeof(XShmSegmentInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    if (shminfo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    memset(shminfo, 0, sizeof(XShmSegmentInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    img = XShmCreateImage(awt_display, xsdo->configData->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                          xsdo->depth, ZPixmap, NULL, shminfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                          width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        free((void *)shminfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    shminfo->shmid =
18184
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   551
        shmget(IPC_PRIVATE, height * img->bytes_per_line,
75811cab0180 8001034: Memory management improvements
bae
parents: 15504
diff changeset
   552
               IPC_CREAT|mitShmPermissionMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    if (shminfo->shmid < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                       "X11SD_SetupSharedSegment shmget has failed: %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                       strerror(errno));
12170
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   557
        free((void *)shminfo);
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   558
        XDestroyImage(img);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    if (shminfo->shmaddr == ((char *) -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        shmctl(shminfo->shmid, IPC_RMID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                       "X11SD_SetupSharedSegment shmat has failed: %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                       strerror(errno));
12170
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   568
        free((void *)shminfo);
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   569
        XDestroyImage(img);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    shminfo->readOnly = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
21939
5169fd314636 8025775: JNI warnings in TryXShmAttach
alitvinov
parents: 20425
diff changeset
   575
    resetXShmAttachFailed();
5169fd314636 8025775: JNI warnings in TryXShmAttach
alitvinov
parents: 20425
diff changeset
   576
    EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
5169fd314636 8025775: JNI warnings in TryXShmAttach
alitvinov
parents: 20425
diff changeset
   577
                             XShmAttach(awt_display, shminfo));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Once the XSync round trip has finished then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * can get rid of the id so that this segment does not stick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * around after we go away, holding system resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    shmctl(shminfo->shmid, IPC_RMID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
21939
5169fd314636 8025775: JNI warnings in TryXShmAttach
alitvinov
parents: 20425
diff changeset
   586
    if (isXShmAttachFailed() == JNI_TRUE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        J2dRlsTraceLn1(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                       "X11SD_SetupSharedSegment XShmAttach has failed: %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                       strerror(errno));
12170
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   590
        shmdt(shminfo->shmaddr);
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   591
        free((void *)shminfo);
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
   592
        XDestroyImage(img);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    img->data = shminfo->shmaddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    img->obdata = (char *)shminfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    return img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
XImage* X11SD_GetSharedImage(X11SDOps *xsdo, jint width, jint height,
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   603
                             jint maxWidth, jint maxHeight, jboolean readBits)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    XImage * retImage = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    if (cachedXImage != NULL &&
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   607
        X11SD_CachedXImageFits(width, height, maxWidth, maxHeight,
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   608
                               xsdo->depth, readBits)) {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   609
        /* sync so previous data gets flushed */
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   610
        XSync(awt_display, False);
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   611
        retImage = cachedXImage;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   612
        cachedXImage = (XImage *)NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    } else if (width * height * xsdo->depth > 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        retImage = X11SD_CreateSharedImage(xsdo, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    return retImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
Drawable X11SD_CreateSharedPixmap(X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    XShmSegmentInfo *shminfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    XImage *img = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    Drawable pixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    int scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    int width = xsdo->pmWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    int height = xsdo->pmHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    if (xsdo->shmPMData.pmSize < 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        /* only use shared mem pixmaps for relatively big images */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /* need to create shared(!) image to get bytes_per_line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    img = X11SD_CreateSharedImage(xsdo, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    scan = img->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    shminfo = (XShmSegmentInfo*)img->obdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    XFree(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    pixmap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        XShmCreatePixmap(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                         RootWindow(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                                    xsdo->configData->awt_visInfo.screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                         shminfo->shmaddr, shminfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                         width, height, xsdo->depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    if (pixmap == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        X11SD_DropSharedSegment(shminfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    xsdo->shmPMData.shmSegInfo = shminfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    xsdo->shmPMData.bytesPerLine = scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    return pixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
void X11SD_PuntPixmap(X11SDOps *xsdo, jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    if (useMitShmPixmaps != CAN_USE_MITSHM || forceSharedPixmaps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /* we wouldn't be here if it's a shared pixmap, so no check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * for !usingShmPixmap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    xsdo->shmPMData.numBltsSinceRead = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    xsdo->shmPMData.pixelsReadSinceBlt += width * height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    if (xsdo->shmPMData.pixelsReadSinceBlt >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        xsdo->shmPMData.pixelsReadThreshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (!xsdo->shmPMData.shmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            xsdo->shmPMData.shmPixmap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                X11SD_CreateSharedPixmap(xsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (xsdo->shmPMData.shmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            GC xgc = XCreateGC(awt_display, xsdo->shmPMData.shmPixmap, 0L, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (xgc != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                xsdo->drawable = xsdo->shmPMData.shmPixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                XCopyArea(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                          xsdo->shmPMData.pixmap, xsdo->drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                          0, 0, xsdo->pmWidth, xsdo->pmHeight, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                xsdo->shmPMData.xRequestSent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                XFreeGC(awt_display, xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
void X11SD_UnPuntPixmap(X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    if (useMitShmPixmaps != CAN_USE_MITSHM || forceSharedPixmaps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    xsdo->shmPMData.pixelsReadSinceBlt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    if (xsdo->shmPMData.numBltsSinceRead >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        xsdo->shmPMData.numBltsThreshold)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (xsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (!xsdo->shmPMData.pixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                xsdo->shmPMData.pixmap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                    XCreatePixmap(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                                  RootWindow(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                                             xsdo->configData->awt_visInfo.screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                                  xsdo->pmWidth, xsdo->pmHeight, xsdo->depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (xsdo->shmPMData.pixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                GC xgc = XCreateGC(awt_display, xsdo->shmPMData.pixmap, 0L, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                if (xgc != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    xsdo->drawable = xsdo->shmPMData.pixmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    XCopyArea(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                              xsdo->shmPMData.shmPixmap, xsdo->drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                              0, 0, xsdo->pmWidth, xsdo->pmHeight, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    XFreeGC(awt_display, xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    xsdo->shmPMData.xRequestSent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    xsdo->shmPMData.numBltsThreshold *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        xsdo->shmPMData.numBltsSinceRead++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
 * Determines if the cached image can be used for current operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
 * If the image is to be used to be read into by XShmGetImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
 * it must be close enough to avoid excessive reading from the screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
 * otherwise it should just be at least the size requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 */
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   737
jboolean X11SD_CachedXImageFits(jint width, jint height, jint maxWidth,
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   738
                                jint maxHeight, jint depth, jboolean readBits)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    /* we assume here that the cached image exists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    jint imgWidth = cachedXImage->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    jint imgHeight = cachedXImage->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    if (imgWidth < width || imgHeight < height || depth != cachedXImage->depth)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        /* doesn't fit if any of the cached image dimensions is smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
           or the depths are different */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    if (!readBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        /* Not reading from this image, so any image at least of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
           size requested will do */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   756
    if ((imgWidth < width + 64) && (imgHeight < height + 64)
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   757
         && imgWidth <= maxWidth && imgHeight <= maxHeight)
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   758
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        /* Cached image's width/height shouldn't be more than 64 pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         * larger than requested, because the region in XShmGetImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         * can't be specified and we don't want to read too much.
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   762
         * Furthermore it has to be smaller than maxWidth/Height
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
   763
         * so drawables are not read out of bounds.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
   772
jint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    if (xsdo->isPixmap == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    xsdo->cData = xsdo->configData->color_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    return SD_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
static jint X11SD_Lock(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                       SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                       SurfaceDataRasInfo *pRasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                       jint lockflags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    X11SDOps *xsdo = (X11SDOps *) ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    int ret = SD_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    if (xsdo->invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        SurfaceData_ThrowInvalidPipeException(env, "bounds changed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    xsdo->cData = xsdo->configData->color_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    if (xsdo->drawable == 0 && X11SD_InitWindow(env, xsdo) == SD_FAILURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    if ((lockflags & SD_LOCK_LUT) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        (xsdo->cData == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         xsdo->cData->awt_icmLUT == NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        JNU_ThrowNullPointerException(env, "colormap lookup table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    if ((lockflags & SD_LOCK_INVCOLOR) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        (xsdo->cData == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         xsdo->cData->img_clr_tbl == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
         xsdo->cData->img_oda_red == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
         xsdo->cData->img_oda_green == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
         xsdo->cData->img_oda_blue == NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        JNU_ThrowNullPointerException(env, "inverse colormap lookup table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    if ((lockflags & SD_LOCK_INVGRAY) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        (xsdo->cData == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
         xsdo->cData->pGrayInverseLutData == NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        JNU_ThrowNullPointerException(env, "inverse gray lookup table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    if (xsdo->dgaAvailable && (lockflags & (SD_LOCK_RD_WR))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        int dgaret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        dgaret = (*pJDgaInfo->pGetLock)(env, awt_display, &xsdo->dgaDev,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                        xsdo->drawable, &xsdo->surfInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                                        pRasInfo->bounds.x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                                        pRasInfo->bounds.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                                        pRasInfo->bounds.x2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                                        pRasInfo->bounds.y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        if (dgaret == JDGA_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            int wx = xsdo->surfInfo.window.lox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            int wy = xsdo->surfInfo.window.loy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            pRasInfo->bounds.x1 = xsdo->surfInfo.visible.lox - wx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            pRasInfo->bounds.y1 = xsdo->surfInfo.visible.loy - wy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            pRasInfo->bounds.x2 = xsdo->surfInfo.visible.hix - wx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            pRasInfo->bounds.y2 = xsdo->surfInfo.visible.hiy - wy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            xpriv->lockType = X11SD_LOCK_BY_DGA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            xpriv->lockFlags = lockflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            return SD_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        } else if (dgaret == JDGA_UNAVAILABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            xsdo->dgaAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    if (lockflags & SD_LOCK_RD_WR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (lockflags & SD_LOCK_FASTEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            ret = SD_SLOWLOCK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        xpriv->lockType = X11SD_LOCK_BY_XIMAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        if (xsdo->isPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (xsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                xpriv->lockType = X11SD_LOCK_BY_SHMEM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            if (pRasInfo->bounds.x1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                pRasInfo->bounds.x1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            if (pRasInfo->bounds.y1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                pRasInfo->bounds.y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            if (pRasInfo->bounds.x2 > xsdo->pmWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                pRasInfo->bounds.x2 = xsdo->pmWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            if (pRasInfo->bounds.y2 > xsdo->pmHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                pRasInfo->bounds.y2 = xsdo->pmHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        /* They didn't lock for anything - we won't give them anything */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        xpriv->lockType = X11SD_LOCK_BY_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    xpriv->lockFlags = lockflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    xpriv->img = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    /* AWT_UNLOCK() called in Unlock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
static void X11SD_GetRasInfo(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                             SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                             SurfaceDataRasInfo *pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    X11SDOps *xsdo = (X11SDOps *) ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    jint lockFlags = xpriv->lockFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    jint depth = xsdo->depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    int mult = xsdo->configData->pixelStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    if (xsdo->dgaAvailable &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        xpriv->lockType == X11SD_LOCK_BY_XIMAGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        (lockFlags & SD_LOCK_FASTEST))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        /* Try one more time to use DGA (now with smaller bounds)... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        int dgaret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        dgaret = (*pJDgaInfo->pGetLock)(env, awt_display, &xsdo->dgaDev,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                                        xsdo->drawable, &xsdo->surfInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                        pRasInfo->bounds.x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                        pRasInfo->bounds.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                        pRasInfo->bounds.x2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                                        pRasInfo->bounds.y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (dgaret == JDGA_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            int wx = xsdo->surfInfo.window.lox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            int wy = xsdo->surfInfo.window.loy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            pRasInfo->bounds.x1 = xsdo->surfInfo.visible.lox - wx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            pRasInfo->bounds.y1 = xsdo->surfInfo.visible.loy - wy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            pRasInfo->bounds.x2 = xsdo->surfInfo.visible.hix - wx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            pRasInfo->bounds.y2 = xsdo->surfInfo.visible.hiy - wy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            xpriv->lockType = X11SD_LOCK_BY_DGA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        } else if (dgaret == JDGA_UNAVAILABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            xsdo->dgaAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    if (xpriv->lockType == X11SD_LOCK_BY_DGA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        int scan = xsdo->surfInfo.surfaceScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        int wx = xsdo->surfInfo.window.lox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        int wy = xsdo->surfInfo.window.loy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        pRasInfo->rasBase =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            (void *)(((uintptr_t) xsdo->surfInfo.basePtr) + (scan*wy + wx) * mult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        pRasInfo->pixelStride = mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        pRasInfo->scanStride = scan * mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    } else if (xpriv->lockType == X11SD_LOCK_BY_SHMEM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (xsdo->shmPMData.xRequestSent == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            /* need to sync before using shared mem pixmap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
             if any x calls were issued for this pixmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            xsdo->shmPMData.xRequestSent = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        xpriv->x = pRasInfo->bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        xpriv->y = pRasInfo->bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        pRasInfo->rasBase = xsdo->shmPMData.shmSegInfo->shmaddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        pRasInfo->pixelStride = mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        pRasInfo->scanStride = xsdo->shmPMData.bytesPerLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    } else if (xpriv->lockType == X11SD_LOCK_BY_XIMAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        int x, y, w, h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        x = pRasInfo->bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        y = pRasInfo->bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        w = pRasInfo->bounds.x2 - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        h = pRasInfo->bounds.y2 - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        xpriv->img = X11SD_GetImage(env, xsdo, &pRasInfo->bounds, lockFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (xpriv->img) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            int scan = xpriv->img->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            xpriv->x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            xpriv->y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            pRasInfo->rasBase = xpriv->img->data - x * mult - y * scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            pRasInfo->pixelStride = mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            pRasInfo->scanStride = scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            pRasInfo->rasBase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            pRasInfo->pixelStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            pRasInfo->scanStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        /* They didn't lock for anything - we won't give them anything */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        pRasInfo->rasBase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        pRasInfo->pixelStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        pRasInfo->scanStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    if (lockFlags & SD_LOCK_LUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        pRasInfo->lutBase = (jint *) xsdo->cData->awt_icmLUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        pRasInfo->lutSize = xsdo->cData->awt_numICMcolors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        pRasInfo->lutBase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        pRasInfo->lutSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    if (lockFlags & SD_LOCK_INVCOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        pRasInfo->invColorTable = xsdo->cData->img_clr_tbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        pRasInfo->redErrTable = xsdo->cData->img_oda_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        pRasInfo->grnErrTable = xsdo->cData->img_oda_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        pRasInfo->bluErrTable = xsdo->cData->img_oda_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        pRasInfo->invColorTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        pRasInfo->redErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        pRasInfo->grnErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        pRasInfo->bluErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    if (lockFlags & SD_LOCK_INVGRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        pRasInfo->invGrayTable = xsdo->cData->pGrayInverseLutData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        pRasInfo->invGrayTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
static void X11SD_Unlock(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                         SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                         SurfaceDataRasInfo *pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    X11SDOps *xsdo = (X11SDOps *) ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    X11RIPrivate *xpriv = (X11RIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    if (xpriv->lockType == X11SD_LOCK_BY_DGA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        (*pJDgaInfo->pReleaseLock)(env, xsdo->dgaDev, xsdo->drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    } else if (xpriv->lockType == X11SD_LOCK_BY_XIMAGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
               xpriv->img != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        if (xpriv->lockFlags & SD_LOCK_WRITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            int x = xpriv->x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            int y = xpriv->y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            int w = pRasInfo->bounds.x2 - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            int h = pRasInfo->bounds.y2 - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            Drawable drawable = xsdo->drawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            GC xgc = xsdo->cachedGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            if (xgc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                xsdo->cachedGC = xgc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    XCreateGC(awt_display, drawable, 0L, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            if (xpriv->img->byte_order != nativeByteOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                /* switching bytes back in 24 and 32 bpp cases. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                /* For 16 bit XLib will switch for us.          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                if (xsdo->depth > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    X11SD_SwapBytes(xsdo, xpriv->img, xsdo->depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                        xsdo->configData->awtImage->wsImageFormat.bits_per_pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            if (xpriv->img->obdata != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                XShmPutImage(awt_display, drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                             xpriv->img, 0, 0, x, y, w, h, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                XFlush(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                XPutImage(awt_display, drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                          xpriv->img, 0, 0, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            if (xsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                xsdo->shmPMData.xRequestSent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            XPutImage(awt_display, drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                      xpriv->img, 0, 0, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            (*pJDgaInfo->pXRequestSent)(env, xsdo->dgaDev, drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        X11SD_DisposeOrCacheXImage(xpriv->img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        xpriv->img = (XImage *)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    /* the background pixel is not valid anymore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    if (xpriv->lockFlags & SD_LOCK_WRITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        xsdo->isBgInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    xpriv->lockType = X11SD_LOCK_UNLOCKED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                 X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    Position x1=0, y1=0, x2=0, y2=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    int tmpx, tmpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    Window tmpchild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    Window window = (Window)(xsdo->drawable); /* is always a Window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    XWindowAttributes winAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    Status status = XGetWindowAttributes(awt_display, window, &winAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    if (status == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        /* Failure, X window no longer valid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    if (!XTranslateCoordinates(awt_display, window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                               RootWindowOfScreen(winAttr.screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                               0, 0, &tmpx, &tmpy, &tmpchild)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    x1 = -(x1 + tmpx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    y1 = -(y1 + tmpy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    x2 = x1 + DisplayWidth(awt_display, xsdo->configData->awt_visInfo.screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    y2 = y1 + DisplayHeight(awt_display, xsdo->configData->awt_visInfo.screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    x1 = MAX(bounds->x1, x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    y1 = MAX(bounds->y1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    x2 = MIN(bounds->x2, x2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    y2 = MIN(bounds->y2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    if ((x1 >= x2) || (y1 >= y2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    b->x1 = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    b->y1 = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    b->x2 = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    b->y2 = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
 * x1, y1, x2, y2 - our rectangle in the coord system of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
 * the widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
 * px1, xy1, px2, py2 - current parent rect coords in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
 * same system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds, X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
X11SD_SwapBytes(X11SDOps *xsdo, XImage * img, int depth, int bpp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    int lengthInBytes = img->height * img->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    switch (depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    case 12:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    case 15:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            /* AB -> BA */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            unsigned short *d = (unsigned short *)img->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            unsigned short t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            for (i = 0; i < lengthInBytes/2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                t = *d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                *d++ = (t >> 8) | (t << 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            img->byte_order = nativeByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            img->bitmap_bit_order = nativeByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    case 24:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            /* ABC -> CBA */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            if (bpp == 24) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                // 4517321: Only swap if we have a "real" ThreeByteBgr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                // visual (denoted by a red_mask of 0xff).  Due to ambiguity
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                // in the X11 spec, it appears that the swap is not required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                // on Linux configurations that use 24 bits per pixel (denoted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                // by a red_mask of 0xff0000).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                if (xsdo->configData->awt_visInfo.red_mask == 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    int scan = img->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                    unsigned char *d = (unsigned char *) img->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    unsigned char *d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    unsigned int t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    for (i = 0; i < img->height; i++, d += scan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                        d1 = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                        for (j = 0; j < img->width; j++, d1 += 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                            /* not obvious opt from XLib src */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                            t = d1[0]; d1[0] = d1[2]; d1[2] = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        /* FALL THROUGH for 32-bit case */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    case 32:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            /* ABCD -> DCBA */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            unsigned int *d = (unsigned int *) img->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            unsigned int t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            for (i = 0; i < lengthInBytes/4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                t = *d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                *d++ = ((t >> 24) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                        ((t >> 8) & 0xff00) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                        ((t & 0xff00) << 8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                        (t << 24));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
static XImage * X11SD_GetImage(JNIEnv *env, X11SDOps *xsdo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                               SurfaceDataBounds *bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                               jint lockFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
{
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1190
    int x, y, w, h, maxWidth, maxHeight;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    int scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    XImage * img = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    Drawable drawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    int depth = xsdo->depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    int mult = xsdo->configData->pixelStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    int pad = (mult == 3) ? 32 : mult * 8; // pad must be 8, 16, or 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    jboolean readBits = lockFlags & SD_LOCK_NEED_PIXELS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    x = bounds->x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    y = bounds->y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    w = bounds->x2 - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    h = bounds->y2 - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    if (useMitShmExt == CAN_USE_MITSHM) {
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1206
        if (xsdo->isPixmap) {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1207
            if (readBits) {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1208
                X11SD_PuntPixmap(xsdo, w, h);
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1209
            }
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1210
            maxWidth = xsdo->pmWidth;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1211
            maxHeight = xsdo->pmHeight;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1212
        } else {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1213
            XWindowAttributes winAttr;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1214
            if (XGetWindowAttributes(awt_display,
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1215
                                     (Window) xsdo->drawable, &winAttr) != 0) {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1216
                maxWidth = winAttr.width;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1217
                maxHeight = winAttr.height;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1218
           } else {
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1219
                /* XGWA failed which isn't a good thing. Defaulting to using
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1220
                 * x,y means that after the subtraction of these we will use
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1221
                 * w=0, h=0 which is a reasonable default on such a failure.
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1222
                 */
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1223
                maxWidth = x;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1224
                maxHeight = y;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1225
           }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
8356
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1227
        maxWidth -= x;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1228
        maxHeight -= y;
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1229
64c792dbf671 7018364: XShmGetImage with image's > drawable's size causes BadMatch
prr
parents: 7668
diff changeset
  1230
        img = X11SD_GetSharedImage(xsdo, w, h, maxWidth, maxHeight, readBits);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    drawable = xsdo->drawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    if (readBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        if (img != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            if (!XShmGetImage(awt_display, drawable, img, x, y, -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                X11SD_DisposeOrCacheXImage(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                img = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            img = XGetImage(awt_display, drawable, x, y, w, h, -1, ZPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            if (img != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                img->obdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        img = XGetImage(awt_display, drawable, x, y, w, h, -1, ZPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            SurfaceDataBounds temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            img = XCreateImage(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                               xsdo->configData->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                               depth, ZPixmap, 0, NULL, w, h, pad, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            scan = img->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            img->data = malloc(h * scan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            if (img->data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                XFree(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            if (xsdo->isPixmap == JNI_FALSE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                X11SD_ClipToRoot(&temp, bounds, xsdo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                XImage * temp_image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                temp_image = XGetImage(awt_display, drawable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                                       temp.x1, temp.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                                       temp.x2 - temp.x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                                       temp.y2 - temp.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                                       -1, ZPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                if (temp_image == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                    XGrabServer(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    if (X11SD_FindClip(&temp, bounds, xsdo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                        temp_image =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                            XGetImage(awt_display, drawable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                                      temp.x1, temp.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                                      temp.x2 - temp.x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                                      temp.y2 - temp.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                                      -1, ZPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                    XUngrabServer(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                    /* Workaround for bug 5039226 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                if (temp_image != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                    int temp_scan, bytes_to_copy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                    char * img_addr, * temp_addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    img_addr = img->data +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                        (temp.y1 - y) * scan + (temp.x1 - x) * mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    temp_scan = temp_image->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    temp_addr = temp_image->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    bytes_to_copy = (temp.x2 - temp.x1) * mult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    for (i = temp.y1; i < temp.y2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                        memcpy(img_addr, temp_addr, bytes_to_copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                        img_addr += scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                        temp_addr += temp_scan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                    XDestroyImage(temp_image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            img->obdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        if (depth > 8 && img->byte_order != nativeByteOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            X11SD_SwapBytes(xsdo, img, depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                xsdo->configData->awtImage->wsImageFormat.bits_per_pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
         * REMIND: This might be better to move to the Lock function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
         * to avoid lengthy I/O pauses inside what may be a critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
         * section.  This will be more critical when SD_LOCK_READ is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
         * implemented.  Another solution is to cache the pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
         * to avoid reading for every operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            img = XCreateImage(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                               xsdo->configData->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                               depth, ZPixmap, 0, NULL, w, h, pad, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            if (img == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            img->data = malloc(h * img->bytes_per_line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            if (img->data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                XFree(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            img->obdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            if (img->byte_order != nativeByteOrder &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                (depth == 15 || depth == 16 || depth == 12)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                /* bytes will be swapped by XLib. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                img->byte_order = nativeByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                img->bitmap_bit_order = nativeByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    return img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
void X11SD_DisposeOrCacheXImage(XImage * image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /* REMIND: might want to check if the new image worth caching. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    /* Cache only shared images. Passed image is assumed to be non-null. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    if (image->obdata != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        if (cachedXImage != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            X11SD_DisposeXImage(cachedXImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        cachedXImage = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        X11SD_DisposeXImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
void X11SD_DisposeXImage(XImage * image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    if (image != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (image->obdata != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            X11SD_DropSharedSegment((XShmSegmentInfo*)image->obdata);
12170
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
  1368
            image->obdata = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
#endif /* MITSHM */
12170
bdd7741e16de 7151427: Fix the potential memory leak in error handling code in X11SurfaceData.c
littlee
parents: 11093
diff changeset
  1371
        XDestroyImage(image);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
static JDgaStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    GetLockStub(JNIEnv *env, Display *display, void **dgaDev,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                Drawable d, JDgaSurfaceInfo *pSurface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                jint lox, jint loy, jint hix, jint hiy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    return JDGA_UNAVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
static JDgaStatus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    ReleaseLockStub(JNIEnv *env, void *dgaDev, Drawable d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    return JDGA_FAILED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    XRequestSentStub(JNIEnv *env, void *dgaDev, Drawable d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    LibDisposeStub(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
static JDgaLibInfo DgaLibInfoStub = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    GetLockStub,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    ReleaseLockStub,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    XRequestSentStub,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    LibDisposeStub,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
void X11SD_LibDispose(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    if (pJDgaInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        pJDgaInfo->pLibDispose(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        pJDgaInfo = &DgaLibInfoStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
X11SD_DirectRenderNotify(JNIEnv *env, X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    if (xsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        xsdo->shmPMData.xRequestSent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    (*pJDgaInfo->pXRequestSent)(env, xsdo->dgaDev, xsdo->drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    awt_output_flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
 * Sets transparent pixels in the pixmap to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
 * the specified solid background color and returns it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
 * Doesn't update source pixmap unless the color of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
 * transparent pixels is different from the specified color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
 * Note: The AWT lock must be held by the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
 * while calling into this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
static Drawable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
X11SD_GetPixmapWithBg(JNIEnv *env, X11SDOps *xsdo, jint pixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    /* assert AWT_CHECK_HAVE_LOCK(); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    if (xsdo->invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        SurfaceData_ThrowInvalidPipeException(env, "bounds changed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    /* the image doesn't have transparency, just return it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    if (xsdo->bitmask == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        /* don't need to unlock here, the caller will unlock through
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
           the release call */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        return xsdo->drawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    /* Check if current color of the transparent pixels is different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
       from the specified one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    if (xsdo->isBgInitialized == JNI_FALSE || xsdo->bgPixel != pixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        GC srcGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        GC bmGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        if (xsdo->drawable == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        bmGC = XCreateGC(awt_display, xsdo->bitmask, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        if (bmGC == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        /* invert the bitmask */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        XSetFunction(awt_display, bmGC, GXxor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        XSetForeground(awt_display, bmGC, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        XFillRectangle(awt_display, xsdo->bitmask, bmGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                       0, 0, xsdo->pmWidth, xsdo->pmHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        srcGC = XCreateGC(awt_display, xsdo->drawable, 0L, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        if (srcGC == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            XFreeGC(awt_display, bmGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        /* set transparent pixels in the source pm to the bg color */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        XSetClipMask(awt_display, srcGC, xsdo->bitmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        XSetForeground(awt_display, srcGC, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        XFillRectangle(awt_display, xsdo->drawable, srcGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                       0, 0, xsdo->pmWidth, xsdo->pmHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        /* invert the mask back */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        XFillRectangle(awt_display, xsdo->bitmask, bmGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                       0, 0, xsdo->pmWidth, xsdo->pmHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        XFreeGC(awt_display, bmGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        XFreeGC(awt_display, srcGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        xsdo->bgPixel = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        xsdo->isBgInitialized = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    return xsdo->drawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
X11SD_ReleasePixmapWithBg(JNIEnv *env, X11SDOps *xsdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    if (xsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        xsdo->shmPMData.xRequestSent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
 * Method:    XCreateGC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
 * Signature: (I)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
JNIEXPORT jlong JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
  1522
Java_sun_java2d_x11_XSurfaceData_XCreateGC
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    (JNIEnv *env, jclass xsd, jlong pXSData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    jlong ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    X11SDOps *xsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XCreateGC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    xsdo = (X11SDOps *) pXSData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    if (xsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    xsdo->javaGC = XCreateGC(awt_display, xsdo->drawable, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    ret = (jlong) xsdo->javaGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
#else /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    ret = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
 * Method:    XResetClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
 * Signature: (JIIIILsun/java2d/pipe/Region;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
  1552
Java_sun_java2d_x11_XSurfaceData_XResetClip
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    (JNIEnv *env, jclass xsd, jlong xgc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XResetClip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    XSetClipMask(awt_display, (GC) xgc, None);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
 * Method:    XSetClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
 * Signature: (JIIIILsun/java2d/pipe/Region;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
  1567
Java_sun_java2d_x11_XSurfaceData_XSetClip
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    (JNIEnv *env, jclass xsd, jlong xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     jint x1, jint y1, jint x2, jint y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     jobject complexclip)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    int numrects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    XRectangle rects[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    XRectangle *pRect = rects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetClip");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    numrects = RegionToYXBandedRectangles(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            x1, y1, x2, y2, complexclip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            &pRect, 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    XSetClipRectangles(awt_display, (GC) xgc, 0, 0, pRect, numrects, YXBanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    if (pRect != rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        free(pRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
 * Method:    XSetCopyMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
Java_sun_java2d_x11_X11SurfaceData_XSetCopyMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    (JNIEnv *env, jclass xsd, jlong xgc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetCopyMode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    XSetFunction(awt_display, (GC) xgc, GXcopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
 * Method:    XSetXorMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
Java_sun_java2d_x11_X11SurfaceData_XSetXorMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    (JNIEnv *env, jclass xr, jlong xgc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetXorMode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    XSetFunction(awt_display, (GC) xgc, GXxor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
 * Method:    XSetForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
 * Signature: (JI)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
Java_sun_java2d_x11_X11SurfaceData_XSetForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    (JNIEnv *env, jclass xsd, jlong xgc, jint pixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    XSetForeground(awt_display, (GC) xgc, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
 * Class:     sun_java2d_x11_X11SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
 * Method:    XSetGraphicsExposures
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
 * Signature: (JZ)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
JNIEXPORT void JNICALL
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 1739
diff changeset
  1642
Java_sun_java2d_x11_XSurfaceData_XSetGraphicsExposures
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    (JNIEnv *env, jclass xsd, jlong xgc, jboolean needExposures)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    J2dTraceLn(J2D_TRACE_INFO, "in X11SurfaceData_XSetGraphicsExposures");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    XSetGraphicsExposures(awt_display, (GC) xgc, needExposures ? True : False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
}