Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskBlit.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 <stdlib.h>26#include <jlong.h>2728#include "MTLMaskBlit.h"29#include "MTLRenderQueue.h"30#include "MTLBlitLoops.h"3132/**33* REMIND: This method assumes that the dimensions of the incoming pixel34* array are less than or equal to the cached blit texture tile;35* these are rather fragile assumptions, and should be cleaned up...36*/37void38MTLMaskBlit_MaskBlit(JNIEnv *env, MTLContext *mtlc, BMTLSDOps * dstOps,39jint dstx, jint dsty,40jint width, jint height,41void *pPixels)42{43J2dTraceLn(J2D_TRACE_INFO, "MTLMaskBlit_MaskBlit");4445if (width <= 0 || height <= 0) {46J2dTraceLn(J2D_TRACE_WARNING, "MTLMaskBlit_MaskBlit: invalid dimensions");47return;48}4950RETURN_IF_NULL(pPixels);51RETURN_IF_NULL(mtlc);5253MTLPooledTextureHandle * texHandle = [mtlc.texturePool54getTexture:width55height:height56format:MTLPixelFormatBGRA8Unorm];57if (texHandle == nil) {58J2dTraceLn(J2D_TRACE_ERROR, "MTLMaskBlit_MaskBlit: can't obtain temporary texture object from pool");59return;60}61[[mtlc getCommandBufferWrapper] registerPooledTexture:texHandle];6263id<MTLTexture> texBuff = texHandle.texture;64MTLRegion region = MTLRegionMake2D(0, 0, width, height);65[texBuff replaceRegion:region mipmapLevel:0 withBytes:pPixels bytesPerRow:4*width];6667drawTex2Tex(mtlc, texBuff, dstOps->pTexture, JNI_FALSE, dstOps->isOpaque, 0,680, 0, width, height, dstx, dsty, dstx + width, dsty + height);69}707172