Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/vis_SrcMaskFill.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 <vis_AlphaMacros.h>2829/***************************************************************/3031/* ##############################################################32* IntArgbSrcMaskFill()33* FourByteAbgrSrcMaskFill()34*/3536#define MASK_FILL(rr, pathA, dstA, dstARGB) \37{ \38mlib_d64 t0, t1; \39\40dstA = MUL8_INT(dstA, 0xff - pathA); \41\42t0 = MUL8_VIS(cnstARGB0, pathA); \43t1 = MUL8_VIS(dstARGB, dstA); \44rr = vis_fpadd16(t0, t1); \45\46dstA = dstA + mul8_cnstA[pathA]; \47DIV_ALPHA(rr, dstA); \48}4950/***************************************************************/5152static void IntArgbSrcMaskFill_line(mlib_f32 *dst_ptr,53mlib_u8 *pMask,54mlib_s32 width,55mlib_d64 fgARGB,56mlib_f32 cnstARGB0,57mlib_u8 *mul8_cnstA,58mlib_u8 *mul8_tbl)59{60mlib_s32 i, i0;61mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;62mlib_d64 res0, res1, dstARGB;63mlib_f32 dstARGB0;6465i = i0 = 0;6667if ((mlib_s32)dst_ptr & 7) {68pathA0 = pMask[i];6970if (pathA0 == 0xff) {71dst_ptr[i] = vis_read_hi(fgARGB);72} else if (pathA0) {73dstA0 = *(mlib_u8*)(dst_ptr + i);74dstARGB0 = dst_ptr[i];75MASK_FILL(res0, pathA0, dstA0, dstARGB0);76dst_ptr[i] = vis_fpack16(res0);77*(mlib_u8*)(dst_ptr + i) = dstA0;78}7980i0 = 1;81}8283#pragma pipeloop(0)84for (i = i0; i <= width - 2; i += 2) {85pathA0 = pMask[i];86pathA1 = pMask[i + 1];87dstA0 = *(mlib_u8*)(dst_ptr + i);88dstA1 = *(mlib_u8*)(dst_ptr + i + 1);89dstARGB = *(mlib_d64*)(dst_ptr + i);9091MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));92MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));9394res0 = vis_fpack16_pair(res0, res1);9596msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;97vis_pst_32(res0, dst_ptr + i, msk);9899*(mlib_u8*)(dst_ptr + i ) = dstA0;100*(mlib_u8*)(dst_ptr + i + 1) = dstA1;101102msk = (((254 - pathA0) & (1 << 11)) |103((254 - pathA1) & (1 << 10))) >> 10;104vis_pst_32(fgARGB, dst_ptr + i, msk);105}106107if (i < width) {108pathA0 = pMask[i];109110if (pathA0 == 0xff) {111dst_ptr[i] = vis_read_hi(fgARGB);112} else if (pathA0) {113dstA0 = *(mlib_u8*)(dst_ptr + i);114dstARGB0 = dst_ptr[i];115MASK_FILL(res0, pathA0, dstA0, dstARGB0);116dst_ptr[i] = vis_fpack16(res0);117*(mlib_u8*)(dst_ptr + i) = dstA0;118}119}120}121122/***************************************************************/123124void ADD_SUFF(IntArgbSrcMaskFill)(void *rasBase,125jubyte *pMask,126jint maskOff,127jint maskScan,128jint width,129jint height,130jint fgColor,131SurfaceDataRasInfo *pRasInfo,132NativePrimitive *pPrim,133CompositeInfo *pCompInfo)134{135mlib_s32 cnstA, cnstR, cnstG, cnstB;136mlib_s32 rasScan = pRasInfo->scanStride;137mlib_f32 cnstARGB0;138mlib_d64 fgARGB;139mlib_u8 *mul8_cnstA;140mlib_s32 j;141142cnstA = (fgColor >> 24) & 0xff;143cnstR = (fgColor >> 16) & 0xff;144cnstG = (fgColor >> 8) & 0xff;145cnstB = (fgColor ) & 0xff;146147if (cnstA == 0) {148fgColor = 0;149}150151if (pMask == NULL) {152void *pBase = pRasInfo->rasBase;153pRasInfo->rasBase = rasBase;154ADD_SUFF(AnyIntSetRect)(pRasInfo,1550, 0, width, height,156fgColor, pPrim, pCompInfo);157pRasInfo->rasBase = pBase;158return;159}160161mul8_cnstA = mul8table[cnstA];162if (cnstA != 0xff) {163cnstR = mul8_cnstA[cnstR];164cnstG = mul8_cnstA[cnstG];165cnstB = mul8_cnstA[cnstB];166}167168cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);169170fgARGB = vis_to_double_dup(fgColor);171172pMask += maskOff;173174if (rasScan == 4*width && maskScan == width) {175width *= height;176height = 1;177}178179vis_write_gsr(7 << 3);180181for (j = 0; j < height; j++) {182IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,183mul8_cnstA, (void*)mul8table);184185PTR_ADD(rasBase, rasScan);186PTR_ADD(pMask, maskScan);187}188}189190/***************************************************************/191192void ADD_SUFF(FourByteAbgrSrcMaskFill)(void *rasBase,193jubyte *pMask,194jint maskOff,195jint maskScan,196jint width,197jint height,198jint fgColor,199SurfaceDataRasInfo *pRasInfo,200NativePrimitive *pPrim,201CompositeInfo *pCompInfo)202{203mlib_d64 buff[BUFF_SIZE/2];204void *pbuff = buff;205mlib_s32 cnstA, cnstR, cnstG, cnstB;206mlib_s32 rasScan = pRasInfo->scanStride;207mlib_f32 cnstARGB0;208mlib_d64 fgARGB;209mlib_u8 *mul8_cnstA;210mlib_s32 j;211212cnstA = (mlib_u32)fgColor >> 24;213cnstR = (fgColor >> 16) & 0xff;214cnstG = (fgColor >> 8) & 0xff;215cnstB = (fgColor ) & 0xff;216217if (pMask == NULL) {218void *pBase = pRasInfo->rasBase;219pRasInfo->rasBase = rasBase;220if (cnstA == 0) {221fgColor = 0;222} else {223fgColor = (fgColor << 8) | cnstA;224}225ADD_SUFF(Any4ByteSetRect)(pRasInfo,2260, 0, width, height,227fgColor, pPrim, pCompInfo);228pRasInfo->rasBase = pBase;229return;230}231232mul8_cnstA = mul8table[cnstA];233234if (cnstA == 0) {235fgColor = 0;236cnstR = cnstG = cnstB = 0;237} else {238fgColor = (cnstA << 24) | (cnstB << 16) | (cnstG << 8) | cnstR;239if (cnstA != 0xff) {240cnstR = mul8_cnstA[cnstR];241cnstG = mul8_cnstA[cnstG];242cnstB = mul8_cnstA[cnstB];243}244}245246cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);247248fgARGB = vis_to_double_dup(fgColor);249250pMask += maskOff;251252if (((mlib_s32)rasBase | rasScan) & 3) {253if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));254} else {255if (rasScan == 4*width && maskScan == width) {256width *= height;257height = 1;258}259}260261vis_write_gsr(7 << 3);262263for (j = 0; j < height; j++) {264if (!((mlib_s32)rasBase & 3)) {265IntArgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,266mul8_cnstA, (void*)mul8table);267} else {268mlib_ImageCopy_na(rasBase, pbuff, width*sizeof(mlib_s32));269IntArgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,270mul8_cnstA, (void*)mul8table);271mlib_ImageCopy_na(pbuff, rasBase, width*sizeof(mlib_s32));272}273274PTR_ADD(rasBase, rasScan);275PTR_ADD(pMask, maskScan);276}277278if (pbuff != buff) {279mlib_free(pbuff);280}281}282283/***************************************************************/284285/* ##############################################################286* IntRgbSrcMaskFill()287* IntBgrSrcMaskFill()288*/289290#undef MASK_FILL291#define MASK_FILL(rr, pathA, dstA, dstARGB) \292{ \293mlib_d64 t0, t1; \294\295dstA = 0xff - pathA; \296\297t0 = MUL8_VIS(cnstARGB0, pathA); \298t1 = MUL8_VIS(dstARGB, dstA); \299rr = vis_fpadd16(t0, t1); \300\301dstA = dstA + mul8_cnstA[pathA]; \302DIV_ALPHA_RGB(rr, dstA); \303}304305/***************************************************************/306307static void IntRgbSrcMaskFill_line(mlib_f32 *dst_ptr,308mlib_u8 *pMask,309mlib_s32 width,310mlib_d64 fgARGB,311mlib_f32 cnstARGB0,312mlib_u8 *mul8_cnstA,313mlib_u8 *mul8_tbl)314{315mlib_s32 i, i0;316mlib_s32 pathA0, pathA1, dstA0, dstA1, msk;317mlib_d64 res0, res1, dstARGB;318mlib_f32 dstARGB0;319320i = i0 = 0;321322if ((mlib_s32)dst_ptr & 7) {323pathA0 = pMask[i];324325if (pathA0 == 0xff) {326dst_ptr[i] = vis_read_hi(fgARGB);327} else if (pathA0) {328dstARGB0 = dst_ptr[i];329MASK_FILL(res0, pathA0, dstA0, dstARGB0);330dst_ptr[i] = vis_fpack16(res0);331}332333i0 = 1;334}335336#pragma pipeloop(0)337for (i = i0; i <= width - 2; i += 2) {338pathA0 = pMask[i];339pathA1 = pMask[i + 1];340dstARGB = *(mlib_d64*)(dst_ptr + i);341342MASK_FILL(res0, pathA0, dstA0, vis_read_hi(dstARGB));343MASK_FILL(res1, pathA1, dstA1, vis_read_lo(dstARGB));344345res0 = vis_fpack16_pair(res0, res1);346347msk = (((-pathA0) & (1 << 11)) | ((-pathA1) & (1 << 10))) >> 10;348vis_pst_32(res0, dst_ptr + i, msk);349350msk = (((254 - pathA0) & (1 << 11)) |351((254 - pathA1) & (1 << 10))) >> 10;352vis_pst_32(fgARGB, dst_ptr + i, msk);353}354355if (i < width) {356pathA0 = pMask[i];357358if (pathA0 == 0xff) {359dst_ptr[i] = vis_read_hi(fgARGB);360} else if (pathA0) {361dstARGB0 = dst_ptr[i];362MASK_FILL(res0, pathA0, dstA0, dstARGB0);363dst_ptr[i] = vis_fpack16(res0);364}365}366}367368/***************************************************************/369370void ADD_SUFF(IntRgbSrcMaskFill)(void *rasBase,371jubyte *pMask,372jint maskOff,373jint maskScan,374jint width,375jint height,376jint fgColor,377SurfaceDataRasInfo *pRasInfo,378NativePrimitive *pPrim,379CompositeInfo *pCompInfo)380{381mlib_s32 cnstA, cnstR, cnstG, cnstB;382mlib_s32 rasScan = pRasInfo->scanStride;383mlib_f32 cnstARGB0;384mlib_d64 fgARGB;385mlib_u8 *mul8_cnstA;386mlib_s32 j;387388cnstA = (fgColor >> 24) & 0xff;389cnstR = (fgColor >> 16) & 0xff;390cnstG = (fgColor >> 8) & 0xff;391cnstB = (fgColor ) & 0xff;392393if (cnstA == 0) fgColor = 0;394395if (pMask == NULL) {396void *pBase = pRasInfo->rasBase;397pRasInfo->rasBase = rasBase;398ADD_SUFF(AnyIntSetRect)(pRasInfo,3990, 0, width, height,400fgColor, pPrim, pCompInfo);401pRasInfo->rasBase = pBase;402return;403}404405mul8_cnstA = mul8table[cnstA];406if (cnstA != 0xff) {407cnstR = mul8_cnstA[cnstR];408cnstG = mul8_cnstA[cnstG];409cnstB = mul8_cnstA[cnstB];410}411412cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);413414fgARGB = vis_to_double_dup(fgColor);415416pMask += maskOff;417418if (rasScan == 4*width && maskScan == width) {419width *= height;420height = 1;421}422423vis_write_gsr(7 << 3);424425for (j = 0; j < height; j++) {426IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,427mul8_cnstA, (void*)mul8table);428429PTR_ADD(rasBase, rasScan);430PTR_ADD(pMask, maskScan);431}432}433434/***************************************************************/435436void ADD_SUFF(IntBgrSrcMaskFill)(void *rasBase,437jubyte *pMask,438jint maskOff,439jint maskScan,440jint width,441jint height,442jint fgColor,443SurfaceDataRasInfo *pRasInfo,444NativePrimitive *pPrim,445CompositeInfo *pCompInfo)446{447mlib_s32 cnstA, cnstR, cnstG, cnstB;448mlib_s32 rasScan = pRasInfo->scanStride;449mlib_f32 cnstARGB0;450mlib_d64 fgARGB;451mlib_u8 *mul8_cnstA;452mlib_s32 j;453454cnstA = (fgColor >> 24) & 0xff;455cnstR = (fgColor >> 16) & 0xff;456cnstG = (fgColor >> 8) & 0xff;457cnstB = (fgColor ) & 0xff;458459if (cnstA == 0) {460fgColor = 0;461} else {462fgColor = (cnstB << 16) | (cnstG << 8) | (cnstR);463}464465if (pMask == NULL) {466void *pBase = pRasInfo->rasBase;467pRasInfo->rasBase = rasBase;468ADD_SUFF(AnyIntSetRect)(pRasInfo,4690, 0, width, height,470fgColor, pPrim, pCompInfo);471pRasInfo->rasBase = pBase;472return;473}474475mul8_cnstA = mul8table[cnstA];476if (cnstA != 0xff) {477cnstR = mul8_cnstA[cnstR];478cnstG = mul8_cnstA[cnstG];479cnstB = mul8_cnstA[cnstB];480}481482cnstARGB0 = F32_FROM_U8x4(cnstA, cnstB, cnstG, cnstR);483484fgARGB = vis_to_double_dup(fgColor);485486pMask += maskOff;487488if (rasScan == 4*width && maskScan == width) {489width *= height;490height = 1;491}492493vis_write_gsr(7 << 3);494495for (j = 0; j < height; j++) {496IntRgbSrcMaskFill_line(rasBase, pMask, width, fgARGB, cnstARGB0,497mul8_cnstA, (void*)mul8table);498499PTR_ADD(rasBase, rasScan);500PTR_ADD(pMask, maskScan);501}502}503504/***************************************************************/505506void ADD_SUFF(ThreeByteBgrSrcMaskFill)(void *rasBase,507jubyte *pMask,508jint maskOff,509jint maskScan,510jint width,511jint height,512jint fgColor,513SurfaceDataRasInfo *pRasInfo,514NativePrimitive *pPrim,515CompositeInfo *pCompInfo)516{517mlib_d64 buff[BUFF_SIZE/2];518void *pbuff = buff;519mlib_s32 cnstA, cnstR, cnstG, cnstB;520mlib_s32 rasScan = pRasInfo->scanStride;521mlib_f32 cnstARGB0;522mlib_d64 fgARGB;523mlib_u8 *mul8_cnstA;524mlib_s32 j;525526cnstA = (fgColor >> 24) & 0xff;527cnstR = (fgColor >> 16) & 0xff;528cnstG = (fgColor >> 8) & 0xff;529cnstB = (fgColor ) & 0xff;530531if (cnstA == 0) {532fgColor = 0;533}534535if (pMask == NULL) {536void *pBase = pRasInfo->rasBase;537pRasInfo->rasBase = rasBase;538ADD_SUFF(Any3ByteSetRect)(pRasInfo,5390, 0, width, height,540fgColor, pPrim, pCompInfo);541pRasInfo->rasBase = pBase;542return;543}544545mul8_cnstA = mul8table[cnstA];546if (cnstA != 0xff) {547cnstR = mul8_cnstA[cnstR];548cnstG = mul8_cnstA[cnstG];549cnstB = mul8_cnstA[cnstB];550}551552cnstARGB0 = F32_FROM_U8x4(cnstA, cnstR, cnstG, cnstB);553554fgARGB = vis_to_double_dup(fgColor);555556pMask += maskOff;557558if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32));559560vis_write_gsr(7 << 3);561562for (j = 0; j < height; j++) {563ADD_SUFF(ThreeByteBgrToIntArgbConvert)(rasBase, pbuff, width, 1,564pRasInfo, pRasInfo,565pPrim, pCompInfo);566567IntRgbSrcMaskFill_line(pbuff, pMask, width, fgARGB, cnstARGB0,568mul8_cnstA, (void*)mul8table);569570IntArgbToThreeByteBgrConvert(pbuff, rasBase, width, 1,571pRasInfo, pRasInfo, pPrim, pCompInfo);572573PTR_ADD(rasBase, rasScan);574PTR_ADD(pMask, maskScan);575}576577if (pbuff != buff) {578mlib_free(pbuff);579}580}581582/***************************************************************/583584#endif585586587