D3DMaskFill.cpp revision 0
869N/A/*
869N/A * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation. Sun designates this
869N/A * particular file as subject to the "Classpath" exception as provided
869N/A * by Sun in the LICENSE file that accompanied this code.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
873N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
869N/A *
869N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
869N/A * CA 95054 USA or visit www.sun.com if you need additional information or
869N/A * have any questions.
869N/A */
869N/A
0N/A#include <stdlib.h>
0N/A#include <jni.h>
0N/A#include "ddrawUtils.h"
0N/A#include "GraphicsPrimitiveMgr.h"
869N/A#include "j2d_md.h"
0N/A#include "jlong.h"
0N/A
0N/A#include "sun_java2d_d3d_D3DMaskFill.h"
869N/A
0N/A#include "Win32SurfaceData.h"
869N/A
0N/A#include "D3DContext.h"
869N/A#include "D3DUtils.h"
869N/A
869N/A
0N/Aextern "C" {
869N/A
48N/Ainline static HRESULT doMaskFill
869N/A (JNIEnv *env, jobject self,
0N/A Win32SDOps *wsdo, D3DContext *d3dc,
869N/A jint x, jint y, jint w, jint h,
716N/A jbyteArray maskArray,
869N/A jint maskoff, jint maskscan);
1958N/A
1963N/A
1954N/AJNIEXPORT void JNICALL
1954N/AJava_sun_java2d_d3d_D3DMaskFill_MaskFill
1954N/A (JNIEnv *env, jobject self,
1954N/A jlong pData, jlong pCtx,
1954N/A jint x, jint y, jint w, jint h,
1954N/A jbyteArray maskArray,
1954N/A jint maskoff, jint maskscan)
1954N/A{
1954N/A Win32SDOps *wsdo = (Win32SDOps *)jlong_to_ptr(pData);
1954N/A D3DContext *d3dc = (D3DContext *)jlong_to_ptr(pCtx);
1954N/A
1954N/A J2dTraceLn(J2D_TRACE_INFO, "D3DMaskFill_MaskFill");
0N/A J2dTraceLn4(J2D_TRACE_VERBOSE, " x=%-4d y=%-4d w=%-4d h=%-4d",
0N/A x, y, w, h);
869N/A J2dTraceLn2(J2D_TRACE_VERBOSE, " maskoff=%-4d maskscan=%-4d",
868N/A maskoff, maskscan);
983N/A
1928N/A if (d3dc == NULL || wsdo == NULL) {
2042N/A J2dTraceLn(J2D_TRACE_WARNING,
1004N/A "D3DMaskFill_MaskFill: context is null");
1007N/A return;
1378N/A }
1411N/A
1503N/A HRESULT res;
869N/A D3D_EXEC_PRIM_LOOP(env, res, wsdo,
1774N/A doMaskFill(env, self, wsdo, d3dc,
1004N/A x, y, w, h,
0N/A maskArray, maskoff, maskscan));
0N/A}
869N/A
868N/Ainline static HRESULT doMaskFill
0N/A (JNIEnv *env, jobject self,
0N/A Win32SDOps *wsdo, D3DContext *d3dc,
65N/A jint x, jint y, jint w, jint h,
869N/A jbyteArray maskArray,
868N/A jint maskoff, jint maskscan)
65N/A{
869N/A DXSurface *maskTexture;
65N/A static J2DLVERTEX quadVerts[4] = {
65N/A { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f },
65N/A { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f },
65N/A { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f },
65N/A { 0.0f, 0.0f, 0.0f, 0x0, 0.0f, 0.0f }
65N/A };
65N/A
65N/A DDrawSurface *ddTargetSurface = d3dc->GetTargetSurface();
65N/A if (ddTargetSurface == NULL) {
65N/A return DDERR_GENERIC;
65N/A }
65N/A
65N/A ddTargetSurface->GetExclusiveAccess();
65N/A d3dc->GetExclusiveAccess();
65N/A
0N/A IDirect3DDevice7 *d3dDevice = d3dc->Get3DDevice();
869N/A
868N/A HRESULT res = D3D_OK;
0N/A if (maskArray) {
0N/A jubyte *pMask =
0N/A (jubyte*)env->GetPrimitiveArrayCritical(maskArray, 0);
0N/A float tx1, ty1, tx2, ty2;
0N/A jint tw, th, x0;
0N/A jint sx1, sy1, sx2, sy2;
0N/A jint sx, sy, sw, sh;
1501N/A
0N/A if (pMask == NULL) {
0N/A d3dc->ReleaseExclusiveAccess();
869N/A ddTargetSurface->ReleaseExclusiveAccess();
868N/A return DDERR_GENERIC;
0N/A }
0N/A
869N/A maskTexture = d3dc->GetMaskTexture();
0N/A if (maskTexture == NULL ||
0N/A FAILED(res = d3dc->BeginScene(STATE_MASKOP)))
869N/A {
868N/A env->ReleasePrimitiveArrayCritical(maskArray, pMask, JNI_ABORT);
869N/A d3dc->ReleaseExclusiveAccess();
869N/A ddTargetSurface->ReleaseExclusiveAccess();
868N/A return DDERR_GENERIC;
868N/A }
869N/A
869N/A if (FAILED(res = d3dc->SetTexture(maskTexture))) {
0N/A d3dc->EndScene(res);
0N/A env->ReleasePrimitiveArrayCritical(maskArray, pMask, JNI_ABORT);
1790N/A d3dc->ReleaseExclusiveAccess();
48N/A ddTargetSurface->ReleaseExclusiveAccess();
869N/A return res;
869N/A }
869N/A
868N/A x0 = x;
869N/A tx1 = 0.0f;
868N/A ty1 = 0.0f;
869N/A tw = D3DSD_MASK_TILE_SIZE;
1155N/A th = D3DSD_MASK_TILE_SIZE;
1155N/A sx1 = maskoff % maskscan;
1155N/A sy1 = maskoff / maskscan;
1155N/A sx2 = sx1 + w;
1155N/A sy2 = sy1 + h;
1155N/A
1155N/A D3DU_INIT_VERTEX_QUAD_COLOR(quadVerts, d3dc->colorPixel);
1155N/A for (sy = sy1; (sy < sy2) && SUCCEEDED(res); sy += th, y += th) {
1155N/A x = x0;
1155N/A sh = ((sy + th) > sy2) ? (sy2 - sy) : th;
1155N/A
1155N/A for (sx = sx1; (sx < sx2) && SUCCEEDED(res); sx += tw, x += tw) {
1155N/A sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;
1155N/A
1155N/A if (FAILED(d3dc->UploadImageToTexture(maskTexture,
0N/A pMask,
0N/A 0, 0, sx, sy, sw, sh,
869N/A maskscan)))
868N/A {
0N/A continue;
0N/A }
848N/A
848N/A // update the lower right texture coordinates
848N/A tx2 = ((float)sw) / tw;
869N/A ty2 = ((float)sh) / th;
868N/A
848N/A D3DU_INIT_VERTEX_QUAD_XYUV(quadVerts,
0N/A (float)x, (float)y,
0N/A (float)(x+sw), (float)(y+sh),
0N/A tx1, ty1, tx2, ty2);
869N/A if (SUCCEEDED(res = ddTargetSurface->IsLost())) {
0N/A // render texture tile to the destination surface
0N/A res = d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
0N/A D3DFVF_J2DLVERTEX,
868N/A quadVerts, 4, 0);
868N/A }
868N/A
868N/A }
869N/A }
868N/A
115N/A d3dc->EndScene(res);
868N/A
868N/A env->ReleasePrimitiveArrayCritical(maskArray, pMask, JNI_ABORT);
868N/A } else {
868N/A float x1 = (float)x;
868N/A float y1 = (float)y;
869N/A float x2 = x1 + (float)w;
868N/A float y2 = y1 + (float)h;
868N/A D3DU_INIT_VERTEX_QUAD_COLOR(quadVerts, d3dc->colorPixel);
868N/A D3DU_INIT_VERTEX_QUAD_XY(quadVerts, x1, y1, x2, y2);
868N/A if (SUCCEEDED(res = d3dc->BeginScene(STATE_RENDEROP))) {
868N/A if (SUCCEEDED(res = ddTargetSurface->IsLost())) {
868N/A res = d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
868N/A D3DFVF_J2DLVERTEX,
869N/A quadVerts, 4, 0);
868N/A }
868N/A d3dc->EndScene(res);
868N/A }
868N/A }
868N/A
869N/A d3dc->ReleaseExclusiveAccess();
868N/A ddTargetSurface->ReleaseExclusiveAccess();
868N/A
868N/A return res;
868N/A}
868N/A
869N/A}
868N/A