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.cpp
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
#include "D3DResourceManager.h"
27
#include "awt.h"
28
#include "D3DPaints.h"
29
#include "D3DTextRenderer.h"
30
31
void
32
D3DResource::Init(IDirect3DResource9 *pRes, IDirect3DSwapChain9 *pSC)
33
{
34
J2dTraceLn(J2D_TRACE_INFO, "D3DResource::Init");
35
36
pResource = NULL;
37
pSwapChain = pSC;
38
pSurface = NULL;
39
pTexture = NULL;
40
pOps = NULL;
41
ZeroMemory(&desc, sizeof(desc));
42
desc.Format = D3DFMT_UNKNOWN;
43
44
if (pRes != NULL) {
45
pResource = pRes;
46
47
D3DRESOURCETYPE type = pResource->GetType();
48
switch (type) {
49
case D3DRTYPE_TEXTURE:
50
// addRef is needed because both pResource and pTexture will be
51
// Release()d, and they point to the same object
52
pResource->AddRef();
53
pTexture = (IDirect3DTexture9*)pResource;
54
pTexture->GetSurfaceLevel(0, &pSurface);
55
break;
56
case D3DRTYPE_SURFACE:
57
pResource->AddRef();
58
pSurface = (IDirect3DSurface9*)pResource;
59
break;
60
case D3DRTYPE_CUBETEXTURE:
61
((IDirect3DCubeTexture9*)pResource)->GetLevelDesc(0, &desc);
62
break;
63
default:
64
J2dTraceLn1(J2D_TRACE_VERBOSE, " resource type=%d", type);
65
}
66
} else if (pSwapChain != NULL) {
67
pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurface);
68
} else {
69
J2dTraceLn(J2D_TRACE_VERBOSE, " pResource == pSwapChain == NULL");
70
}
71
72
if (pSurface != NULL) {
73
pSurface->GetDesc(&desc);
74
}
75
76
SAFE_PRINTLN(pResource);
77
SAFE_PRINTLN(pSurface);
78
SAFE_PRINTLN(pTexture);
79
SAFE_PRINTLN(pSwapChain);
80
}
81
82
D3DResource::~D3DResource()
83
{
84
Release();
85
}
86
87
void
88
D3DResource::SetSDOps(D3DSDOps *pOps)
89
{
90
if (pOps != NULL && this->pOps != NULL) {
91
// something's wrong, we're overwriting
92
// a non-null field (setting it to null is allowed)
93
J2dTraceLn2(J2D_TRACE_WARNING,
94
"D3DResource::SetSDOps: overwriting "\
95
"this->pOps=0x%x with pOps=0x%x", this->pOps, pOps);
96
}
97
this->pOps = pOps;
98
}
99
100
BOOL
101
D3DResource::IsDefaultPool()
102
{
103
if (desc.Format != D3DFMT_UNKNOWN) {
104
return (desc.Pool == D3DPOOL_DEFAULT);
105
}
106
return TRUE;
107
}
108
109
void
110
D3DResource::Release()
111
{
112
J2dTraceLn(J2D_TRACE_INFO, "D3DResource::Release");
113
114
SAFE_PRINTLN(pResource);
115
SAFE_PRINTLN(pSurface);
116
SAFE_PRINTLN(pTexture);
117
SAFE_PRINTLN(pSwapChain);
118
119
SAFE_RELEASE(pSurface);
120
SAFE_RELEASE(pTexture);
121
SAFE_RELEASE(pResource);
122
SAFE_RELEASE(pSwapChain);
123
124
if (pOps != NULL) {
125
// if sdOps is not NULL it means that the release was initiated
126
// from the native level, and is caused by a surface loss
127
D3DSD_MarkLost(pOps);
128
pOps->pResource = NULL;
129
pOps = NULL;
130
}
131
}
132
133
HRESULT
134
D3DResourceManager::CreateInstance(D3DContext *pCtx,
135
D3DResourceManager** ppResourceMgr)
136
{
137
HRESULT res;
138
139
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateInstance");
140
141
*ppResourceMgr = new D3DResourceManager();
142
if (FAILED(res = (*ppResourceMgr)->Init(pCtx))) {
143
delete *ppResourceMgr;
144
*ppResourceMgr = NULL;
145
}
146
return res;
147
}
148
149
D3DResourceManager::D3DResourceManager()
150
{
151
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::D3DRM");
152
153
this->pCtx = NULL;
154
this->pHead = NULL;
155
}
156
157
HRESULT
158
D3DResourceManager::Init(D3DContext *pCtx)
159
{
160
J2dTraceLn1(J2D_TRACE_INFO, "D3DRM::Init pCtx=%x", pCtx);
161
if (this->pCtx != pCtx ||
162
(this->pCtx != NULL &&
163
this->pCtx->Get3DDevice() != pCtx->Get3DDevice()))
164
{
165
ReleaseAll();
166
}
167
this->pCtx = pCtx;
168
return S_OK;
169
}
170
171
D3DResourceManager::~D3DResourceManager()
172
{
173
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::~D3DRM");
174
ReleaseAll();
175
pCtx = NULL;
176
pHead = NULL;
177
}
178
179
void
180
D3DResourceManager::ReleaseAll()
181
{
182
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseAll");
183
IManagedResource* pCurrent;
184
while (pHead != NULL) {
185
pCurrent = pHead;
186
pHead = pHead->pNext;
187
delete pCurrent;
188
}
189
pCachedDestTexture = NULL;
190
pBlitTexture = NULL;
191
pBlitRTTexture = NULL;
192
pBlitOSPSurface = NULL;
193
pGradientTexture = NULL;
194
pLookupOpLutTexture = NULL;
195
pMaskTexture = NULL;
196
pMultiGradientTexture = NULL;
197
pLockableRTSurface = NULL;
198
}
199
200
void
201
D3DResourceManager::ReleaseDefPoolResources()
202
{
203
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseDefPoolResources");
204
// REMIND: for now, release all resources
205
ReleaseAll();
206
}
207
208
HRESULT
209
D3DResourceManager::ReleaseResource(IManagedResource* pResource)
210
{
211
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::ReleaseResource");
212
213
if (pResource != NULL) {
214
J2dTraceLn1(J2D_TRACE_VERBOSE, " releasing pResource=%x", pResource);
215
if (pResource->pPrev != NULL) {
216
pResource->pPrev->pNext = pResource->pNext;
217
} else {
218
// it's the head
219
pHead = pResource->pNext;
220
if (pHead != NULL) {
221
pHead->pPrev = NULL;
222
}
223
}
224
if (pResource->pNext != NULL) {
225
pResource->pNext->pPrev = pResource->pPrev;
226
}
227
delete pResource;
228
}
229
return S_OK;
230
}
231
232
HRESULT
233
D3DResourceManager::AddResource(IManagedResource* pResource)
234
{
235
HRESULT res = S_OK;
236
237
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::AddResource");
238
239
if (pResource != NULL) {
240
J2dTraceLn1(J2D_TRACE_VERBOSE, " pResource=%x", pResource);
241
pResource->pPrev = NULL;
242
pResource->pNext = pHead;
243
if (pHead != NULL) {
244
pHead->pPrev = pResource;
245
}
246
pHead = pResource;
247
}
248
249
return S_OK;
250
}
251
252
HRESULT
253
D3DResourceManager::CreateTexture(UINT width, UINT height,
254
BOOL isRTT, BOOL isOpaque,
255
D3DFORMAT *pFormat, DWORD dwUsage,
256
D3DResource **ppTextureResource)
257
{
258
D3DPOOL pool;
259
D3DFORMAT format;
260
HRESULT res;
261
IDirect3DDevice9 *pd3dDevice;
262
263
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateTexture");
264
J2dTraceLn4(J2D_TRACE_VERBOSE, " w=%d h=%d isRTT=%d isOpaque=%d",
265
width, height, isRTT, isOpaque);
266
267
if (ppTextureResource == NULL || pCtx == NULL ||
268
(pd3dDevice = pCtx->Get3DDevice()) == NULL)
269
{
270
return E_FAIL;
271
}
272
if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
273
return res;
274
}
275
276
if (pFormat != NULL && *pFormat != D3DFMT_UNKNOWN) {
277
format = *pFormat;
278
} else {
279
if (isOpaque) {
280
format = D3DFMT_X8R8G8B8;
281
} else {
282
format = D3DFMT_A8R8G8B8;
283
}
284
}
285
286
if (isRTT) {
287
dwUsage = D3DUSAGE_RENDERTARGET;
288
pool = D3DPOOL_DEFAULT;
289
} else {
290
if (dwUsage == D3DUSAGE_DYNAMIC && !pCtx->IsDynamicTextureSupported()) {
291
dwUsage = 0;
292
}
293
if (dwUsage == D3DUSAGE_DYNAMIC) {
294
pool = D3DPOOL_DEFAULT;
295
} else {
296
pool = pCtx->IsHWRasterizer() ?
297
D3DPOOL_MANAGED : D3DPOOL_SYSTEMMEM;
298
}
299
}
300
301
if (pCtx->IsPow2TexturesOnly()) {
302
UINT w, h;
303
for (w = 1; width > w; w <<= 1);
304
for (h = 1; height > h; h <<= 1);
305
width = w;
306
height = h;
307
}
308
if (pCtx->IsSquareTexturesOnly()) {
309
if (width > height) {
310
height = width;
311
} else {
312
width = height;
313
}
314
}
315
316
IDirect3DTexture9 *pTexture = NULL;
317
res = pd3dDevice->CreateTexture(width, height, 1/*levels*/, dwUsage,
318
format, pool, &pTexture, 0);
319
if (SUCCEEDED(res)) {
320
J2dTraceLn1(J2D_TRACE_VERBOSE, " created texture: 0x%x", pTexture);
321
*ppTextureResource = new D3DResource((IDirect3DResource9*)pTexture);
322
res = AddResource(*ppTextureResource);
323
} else {
324
DebugPrintD3DError(res, "D3DRM::CreateTexture failed");
325
*ppTextureResource = NULL;
326
format = D3DFMT_UNKNOWN;
327
}
328
329
if (pFormat != NULL) {
330
*pFormat = format;
331
}
332
333
return res;
334
}
335
336
HRESULT D3DResourceManager::CreateRTSurface(UINT width, UINT height,
337
BOOL isOpaque, BOOL isLockable,
338
D3DFORMAT *pFormat/*out*/,
339
D3DResource** ppSurfaceResource/*out*/)
340
{
341
HRESULT res;
342
IDirect3DDevice9 *pd3dDevice;
343
344
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateRTSurface");
345
J2dTraceLn3(J2D_TRACE_VERBOSE, " w=%d h=%d isOpaque=%d",
346
width, height, isOpaque);
347
348
if (pCtx == NULL || ppSurfaceResource == NULL ||
349
(pd3dDevice = pCtx->Get3DDevice()) == NULL)
350
{
351
return E_FAIL;
352
}
353
if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
354
return res;
355
}
356
357
D3DPRESENT_PARAMETERS *curParams = pCtx->GetPresentationParams();
358
D3DFORMAT format = isOpaque ? curParams->BackBufferFormat : D3DFMT_A8R8G8B8;
359
IDirect3DSurface9 *pSurface = NULL;
360
361
res = pd3dDevice->CreateRenderTarget(width, height, format,
362
D3DMULTISAMPLE_NONE, 0,
363
isLockable,
364
&pSurface, NULL);
365
if (SUCCEEDED(res)) {
366
J2dTraceLn1(J2D_TRACE_VERBOSE, " created RT Surface: 0x%x ", pSurface);
367
if (pFormat != NULL) {
368
*pFormat = format;
369
}
370
*ppSurfaceResource = new D3DResource((IDirect3DResource9*)pSurface);
371
res = AddResource(*ppSurfaceResource);
372
} else {
373
DebugPrintD3DError(res, "D3DRM::CreateRTSurface failed");
374
ppSurfaceResource = NULL;
375
}
376
return res;
377
}
378
379
// REMIND: this method is currently unused; consider removing it later...
380
HRESULT D3DResourceManager::CreateOSPSurface(UINT width, UINT height,
381
D3DFORMAT fmt,
382
D3DResource** ppSurfaceResource/*out*/)
383
{
384
HRESULT res;
385
IDirect3DDevice9 *pd3dDevice;
386
387
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateOSPSurface");
388
J2dTraceLn2(J2D_TRACE_VERBOSE, " w=%d h=%d", width, height);
389
390
if (pCtx == NULL || ppSurfaceResource == NULL ||
391
(pd3dDevice = pCtx->Get3DDevice()) == NULL)
392
{
393
return E_FAIL;
394
}
395
if (FAILED(res = pd3dDevice->TestCooperativeLevel())) {
396
return res;
397
}
398
399
// since the off-screen plain surface is intended to be used with
400
// the UpdateSurface() method, it is essential that it be created
401
// in the same format as the destination and allocated in the
402
// SYSTEMMEM pool (otherwise UpdateSurface() will fail)
403
D3DFORMAT format;
404
if (fmt == D3DFMT_UNKNOWN) {
405
format = pCtx->GetPresentationParams()->BackBufferFormat;
406
} else {
407
format = fmt;
408
}
409
D3DPOOL pool = D3DPOOL_SYSTEMMEM;
410
IDirect3DSurface9 *pSurface = NULL;
411
412
res = pd3dDevice->CreateOffscreenPlainSurface(width, height,
413
format, pool,
414
&pSurface, NULL);
415
if (SUCCEEDED(res)) {
416
J2dTraceLn1(J2D_TRACE_VERBOSE, " created OSP Surface: 0x%x ",pSurface);
417
*ppSurfaceResource = new D3DResource((IDirect3DResource9*)pSurface);
418
res = AddResource(*ppSurfaceResource);
419
} else {
420
DebugPrintD3DError(res, "D3DRM::CreateOSPSurface failed");
421
ppSurfaceResource = NULL;
422
}
423
return res;
424
}
425
426
HRESULT
427
D3DResourceManager::CreateSwapChain(HWND hWnd, UINT numBuffers,
428
UINT width, UINT height,
429
D3DSWAPEFFECT swapEffect,
430
UINT presentationInterval,
431
D3DResource ** ppSwapChainResource)
432
{
433
HRESULT res;
434
IDirect3DDevice9 *pd3dDevice;
435
IDirect3DSwapChain9 *pSwapChain = NULL;
436
D3DPRESENT_PARAMETERS newParams, *curParams;
437
438
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::CreateSwapChain");
439
J2dTraceLn4(J2D_TRACE_VERBOSE, " w=%d h=%d hwnd=%x numBuffers=%d",
440
width, height, hWnd, numBuffers);
441
442
if (pCtx == NULL || ppSwapChainResource == NULL ||
443
(pd3dDevice = pCtx->Get3DDevice()) == NULL)
444
{
445
return E_FAIL;
446
}
447
RETURN_STATUS_IF_FAILED(res = pd3dDevice->TestCooperativeLevel());
448
449
curParams = pCtx->GetPresentationParams();
450
451
if (curParams->Windowed == FALSE) {
452
// there's a single swap chain in full-screen mode, use it if
453
// it fits our parameters, reset the device otherwise
454
if (curParams->BackBufferCount != numBuffers ||
455
curParams->SwapEffect != swapEffect ||
456
curParams->PresentationInterval != presentationInterval)
457
{
458
newParams = *curParams;
459
newParams.BackBufferCount = numBuffers;
460
newParams.SwapEffect = swapEffect;
461
newParams.PresentationInterval = presentationInterval;
462
463
res = pCtx->ConfigureContext(&newParams);
464
RETURN_STATUS_IF_FAILED(res);
465
// this reset will not have released the device, so our pd3dDevice
466
// is still valid, but to be on a safe side, reset it
467
pd3dDevice = pCtx->Get3DDevice();
468
}
469
res = pd3dDevice->GetSwapChain(0, &pSwapChain);
470
} else {
471
ZeroMemory(&newParams, sizeof(D3DPRESENT_PARAMETERS));
472
newParams.BackBufferWidth = width;
473
newParams.BackBufferHeight = height;
474
newParams.hDeviceWindow = hWnd;
475
newParams.Windowed = TRUE;
476
newParams.BackBufferCount = numBuffers;
477
newParams.SwapEffect = swapEffect;
478
newParams.PresentationInterval = presentationInterval;
479
480
res = pd3dDevice->CreateAdditionalSwapChain(&newParams, &pSwapChain);
481
}
482
483
if (SUCCEEDED(res)) {
484
J2dTraceLn1(J2D_TRACE_VERBOSE," created swap chain: 0x%x ",pSwapChain);
485
*ppSwapChainResource = new D3DResource(pSwapChain);
486
res = AddResource(*ppSwapChainResource);
487
} else {
488
DebugPrintD3DError(res, "D3DRM::CreateSwapChain failed");
489
*ppSwapChainResource = NULL;
490
}
491
return res;
492
}
493
494
HRESULT
495
D3DResourceManager::GetMaskTexture(D3DResource **ppTextureResource)
496
{
497
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetMaskTexture");
498
499
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
500
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
501
502
D3DFORMAT format = pCtx->IsTextureFormatSupported(D3DFMT_A8) ?
503
D3DFMT_A8 : D3DFMT_A8R8G8B8;
504
505
jboolean needsInit = (pMaskTexture == NULL);
506
HRESULT res;
507
if (FAILED(res =
508
GetStockTextureResource(D3D_MASK_CACHE_WIDTH_IN_TEXELS,
509
D3D_MASK_CACHE_HEIGHT_IN_TEXELS,
510
FALSE/*isRTT*/, FALSE/*isOpaque*/, &format, 0,
511
&pMaskTexture)))
512
{
513
return res;
514
}
515
516
if (needsInit) {
517
// init special fully opaque tile in the upper-right corner of
518
// the mask cache texture
519
jubyte allOnes[D3D_MASK_CACHE_TILE_SIZE];
520
memset(allOnes, 0xff, D3D_MASK_CACHE_TILE_SIZE);
521
if (FAILED(res = pCtx->UploadTileToTexture(
522
pMaskTexture,
523
allOnes,
524
D3D_MASK_CACHE_SPECIAL_TILE_X,
525
D3D_MASK_CACHE_SPECIAL_TILE_Y,
526
0, 0,
527
D3D_MASK_CACHE_TILE_WIDTH,
528
D3D_MASK_CACHE_TILE_HEIGHT,
529
D3D_MASK_CACHE_TILE_WIDTH,
530
TILEFMT_1BYTE_ALPHA)))
531
{
532
return res;
533
}
534
}
535
536
*ppTextureResource = pMaskTexture;
537
538
return res;
539
}
540
541
HRESULT
542
D3DResourceManager::GetBlitTexture(D3DResource **ppTextureResource)
543
{
544
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitTexture");
545
546
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
547
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
548
549
HRESULT res =
550
GetStockTextureResource(D3DC_BLIT_TILE_SIZE, D3DC_BLIT_TILE_SIZE,
551
FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL,
552
D3DUSAGE_DYNAMIC,
553
&pBlitTexture);
554
*ppTextureResource = pBlitTexture;
555
556
return res;
557
}
558
559
HRESULT
560
D3DResourceManager::GetGradientTexture(D3DResource **ppTextureResource)
561
{
562
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetGradientTexture");
563
564
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
565
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
566
567
HRESULT res =
568
GetStockTextureResource(2, 1,
569
FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL, 0,
570
&pGradientTexture);
571
*ppTextureResource = pGradientTexture;
572
573
return res;
574
}
575
576
HRESULT
577
D3DResourceManager::GetMultiGradientTexture(D3DResource **ppTextureResource)
578
{
579
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetMultiGradientTexture");
580
581
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
582
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
583
584
HRESULT res =
585
GetStockTextureResource(MAX_MULTI_GRADIENT_COLORS, 1,
586
FALSE/*isRTT*/, FALSE/*isOpaque*/, NULL, 0,
587
&pMultiGradientTexture);
588
*ppTextureResource = pMultiGradientTexture;
589
590
return res;
591
}
592
593
HRESULT
594
D3DResourceManager::GetLookupOpLutTexture(D3DResource **ppTextureResource)
595
{
596
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetLookupOpTexture");
597
598
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
599
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
600
601
D3DFORMAT format = D3DFMT_L16;
602
HRESULT res =
603
GetStockTextureResource(256, 4,
604
FALSE/*isRTT*/, FALSE/*isOpaque*/, &format, 0,
605
&pLookupOpLutTexture);
606
*ppTextureResource = pLookupOpLutTexture;
607
608
return res;
609
}
610
611
HRESULT
612
D3DResourceManager::GetBlitRTTexture(UINT width, UINT height, D3DFORMAT format,
613
D3DResource **ppTextureResource)
614
{
615
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitRTTexture");
616
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
617
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
618
619
HRESULT res = GetStockTextureResource(width, height,
620
TRUE/*isRTT*/, FALSE/*isOpaque*/,
621
&format, 0,
622
&pBlitRTTexture);
623
if (SUCCEEDED(res)) {
624
D3DSURFACE_DESC *pDesc = pBlitRTTexture->GetDesc();
625
D3DCAPS9 *pDevCaps = pCtx->GetDeviceCaps();
626
if ((width <= pDesc->Width && height <= pDesc->Height) &&
627
(format == pDesc->Format ||
628
SUCCEEDED(pCtx->Get3DObject()->CheckDeviceFormatConversion(
629
pDevCaps->AdapterOrdinal,
630
pDevCaps->DeviceType, format, pDesc->Format))))
631
{
632
*ppTextureResource = pBlitRTTexture;
633
return res;
634
}
635
// current texture doesn't fit, release and allocate a new one
636
ReleaseResource(pBlitRTTexture);
637
pBlitRTTexture = NULL;
638
}
639
if (width < D3DC_BLIT_TILE_SIZE) width = D3DC_BLIT_TILE_SIZE;
640
if (height < D3DC_BLIT_TILE_SIZE) height = D3DC_BLIT_TILE_SIZE;
641
642
res = CreateTexture(width, height, TRUE, FALSE, &format, 0,&pBlitRTTexture);
643
*ppTextureResource = pBlitRTTexture;
644
645
return res;
646
}
647
648
HRESULT
649
D3DResourceManager::GetBlitOSPSurface(UINT width, UINT height, D3DFORMAT fmt,
650
D3DResource **ppSurfaceResource)
651
{
652
HRESULT res = S_OK;
653
654
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetBlitOSPSurface");
655
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
656
RETURN_STATUS_IF_NULL(ppSurfaceResource, E_FAIL);
657
658
if (pBlitOSPSurface != NULL) {
659
D3DSURFACE_DESC *pDesc = pBlitOSPSurface->GetDesc();
660
if (width == pDesc->Width && height == pDesc->Height &&
661
(fmt == pDesc->Format || fmt == D3DFMT_UNKNOWN))
662
{
663
*ppSurfaceResource = pBlitOSPSurface;
664
return res;
665
}
666
// current surface doesn't fit, release and allocate a new one
667
ReleaseResource(pBlitOSPSurface);
668
pBlitOSPSurface = NULL;
669
}
670
671
res = CreateOSPSurface(width, height, fmt, &pBlitOSPSurface);
672
*ppSurfaceResource = pBlitOSPSurface;
673
674
return res;
675
}
676
677
HRESULT
678
D3DResourceManager::GetLockableRTSurface(UINT width, UINT height,
679
D3DFORMAT format,
680
D3DResource **ppSurfaceResource)
681
{
682
HRESULT res = S_OK;
683
684
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetLockableRTSurface");
685
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
686
RETURN_STATUS_IF_NULL(ppSurfaceResource, E_FAIL);
687
688
if (pLockableRTSurface != NULL) {
689
D3DSURFACE_DESC *pDesc = pLockableRTSurface->GetDesc();
690
if (width <= pDesc->Width && height <= pDesc->Height &&
691
format == pDesc->Format)
692
{
693
*ppSurfaceResource = pLockableRTSurface;
694
return res;
695
}
696
// current surface doesn't fit, release and allocate a new one
697
ReleaseResource(pLockableRTSurface);
698
pLockableRTSurface = NULL;
699
}
700
if (width < D3DC_BLIT_TILE_SIZE) width = D3DC_BLIT_TILE_SIZE;
701
if (height < D3DC_BLIT_TILE_SIZE) height = D3DC_BLIT_TILE_SIZE;
702
703
res = CreateRTSurface(width,height,
704
(format != D3DFMT_A8R8G8B8), TRUE /*lockable*/,
705
&format, &pLockableRTSurface);
706
*ppSurfaceResource = pLockableRTSurface;
707
708
return res;
709
}
710
711
HRESULT
712
D3DResourceManager::GetCachedDestTexture(D3DFORMAT format,
713
D3DResource **ppTextureResource)
714
{
715
J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetCachedDestTexture");
716
717
RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
718
RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);
719
720
HRESULT res =
721
GetStockTextureResource(D3DTR_CACHED_DEST_WIDTH,
722
D3DTR_CACHED_DEST_HEIGHT,
723
TRUE/*isRTT*/, FALSE/*isOpaque*/,
724
&format, 0, &pCachedDestTexture);
725
if (SUCCEEDED(res)) {
726
D3DSURFACE_DESC *pDesc = pCachedDestTexture->GetDesc();
727
D3DCAPS9 *pDevCaps = pCtx->GetDeviceCaps();
728
if ((format == pDesc->Format ||
729
SUCCEEDED(pCtx->Get3DObject()->CheckDeviceFormatConversion(
730
pDevCaps->AdapterOrdinal,
731
pDevCaps->DeviceType, format, pDesc->Format))))
732
{
733
*ppTextureResource = pCachedDestTexture;
734
return res;
735
}
736
// current texture doesn't fit, release and allocate a new one
737
ReleaseResource(pCachedDestTexture);
738
pCachedDestTexture = NULL;
739
}
740
res = CreateTexture(D3DTR_CACHED_DEST_WIDTH, D3DTR_CACHED_DEST_HEIGHT,
741
TRUE, FALSE, &format, 0,
742
&pCachedDestTexture);
743
*ppTextureResource = pCachedDestTexture;
744
return res;
745
}
746
747
HRESULT
748
D3DResourceManager::GetStockTextureResource(UINT width, UINT height,
749
BOOL isRTT, BOOL isOpaque,
750
D3DFORMAT *pFormat/*in/out*/,
751
DWORD dwUsage,
752
D3DResource **ppTextureResource)
753
{
754
D3DResource *pResource = *ppTextureResource;
755
if (pResource != NULL) {
756
if (pResource->GetTexture() != NULL) {
757
return S_OK;
758
}
759
ReleaseResource(pResource);
760
*ppTextureResource = NULL;
761
}
762
763
return CreateTexture(width, height, isRTT, isOpaque, pFormat, dwUsage,
764
ppTextureResource);
765
}
766
767