Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DResourceManager.h
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*/242526#ifndef _D3DRESOURCEMANAGER_H_27#define _D3DRESOURCEMANAGER_H_2829#include "D3DContext.h"30#include "D3DSurfaceData.h"3132class D3DResourceManager;33class D3DContext;3435/**36* This interface represents a Direct3D resource which is managed by the37* D3DResourceManager.38*39* Subclasses will need to override Release() and the destructor to release40* the resources held by the object.41*42* The subclasses then can be used like this:43* class D3DShaderResource : public IManagedResource {44* D3DShaderResource(IDirect3DPixelShader9 *pShader) { // ... }45* virtual ~D3DShaderResource() { Release(); }46* virtual Release() { SAFE_RELEASE(pShader); }47* virtual IsDefaultPool() { return FALSE; }48* private:49* IDirect3DPixelShader9 *pShader;50* }51*52* pD3DDevice->CreatePixelShader(..., &pShader);53* IManagedResource *pShaderRes = new D3DShaderResource(pShader);54* pCtx->GetResourceManager()->AddResource(pShaderRes);55*56* D3DResourceManager::ReleaseResource() must be used to dispose of the57* resource:58* pCtx->GetResourceManager()->ReleaseResource(pShaderRes);59* // pShaderRes is now invalid, it was deleted60* shaderRes = NULL;61*62* In certain cases the D3DResourceManager may need to release all its63* resources (like when resetting the device), so the subclasses must be64* ready to be released at any time, and be able to notify their users.65* For an example of how this can be achieved see how D3DSDO's66* pResource field and D3DResource subclass. d3dsdo->pResource is reset when67* the D3DResource it was pointing to is disposed.68*/69class IManagedResource {70friend class D3DResourceManager;71public:72// determines whether the resource should be released by the manager73// when defaul pool resources are to be released74virtual BOOL IsDefaultPool() = 0;75protected:76IManagedResource() { pPrev = pNext = NULL; };77virtual ~IManagedResource() { pPrev = pNext = NULL; };78virtual void Release() = 0;79private:80// prevents accidental bad things like copying the object81IManagedResource& operator=(const IManagedResource&);8283IManagedResource* pPrev;84IManagedResource* pNext;85};8687/**88* This class handles either IDirect3DResource9 or IDirect3DSwapChain989* type of resources and provides access to Texture, Surface or SwapChain,90* as well as the surface description.91*/92class D3DResource : public IManagedResource {93public:94D3DResource(IDirect3DResource9 *pRes)95{ Init(pRes, NULL); }96D3DResource(IDirect3DSwapChain9 *pSC)97{ Init(NULL, pSC); }98IDirect3DResource9* GetResource() { return pResource; }99IDirect3DTexture9* GetTexture() { return pTexture; }100IDirect3DSurface9* GetSurface() { return pSurface; }101IDirect3DSwapChain9* GetSwapChain() { return pSwapChain; }102D3DSDOps* GetSDOps() { return pOps; }103void SetSDOps(D3DSDOps *pOps);104D3DSURFACE_DESC* GetDesc() { return &desc; }105virtual BOOL IsDefaultPool();106107protected:108// these are protected because we want D3DResource to be only released via109// ResourceManager110virtual ~D3DResource();111virtual void Release();112void Init(IDirect3DResource9*, IDirect3DSwapChain9*);113114private:115// prevents accidental bad things like copying the object116D3DResource() {}117D3DResource& operator=(const D3DResource&);118119IDirect3DResource9* pResource;120IDirect3DSwapChain9* pSwapChain;121IDirect3DSurface9* pSurface;122IDirect3DTexture9* pTexture;123D3DSDOps* pOps;124D3DSURFACE_DESC desc;125};126127/**128* This class maintains a list of d3d resources created by the pipeline or129* other clients. It is needed because in some cases all resources have to be130* released in order to reset the device so we must keep track of them.131*132* There is one instance of this class per D3DContext. Clients can either133* use factory methods for creating resources or create their own encapsulated134* in an IManagedResource interface subclass and add them to the list135* using the AddResource() method. Resources added to the list must be released136* via the ReleaseResource() method so that they can be stopped being managed.137*/138class D3DResourceManager {139140public:141~D3DResourceManager();142HRESULT Init(D3DContext *pCtx);143// Releases and deletes all resources managed by this manager.144void ReleaseAll();145// Releases (and deletes) all resources belonging to the default pool.146// Note: this method may release other resources as well.147void ReleaseDefPoolResources();148149// Adds the resource to the list managed by this class.150HRESULT AddResource(IManagedResource* pResource);151// Removes the resource from the list of managed resources, and deletes152// it. The argument pointer is invalid after this method returns.153HRESULT ReleaseResource(IManagedResource* pResource);154155HRESULT CreateTexture(UINT width, UINT height,156BOOL isRTT, BOOL isOpaque,157D3DFORMAT *pFormat/*in/out*/,158DWORD dwUsage,159D3DResource **ppTextureResource/*out*/);160161HRESULT CreateRTSurface(UINT width, UINT height,162BOOL isOpaque, BOOL isLockable,163D3DFORMAT *pFormat/*in/out*/,164D3DResource ** ppSurfaceResource/*out*/);165166HRESULT CreateSwapChain(HWND hWnd, UINT numBuffers, UINT width, UINT height,167D3DSWAPEFFECT swapEffect, UINT presentationInterval,168D3DResource ** ppSwapChainResource/*out*/);169170HRESULT GetCachedDestTexture(D3DFORMAT format,171D3DResource **ppTextureResource);172HRESULT GetBlitTexture(D3DResource **ppTextureResource);173HRESULT GetBlitRTTexture(UINT width, UINT height, D3DFORMAT format,174D3DResource **ppTextureResource);175HRESULT GetBlitOSPSurface(UINT width, UINT height, D3DFORMAT fmt,176D3DResource **ppSurfaceResource);177HRESULT GetMaskTexture(D3DResource **ppTextureResource);178HRESULT GetGradientTexture(D3DResource **ppTextureResource);179HRESULT GetMultiGradientTexture(D3DResource **ppTextureResource);180HRESULT GetLookupOpLutTexture(D3DResource **ppTextureResource);181HRESULT GetLockableRTSurface(UINT width, UINT height, D3DFORMAT format,182D3DResource **ppSurfaceResource);183184static185HRESULT CreateInstance(D3DContext *pCtx, D3DResourceManager **ppResMgr);186187private:188D3DResourceManager();189HRESULT GetStockTextureResource(UINT width, UINT height,190BOOL isRTT, BOOL isOpaque,191D3DFORMAT *pFormat/*in/out*/,192DWORD dwUsage,193D3DResource **ppTextureResource/*out*/);194195HRESULT CreateOSPSurface(UINT width, UINT height,196D3DFORMAT fmt,197D3DResource ** ppSurfaceResource/*out*/);198199D3DResource* pCachedDestTexture;200D3DResource* pBlitTexture;201D3DResource* pBlitRTTexture;202D3DResource* pBlitOSPSurface;203D3DResource* pGradientTexture;204D3DResource* pLookupOpLutTexture;205D3DResource* pMaskTexture;206D3DResource* pMultiGradientTexture;207D3DResource* pLockableRTSurface;208209D3DContext* pCtx;210211IManagedResource* pHead;212};213#endif _D3DRESOURCEMANAGER_H_214215216