Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DMaskFill.cpp
32288 views
/*1* Copyright (c) 2007, 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#include "sun_java2d_d3d_D3DMaskFill.h"2627#include "D3DMaskFill.h"28#include "D3DRenderQueue.h"2930/**31* This implementation first copies the alpha tile into a texture and then32* maps that texture to the destination surface. This approach appears to33* offer the best performance despite being a two-step process.34*35* Here are some descriptions of the many variables used in this method:36* x,y - upper left corner of the tile destination37* w,h - width/height of the mask tile38* x0 - placekeeper for the original destination x location39* tw,th - width/height of the actual texture tile in pixels40* sx1,sy1 - upper left corner of the mask tile source region41* sx2,sy2 - lower left corner of the mask tile source region42* sx,sy - "current" upper left corner of the mask tile region of interest43*/44HRESULT45D3DMaskFill_MaskFill(D3DContext *d3dc,46jint x, jint y, jint w, jint h,47jint maskoff, jint maskscan, jint masklen,48unsigned char *pMask)49{50HRESULT res = S_OK;5152J2dTraceLn(J2D_TRACE_INFO, "D3DMaskFill_MaskFill");5354RETURN_STATUS_IF_NULL(d3dc, E_FAIL);5556J2dTraceLn4(J2D_TRACE_VERBOSE, " x=%d y=%d w=%d h=%d", x, y, w, h);57J2dTraceLn2(J2D_TRACE_VERBOSE, " maskoff=%d maskscan=%d",58maskoff, maskscan);5960{61D3DMaskCache *maskCache = d3dc->GetMaskCache();62jint tw, th, x0;63jint sx1, sy1, sx2, sy2;64jint sx, sy, sw, sh;6566res = d3dc->BeginScene(STATE_MASKOP);67RETURN_STATUS_IF_FAILED(res);6869x0 = x;70tw = D3D_MASK_CACHE_TILE_WIDTH;71th = D3D_MASK_CACHE_TILE_HEIGHT;72sx1 = maskoff % maskscan;73sy1 = maskoff / maskscan;74sx2 = sx1 + w;75sy2 = sy1 + h;7677for (sy = sy1; sy < sy2; sy += th, y += th) {78x = x0;79sh = ((sy + th) > sy2) ? (sy2 - sy) : th;8081for (sx = sx1; sx < sx2; sx += tw, x += tw) {82sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;8384res = maskCache->AddMaskQuad(sx, sy, x, y, sw, sh,85maskscan, pMask);86}87}88}89return res;90}9192JNIEXPORT void JNICALL93Java_sun_java2d_d3d_D3DMaskFill_maskFill94(JNIEnv *env, jobject self,95jint x, jint y, jint w, jint h,96jint maskoff, jint maskscan, jint masklen,97jbyteArray maskArray)98{99D3DContext *d3dc = D3DRQ_GetCurrentContext();100unsigned char *mask;101102J2dTraceLn(J2D_TRACE_ERROR, "D3DMaskFill_maskFill");103104if (maskArray != NULL) {105mask = (unsigned char *)106env->GetPrimitiveArrayCritical(maskArray, NULL);107} else {108mask = NULL;109}110111D3DMaskFill_MaskFill(d3dc,112x, y, w, h,113maskoff, maskscan, masklen, mask);114115// reset current state, and ensure rendering is flushed to dest116if (d3dc != NULL) {117d3dc->FlushVertexQueue();118}119120if (mask != NULL) {121env->ReleasePrimitiveArrayCritical(maskArray, mask, JNI_ABORT);122}123}124125126