Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/java2d/loops/vis_FourByteAbgrPre.c
32288 views
/*1* Copyright (c) 2003, 2008, 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#define FUNC_CONVERT(TYPE, OPER) \32void ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(BLIT_PARAMS) \33{ \34mlib_d64 buff[BUFF_SIZE/2]; \35void *pbuff = buff; \36mlib_s32 dstScan = pDstInfo->scanStride; \37mlib_s32 srcScan = pSrcInfo->scanStride; \38mlib_s32 j; \39\40if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32)); \41\42for (j = 0; j < height; j++) { \43ADD_SUFF(TYPE##ToIntArgbPre##OPER)(srcBase, pbuff, width, 1, \44pSrcInfo, pDstInfo, \45pPrim, pCompInfo); \46\47ADD_SUFF(IntArgbToFourByteAbgrConvert)(pbuff, dstBase, width, 1, \48pSrcInfo, pDstInfo, \49pPrim, pCompInfo); \50\51PTR_ADD(dstBase, dstScan); \52PTR_ADD(srcBase, srcScan); \53} \54\55if (pbuff != buff) { \56mlib_free(pbuff); \57} \58}5960/***************************************************************/6162#define FUNC_SCALE_1(TYPE, OPER) \63void ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(SCALE_PARAMS) \64{ \65mlib_d64 buff[BUFF_SIZE/2]; \66void *pbuff = buff; \67mlib_s32 dstScan = pDstInfo->scanStride; \68mlib_s32 j; \69\70if (width > BUFF_SIZE) pbuff = mlib_malloc(width*sizeof(mlib_s32)); \71\72for (j = 0; j < height; j++) { \73ADD_SUFF(TYPE##ToIntArgbPre##OPER)(srcBase, pbuff, width, 1, \74sxloc, syloc, \75sxinc, syinc, shift, \76pSrcInfo, pDstInfo, \77pPrim, pCompInfo); \78\79ADD_SUFF(IntArgbToFourByteAbgrConvert)(pbuff, dstBase, width, 1, \80pSrcInfo, pDstInfo, \81pPrim, pCompInfo); \82\83PTR_ADD(dstBase, dstScan); \84syloc += syinc; \85} \86\87if (pbuff != buff) { \88mlib_free(pbuff); \89} \90}9192/***************************************************************/9394#define FUNC_INDEXED(TYPE, OPER, PARAMS, CALL_PARAMS) \95void ADD_SUFF(TYPE##ToFourByteAbgrPre##OPER)(PARAMS) \96{ \97SurfaceDataRasInfo new_src[1]; \98jint *pixLut = pSrcInfo->lutBase; \99mlib_s32 buff[256]; \100\101ADD_SUFF(IntArgbToIntArgbPreConvert)(pixLut, buff, 256, 1, \102pSrcInfo, pDstInfo, \103pPrim, pCompInfo); \104\105new_src->lutBase = buff; \106new_src->scanStride = pSrcInfo->scanStride; \107pSrcInfo = new_src; \108\109ADD_SUFF(TYPE##ToFourByteAbgr##OPER)(CALL_PARAMS); \110}111112/***************************************************************/113114void ADD_SUFF(FourByteAbgrPreToIntArgbConvert)(BLIT_PARAMS)115{116ADD_SUFF(FourByteAbgrToIntArgbConvert)(BLIT_CALL_PARAMS);117pSrcInfo = pDstInfo;118srcBase = dstBase;119ADD_SUFF(IntArgbPreToIntArgbConvert)(BLIT_CALL_PARAMS);120}121122/***************************************************************/123124void ADD_SUFF(FourByteAbgrPreToIntArgbScaleConvert)(SCALE_PARAMS)125{126ADD_SUFF(FourByteAbgrToIntArgbScaleConvert)(SCALE_CALL_PARAMS);127pSrcInfo = pDstInfo;128srcBase = dstBase;129ADD_SUFF(IntArgbPreToIntArgbConvert)(BLIT_CALL_PARAMS);130}131132/***************************************************************/133134FUNC_CONVERT(ByteGray, Convert)135FUNC_CONVERT(IntArgb, Convert)136FUNC_CONVERT(IntRgb, Convert)137FUNC_CONVERT(ThreeByteBgr, Convert)138139FUNC_SCALE_1(ByteGray, ScaleConvert)140FUNC_SCALE_1(IntArgb, ScaleConvert)141FUNC_SCALE_1(IntRgb, ScaleConvert)142FUNC_SCALE_1(ThreeByteBgr, ScaleConvert)143144FUNC_INDEXED(ByteIndexed, Convert, BLIT_PARAMS, BLIT_CALL_PARAMS)145FUNC_INDEXED(ByteIndexedBm, XparOver, BLIT_PARAMS, BLIT_CALL_PARAMS)146FUNC_INDEXED(ByteIndexedBm, XparBgCopy, BCOPY_PARAMS, BCOPY_CALL_PARAMS)147FUNC_INDEXED(ByteIndexedBm, ScaleXparOver, SCALE_PARAMS, SCALE_CALL_PARAMS)148FUNC_INDEXED(ByteIndexed, ScaleConvert, SCALE_PARAMS, SCALE_CALL_PARAMS)149150/***************************************************************/151152void ADD_SUFF(FourByteAbgrPreDrawGlyphListAA)(SurfaceDataRasInfo * pRasInfo,153ImageRef *glyphs,154jint totalGlyphs,155jint fgpixel, jint argbcolor,156jint clipLeft, jint clipTop,157jint clipRight, jint clipBottom,158NativePrimitive * pPrim,159CompositeInfo * pCompInfo)160{161mlib_d64 buff[BUFF_SIZE/2];162void *pbuff = buff;163mlib_s32 glyphCounter;164mlib_s32 scan = pRasInfo->scanStride;165mlib_u8 *dstBase;166mlib_s32 solidpix0, solidpix1, solidpix2, solidpix3;167mlib_s32 i, j;168mlib_d64 dmix0, dmix1, dd, d0, d1, e0, e1;169mlib_d64 done, d_half;170mlib_s32 pix;171mlib_f32 srcG_f;172mlib_s32 max_width = BUFF_SIZE;173174solidpix0 = fgpixel;175solidpix1 = fgpixel >> 8;176solidpix2 = fgpixel >> 16;177solidpix3 = fgpixel >> 24;178179done = vis_to_double_dup(0x7fff7fff);180d_half = vis_to_double_dup((1 << (16 + 6)) | (1 << 6));181182srcG_f = vis_to_float(argbcolor);183ARGB2ABGR_FL(srcG_f);184185for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {186const jubyte *pixels;187unsigned int rowBytes;188int left, top;189int width, height;190int right, bottom;191192pixels = (const jubyte *) glyphs[glyphCounter].pixels;193194if (!pixels) continue;195196left = glyphs[glyphCounter].x;197top = glyphs[glyphCounter].y;198width = glyphs[glyphCounter].width;199height = glyphs[glyphCounter].height;200rowBytes = width;201right = left + width;202bottom = top + height;203if (left < clipLeft) {204pixels += clipLeft - left;205left = clipLeft;206}207if (top < clipTop) {208pixels += (clipTop - top) * rowBytes;209top = clipTop;210}211if (right > clipRight) {212right = clipRight;213}214if (bottom > clipBottom) {215bottom = clipBottom;216}217if (right <= left || bottom <= top) {218continue;219}220width = right - left;221height = bottom - top;222223dstBase = pRasInfo->rasBase;224PTR_ADD(dstBase, top*scan + 4*left);225226if (((mlib_s32)dstBase | scan) & 3) {227if (width > max_width) {228if (pbuff != buff) {229mlib_free(pbuff);230}231pbuff = mlib_malloc(width*sizeof(mlib_s32));232if (pbuff == NULL) return;233max_width = width;234}235}236237for (j = 0; j < height; j++) {238mlib_u8 *src = (void*)pixels;239mlib_s32 *dst, *dst_end;240mlib_u8 *dst8;241mlib_u8* dst_start = dstBase;242243/*244* Typically the inner loop here works on Argb input data, an245* Argb color, and produces ArgbPre output data. To use that246* standard approach we would need a FourByteAbgrPre to IntArgb247* converter for the front end and an IntArgbPre to FourByteAbgrPre248* converter for the back end. The converter exists for the249* front end, but it is a workaround implementation that uses a 2250* stage conversion and an intermediate buffer that is allocated251* on every call. The converter for the back end doesn't really252* exist, but we could reuse the IntArgb to FourByteAbgr converter253* to do the same work - at the cost of swapping the components as254* we copy the data back. All of this is more work than we really255* need so we use an alternate procedure:256* - Copy the data into an int-aligned temporary buffer (if needed)257* - Convert the data from FourByteAbgrPre to IntAbgr by using the258* IntArgbPre to IntArgb converter in the int-aligned buffer.259* - Swap the color data to Abgr so that the inner loop goes from260* IntAbgr data to IntAbgrPre data261* - Simply copy the IntAbgrPre data back into place.262*/263if (((mlib_s32)dstBase) & 3) {264COPY_NA(dstBase, pbuff, width*sizeof(mlib_s32));265dst_start = pbuff;266}267ADD_SUFF(IntArgbPreToIntArgbConvert)(dst_start, pbuff, width, 1,268pRasInfo, pRasInfo,269pPrim, pCompInfo);270271vis_write_gsr(0 << 3);272273dst = pbuff;274dst_end = dst + width;275276if ((mlib_s32)dst & 7) {277pix = *src++;278dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half);279dd = vis_fpadd16(MUL8_VIS(*(mlib_f32*)dst, 255 - pix), dd);280*(mlib_f32*)dst = vis_fpack16(dd);281dst++;282}283284#pragma pipeloop(0)285for (; dst <= (dst_end - 2); dst += 2) {286dmix0 = vis_freg_pair(((mlib_f32 *)vis_mul8s_tbl)[src[0]],287((mlib_f32 *)vis_mul8s_tbl)[src[1]]);288dmix1 = vis_fpsub16(done, dmix0);289src += 2;290291dd = *(mlib_d64*)dst;292d0 = vis_fmul8x16al(srcG_f, vis_read_hi(dmix0));293d1 = vis_fmul8x16al(srcG_f, vis_read_lo(dmix0));294e0 = vis_fmul8x16al(vis_read_hi(dd), vis_read_hi(dmix1));295e1 = vis_fmul8x16al(vis_read_lo(dd), vis_read_lo(dmix1));296d0 = vis_fpadd16(vis_fpadd16(d0, d_half), e0);297d1 = vis_fpadd16(vis_fpadd16(d1, d_half), e1);298dd = vis_fpack16_pair(d0, d1);299300*(mlib_d64*)dst = dd;301}302303while (dst < dst_end) {304pix = *src++;305dd = vis_fpadd16(MUL8_VIS(srcG_f, pix), d_half);306dd = vis_fpadd16(MUL8_VIS(*(mlib_f32*)dst, 255 - pix), dd);307*(mlib_f32*)dst = vis_fpack16(dd);308dst++;309}310311COPY_NA(pbuff, dstBase, width*sizeof(mlib_s32));312313src = (void*)pixels;314dst8 = (void*)dstBase;315316#pragma pipeloop(0)317for (i = 0; i < width; i++) {318if (src[i] == 255) {319dst8[4*i ] = solidpix0;320dst8[4*i + 1] = solidpix1;321dst8[4*i + 2] = solidpix2;322dst8[4*i + 3] = solidpix3;323}324}325326PTR_ADD(dstBase, scan);327pixels += rowBytes;328}329}330331if (pbuff != buff) {332mlib_free(pbuff);333}334}335336/***************************************************************/337338#endif /* JAVA2D_NO_MLIB */339340341