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