430N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/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
430N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/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.
430N/A */
430N/A
430N/A#include <stdlib.h>
430N/A#include <jlong.h>
430N/A
430N/A#include "D3DMaskBlit.h"
430N/A#include "D3DRenderQueue.h"
430N/A#include "D3DSurfaceData.h"
430N/A
430N/A/**
430N/A * REMIND: This method assumes that the dimensions of the incoming pixel
430N/A * array are less than or equal to the cached blit texture tile;
430N/A * these are rather fragile assumptions, and should be cleaned up...
430N/A */
430N/AHRESULT
430N/AD3DMaskBlit_MaskBlit(JNIEnv *env, D3DContext *d3dc,
430N/A jint dstx, jint dsty,
430N/A jint width, jint height,
430N/A void *pPixels)
430N/A{
430N/A HRESULT res = S_OK;
430N/A jfloat dx1, dy1, dx2, dy2;
430N/A jfloat tx1, ty1, tx2, ty2;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DMaskBlit_MaskBlit");
430N/A
430N/A if (width <= 0 || height <= 0) {
430N/A J2dTraceLn(J2D_TRACE_WARNING,
430N/A "D3DMaskBlit_MaskBlit: invalid dimensions");
430N/A return res;
430N/A }
430N/A
430N/A RETURN_STATUS_IF_NULL(pPixels, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(d3dc, E_FAIL);
430N/A if (FAILED(res = d3dc->BeginScene(STATE_TEXTUREOP))) {
430N/A return res;
430N/A }
430N/A
430N/A D3DResource *pBlitTexRes;
430N/A if (FAILED(res =
430N/A d3dc->GetResourceManager()->GetBlitTexture(&pBlitTexRes)))
430N/A {
430N/A return res;
430N/A }
430N/A IDirect3DTexture9 *pBlitTex = pBlitTexRes->GetTexture();
430N/A
430N/A if (FAILED(res = d3dc->SetTexture(pBlitTex, 0))) {
430N/A return res;
430N/A }
430N/A
430N/A IDirect3DDevice9 *pd3dDevice = d3dc->Get3DDevice();
430N/A D3DTEXTUREFILTERTYPE fhint =
430N/A d3dc->IsTextureFilteringSupported(D3DTEXF_NONE) ?
430N/A D3DTEXF_NONE : D3DTEXF_POINT;
430N/A pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, fhint);
430N/A pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, fhint);
430N/A
430N/A // copy system memory IntArgbPre surface into cached texture
430N/A if (FAILED(res = d3dc->UploadTileToTexture(pBlitTexRes, pPixels,
430N/A 0, 0, 0, 0,
430N/A width, height,
430N/A width*4,
430N/A TILEFMT_4BYTE_ARGB_PRE)))
430N/A {
430N/A return res;
430N/A }
430N/A
430N/A dx1 = (jfloat)dstx;
430N/A dy1 = (jfloat)dsty;
430N/A dx2 = dx1 + width;
430N/A dy2 = dy1 + height;
430N/A
430N/A tx1 = 0.0f;
430N/A ty1 = 0.0f;
430N/A tx2 = ((jfloat)width) / D3DC_BLIT_TILE_SIZE;
430N/A ty2 = ((jfloat)height) / D3DC_BLIT_TILE_SIZE;
430N/A
430N/A // render cached texture to the destination surface
430N/A res = d3dc->pVCacher->DrawTexture(dx1, dy1, dx2, dy2,
430N/A tx1, ty1, tx2, ty2);
430N/A res = d3dc->pVCacher->Render();
430N/A
430N/A return res;
430N/A}