Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/x11/X11PMBlitLoops.c
32288 views
/*1* Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdlib.h>26#include <jni.h>27#include <jlong.h>28#include "X11SurfaceData.h"29#include "Region.h"3031JNIEXPORT void JNICALL32Java_sun_java2d_x11_X11PMBlitLoops_nativeBlit33(JNIEnv *env, jobject joSelf,34jlong srcData, jlong dstData,35jlong gc, jobject clip,36jint srcx, jint srcy,37jint dstx, jint dsty,38jint width, jint height)39{40#ifndef HEADLESS41X11SDOps *srcXsdo, *dstXsdo;42SurfaceDataBounds span, srcBounds;43RegionData clipInfo;44GC xgc;4546if (width <= 0 || height <= 0) {47return;48}4950srcXsdo = (X11SDOps *)jlong_to_ptr(srcData);51if (srcXsdo == NULL) {52return;53}54dstXsdo = (X11SDOps *)jlong_to_ptr(dstData);55if (dstXsdo == NULL) {56return;57}58if (Region_GetInfo(env, clip, &clipInfo)) {59return;60}6162xgc = (GC)gc;63if (xgc == NULL) {64return;65}6667#ifdef MITSHM68if (srcXsdo->isPixmap) {69X11SD_UnPuntPixmap(srcXsdo);70}71#endif /* MITSHM */7273/* clip the source rect to the source pixmap's dimensions */74srcBounds.x1 = srcx;75srcBounds.y1 = srcy;76srcBounds.x2 = srcx + width;77srcBounds.y2 = srcy + height;78SurfaceData_IntersectBoundsXYXY(&srcBounds,790, 0, srcXsdo->pmWidth, srcXsdo->pmHeight);80span.x1 = dstx;81span.y1 = dsty;82span.x2 = dstx + width;83span.y2 = dsty + height;8485/* intersect the source and dest rects */86SurfaceData_IntersectBlitBounds(&srcBounds, &span,87dstx - srcx, dsty - srcy);88srcx = srcBounds.x1;89srcy = srcBounds.y1;90dstx = span.x1;91dsty = span.y1;9293if (srcXsdo->bitmask != 0) {94XSetClipOrigin(awt_display, xgc, dstx - srcx, dsty - srcy);95XSetClipMask(awt_display, xgc, srcXsdo->bitmask);96}9798Region_IntersectBounds(&clipInfo, &span);99if (!Region_IsEmpty(&clipInfo)) {100Region_StartIteration(env, &clipInfo);101srcx -= dstx;102srcy -= dsty;103while (Region_NextIteration(&clipInfo, &span)) {104XCopyArea(awt_display, srcXsdo->drawable, dstXsdo->drawable, xgc,105srcx + span.x1, srcy + span.y1,106span.x2 - span.x1, span.y2 - span.y1,107span.x1, span.y1);108}109Region_EndIteration(env, &clipInfo);110}111112if (srcXsdo->bitmask != 0) {113XSetClipMask(awt_display, xgc, None);114}115116#ifdef MITSHM117if (srcXsdo->shmPMData.usingShmPixmap) {118srcXsdo->shmPMData.xRequestSent = JNI_TRUE;119}120#endif /* MITSHM */121X11SD_DirectRenderNotify(env, dstXsdo);122#endif /* !HEADLESS */123}124125JNIEXPORT void JNICALL126Java_sun_java2d_x11_X11PMBlitBgLoops_nativeBlitBg127(JNIEnv *env, jobject joSelf,128jlong srcData, jlong dstData,129jlong xgc, jint pixel,130jint srcx, jint srcy,131jint dstx, jint dsty,132jint width, jint height)133{134#ifndef HEADLESS135X11SDOps *srcXsdo, *dstXsdo;136GC dstGC;137SurfaceDataBounds dstBounds, srcBounds;138Drawable srcDrawable;139140if (width <= 0 || height <= 0) {141return;142}143144srcXsdo = (X11SDOps *)jlong_to_ptr(srcData);145if (srcXsdo == NULL) {146return;147}148dstXsdo = (X11SDOps *)jlong_to_ptr(dstData);149if (dstXsdo == NULL) {150return;151}152153dstGC = (GC)xgc;154if (dstGC == NULL) {155return;156}157158#ifdef MITSHM159if (srcXsdo->isPixmap) {160X11SD_UnPuntPixmap(srcXsdo);161}162#endif /* MITSHM */163164srcDrawable = srcXsdo->GetPixmapWithBg(env, srcXsdo, pixel);165if (srcDrawable == 0) {166return;167}168169/* clip the source rect to the source pixmap's dimensions */170srcBounds.x1 = srcx;171srcBounds.y1 = srcy;172srcBounds.x2 = srcx + width;173srcBounds.y2 = srcy + height;174SurfaceData_IntersectBoundsXYXY(&srcBounds,1750, 0, srcXsdo->pmWidth, srcXsdo->pmHeight);176dstBounds.x1 = dstx;177dstBounds.y1 = dsty;178dstBounds.x2 = dstx + width;179dstBounds.y2 = dsty + height;180181/* intersect the source and dest rects */182SurfaceData_IntersectBlitBounds(&srcBounds, &dstBounds,183dstx - srcx, dsty - srcy);184srcx = srcBounds.x1;185srcy = srcBounds.y1;186dstx = dstBounds.x1;187dsty = dstBounds.y1;188width = srcBounds.x2 - srcBounds.x1;189height = srcBounds.y2 - srcBounds.y1;190191/* do an unmasked copy as we've already filled transparent192pixels of the source image with the desired color */193XCopyArea(awt_display, srcDrawable, dstXsdo->drawable, dstGC,194srcx, srcy, width, height, dstx, dsty);195196srcXsdo->ReleasePixmapWithBg(env, srcXsdo);197X11SD_DirectRenderNotify(env, dstXsdo);198#endif /* !HEADLESS */199}200201/*202* Class: sun_java2d_x11_X11PMBlitLoops203* Method: updateBitmask204* Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;)V205*/206JNIEXPORT void JNICALL207Java_sun_java2d_x11_X11PMBlitLoops_updateBitmask208(JNIEnv *env, jclass xpmbl, jobject srcsd, jobject dstsd, jboolean isICM)209{210#ifndef HEADLESS211SurfaceDataOps *srcOps = SurfaceData_GetOps(env, srcsd);212X11SDOps *xsdo = (X11SDOps *) SurfaceData_GetOps(env, dstsd);213SurfaceDataRasInfo srcInfo;214215int flags;216int screen;217int width;218int height;219jint srcScan, dstScan;220int rowCount;221unsigned char *pDst;222XImage *image;223GC xgc;224225if (srcOps == NULL || xsdo == NULL) {226JNU_ThrowNullPointerException(env, "Null BISD in updateMaskRegion");227return;228}229230AWT_LOCK();231232screen = xsdo->configData->awt_visInfo.screen;233width = xsdo->pmWidth;234height = xsdo->pmHeight;235236if (xsdo->bitmask == 0) {237/* create the bitmask if it is not yet created */238xsdo->bitmask = XCreatePixmap(awt_display,239RootWindow(awt_display, screen),240width, height, 1);241if (xsdo->bitmask == 0) {242AWT_UNLOCK();243if (!(*env)->ExceptionCheck(env))244{245JNU_ThrowOutOfMemoryError(env,246"Cannot create bitmask for "247"offscreen surface");248}249return;250}251}252253/* Create a bitmask image and then blit it to the pixmap. */254image = XCreateImage(awt_display, DefaultVisual(awt_display, screen),2551, XYBitmap, 0, NULL, width, height, 32, 0);256if (image == NULL) {257AWT_UNLOCK();258if (!(*env)->ExceptionCheck(env))259{260JNU_ThrowOutOfMemoryError(env, "Cannot allocate bitmask for mask");261}262return;263}264dstScan = image->bytes_per_line;265image->data = malloc((size_t) dstScan * height);266if (image->data == NULL) {267XFree(image);268AWT_UNLOCK();269if (!(*env)->ExceptionCheck(env))270{271JNU_ThrowOutOfMemoryError(env, "Cannot allocate bitmask for mask");272}273return;274}275pDst = (unsigned char *)image->data;276277srcInfo.bounds.x1 = 0;278srcInfo.bounds.y1 = 0;279srcInfo.bounds.x2 = width;280srcInfo.bounds.y2 = height;281282flags = (isICM ? (SD_LOCK_LUT | SD_LOCK_READ) : SD_LOCK_READ);283if (srcOps->Lock(env, srcOps, &srcInfo, flags) != SD_SUCCESS) {284XDestroyImage(image);285AWT_UNLOCK();286return;287}288srcOps->GetRasInfo(env, srcOps, &srcInfo);289290rowCount = height;291if (isICM) {292unsigned char *pSrc;293jint *srcLut;294295srcScan = srcInfo.scanStride;296srcLut = srcInfo.lutBase;297pSrc = (unsigned char *)srcInfo.rasBase;298299if (image->bitmap_bit_order == MSBFirst) {300do {301int x = 0, bx = 0;302unsigned int pix = 0;303unsigned int bit = 0x80;304unsigned char *srcPixel = pSrc;305do {306if (bit == 0) {307pDst[bx++] = (unsigned char)pix;308pix = 0;309bit = 0x80;310}311pix |= bit & (srcLut[*srcPixel++] >> 31);312bit >>= 1;313} while (++x < width);314pDst[bx] = (unsigned char)pix;315pDst += dstScan;316pSrc = (unsigned char *) (((intptr_t)pSrc) + srcScan);317} while (--rowCount > 0);318} else {319do {320int x = 0, bx = 0;321unsigned int pix = 0;322unsigned int bit = 1;323unsigned char *srcPixel = pSrc;324do {325if ((bit >> 8) != 0) {326pDst[bx++] = (unsigned char) pix;327pix = 0;328bit = 1;329}330pix |= bit & (srcLut[*srcPixel++] >> 31);331bit <<= 1;332} while (++x < width);333pDst[bx] = (unsigned char) pix;334pDst += dstScan;335pSrc = (unsigned char *) (((intptr_t)pSrc) + srcScan);336} while (--rowCount > 0);337}338} else /*DCM with ARGB*/ {339unsigned int *pSrc;340341/* this is a number of pixels in a row, not number of bytes */342srcScan = srcInfo.scanStride;343pSrc = (unsigned int *)srcInfo.rasBase;344345if (image->bitmap_bit_order == MSBFirst) {346do {347int x = 0, bx = 0;348unsigned int pix = 0;349unsigned int bit = 0x80;350int *srcPixel = (int *) pSrc;351do {352if (bit == 0) {353/* next word */354pDst[bx++] = (unsigned char)pix;355pix = 0;356bit = 0x80;357}358if (*srcPixel++ & 0xff000000) {359/* if src pixel is opaque, set the bit in the bitmap */360pix |= bit;361}362bit >>= 1;363} while (++x < width);364/* last pixels in a row */365pDst[bx] = (unsigned char)pix;366367pDst += dstScan;368pSrc = (unsigned int *) (((intptr_t)pSrc) + srcScan);369} while (--rowCount > 0);370} else {371do {372int x = 0, bx = 0;373unsigned int pix = 0;374unsigned int bit = 1;375int *srcPixel = (int *) pSrc;376do {377if ((bit >> 8) != 0) {378pDst[bx++] = (unsigned char)pix;379pix = 0;380bit = 1;381}382if (*srcPixel++ & 0xff000000) {383/* if src pixel is opaque, set the bit in the bitmap */384pix |= bit;385}386bit <<= 1;387} while (++x < width);388pDst[bx] = (unsigned char)pix;389pDst += dstScan;390pSrc = (unsigned int *) (((intptr_t)pSrc) + srcScan);391} while (--rowCount > 0);392}393}394SurfaceData_InvokeRelease(env, srcOps, &srcInfo);395SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);396397xgc = XCreateGC(awt_display, xsdo->bitmask, 0L, NULL);398XSetForeground(awt_display, xgc, 1);399XSetBackground(awt_display, xgc, 0);400XPutImage(awt_display, xsdo->bitmask, xgc,401image, 0, 0, 0, 0, width, height);402403XFreeGC(awt_display, xgc);404XDestroyImage(image);405406AWT_UNLOCK();407#endif /* !HEADLESS */408}409410411