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