Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/java2d_Mlib.c
32288 views
/*1* Copyright (c) 2003, 2010, 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#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)2627#include "java2d_Mlib.h"28#include "SurfaceData.h"2930#include "mlib_ImageZoom.h"3132/***************************************************************/3334#define DEFINE_ISO_COPY(FUNC, ANYTYPE) \35void ADD_SUFF(ANYTYPE##FUNC)(BLIT_PARAMS) \36{ \37mlib_s32 srcScan = pSrcInfo->scanStride; \38mlib_s32 dstScan = pDstInfo->scanStride; \39mlib_s32 xsize = width*ANYTYPE##PixelStride; \40mlib_s32 i; \41\42if (srcScan == xsize && dstScan == xsize) { \43xsize *= height; \44height = 1; \45} \46\47for (i = 0; i < height; i++) { \48mlib_ImageCopy_na(srcBase, dstBase, xsize); \49srcBase = (mlib_u8*)srcBase + srcScan; \50dstBase = (mlib_u8*)dstBase + dstScan; \51} \52}5354DEFINE_ISO_COPY(IsomorphicCopy, Any3Byte)55DEFINE_ISO_COPY(IsomorphicCopy, Any4Byte)56DEFINE_ISO_COPY(IsomorphicCopy, AnyByte)57DEFINE_ISO_COPY(IsomorphicCopy, AnyInt)58DEFINE_ISO_COPY(IsomorphicCopy, AnyShort)5960/***************************************************************/6162#define SET_PIX(index, chan) \63dst_ptr[index] = pixel##chan6465#define W_LEVEL_1 866#define W_LEVEL_3 1667#define W_LEVEL_4 86869#define DEFINE_SET_RECT(FUNC, ANYTYPE, NCHAN) \70void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \71jint lox, jint loy, jint hix, \72jint hiy, jint pixel, \73NativePrimitive * pPrim, \74CompositeInfo * pCompInfo) \75{ \76mlib_image dst[1]; \77mlib_s32 dstScan = pRasInfo->scanStride; \78mlib_s32 height = hiy - loy; \79mlib_s32 width = hix - lox; \80mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase); \81mlib_s32 c_arr[4]; \82\83dstBase += loy*dstScan + lox*ANYTYPE##PixelStride; \84\85if (width <= W_LEVEL_##NCHAN) { \86EXTRACT_CONST_##NCHAN(pixel); \87\88LOOP_DST(ANYTYPE, NCHAN, dstBase, dstScan, SET_PIX); \89return; \90} \91\92STORE_CONST_##NCHAN(c_arr, pixel); \93\94MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \95width, height, dstScan, dstBase); \96\97mlib_ImageClear(dst, c_arr); \98}99100DEFINE_SET_RECT(SetRect, Any3Byte, 3)101DEFINE_SET_RECT(SetRect, Any4Byte, 4)102DEFINE_SET_RECT(SetRect, AnyByte, 1)103DEFINE_SET_RECT(SetRect, AnyInt, 1)104DEFINE_SET_RECT(SetRect, AnyShort, 1)105106/***************************************************************/107108#define XOR_PIX(index, chan) \109dst_ptr[index] ^= pixel##chan110111#define DEFINE_XOR_RECT(FUNC, ANYTYPE, NCHAN) \112void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \113jint lox, jint loy, jint hix, \114jint hiy, jint pixel, \115NativePrimitive * pPrim, \116CompositeInfo * pCompInfo) \117{ \118mlib_image dst[1]; \119mlib_s32 dstScan = pRasInfo->scanStride; \120mlib_s32 height = hiy - loy; \121mlib_s32 width = hix - lox; \122mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase); \123mlib_s32 c_arr[4]; \124mlib_s32 xorpixel = pCompInfo->details.xorPixel; \125mlib_s32 alphamask = pCompInfo->alphaMask; \126\127pixel = (pixel ^ xorpixel) &~ alphamask; \128\129dstBase += loy*dstScan + lox*ANYTYPE##PixelStride; \130\131if (width < 8) { \132EXTRACT_CONST_##NCHAN(pixel); \133\134LOOP_DST(ANYTYPE, NCHAN, dstBase, dstScan, XOR_PIX); \135return; \136} \137\138STORE_CONST_##NCHAN(c_arr, pixel); \139\140MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \141width, height, dstScan, dstBase); \142\143mlib_ImageConstXor(dst, dst, c_arr); \144}145146DEFINE_XOR_RECT(XorRect, Any3Byte, 3)147DEFINE_XOR_RECT(XorRect, Any4Byte, 4)148DEFINE_XOR_RECT(XorRect, AnyByte, 1)149DEFINE_XOR_RECT(XorRect, AnyInt, 1)150DEFINE_XOR_RECT(XorRect, AnyShort, 1)151152/***************************************************************/153154#define XOR_COPY(index, chan) \155dst_ptr[index] = dst_ptr[index] ^ src_ptr[index] ^ pixel##chan156157#define DEFINE_XOR_COPY(FUNC, ANYTYPE, NCHAN) \158void ADD_SUFF(ANYTYPE##FUNC)(void *srcBase, \159void *dstBase, \160juint width, \161juint height, \162SurfaceDataRasInfo *pSrcInfo, \163SurfaceDataRasInfo *pDstInfo, \164NativePrimitive *pPrim, \165CompositeInfo *pCompInfo) \166{ \167mlib_image src[1], dst[1]; \168mlib_s32 srcScan = pSrcInfo->scanStride; \169mlib_s32 dstScan = pDstInfo->scanStride; \170mlib_s32 c_arr[4]; \171mlib_s32 pixel = pCompInfo->details.xorPixel; \172\173if (width < 8*sizeof(ANYTYPE##DataType)) { \174EXTRACT_CONST_##NCHAN(pixel); \175\176LOOP_DST_SRC(ANYTYPE, NCHAN, dstBase, dstScan, \177srcBase, srcScan, XOR_COPY); \178return; \179} \180\181STORE_CONST_##NCHAN(c_arr, pixel); \182\183MLIB_IMAGE_SET(src, MLIB_##ANYTYPE, NCHAN, \184width, height, srcScan, srcBase); \185MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN, \186width, height, dstScan, dstBase); \187\188mlib_ImageXor(dst, dst, src); \189mlib_ImageConstXor(dst, dst, c_arr); \190}191192DEFINE_XOR_COPY(IsomorphicXorCopy, Any3Byte, 3)193DEFINE_XOR_COPY(IsomorphicXorCopy, Any4Byte, 4)194DEFINE_XOR_COPY(IsomorphicXorCopy, AnyByte, 1)195DEFINE_XOR_COPY(IsomorphicXorCopy, AnyInt, 1)196DEFINE_XOR_COPY(IsomorphicXorCopy, AnyShort, 1)197198/***************************************************************/199200#define DEFINE_SET_SPANS(FUNC, ANYTYPE, NCHAN) \201void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \202SpanIteratorFuncs * pSpanFuncs, \203void *siData, jint pixel, \204NativePrimitive * pPrim, \205CompositeInfo * pCompInfo) \206{ \207mlib_image dst[1]; \208mlib_s32 dstScan = pRasInfo->scanStride; \209mlib_s32 height; \210mlib_s32 width; \211mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase), *pdst; \212mlib_s32 c_arr[4]; \213jint bbox[4]; \214\215STORE_CONST_##NCHAN(c_arr, pixel); \216\217while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \218mlib_s32 lox = bbox[0]; \219mlib_s32 loy = bbox[1]; \220mlib_s32 width = bbox[2] - lox; \221mlib_s32 height = bbox[3] - loy; \222\223pdst = dstBase + loy*dstScan + lox*ANYTYPE##PixelStride; \224\225MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN_##ANYTYPE, \226width, height, dstScan, pdst); \227\228mlib_ImageClear(dst, c_arr); \229} \230}231232DEFINE_SET_SPANS(SetSpans, Any3Byte, 3)233DEFINE_SET_SPANS(SetSpans, Any4Byte, 4)234DEFINE_SET_SPANS(SetSpans, AnyByte, 1)235DEFINE_SET_SPANS(SetSpans, AnyInt, 1)236DEFINE_SET_SPANS(SetSpans, AnyShort, 1)237238/***************************************************************/239240#define DEFINE_XOR_SPANS(FUNC, ANYTYPE, NCHAN) \241void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo * pRasInfo, \242SpanIteratorFuncs * pSpanFuncs, \243void *siData, jint pixel, \244NativePrimitive * pPrim, \245CompositeInfo * pCompInfo) \246{ \247mlib_image dst[1]; \248mlib_s32 dstScan = pRasInfo->scanStride; \249mlib_s32 height; \250mlib_s32 width; \251mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase), *pdst; \252mlib_s32 c_arr[4]; \253mlib_s32 xorpixel = pCompInfo->details.xorPixel; \254mlib_s32 alphamask = pCompInfo->alphaMask; \255jint bbox[4]; \256\257pixel = (pixel ^ xorpixel) &~ alphamask; \258\259STORE_CONST_##NCHAN(c_arr, pixel); \260\261while ((*pSpanFuncs->nextSpan)(siData, bbox)) { \262mlib_s32 lox = bbox[0]; \263mlib_s32 loy = bbox[1]; \264mlib_s32 width = bbox[2] - lox; \265mlib_s32 height = bbox[3] - loy; \266\267pdst = dstBase + loy*dstScan + lox*ANYTYPE##PixelStride; \268\269MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN_##ANYTYPE, \270width, height, dstScan, pdst); \271\272mlib_ImageConstXor(dst, dst, c_arr); \273} \274}275276DEFINE_XOR_SPANS(XorSpans, Any3Byte, 3)277DEFINE_XOR_SPANS(XorSpans, Any4Byte, 4)278DEFINE_XOR_SPANS(XorSpans, AnyByte, 1)279DEFINE_XOR_SPANS(XorSpans, AnyInt, 1)280DEFINE_XOR_SPANS(XorSpans, AnyShort, 1)281282/***************************************************************/283284#define DEFINE_SET_PGRAM(FUNC, ANYTYPE, NCHAN) \285void ADD_SUFF(ANYTYPE##FUNC)(SurfaceDataRasInfo *pRasInfo, \286jint lox, jint loy, \287jint hix, jint hiy, \288jlong leftx, jlong dleftx, \289jlong rightx, jlong drightx, \290jint pixel, NativePrimitive * pPrim, \291CompositeInfo * pCompInfo) \292{ \293mlib_image dst[1]; \294mlib_s32 dstScan = pRasInfo->scanStride; \295mlib_u8 *dstBase = (mlib_u8*)(pRasInfo->rasBase), *pdst; \296mlib_s32 c_arr[4]; \297\298STORE_CONST_##NCHAN(c_arr, pixel); \299pdst = dstBase + loy*dstScan; \300\301while (loy < hiy) { \302jint lx = WholeOfLong(leftx); \303jint rx = WholeOfLong(rightx); \304if (lx < lox) lx = lox; \305if (rx > hix) rx = hix; \306\307MLIB_IMAGE_SET(dst, MLIB_##ANYTYPE, NCHAN_##ANYTYPE, \308rx-lx, 1, dstScan, \309pdst + lx*ANYTYPE##PixelStride); \310\311mlib_ImageClear(dst, c_arr); \312\313pdst = PtrAddBytes(pdst, dstScan); \314leftx += dleftx; \315rightx += drightx; \316loy++; \317} \318}319320DEFINE_SET_PGRAM(SetParallelogram, Any3Byte, 3)321DEFINE_SET_PGRAM(SetParallelogram, Any4Byte, 4)322DEFINE_SET_PGRAM(SetParallelogram, AnyByte, 1)323DEFINE_SET_PGRAM(SetParallelogram, AnyInt, 1)324DEFINE_SET_PGRAM(SetParallelogram, AnyShort, 1)325326/***************************************************************/327328#define SCALE_COPY(index, chan) \329pDst[chan] = pSrc[index]330331#define MLIB_ZOOM_NN_AnyByte mlib_ImageZoom_U8_1_Nearest(param);332#define MLIB_ZOOM_NN_Any3Byte mlib_ImageZoom_U8_3_Nearest(param);333#define MLIB_ZOOM_NN_AnyShort mlib_ImageZoom_S16_1_Nearest(param);334#define MLIB_ZOOM_NN_AnyInt mlib_ImageZoom_S32_1_Nearest(param);335336#define MLIB_ZOOM_NN_Any4Byte \337{ \338mlib_s32 b_align = (mlib_s32)srcBase | (mlib_s32)dstBase | \339srcScan | dstScan; \340\341if (!(b_align & 3)) { \342mlib_ImageZoom_S32_1_Nearest(param); \343} else if (!(b_align & 1)) { \344mlib_ImageZoom_S16_2_Nearest(param); \345} else { \346mlib_ImageZoom_U8_4_Nearest(param); \347} \348}349350#define DEFINE_ISO_SCALE(FUNC, ANYTYPE, NCHAN) \351void ADD_SUFF(ANYTYPE##FUNC)(void *srcBase, void *dstBase, \352juint width, juint height, \353jint sxloc, jint syloc, \354jint sxinc, jint syinc, \355jint shift, \356SurfaceDataRasInfo *pSrcInfo, \357SurfaceDataRasInfo *pDstInfo, \358NativePrimitive *pPrim, \359CompositeInfo *pCompInfo) \360{ \361mlib_work_image param[1]; \362mlib_clipping current[1]; \363mlib_s32 srcScan = pSrcInfo->scanStride; \364mlib_s32 dstScan = pDstInfo->scanStride; \365\366if (width <= 32) { \367ANYTYPE##DataType *pSrc; \368ANYTYPE##DataType *pDst = dstBase; \369dstScan -= (width) * ANYTYPE##PixelStride; \370\371do { \372juint w = width; \373jint tmpsxloc = sxloc; \374pSrc = srcBase; \375PTR_ADD(pSrc, (syloc >> shift) * srcScan); \376do { \377jint i = (tmpsxloc >> shift); \378PROCESS_PIX_##NCHAN(SCALE_COPY); \379pDst += NCHAN; \380tmpsxloc += sxinc; \381} \382while (--w > 0); \383PTR_ADD(pDst, dstScan); \384syloc += syinc; \385} \386while (--height > 0); \387return; \388} \389\390param->current = current; \391\392if (shift <= MLIB_SHIFT /* 16 */) { \393jint dshift = MLIB_SHIFT - shift; \394sxloc <<= dshift; \395syloc <<= dshift; \396sxinc <<= dshift; \397syinc <<= dshift; \398} else { \399jint dshift = shift - MLIB_SHIFT; \400sxloc >>= dshift; \401syloc >>= dshift; \402sxinc >>= dshift; \403syinc >>= dshift; \404} \405\406current->width = width; \407current->height = height; \408param->DX = sxinc; \409param->DY = syinc; \410param->src_stride = srcScan; \411param->dst_stride = dstScan; \412current->srcX = sxloc; \413current->srcY = syloc; \414current->sp = (mlib_u8*)srcBase \415+ (sxloc >> MLIB_SHIFT)*ANYTYPE##PixelStride \416+ (syloc >> MLIB_SHIFT)*srcScan; \417current->dp = dstBase; \418\419MLIB_ZOOM_NN_##ANYTYPE \420}421422DEFINE_ISO_SCALE(IsomorphicScaleCopy, Any3Byte, 3)423DEFINE_ISO_SCALE(IsomorphicScaleCopy, Any4Byte, 4)424DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyByte, 1)425DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyInt, 1)426DEFINE_ISO_SCALE(IsomorphicScaleCopy, AnyShort, 1)427428/***************************************************************/429430#endif /* JAVA2D_NO_MLIB */431432433