Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m
41159 views
/*1* Copyright (c) 2019, 2021, 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 "sun_java2d_metal_MTLMaskFill.h"2627#include "MTLMaskFill.h"28#include "MTLRenderQueue.h"29#include "MTLVertexCache.h"3031/**32* In case of Metal we use shader for texture mapping.33*34* Descriptions of the many variables used in this method:35* x,y - upper left corner of the tile destination36* w,h - width/height of the mask tile37* x0 - placekeeper for the original destination x location38* tw,th - width/height of the actual texture tile in pixels39* sx1,sy1 - upper left corner of the mask tile source region40* sx2,sy2 - lower left corner of the mask tile source region41* sx,sy - "current" upper left corner of the mask tile region of interest42*/43void44MTLMaskFill_MaskFill(MTLContext *mtlc, BMTLSDOps * dstOps,45jint x, jint y, jint w, jint h,46jint maskoff, jint maskscan, jint masklen,47unsigned char *pMask)48{49J2dTraceLn5(J2D_TRACE_INFO, "MTLMaskFill_MaskFill (x=%d y=%d w=%d h=%d pMask=%p)", x, y, w, h, dstOps->pTexture);50jint tw, th, x0;51jint sx1, sy1, sx2, sy2;52jint sx, sy, sw, sh;5354x0 = x;55tw = MTLVC_MASK_CACHE_TILE_WIDTH;56th = MTLVC_MASK_CACHE_TILE_HEIGHT;57sx1 = maskoff % maskscan;58sy1 = maskoff / maskscan;59sx2 = sx1 + w;60sy2 = sy1 + h;616263for (sy = sy1; sy < sy2; sy += th, y += th) {64x = x0;65sh = ((sy + th) > sy2) ? (sy2 - sy) : th;6667for (sx = sx1; sx < sx2; sx += tw, x += tw) {68sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;69MTLVertexCache_AddMaskQuad(mtlc,70sx, sy, x, y, sw, sh,71maskscan, pMask, dstOps);72}73}74}7576JNIEXPORT void JNICALL77Java_sun_java2d_metal_MTLMaskFill_maskFill78(JNIEnv *env, jobject self,79jint x, jint y, jint w, jint h,80jint maskoff, jint maskscan, jint masklen,81jbyteArray maskArray)82{83MTLContext *mtlc = MTLRenderQueue_GetCurrentContext();84BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();85unsigned char *mask;8687J2dTraceLn(J2D_TRACE_ERROR, "MTLMaskFill_maskFill");8889if (maskArray != NULL) {90mask = (unsigned char *)91(*env)->GetPrimitiveArrayCritical(env, maskArray, NULL);92} else {93mask = NULL;94}9596MTLMaskFill_MaskFill(mtlc, dstOps,97x, y, w, h,98maskoff, maskscan, masklen, mask);99if (mtlc != NULL) {100RESET_PREVIOUS_OP();101[mtlc.encoderManager endEncoder];102MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];103id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];104[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {105[cbwrapper release];106}];107[commandbuf commit];108}109110if (mask != NULL) {111(*env)->ReleasePrimitiveArrayCritical(env, maskArray, mask, JNI_ABORT);112}113}114115116