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 "D3DResourceManager.h"
430N/A#include "awt.h"
430N/A#include "D3DPaints.h"
430N/A#include "D3DTextRenderer.h"
430N/A
430N/Avoid
430N/AD3DResource::Init(IDirect3DResource9 *pRes, IDirect3DSwapChain9 *pSC)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DResource::Init");
430N/A
430N/A pResource = NULL;
430N/A pSwapChain = pSC;
430N/A pSurface = NULL;
430N/A pTexture = NULL;
430N/A pOps = NULL;
430N/A ZeroMemory(&desc, sizeof(desc));
430N/A desc.Format = D3DFMT_UNKNOWN;
430N/A
430N/A if (pRes != NULL) {
430N/A pResource = pRes;
430N/A
430N/A D3DRESOURCETYPE type = pResource->GetType();
430N/A switch (type) {
430N/A case D3DRTYPE_TEXTURE:
430N/A // addRef is needed because both pResource and pTexture will be
430N/A // Release()d, and they point to the same object
430N/A pResource->AddRef();
430N/A pTexture = (IDirect3DTexture9*)pResource;
430N/A pTexture->GetSurfaceLevel(0, &pSurface);
430N/A break;
430N/A case D3DRTYPE_SURFACE:
430N/A pResource->AddRef();
430N/A pSurface = (IDirect3DSurface9*)pResource;
430N/A break;
430N/A case D3DRTYPE_CUBETEXTURE:
430N/A ((IDirect3DCubeTexture9*)pResource)->GetLevelDesc(0, &desc);
430N/A break;
430N/A default:
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " resource type=%d", type);
430N/A }
430N/A } else if (pSwapChain != NULL) {
430N/A pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurface);
430N/A } else {
430N/A J2dTraceLn(J2D_TRACE_VERBOSE, " pResource == pSwapChain == NULL");
430N/A }
430N/A
430N/A if (pSurface != NULL) {
430N/A pSurface->GetDesc(&desc);
430N/A }
430N/A
430N/A SAFE_PRINTLN(pResource);
430N/A SAFE_PRINTLN(pSurface);
430N/A SAFE_PRINTLN(pTexture);
430N/A SAFE_PRINTLN(pSwapChain);
430N/A}
430N/A
430N/AD3DResource::~D3DResource()
430N/A{
430N/A Release();
430N/A}
430N/A
430N/Avoid
430N/AD3DResource::SetSDOps(D3DSDOps *pOps)
430N/A{
430N/A if (pOps != NULL && this->pOps != NULL) {
430N/A // something's wrong, we're overwriting
430N/A // a non-null field (setting it to null is allowed)
430N/A J2dTraceLn2(J2D_TRACE_WARNING,
430N/A "D3DResource::SetSDOps: overwriting "\
430N/A "this->pOps=0x%x with pOps=0x%x", this->pOps, pOps);
430N/A }
430N/A this->pOps = pOps;
430N/A}
430N/A
430N/ABOOL
430N/AD3DResource::IsDefaultPool()
430N/A{
430N/A if (desc.Format != D3DFMT_UNKNOWN) {
430N/A return (desc.Pool == D3DPOOL_DEFAULT);
430N/A }
430N/A return TRUE;
430N/A}
430N/A
430N/Avoid
430N/AD3DResource::Release()
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DResource::Release");
430N/A
430N/A SAFE_PRINTLN(pResource);
430N/A SAFE_PRINTLN(pSurface);
430N/A SAFE_PRINTLN(pTexture);
430N/A SAFE_PRINTLN(pSwapChain);
430N/A
430N/A SAFE_RELEASE(pSurface);
430N/A SAFE_RELEASE(pTexture);
430N/A SAFE_RELEASE(pResource);
430N/A SAFE_RELEASE(pSwapChain);
430N/A
430N/A if (pOps != NULL) {
430N/A // if sdOps is not NULL it means that the release was initiated
430N/A // from the native level, and is caused by a surface loss
430N/A D3DSD_MarkLost(pOps);
430N/A pOps->pResource = NULL;
430N/A pOps = NULL;
430N/A }
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::CreateInstance(D3DContext *pCtx,
430N/A D3DResourceManager** ppResourceMgr)
430N/A{
430N/A HRESULT res;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateInstance");
430N/A
430N/A *ppResourceMgr = new D3DResourceManager();
430N/A if (FAILED(res = (*ppResourceMgr)->Init(pCtx))) {
430N/A delete *ppResourceMgr;
430N/A *ppResourceMgr = NULL;
430N/A }
430N/A return res;
430N/A}
430N/A
430N/AD3DResourceManager::D3DResourceManager()
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::D3DRM");
430N/A
430N/A this->pCtx = NULL;
430N/A this->pHead = NULL;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::Init(D3DContext *pCtx)
430N/A{
430N/A J2dTraceLn1(J2D_TRACE_INFO, "D3DRM::Init pCtx=%x", pCtx);
430N/A if (this->pCtx != pCtx ||
430N/A (this->pCtx != NULL &&
430N/A this->pCtx->Get3DDevice() != pCtx->Get3DDevice()))
430N/A {
430N/A ReleaseAll();
430N/A }
430N/A this->pCtx = pCtx;
430N/A return S_OK;
430N/A}
430N/A
430N/AD3DResourceManager::~D3DResourceManager()
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::~D3DRM");
430N/A ReleaseAll();
430N/A pCtx = NULL;
430N/A pHead = NULL;
430N/A}
430N/A
430N/Avoid
430N/AD3DResourceManager::ReleaseAll()
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseAll");
430N/A IManagedResource* pCurrent;
430N/A while (pHead != NULL) {
430N/A pCurrent = pHead;
430N/A pHead = pHead->pNext;
430N/A delete pCurrent;
430N/A }
430N/A pCachedDestTexture = NULL;
430N/A pBlitTexture = NULL;
430N/A pBlitRTTexture = NULL;
430N/A pBlitOSPSurface = NULL;
430N/A pGradientTexture = NULL;
430N/A pLookupOpLutTexture = NULL;
430N/A pMaskTexture = NULL;
430N/A pMultiGradientTexture = NULL;
430N/A pLockableRTSurface = NULL;
430N/A}
430N/A
430N/Avoid
430N/AD3DResourceManager::ReleaseDefPoolResources()
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseDefPoolResources");
430N/A // REMIND: for now, release all resources
430N/A ReleaseAll();
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::ReleaseResource(IManagedResource* pResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseResource");
430N/A
430N/A if (pResource != NULL) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " releasing pResource=%x", pResource);
430N/A if (pResource->pPrev != NULL) {
430N/A pResource->pPrev->pNext = pResource->pNext;
430N/A } else {
430N/A // it's the head
430N/A pHead = pResource->pNext;
430N/A if (pHead != NULL) {
430N/A pHead->pPrev = NULL;
430N/A }
430N/A }
430N/A if (pResource->pNext != NULL) {
430N/A pResource->pNext->pPrev = pResource->pPrev;
430N/A }
430N/A delete pResource;
430N/A }
430N/A return S_OK;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::AddResource(IManagedResource* pResource)
430N/A{
430N/A HRESULT res = S_OK;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::AddResource");
430N/A
430N/A if (pResource != NULL) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " pResource=%x", pResource);
430N/A pResource->pPrev = NULL;
430N/A pResource->pNext = pHead;
430N/A if (pHead != NULL) {
430N/A pHead->pPrev = pResource;
430N/A }
430N/A pHead = pResource;
430N/A }
430N/A
430N/A return S_OK;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::CreateTexture(UINT width, UINT height,
430N/A BOOL isRTT, BOOL isOpaque,
430N/A D3DFORMAT *pFormat, DWORD dwUsage,
430N/A D3DResource **ppTextureResource)
430N/A{
430N/A D3DPOOL pool;
430N/A D3DFORMAT format;
430N/A HRESULT res;
430N/A IDirect3DDevice9 *pd3dDevice;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateTexture");
430N/A J2dTraceLn4(J2D_TRACE_VERBOSE, " w=%d h=%d isRTT=%d isOpaque=%d",
430N/A width, height, isRTT, isOpaque);
430N/A
430N/A if (ppTextureResource == NULL || pCtx == NULL ||
430N/A (pd3dDevice = pCtx->Get3DDevice()) == NULL)
430N/A {
430N/A return E_FAIL;
430N/A }
430N/A if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
430N/A return res;
430N/A }
430N/A
430N/A if (pFormat != NULL && *pFormat != D3DFMT_UNKNOWN) {
430N/A format = *pFormat;
430N/A } else {
430N/A if (isOpaque) {
430N/A format = D3DFMT_X8R8G8B8;
430N/A } else {
430N/A format = D3DFMT_A8R8G8B8;
430N/A }
430N/A }
430N/A
430N/A if (isRTT) {
430N/A dwUsage = D3DUSAGE_RENDERTARGET;
430N/A pool = D3DPOOL_DEFAULT;
430N/A } else {
430N/A if (dwUsage == D3DUSAGE_DYNAMIC && !pCtx->IsDynamicTextureSupported()) {
430N/A dwUsage = 0;
430N/A }
430N/A if (dwUsage == D3DUSAGE_DYNAMIC) {
430N/A pool = D3DPOOL_DEFAULT;
430N/A } else {
430N/A pool = pCtx->IsHWRasterizer() ?
430N/A D3DPOOL_MANAGED : D3DPOOL_SYSTEMMEM;
430N/A }
430N/A }
430N/A
430N/A if (pCtx->IsPow2TexturesOnly()) {
430N/A UINT w, h;
430N/A for (w = 1; width > w; w <<= 1);
430N/A for (h = 1; height > h; h <<= 1);
430N/A width = w;
430N/A height = h;
430N/A }
430N/A if (pCtx->IsSquareTexturesOnly()) {
430N/A if (width > height) {
430N/A height = width;
430N/A } else {
430N/A width = height;
430N/A }
430N/A }
430N/A
430N/A IDirect3DTexture9 *pTexture = NULL;
430N/A res = pd3dDevice->CreateTexture(width, height, 1/*levels*/, dwUsage,
430N/A format, pool, &pTexture, 0);
430N/A if (SUCCEEDED(res)) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " created texture: 0x%x", pTexture);
430N/A *ppTextureResource = new D3DResource((IDirect3DResource9*)pTexture);
430N/A res = AddResource(*ppTextureResource);
430N/A } else {
430N/A DebugPrintD3DError(res, "D3DRM::CreateTexture failed");
430N/A *ppTextureResource = NULL;
430N/A format = D3DFMT_UNKNOWN;
430N/A }
430N/A
430N/A if (pFormat != NULL) {
430N/A *pFormat = format;
430N/A }
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT D3DResourceManager::CreateRTSurface(UINT width, UINT height,
430N/A BOOL isOpaque, BOOL isLockable,
430N/A D3DFORMAT *pFormat/*out*/,
430N/A D3DResource** ppSurfaceResource/*out*/)
430N/A{
430N/A HRESULT res;
430N/A IDirect3DDevice9 *pd3dDevice;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateRTSurface");
430N/A J2dTraceLn3(J2D_TRACE_VERBOSE, " w=%d h=%d isOpaque=%d",
430N/A width, height, isOpaque);
430N/A
430N/A if (pCtx == NULL || ppSurfaceResource == NULL ||
430N/A (pd3dDevice = pCtx->Get3DDevice()) == NULL)
430N/A {
430N/A return E_FAIL;
430N/A }
430N/A if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
430N/A return res;
430N/A }
430N/A
430N/A D3DPRESENT_PARAMETERS *curParams = pCtx->GetPresentationParams();
430N/A D3DFORMAT format = isOpaque ? curParams->BackBufferFormat : D3DFMT_A8R8G8B8;
430N/A IDirect3DSurface9 *pSurface = NULL;
430N/A
430N/A res = pd3dDevice->CreateRenderTarget(width, height, format,
430N/A D3DMULTISAMPLE_NONE, 0,
430N/A isLockable,
430N/A &pSurface, NULL);
430N/A if (SUCCEEDED(res)) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " created RT Surface: 0x%x ", pSurface);
430N/A if (pFormat != NULL) {
430N/A *pFormat = format;
430N/A }
430N/A *ppSurfaceResource = new D3DResource((IDirect3DResource9*)pSurface);
430N/A res = AddResource(*ppSurfaceResource);
430N/A } else {
430N/A DebugPrintD3DError(res, "D3DRM::CreateRTSurface failed");
430N/A ppSurfaceResource = NULL;
430N/A }
430N/A return res;
430N/A}
430N/A
430N/A// REMIND: this method is currently unused; consider removing it later...
430N/AHRESULT D3DResourceManager::CreateOSPSurface(UINT width, UINT height,
430N/A D3DFORMAT fmt,
430N/A D3DResource** ppSurfaceResource/*out*/)
430N/A{
430N/A HRESULT res;
430N/A IDirect3DDevice9 *pd3dDevice;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateOSPSurface");
430N/A J2dTraceLn2(J2D_TRACE_VERBOSE, " w=%d h=%d", width, height);
430N/A
430N/A if (pCtx == NULL || ppSurfaceResource == NULL ||
430N/A (pd3dDevice = pCtx->Get3DDevice()) == NULL)
430N/A {
430N/A return E_FAIL;
430N/A }
430N/A if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
430N/A return res;
430N/A }
430N/A
430N/A // since the off-screen plain surface is intended to be used with
430N/A // the UpdateSurface() method, it is essential that it be created
430N/A // in the same format as the destination and allocated in the
430N/A // SYSTEMMEM pool (otherwise UpdateSurface() will fail)
430N/A D3DFORMAT format;
430N/A if (fmt == D3DFMT_UNKNOWN) {
430N/A format = pCtx->GetPresentationParams()->BackBufferFormat;
430N/A } else {
430N/A format = fmt;
430N/A }
430N/A D3DPOOL pool = D3DPOOL_SYSTEMMEM;
430N/A IDirect3DSurface9 *pSurface = NULL;
430N/A
430N/A res = pd3dDevice->CreateOffscreenPlainSurface(width, height,
430N/A format, pool,
430N/A &pSurface, NULL);
430N/A if (SUCCEEDED(res)) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE, " created OSP Surface: 0x%x ",pSurface);
430N/A *ppSurfaceResource = new D3DResource((IDirect3DResource9*)pSurface);
430N/A res = AddResource(*ppSurfaceResource);
430N/A } else {
430N/A DebugPrintD3DError(res, "D3DRM::CreateOSPSurface failed");
430N/A ppSurfaceResource = NULL;
430N/A }
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::CreateSwapChain(HWND hWnd, UINT numBuffers,
430N/A UINT width, UINT height,
430N/A D3DSWAPEFFECT swapEffect,
430N/A UINT presentationInterval,
430N/A D3DResource ** ppSwapChainResource)
430N/A{
430N/A HRESULT res;
430N/A IDirect3DDevice9 *pd3dDevice;
430N/A IDirect3DSwapChain9 *pSwapChain = NULL;
430N/A D3DPRESENT_PARAMETERS newParams, *curParams;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateSwapChain");
430N/A J2dTraceLn4(J2D_TRACE_VERBOSE, " w=%d h=%d hwnd=%x numBuffers=%d",
430N/A width, height, hWnd, numBuffers);
430N/A
430N/A if (pCtx == NULL || ppSwapChainResource == NULL ||
430N/A (pd3dDevice = pCtx->Get3DDevice()) == NULL)
430N/A {
430N/A return E_FAIL;
430N/A }
430N/A RETURN_STATUS_IF_FAILED(res = pd3dDevice->TestCooperativeLevel());
430N/A
430N/A curParams = pCtx->GetPresentationParams();
430N/A
430N/A if (curParams->Windowed == FALSE) {
430N/A // there's a single swap chain in full-screen mode, use it if
430N/A // it fits our parameters, reset the device otherwise
430N/A if (curParams->BackBufferCount != numBuffers ||
430N/A curParams->SwapEffect != swapEffect ||
430N/A curParams->PresentationInterval != presentationInterval)
430N/A {
430N/A newParams = *curParams;
430N/A newParams.BackBufferCount = numBuffers;
430N/A newParams.SwapEffect = swapEffect;
430N/A newParams.PresentationInterval = presentationInterval;
430N/A
430N/A res = pCtx->ConfigureContext(&newParams);
430N/A RETURN_STATUS_IF_FAILED(res);
430N/A // this reset will not have released the device, so our pd3dDevice
430N/A // is still valid, but to be on a safe side, reset it
430N/A pd3dDevice = pCtx->Get3DDevice();
430N/A }
430N/A res = pd3dDevice->GetSwapChain(0, &pSwapChain);
430N/A } else {
430N/A ZeroMemory(&newParams, sizeof(D3DPRESENT_PARAMETERS));
430N/A newParams.BackBufferWidth = width;
430N/A newParams.BackBufferHeight = height;
430N/A newParams.hDeviceWindow = hWnd;
430N/A newParams.Windowed = TRUE;
430N/A newParams.BackBufferCount = numBuffers;
430N/A newParams.SwapEffect = swapEffect;
430N/A newParams.PresentationInterval = presentationInterval;
430N/A
430N/A res = pd3dDevice->CreateAdditionalSwapChain(&newParams, &pSwapChain);
430N/A }
430N/A
430N/A if (SUCCEEDED(res)) {
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE," created swap chain: 0x%x ",pSwapChain);
430N/A *ppSwapChainResource = new D3DResource(pSwapChain);
430N/A res = AddResource(*ppSwapChainResource);
430N/A } else {
430N/A DebugPrintD3DError(res, "D3DRM::CreateSwapChain failed");
430N/A *ppSwapChainResource = NULL;
430N/A }
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetMaskTexture(D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetMaskTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A D3DFORMAT format = pCtx->IsTextureFormatSupported(D3DFMT_A8) ?
430N/A D3DFMT_A8 : D3DFMT_A8R8G8B8;
430N/A
430N/A jboolean needsInit = (pMaskTexture == NULL);
430N/A HRESULT res;
430N/A if (FAILED(res =
430N/A GetStockTextureResource(D3D_MASK_CACHE_WIDTH_IN_TEXELS,
430N/A D3D_MASK_CACHE_HEIGHT_IN_TEXELS,
430N/A FALSE/*isRTT*/, FALSE/*isOpaque*/, &format, 0,
430N/A &pMaskTexture)))
430N/A {
430N/A return res;
430N/A }
430N/A
430N/A if (needsInit) {
430N/A // init special fully opaque tile in the upper-right corner of
430N/A // the mask cache texture
430N/A jubyte allOnes[D3D_MASK_CACHE_TILE_SIZE];
430N/A memset(allOnes, 0xff, D3D_MASK_CACHE_TILE_SIZE);
430N/A if (FAILED(res = pCtx->UploadTileToTexture(
430N/A pMaskTexture,
430N/A allOnes,
430N/A D3D_MASK_CACHE_SPECIAL_TILE_X,
430N/A D3D_MASK_CACHE_SPECIAL_TILE_Y,
430N/A 0, 0,
430N/A D3D_MASK_CACHE_TILE_WIDTH,
430N/A D3D_MASK_CACHE_TILE_HEIGHT,
430N/A D3D_MASK_CACHE_TILE_WIDTH,
430N/A TILEFMT_1BYTE_ALPHA)))
430N/A {
430N/A return res;
430N/A }
430N/A }
430N/A
430N/A *ppTextureResource = pMaskTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetBlitTexture(D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A HRESULT res =
430N/A GetStockTextureResource(D3DC_BLIT_TILE_SIZE, D3DC_BLIT_TILE_SIZE,
430N/A FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL,
430N/A D3DUSAGE_DYNAMIC,
430N/A &pBlitTexture);
430N/A *ppTextureResource = pBlitTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetGradientTexture(D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetGradientTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A HRESULT res =
430N/A GetStockTextureResource(2, 1,
430N/A FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL, 0,
430N/A &pGradientTexture);
430N/A *ppTextureResource = pGradientTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetMultiGradientTexture(D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetMultiGradientTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A HRESULT res =
430N/A GetStockTextureResource(MAX_MULTI_GRADIENT_COLORS, 1,
430N/A FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL, 0,
430N/A &pMultiGradientTexture);
430N/A *ppTextureResource = pMultiGradientTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetLookupOpLutTexture(D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetLookupOpTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A D3DFORMAT format = D3DFMT_L16;
430N/A HRESULT res =
430N/A GetStockTextureResource(256, 4,
430N/A FALSE/*isRTT*/, FALSE/*isOpaque*/, &format, 0,
430N/A &pLookupOpLutTexture);
430N/A *ppTextureResource = pLookupOpLutTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetBlitRTTexture(UINT width, UINT height, D3DFORMAT format,
430N/A D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitRTTexture");
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A HRESULT res = GetStockTextureResource(width, height,
430N/A TRUE/*isRTT*/, FALSE/*isOpaque*/,
430N/A &format, 0,
430N/A &pBlitRTTexture);
430N/A if (SUCCEEDED(res)) {
430N/A D3DSURFACE_DESC *pDesc = pBlitRTTexture->GetDesc();
430N/A D3DCAPS9 *pDevCaps = pCtx->GetDeviceCaps();
430N/A if ((width <= pDesc->Width && height <= pDesc->Height) &&
430N/A (format == pDesc->Format ||
430N/A SUCCEEDED(pCtx->Get3DObject()->CheckDeviceFormatConversion(
430N/A pDevCaps->AdapterOrdinal,
430N/A pDevCaps->DeviceType, format, pDesc->Format))))
430N/A {
430N/A *ppTextureResource = pBlitRTTexture;
430N/A return res;
430N/A }
430N/A // current texture doesn't fit, release and allocate a new one
430N/A ReleaseResource(pBlitRTTexture);
430N/A pBlitRTTexture = NULL;
430N/A }
430N/A if (width < D3DC_BLIT_TILE_SIZE) width = D3DC_BLIT_TILE_SIZE;
430N/A if (height < D3DC_BLIT_TILE_SIZE) height = D3DC_BLIT_TILE_SIZE;
430N/A
430N/A res = CreateTexture(width, height, TRUE, FALSE, &format, 0,&pBlitRTTexture);
430N/A *ppTextureResource = pBlitRTTexture;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetBlitOSPSurface(UINT width, UINT height, D3DFORMAT fmt,
430N/A D3DResource **ppSurfaceResource)
430N/A{
430N/A HRESULT res = S_OK;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitOSPSurface");
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppSurfaceResource, E_FAIL);
430N/A
430N/A if (pBlitOSPSurface != NULL) {
430N/A D3DSURFACE_DESC *pDesc = pBlitOSPSurface->GetDesc();
430N/A if (width == pDesc->Width && height == pDesc->Height &&
430N/A (fmt == pDesc->Format || fmt == D3DFMT_UNKNOWN))
430N/A {
430N/A *ppSurfaceResource = pBlitOSPSurface;
430N/A return res;
430N/A }
430N/A // current surface doesn't fit, release and allocate a new one
430N/A ReleaseResource(pBlitOSPSurface);
430N/A pBlitOSPSurface = NULL;
430N/A }
430N/A
430N/A res = CreateOSPSurface(width, height, fmt, &pBlitOSPSurface);
430N/A *ppSurfaceResource = pBlitOSPSurface;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetLockableRTSurface(UINT width, UINT height,
430N/A D3DFORMAT format,
430N/A D3DResource **ppSurfaceResource)
430N/A{
430N/A HRESULT res = S_OK;
430N/A
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetLockableRTSurface");
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppSurfaceResource, E_FAIL);
430N/A
430N/A if (pLockableRTSurface != NULL) {
430N/A D3DSURFACE_DESC *pDesc = pLockableRTSurface->GetDesc();
430N/A if (width <= pDesc->Width && height <= pDesc->Height &&
430N/A format == pDesc->Format)
430N/A {
430N/A *ppSurfaceResource = pLockableRTSurface;
430N/A return res;
430N/A }
430N/A // current surface doesn't fit, release and allocate a new one
430N/A ReleaseResource(pLockableRTSurface);
430N/A pLockableRTSurface = NULL;
430N/A }
430N/A if (width < D3DC_BLIT_TILE_SIZE) width = D3DC_BLIT_TILE_SIZE;
430N/A if (height < D3DC_BLIT_TILE_SIZE) height = D3DC_BLIT_TILE_SIZE;
430N/A
430N/A res = CreateRTSurface(width,height,
430N/A (format != D3DFMT_A8R8G8B8), TRUE /*lockable*/,
430N/A &format, &pLockableRTSurface);
430N/A *ppSurfaceResource = pLockableRTSurface;
430N/A
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetCachedDestTexture(D3DFORMAT format,
430N/A D3DResource **ppTextureResource)
430N/A{
430N/A J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetCachedDestTexture");
430N/A
430N/A RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
430N/A RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
430N/A
430N/A HRESULT res =
430N/A GetStockTextureResource(D3DTR_CACHED_DEST_WIDTH,
430N/A D3DTR_CACHED_DEST_HEIGHT,
430N/A TRUE/*isRTT*/, FALSE/*isOpaque*/,
430N/A &format, 0, &pCachedDestTexture);
430N/A if (SUCCEEDED(res)) {
430N/A D3DSURFACE_DESC *pDesc = pCachedDestTexture->GetDesc();
430N/A D3DCAPS9 *pDevCaps = pCtx->GetDeviceCaps();
430N/A if ((format == pDesc->Format ||
430N/A SUCCEEDED(pCtx->Get3DObject()->CheckDeviceFormatConversion(
430N/A pDevCaps->AdapterOrdinal,
430N/A pDevCaps->DeviceType, format, pDesc->Format))))
430N/A {
430N/A *ppTextureResource = pCachedDestTexture;
430N/A return res;
430N/A }
430N/A // current texture doesn't fit, release and allocate a new one
430N/A ReleaseResource(pCachedDestTexture);
430N/A pCachedDestTexture = NULL;
430N/A }
430N/A res = CreateTexture(D3DTR_CACHED_DEST_WIDTH, D3DTR_CACHED_DEST_HEIGHT,
430N/A TRUE, FALSE, &format, 0,
430N/A &pCachedDestTexture);
430N/A *ppTextureResource = pCachedDestTexture;
430N/A return res;
430N/A}
430N/A
430N/AHRESULT
430N/AD3DResourceManager::GetStockTextureResource(UINT width, UINT height,
430N/A BOOL isRTT, BOOL isOpaque,
430N/A D3DFORMAT *pFormat/*in/out*/,
430N/A DWORD dwUsage,
430N/A D3DResource **ppTextureResource)
430N/A{
430N/A D3DResource *pResource = *ppTextureResource;
430N/A if (pResource != NULL) {
430N/A if (pResource->GetTexture() != NULL) {
430N/A return S_OK;
430N/A }
430N/A ReleaseResource(pResource);
430N/A *ppTextureResource = NULL;
430N/A }
430N/A
430N/A return CreateTexture(width, height, isRTT, isOpaque, pFormat, dwUsage,
430N/A ppTextureResource);
430N/A}