1 //
2 // Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // RenderTarget9.cpp: Implements a D3D9-specific wrapper for IDirect3DSurface9
8 // pointers retained by renderbuffers.
9
10 #include "libANGLE/renderer/d3d/d3d9/RenderTarget9.h"
11 #include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
12 #include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
13 #include "libANGLE/renderer/d3d/d3d9/SwapChain9.h"
14 #include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
15
16 namespace rx
17 {
18
19 // TODO: AddRef the incoming surface to take ownership instead of expecting that its ref is being given.
TextureRenderTarget9(IDirect3DBaseTexture9 * texture,size_t textureLevel,IDirect3DSurface9 * surface,GLenum internalFormat,GLsizei width,GLsizei height,GLsizei depth,GLsizei samples)20 TextureRenderTarget9::TextureRenderTarget9(IDirect3DBaseTexture9 *texture,
21 size_t textureLevel,
22 IDirect3DSurface9 *surface,
23 GLenum internalFormat,
24 GLsizei width,
25 GLsizei height,
26 GLsizei depth,
27 GLsizei samples)
28 : mWidth(width),
29 mHeight(height),
30 mDepth(depth),
31 mInternalFormat(internalFormat),
32 mD3DFormat(D3DFMT_UNKNOWN),
33 mSamples(samples),
34 mTexture(texture),
35 mTextureLevel(textureLevel),
36 mRenderTarget(surface)
37 {
38 ASSERT(mDepth == 1);
39
40 if (mRenderTarget)
41 {
42 D3DSURFACE_DESC description;
43 mRenderTarget->GetDesc(&description);
44 mD3DFormat = description.Format;
45 }
46 }
47
~TextureRenderTarget9()48 TextureRenderTarget9::~TextureRenderTarget9()
49 {
50 SafeRelease(mTexture);
51 SafeRelease(mRenderTarget);
52 }
53
getWidth() const54 GLsizei TextureRenderTarget9::getWidth() const
55 {
56 return mWidth;
57 }
58
getHeight() const59 GLsizei TextureRenderTarget9::getHeight() const
60 {
61 return mHeight;
62 }
63
getDepth() const64 GLsizei TextureRenderTarget9::getDepth() const
65 {
66 return mDepth;
67 }
68
getInternalFormat() const69 GLenum TextureRenderTarget9::getInternalFormat() const
70 {
71 return mInternalFormat;
72 }
73
getSamples() const74 GLsizei TextureRenderTarget9::getSamples() const
75 {
76 return mSamples;
77 }
78
getTexture() const79 IDirect3DBaseTexture9 *TextureRenderTarget9::getTexture() const
80 {
81 return mTexture;
82 }
83
getTextureLevel() const84 size_t TextureRenderTarget9::getTextureLevel() const
85 {
86 return mTextureLevel;
87 }
88
getSurface() const89 IDirect3DSurface9 *TextureRenderTarget9::getSurface() const
90 {
91 // Caller is responsible for releasing the returned surface reference.
92 // TODO: remove the AddRef to match RenderTarget11
93 if (mRenderTarget)
94 {
95 mRenderTarget->AddRef();
96 }
97
98 return mRenderTarget;
99 }
100
getD3DFormat() const101 D3DFORMAT TextureRenderTarget9::getD3DFormat() const
102 {
103 return mD3DFormat;
104 }
105
SurfaceRenderTarget9(SwapChain9 * swapChain,bool depth)106 SurfaceRenderTarget9::SurfaceRenderTarget9(SwapChain9 *swapChain, bool depth)
107 : mSwapChain(swapChain),
108 mDepth(depth)
109 {
110 }
111
~SurfaceRenderTarget9()112 SurfaceRenderTarget9::~SurfaceRenderTarget9()
113 {
114 }
115
getWidth() const116 GLsizei SurfaceRenderTarget9::getWidth() const
117 {
118 return mSwapChain->getWidth();
119 }
120
getHeight() const121 GLsizei SurfaceRenderTarget9::getHeight() const
122 {
123 return mSwapChain->getHeight();
124 }
125
getDepth() const126 GLsizei SurfaceRenderTarget9::getDepth() const
127 {
128 return 1;
129 }
130
getInternalFormat() const131 GLenum SurfaceRenderTarget9::getInternalFormat() const
132 {
133 return (mDepth ? mSwapChain->getDepthBufferInternalFormat()
134 : mSwapChain->getRenderTargetInternalFormat());
135 }
136
getSamples() const137 GLsizei SurfaceRenderTarget9::getSamples() const
138 {
139 // Our EGL surfaces do not support multisampling.
140 return 0;
141 }
142
getSurface() const143 IDirect3DSurface9 *SurfaceRenderTarget9::getSurface() const
144 {
145 return (mDepth ? mSwapChain->getDepthStencil() : mSwapChain->getRenderTarget());
146 }
147
getTexture() const148 IDirect3DBaseTexture9 *SurfaceRenderTarget9::getTexture() const
149 {
150 return (mDepth ? nullptr : mSwapChain->getOffscreenTexture());
151 }
152
getTextureLevel() const153 size_t SurfaceRenderTarget9::getTextureLevel() const
154 {
155 return 0;
156 }
157
getD3DFormat() const158 D3DFORMAT SurfaceRenderTarget9::getD3DFormat() const
159 {
160 return d3d9::GetTextureFormatInfo(getInternalFormat()).texFormat;
161 }
162
163 }
164