Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DResourceManager.h
32288 views
1
/*
2
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
27
#ifndef _D3DRESOURCEMANAGER_H_
28
#define _D3DRESOURCEMANAGER_H_
29
30
#include "D3DContext.h"
31
#include "D3DSurfaceData.h"
32
33
class D3DResourceManager;
34
class D3DContext;
35
36
/**
37
* This interface represents a Direct3D resource which is managed by the
38
* D3DResourceManager.
39
*
40
* Subclasses will need to override Release() and the destructor to release
41
* the resources held by the object.
42
*
43
* The subclasses then can be used like this:
44
* class D3DShaderResource : public IManagedResource {
45
* D3DShaderResource(IDirect3DPixelShader9 *pShader) { // ... }
46
* virtual ~D3DShaderResource() { Release(); }
47
* virtual Release() { SAFE_RELEASE(pShader); }
48
* virtual IsDefaultPool() { return FALSE; }
49
* private:
50
* IDirect3DPixelShader9 *pShader;
51
* }
52
*
53
* pD3DDevice->CreatePixelShader(..., &pShader);
54
* IManagedResource *pShaderRes = new D3DShaderResource(pShader);
55
* pCtx->GetResourceManager()->AddResource(pShaderRes);
56
*
57
* D3DResourceManager::ReleaseResource() must be used to dispose of the
58
* resource:
59
* pCtx->GetResourceManager()->ReleaseResource(pShaderRes);
60
* // pShaderRes is now invalid, it was deleted
61
* shaderRes = NULL;
62
*
63
* In certain cases the D3DResourceManager may need to release all its
64
* resources (like when resetting the device), so the subclasses must be
65
* ready to be released at any time, and be able to notify their users.
66
* For an example of how this can be achieved see how D3DSDO's
67
* pResource field and D3DResource subclass. d3dsdo->pResource is reset when
68
* the D3DResource it was pointing to is disposed.
69
*/
70
class IManagedResource {
71
friend class D3DResourceManager;
72
public:
73
// determines whether the resource should be released by the manager
74
// when defaul pool resources are to be released
75
virtual BOOL IsDefaultPool() = 0;
76
protected:
77
IManagedResource() { pPrev = pNext = NULL; };
78
virtual ~IManagedResource() { pPrev = pNext = NULL; };
79
virtual void Release() = 0;
80
private:
81
// prevents accidental bad things like copying the object
82
IManagedResource& operator=(const IManagedResource&);
83
84
IManagedResource* pPrev;
85
IManagedResource* pNext;
86
};
87
88
/**
89
* This class handles either IDirect3DResource9 or IDirect3DSwapChain9
90
* type of resources and provides access to Texture, Surface or SwapChain,
91
* as well as the surface description.
92
*/
93
class D3DResource : public IManagedResource {
94
public:
95
D3DResource(IDirect3DResource9 *pRes)
96
{ Init(pRes, NULL); }
97
D3DResource(IDirect3DSwapChain9 *pSC)
98
{ Init(NULL, pSC); }
99
IDirect3DResource9* GetResource() { return pResource; }
100
IDirect3DTexture9* GetTexture() { return pTexture; }
101
IDirect3DSurface9* GetSurface() { return pSurface; }
102
IDirect3DSwapChain9* GetSwapChain() { return pSwapChain; }
103
D3DSDOps* GetSDOps() { return pOps; }
104
void SetSDOps(D3DSDOps *pOps);
105
D3DSURFACE_DESC* GetDesc() { return &desc; }
106
virtual BOOL IsDefaultPool();
107
108
protected:
109
// these are protected because we want D3DResource to be only released via
110
// ResourceManager
111
virtual ~D3DResource();
112
virtual void Release();
113
void Init(IDirect3DResource9*, IDirect3DSwapChain9*);
114
115
private:
116
// prevents accidental bad things like copying the object
117
D3DResource() {}
118
D3DResource& operator=(const D3DResource&);
119
120
IDirect3DResource9* pResource;
121
IDirect3DSwapChain9* pSwapChain;
122
IDirect3DSurface9* pSurface;
123
IDirect3DTexture9* pTexture;
124
D3DSDOps* pOps;
125
D3DSURFACE_DESC desc;
126
};
127
128
/**
129
* This class maintains a list of d3d resources created by the pipeline or
130
* other clients. It is needed because in some cases all resources have to be
131
* released in order to reset the device so we must keep track of them.
132
*
133
* There is one instance of this class per D3DContext. Clients can either
134
* use factory methods for creating resources or create their own encapsulated
135
* in an IManagedResource interface subclass and add them to the list
136
* using the AddResource() method. Resources added to the list must be released
137
* via the ReleaseResource() method so that they can be stopped being managed.
138
*/
139
class D3DResourceManager {
140
141
public:
142
~D3DResourceManager();
143
HRESULT Init(D3DContext *pCtx);
144
// Releases and deletes all resources managed by this manager.
145
void ReleaseAll();
146
// Releases (and deletes) all resources belonging to the default pool.
147
// Note: this method may release other resources as well.
148
void ReleaseDefPoolResources();
149
150
// Adds the resource to the list managed by this class.
151
HRESULT AddResource(IManagedResource* pResource);
152
// Removes the resource from the list of managed resources, and deletes
153
// it. The argument pointer is invalid after this method returns.
154
HRESULT ReleaseResource(IManagedResource* pResource);
155
156
HRESULT CreateTexture(UINT width, UINT height,
157
BOOL isRTT, BOOL isOpaque,
158
D3DFORMAT *pFormat/*in/out*/,
159
DWORD dwUsage,
160
D3DResource **ppTextureResource/*out*/);
161
162
HRESULT CreateRTSurface(UINT width, UINT height,
163
BOOL isOpaque, BOOL isLockable,
164
D3DFORMAT *pFormat/*in/out*/,
165
D3DResource ** ppSurfaceResource/*out*/);
166
167
HRESULT CreateSwapChain(HWND hWnd, UINT numBuffers, UINT width, UINT height,
168
D3DSWAPEFFECT swapEffect, UINT presentationInterval,
169
D3DResource ** ppSwapChainResource/*out*/);
170
171
HRESULT GetCachedDestTexture(D3DFORMAT format,
172
D3DResource **ppTextureResource);
173
HRESULT GetBlitTexture(D3DResource **ppTextureResource);
174
HRESULT GetBlitRTTexture(UINT width, UINT height, D3DFORMAT format,
175
D3DResource **ppTextureResource);
176
HRESULT GetBlitOSPSurface(UINT width, UINT height, D3DFORMAT fmt,
177
D3DResource **ppSurfaceResource);
178
HRESULT GetMaskTexture(D3DResource **ppTextureResource);
179
HRESULT GetGradientTexture(D3DResource **ppTextureResource);
180
HRESULT GetMultiGradientTexture(D3DResource **ppTextureResource);
181
HRESULT GetLookupOpLutTexture(D3DResource **ppTextureResource);
182
HRESULT GetLockableRTSurface(UINT width, UINT height, D3DFORMAT format,
183
D3DResource **ppSurfaceResource);
184
185
static
186
HRESULT CreateInstance(D3DContext *pCtx, D3DResourceManager **ppResMgr);
187
188
private:
189
D3DResourceManager();
190
HRESULT GetStockTextureResource(UINT width, UINT height,
191
BOOL isRTT, BOOL isOpaque,
192
D3DFORMAT *pFormat/*in/out*/,
193
DWORD dwUsage,
194
D3DResource **ppTextureResource/*out*/);
195
196
HRESULT CreateOSPSurface(UINT width, UINT height,
197
D3DFORMAT fmt,
198
D3DResource ** ppSurfaceResource/*out*/);
199
200
D3DResource* pCachedDestTexture;
201
D3DResource* pBlitTexture;
202
D3DResource* pBlitRTTexture;
203
D3DResource* pBlitOSPSurface;
204
D3DResource* pGradientTexture;
205
D3DResource* pLookupOpLutTexture;
206
D3DResource* pMaskTexture;
207
D3DResource* pMultiGradientTexture;
208
D3DResource* pLockableRTSurface;
209
210
D3DContext* pCtx;
211
212
IManagedResource* pHead;
213
};
214
#endif _D3DRESOURCEMANAGER_H_
215
216