Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DMaskBlit.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 <stdlib.h>26#include <jlong.h>2728#include "D3DMaskBlit.h"29#include "D3DRenderQueue.h"30#include "D3DSurfaceData.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*/37HRESULT38D3DMaskBlit_MaskBlit(JNIEnv *env, D3DContext *d3dc,39jint dstx, jint dsty,40jint width, jint height,41void *pPixels)42{43HRESULT res = S_OK;44jfloat dx1, dy1, dx2, dy2;45jfloat tx1, ty1, tx2, ty2;4647J2dTraceLn(J2D_TRACE_INFO, "D3DMaskBlit_MaskBlit");4849if (width <= 0 || height <= 0) {50J2dTraceLn(J2D_TRACE_WARNING,51"D3DMaskBlit_MaskBlit: invalid dimensions");52return res;53}5455RETURN_STATUS_IF_NULL(pPixels, E_FAIL);56RETURN_STATUS_IF_NULL(d3dc, E_FAIL);57if (FAILED(res = d3dc->BeginScene(STATE_TEXTUREOP))) {58return res;59}6061D3DResource *pBlitTexRes;62if (FAILED(res =63d3dc->GetResourceManager()->GetBlitTexture(&pBlitTexRes)))64{65return res;66}67IDirect3DTexture9 *pBlitTex = pBlitTexRes->GetTexture();6869if (FAILED(res = d3dc->SetTexture(pBlitTex, 0))) {70return res;71}7273IDirect3DDevice9 *pd3dDevice = d3dc->Get3DDevice();74D3DTEXTUREFILTERTYPE fhint =75d3dc->IsTextureFilteringSupported(D3DTEXF_NONE) ?76D3DTEXF_NONE : D3DTEXF_POINT;77pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, fhint);78pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, fhint);7980// copy system memory IntArgbPre surface into cached texture81if (FAILED(res = d3dc->UploadTileToTexture(pBlitTexRes, pPixels,820, 0, 0, 0,83width, height,84width*4,85TILEFMT_4BYTE_ARGB_PRE)))86{87return res;88}8990dx1 = (jfloat)dstx;91dy1 = (jfloat)dsty;92dx2 = dx1 + width;93dy2 = dy1 + height;9495tx1 = 0.0f;96ty1 = 0.0f;97tx2 = ((jfloat)width) / D3DC_BLIT_TILE_SIZE;98ty2 = ((jfloat)height) / D3DC_BLIT_TILE_SIZE;99100// render cached texture to the destination surface101res = d3dc->pVCacher->DrawTexture(dx1, dy1, dx2, dy2,102tx1, ty1, tx2, ty2);103res = d3dc->pVCacher->Render();104105return res;106}107108109