jdk/src/solaris/native/sun/java2d/x11/X11PMBlitLoops.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 25790 ca104ec6b3e7
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2007, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "X11SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "Region.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
Java_sun_java2d_x11_X11PMBlitLoops_nativeBlit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    (JNIEnv *env, jobject joSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
     jlong srcData, jlong dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     jlong gc, jobject clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     jint srcx, jint srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     jint dstx, jint dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     jint width, jint height)
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
    X11SDOps *srcXsdo, *dstXsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    SurfaceDataBounds span, srcBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    RegionData clipInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    GC xgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    if (width <= 0 || height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    srcXsdo = (X11SDOps *)jlong_to_ptr(srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    if (srcXsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    dstXsdo = (X11SDOps *)jlong_to_ptr(dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    if (dstXsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    if (Region_GetInfo(env, clip, &clipInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    xgc = (GC)gc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (xgc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    if (srcXsdo->isPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        X11SD_UnPuntPixmap(srcXsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* clip the source rect to the source pixmap's dimensions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    srcBounds.x1 = srcx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    srcBounds.y1 = srcy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    srcBounds.x2 = srcx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    srcBounds.y2 = srcy + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    SurfaceData_IntersectBoundsXYXY(&srcBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                    0, 0, srcXsdo->pmWidth, srcXsdo->pmHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    span.x1 = dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    span.y1 = dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    span.x2 = dstx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    span.y2 = dsty + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /* intersect the source and dest rects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    SurfaceData_IntersectBlitBounds(&srcBounds, &span,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                    dstx - srcx, dsty - srcy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    srcx = srcBounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    srcy = srcBounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    dstx = span.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    dsty = span.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    if (srcXsdo->bitmask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        XSetClipOrigin(awt_display, xgc, dstx - srcx, dsty - srcy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        XSetClipMask(awt_display, xgc, srcXsdo->bitmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    Region_IntersectBounds(&clipInfo, &span);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    if (!Region_IsEmpty(&clipInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Region_StartIteration(env, &clipInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        srcx -= dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        srcy -= dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        while (Region_NextIteration(&clipInfo, &span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            XCopyArea(awt_display, srcXsdo->drawable, dstXsdo->drawable, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                      srcx + span.x1, srcy + span.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                      span.x2 - span.x1, span.y2 - span.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                      span.x1, span.y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Region_EndIteration(env, &clipInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    if (srcXsdo->bitmask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        XSetClipMask(awt_display, xgc, None);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    if (srcXsdo->shmPMData.usingShmPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        srcXsdo->shmPMData.xRequestSent = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    X11SD_DirectRenderNotify(env, dstXsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
Java_sun_java2d_x11_X11PMBlitBgLoops_nativeBlitBg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    (JNIEnv *env, jobject joSelf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     jlong srcData, jlong dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     jlong xgc, jint pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     jint srcx, jint srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     jint dstx, jint dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    X11SDOps *srcXsdo, *dstXsdo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    GC dstGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    SurfaceDataBounds dstBounds, srcBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    Drawable srcDrawable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    if (width <= 0 || height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    srcXsdo = (X11SDOps *)jlong_to_ptr(srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    if (srcXsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    dstXsdo = (X11SDOps *)jlong_to_ptr(dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    if (dstXsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    dstGC = (GC)xgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    if (dstGC == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#ifdef MITSHM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    if (srcXsdo->isPixmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        X11SD_UnPuntPixmap(srcXsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#endif /* MITSHM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    srcDrawable = srcXsdo->GetPixmapWithBg(env, srcXsdo, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if (srcDrawable == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /* clip the source rect to the source pixmap's dimensions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    srcBounds.x1 = srcx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    srcBounds.y1 = srcy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    srcBounds.x2 = srcx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    srcBounds.y2 = srcy + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    SurfaceData_IntersectBoundsXYXY(&srcBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                    0, 0, srcXsdo->pmWidth, srcXsdo->pmHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    dstBounds.x1 = dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    dstBounds.y1 = dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    dstBounds.x2 = dstx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    dstBounds.y2 = dsty + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /* intersect the source and dest rects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    SurfaceData_IntersectBlitBounds(&srcBounds, &dstBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                    dstx - srcx, dsty - srcy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    srcx = srcBounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    srcy = srcBounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    dstx = dstBounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    dsty = dstBounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    width = srcBounds.x2 - srcBounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    height = srcBounds.y2 - srcBounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /* do an unmasked copy as we've already filled transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
       pixels of the source image with the desired color */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    XCopyArea(awt_display, srcDrawable, dstXsdo->drawable, dstGC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
              srcx, srcy, width, height, dstx, dsty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    srcXsdo->ReleasePixmapWithBg(env, srcXsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    X11SD_DirectRenderNotify(env, dstXsdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * Class:     sun_java2d_x11_X11PMBlitLoops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Method:    updateBitmask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
Java_sun_java2d_x11_X11PMBlitLoops_updateBitmask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    (JNIEnv *env, jclass xpmbl, jobject srcsd, jobject dstsd, jboolean isICM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    SurfaceDataOps *srcOps = SurfaceData_GetOps(env, srcsd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    X11SDOps *xsdo = (X11SDOps *) SurfaceData_GetOps(env, dstsd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    SurfaceDataRasInfo srcInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    int flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    int screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jint srcScan, dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    int rowCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    unsigned char *pDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    XImage *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    GC xgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    if (srcOps == NULL || xsdo == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        JNU_ThrowNullPointerException(env, "Null BISD in updateMaskRegion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    screen = xsdo->configData->awt_visInfo.screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    width = xsdo->pmWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    height = xsdo->pmHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    if (xsdo->bitmask == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        /* create the bitmask if it is not yet created */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        xsdo->bitmask = XCreatePixmap(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                      RootWindow(awt_display, screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                      width, height, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (xsdo->bitmask == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            JNU_ThrowOutOfMemoryError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                      "Cannot create bitmask for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                      "offscreen surface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /* Create a bitmask image and then blit it to the pixmap. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    image = XCreateImage(awt_display, DefaultVisual(awt_display, screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                         1, XYBitmap, 0, NULL, width, height, 32, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (image == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        JNU_ThrowOutOfMemoryError(env, "Cannot allocate bitmask for mask");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    dstScan = image->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    image->data = malloc(dstScan * height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (image->data == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        XFree(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        JNU_ThrowOutOfMemoryError(env, "Cannot allocate bitmask for mask");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    pDst = (unsigned char *)image->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    srcInfo.bounds.x1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    srcInfo.bounds.y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    srcInfo.bounds.x2 = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    srcInfo.bounds.y2 = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    flags = (isICM ? (SD_LOCK_LUT | SD_LOCK_READ) : SD_LOCK_READ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (srcOps->Lock(env, srcOps, &srcInfo, flags) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    srcOps->GetRasInfo(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    rowCount = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if (isICM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        unsigned char *pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        jint *srcLut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        srcScan = srcInfo.scanStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        srcLut = srcInfo.lutBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        pSrc = (unsigned char *)srcInfo.rasBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (image->bitmap_bit_order == MSBFirst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                int x = 0, bx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                unsigned int pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                unsigned int bit = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                unsigned char *srcPixel = pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if (bit == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        pDst[bx++] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        bit = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    pix |= bit & (srcLut[*srcPixel++] >> 31);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    bit >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                } while (++x < width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                pDst[bx] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                pDst += dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                pSrc = (unsigned char *) (((intptr_t)pSrc) + srcScan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            } while (--rowCount > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                int x = 0, bx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                unsigned int pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                unsigned int bit = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                unsigned char *srcPixel = pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    if ((bit >> 8) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        pDst[bx++] = (unsigned char) pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        bit = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    pix |= bit & (srcLut[*srcPixel++] >> 31);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    bit <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                } while (++x < width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                pDst[bx] = (unsigned char) pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                pDst += dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                pSrc = (unsigned char *) (((intptr_t)pSrc) + srcScan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            } while (--rowCount > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    } else /*DCM with ARGB*/ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        unsigned int *pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        /* this is a number of pixels in a row, not number of bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        srcScan = srcInfo.scanStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        pSrc = (unsigned int *)srcInfo.rasBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (image->bitmap_bit_order == MSBFirst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                int x = 0, bx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                unsigned int pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                unsigned int bit = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                int *srcPixel = (int *) pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    if (bit == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        /* next word */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        pDst[bx++] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        bit = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    if (*srcPixel++ & 0xff000000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        /* if src pixel is opaque, set the bit in the bitmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        pix |= bit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    bit >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                } while (++x < width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                /* last pixels in a row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                pDst[bx] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                pDst += dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                pSrc = (unsigned int *) (((intptr_t)pSrc) + srcScan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            } while (--rowCount > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                int x = 0, bx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                unsigned int pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                unsigned int bit = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                int *srcPixel = (int *) pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    if ((bit >> 8) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        pDst[bx++] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        bit = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    if (*srcPixel++ & 0xff000000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        /* if src pixel is opaque, set the bit in the bitmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        pix |= bit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    bit <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                } while (++x < width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                pDst[bx] = (unsigned char)pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                pDst += dstScan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                pSrc = (unsigned int *) (((intptr_t)pSrc) + srcScan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            } while (--rowCount > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    SurfaceData_InvokeRelease(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    xgc = XCreateGC(awt_display, xsdo->bitmask, 0L, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    XSetForeground(awt_display, xgc, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    XSetBackground(awt_display, xgc, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    XPutImage(awt_display, xsdo->bitmask, xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
              image, 0, 0, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    XFreeGC(awt_display, xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    XDestroyImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
}