Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DMaskCache.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 "D3DMaskCache.h"2627HRESULT28D3DMaskCache::CreateInstance(D3DContext *pCtx, D3DMaskCache **ppMaskCache)29{30HRESULT res;3132J2dTraceLn(J2D_TRACE_INFO, "D3DMaskCache::CreateInstance");3334*ppMaskCache = new D3DMaskCache();35if (FAILED(res = (*ppMaskCache)->Init(pCtx))) {36delete *ppMaskCache;37*ppMaskCache = NULL;38}39return res;40}4142D3DMaskCache::D3DMaskCache()43{44J2dTraceLn(J2D_TRACE_INFO, "D3DMaskCache::D3DMaskCache");45this->pCtx = NULL;46maskCacheIndex = 0;47}4849D3DMaskCache::~D3DMaskCache()50{51J2dTraceLn(J2D_TRACE_INFO, "D3DMaskCache::~D3DMaskCache");52pCtx = NULL;53maskCacheIndex = 0;54}5556HRESULT57D3DMaskCache::Init(D3DContext *pCtx)58{59J2dTraceLn1(J2D_TRACE_INFO, "D3DMaskCache::Init pCtx=%x", pCtx);60this->pCtx = pCtx;61this->maskCacheIndex = 0;62return S_OK;63}6465HRESULT D3DMaskCache::Enable()66{67HRESULT res;6869J2dTraceLn(J2D_TRACE_INFO, "D3DMaskCache::Enable");7071D3DResource *pMaskTexRes;72res = pCtx->GetResourceManager()->GetMaskTexture(&pMaskTexRes);73RETURN_STATUS_IF_FAILED(res);7475res = pCtx->SetTexture(pMaskTexRes->GetTexture(), 0);7677IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();78D3DTEXTUREFILTERTYPE fhint =79pCtx->IsTextureFilteringSupported(D3DTEXF_NONE) ?80D3DTEXF_NONE : D3DTEXF_POINT;81pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, fhint);82pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, fhint);8384return res;85}8687HRESULT D3DMaskCache::Disable()88{89J2dTraceLn(J2D_TRACE_INFO, "D3DMaskCache::Disable");9091maskCacheIndex = 0;9293return pCtx->SetTexture(NULL, 0);94}9596HRESULT D3DMaskCache::AddMaskQuad(int srcx, int srcy,97int dstx, int dsty,98int width, int height,99int maskscan, void *mask)100{101HRESULT res;102float tx1, ty1, tx2, ty2;103float dx1, dy1, dx2, dy2;104105J2dTraceLn1(J2D_TRACE_INFO, "D3DVertexCacher::AddMaskQuad: %d",106maskCacheIndex);107108if (maskCacheIndex >= D3D_MASK_CACHE_MAX_INDEX ||109pCtx->pVCacher->GetFreeVertices() < 6)110{111res = pCtx->pVCacher->Render();112RETURN_STATUS_IF_FAILED(res);113maskCacheIndex = 0;114}115116if (mask != NULL) {117int texx = D3D_MASK_CACHE_TILE_WIDTH *118(maskCacheIndex % D3D_MASK_CACHE_WIDTH_IN_TILES);119int texy = D3D_MASK_CACHE_TILE_HEIGHT *120(maskCacheIndex / D3D_MASK_CACHE_WIDTH_IN_TILES);121D3DResource *pMaskTexRes;122123res = pCtx->GetResourceManager()->GetMaskTexture(&pMaskTexRes);124RETURN_STATUS_IF_FAILED(res);125126// copy alpha mask into texture tile127pCtx->UploadTileToTexture(pMaskTexRes, mask,128texx, texy,129srcx, srcy,130width, height,131maskscan,132TILEFMT_1BYTE_ALPHA);133134tx1 = ((float)texx) / D3D_MASK_CACHE_WIDTH_IN_TEXELS;135ty1 = ((float)texy) / D3D_MASK_CACHE_HEIGHT_IN_TEXELS;136137maskCacheIndex++;138} else {139// use special fully opaque tile140tx1 = ((float)D3D_MASK_CACHE_SPECIAL_TILE_X) /141D3D_MASK_CACHE_WIDTH_IN_TEXELS;142ty1 = ((float)D3D_MASK_CACHE_SPECIAL_TILE_Y) /143D3D_MASK_CACHE_HEIGHT_IN_TEXELS;144}145146tx2 = tx1 + (((float)width) / D3D_MASK_CACHE_WIDTH_IN_TEXELS);147ty2 = ty1 + (((float)height) / D3D_MASK_CACHE_HEIGHT_IN_TEXELS);148149dx1 = (float)dstx;150dy1 = (float)dsty;151dx2 = dx1 + width;152dy2 = dy1 + height;153154return pCtx->pVCacher->DrawTexture(dx1, dy1, dx2, dy2,155tx1, ty1, tx2, ty2);156}157158159