0N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include "sun_java2d_d3d_D3DMaskFill.h"
0N/A
430N/A#include "D3DMaskFill.h"
430N/A#include "D3DRenderQueue.h"
0N/A
430N/A/**
430N/A * This implementation first copies the alpha tile into a texture and then
430N/A * maps that texture to the destination surface. This approach appears to
430N/A * offer the best performance despite being a two-step process.
430N/A *
430N/A * Here are some descriptions of the many variables used in this method:
430N/A * x,y - upper left corner of the tile destination
430N/A * w,h - width/height of the mask tile
430N/A * x0 - placekeeper for the original destination x location
430N/A * tw,th - width/height of the actual texture tile in pixels
430N/A * sx1,sy1 - upper left corner of the mask tile source region
430N/A * sx2,sy2 - lower left corner of the mask tile source region
430N/A * sx,sy - "current" upper left corner of the mask tile region of interest
430N/A */
430N/AHRESULT
430N/AD3DMaskFill_MaskFill(D3DContext *d3dc,
430N/A jint x, jint y, jint w, jint h,
430N/A jint maskoff, jint maskscan, jint masklen,
430N/A unsigned char *pMask)
0N/A{
430N/A HRESULT res = S_OK;
0N/A
0N/A J2dTraceLn(J2D_TRACE_INFO, "D3DMaskFill_MaskFill");
430N/A
430N/A RETURN_STATUS_IF_NULL(d3dc, E_FAIL);
430N/A
430N/A J2dTraceLn4(J2D_TRACE_VERBOSE, " x=%d y=%d w=%d h=%d", x, y, w, h);
430N/A J2dTraceLn2(J2D_TRACE_VERBOSE, " maskoff=%d maskscan=%d",
0N/A maskoff, maskscan);
0N/A
430N/A {
430N/A D3DMaskCache *maskCache = d3dc->GetMaskCache();
0N/A jint tw, th, x0;
0N/A jint sx1, sy1, sx2, sy2;
0N/A jint sx, sy, sw, sh;
0N/A
430N/A res = d3dc->BeginScene(STATE_MASKOP);
430N/A RETURN_STATUS_IF_FAILED(res);
0N/A
0N/A x0 = x;
430N/A tw = D3D_MASK_CACHE_TILE_WIDTH;
430N/A th = D3D_MASK_CACHE_TILE_HEIGHT;
0N/A sx1 = maskoff % maskscan;
0N/A sy1 = maskoff / maskscan;
0N/A sx2 = sx1 + w;
0N/A sy2 = sy1 + h;
0N/A
430N/A for (sy = sy1; sy < sy2; sy += th, y += th) {
0N/A x = x0;
0N/A sh = ((sy + th) > sy2) ? (sy2 - sy) : th;
0N/A
430N/A for (sx = sx1; sx < sx2; sx += tw, x += tw) {
0N/A sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;
0N/A
430N/A res = maskCache->AddMaskQuad(sx, sy, x, y, sw, sh,
430N/A maskscan, pMask);
0N/A }
0N/A }
0N/A }
0N/A return res;
0N/A}
0N/A
430N/AJNIEXPORT void JNICALL
430N/AJava_sun_java2d_d3d_D3DMaskFill_maskFill
430N/A (JNIEnv *env, jobject self,
430N/A jint x, jint y, jint w, jint h,
430N/A jint maskoff, jint maskscan, jint masklen,
430N/A jbyteArray maskArray)
430N/A{
430N/A D3DContext *d3dc = D3DRQ_GetCurrentContext();
430N/A unsigned char *mask;
430N/A
430N/A J2dTraceLn(J2D_TRACE_ERROR, "D3DMaskFill_maskFill");
430N/A
430N/A if (maskArray != NULL) {
430N/A mask = (unsigned char *)
430N/A env->GetPrimitiveArrayCritical(maskArray, NULL);
430N/A } else {
430N/A mask = NULL;
430N/A }
430N/A
430N/A D3DMaskFill_MaskFill(d3dc,
430N/A x, y, w, h,
430N/A maskoff, maskscan, masklen, mask);
430N/A
430N/A // reset current state, and ensure rendering is flushed to dest
430N/A if (d3dc != NULL) {
430N/A d3dc->FlushVertexQueue();
430N/A }
430N/A
430N/A if (mask != NULL) {
430N/A env->ReleasePrimitiveArrayCritical(maskArray, mask, JNI_ABORT);
430N/A }
0N/A}