Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: command_buffer/service/win/d3d9/render_surface_d3d9.cc

Issue 176026: C++ Readability (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 15 matching lines...) Expand all
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 32
33 // This file implements the D3D9 versions of the render surface resources, 33 // This file implements the D3D9 versions of the render surface resources,
34 // as well as the related GAPID3D9 function implementations. 34 // as well as the related GAPID3D9 function implementations.
35 35
36 #include "command_buffer/service/win/d3d9/render_surface_d3d9.h"
36 #include "command_buffer/service/win/d3d9/gapi_d3d9.h" 37 #include "command_buffer/service/win/d3d9/gapi_d3d9.h"
37 #include "command_buffer/service/win/d3d9/texture_d3d9.h" 38 #include "command_buffer/service/win/d3d9/texture_d3d9.h"
38 39
39 40
40 namespace o3d { 41 namespace o3d {
41 namespace command_buffer { 42 namespace command_buffer {
42 43
43 RenderSurfaceD3D9::RenderSurfaceD3D9(int width, 44 RenderSurfaceD3D9::RenderSurfaceD3D9(int width,
44 int height, 45 int height,
45 int mip_level, 46 int mip_level,
46 int side, 47 int side,
47 TextureD3D9 *texture, 48 TextureD3D9 *texture,
48 IDirect3DSurface9* direct3d_surface) 49 IDirect3DSurface9 *direct3d_surface)
49 : width_(width), height_(height), mip_level_(mip_level), texture_(texture), 50 : width_(width),
50 direct3d_surface_(direct3d_surface) { 51 height_(height),
52 mip_level_(mip_level),
53 texture_(texture),
54 direct3d_surface_(direct3d_surface) {
55 DCHECK_GT(width, 0);
56 DCHECK_GT(height, 0);
57 DCHECK_GT(mip_level, -1);
58 DCHECK(texture);
51 } 59 }
52 60
53 RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi, 61 RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi,
54 int width, 62 int width,
55 int height, 63 int height,
56 int mip_level, 64 int mip_level,
57 int side, 65 int side,
58 TextureD3D9 *texture) { 66 TextureD3D9 *texture) {
67 DCHECK(gapi);
59 DCHECK_GT(width, 0); 68 DCHECK_GT(width, 0);
60 DCHECK_GT(height, 0); 69 DCHECK_GT(height, 0);
70 DCHECK_GT(mip_level, -1);
71 DCHECK(texture);
61 CComPtr<IDirect3DSurface9> direct3d_surface_handle; 72 CComPtr<IDirect3DSurface9> direct3d_surface_handle;
62 bool success = 73 bool success =
63 texture->CreateRenderSurface(width, height, mip_level, side, 74 texture->CreateRenderSurface(width, height, mip_level, side,
64 &direct3d_surface_handle); 75 &direct3d_surface_handle);
65 if (!success || direct3d_surface_handle == NULL) { 76 if (!success || direct3d_surface_handle == NULL) {
66 // If the surface was not created properly, delete and return nothing. 77 // If the surface was not created properly, delete and return nothing.
67 return NULL; 78 return NULL;
68 } 79 }
69 RenderSurfaceD3D9* render_surface = 80 RenderSurfaceD3D9 *render_surface =
70 new RenderSurfaceD3D9(width, height, mip_level, side, texture, 81 new RenderSurfaceD3D9(width,
71 direct3d_surface_handle); 82 height,
83 mip_level,
84 side,
85 texture,
86 direct3d_surface_handle);
72 return render_surface; 87 return render_surface;
73 } 88 }
74 89
75 RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9( 90 RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9(
76 int width, 91 int width,
77 int height, 92 int height,
78 IDirect3DSurface9* direct3d_surface) 93 IDirect3DSurface9 *direct3d_surface)
79 : width_(width), height_(height), direct3d_surface_(direct3d_surface) { 94 : width_(width),
95 height_(height),
96 direct3d_surface_(direct3d_surface) {
97 DCHECK_GT(width, 0);
98 DCHECK_GT(height, 0);
80 } 99 }
81 100
82 RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create( 101 RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create(
83 GAPID3D9 *gapi, 102 GAPID3D9 *gapi,
84 int width, 103 int width,
85 int height) { 104 int height) {
105 DCHECK(gapi);
86 DCHECK_GT(width, 0); 106 DCHECK_GT(width, 0);
87 DCHECK_GT(height, 0); 107 DCHECK_GT(height, 0);
88 108
89 CComPtr<IDirect3DSurface9> direct3d_surface; 109 CComPtr<IDirect3DSurface9> direct3d_surface;
90 gapi->d3d_device()->CreateDepthStencilSurface( 110 gapi->d3d_device()->CreateDepthStencilSurface(
91 width, 111 width,
92 height, 112 height,
93 D3DFMT_D24S8, 113 D3DFMT_D24S8, // d3d format
94 D3DMULTISAMPLE_NONE, 114 D3DMULTISAMPLE_NONE, // multisampling type
95 0, 115 0, // multisample quality level
96 FALSE, 116 FALSE, // z-buffer discarding disabled
97 &direct3d_surface, 117 &direct3d_surface,
98 NULL); 118 NULL); // This parameter is required to be NULL.
99 if (direct3d_surface == NULL) { 119 if (direct3d_surface == NULL) {
100 return NULL; 120 return NULL;
101 } 121 }
102 RenderDepthStencilSurfaceD3D9* depth_stencil = 122 RenderDepthStencilSurfaceD3D9 *depth_stencil =
103 new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface); 123 new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface);
104 return depth_stencil; 124 return depth_stencil;
105 } 125 }
106 126
127 // GAPI Interface functions ---------------------------------------------------
128
107 // Copies the data from a texture resource. 129 // Copies the data from a texture resource.
108 BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface( 130 BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface(
109 ResourceID id, 131 ResourceID id,
110 unsigned int width, 132 unsigned int width,
111 unsigned int height, 133 unsigned int height,
112 unsigned int mip_level, 134 unsigned int mip_level,
113 unsigned int side, 135 unsigned int side,
114 ResourceID texture_id) { 136 ResourceID texture_id) {
115 if (id == current_surface_id_) { 137 if (id == current_surface_id_) {
116 // This will delete the current surface which would be bad. 138 // This will delete the current surface which would be bad.
117 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 139 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
118 } 140 }
119 TextureD3D9 *texture = textures_.Get(texture_id); 141 TextureD3D9 *texture = textures_.Get(texture_id);
120 if (!texture->render_surfaces_enabled()) { 142 if (!texture->render_surfaces_enabled()) {
121 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 143 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
122 } else { 144 } else {
123 RenderSurfaceD3D9* render_surface = RenderSurfaceD3D9::Create(this, 145 RenderSurfaceD3D9 *render_surface = RenderSurfaceD3D9::Create(this,
124 width, 146 width,
125 height, 147 height,
126 mip_level, 148 mip_level,
127 side, 149 side,
128 texture); 150 texture);
129 if (render_surface == NULL) { 151 if (render_surface == NULL) {
130 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 152 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
131 } 153 }
132 render_surfaces_.Assign(id, render_surface); 154 render_surfaces_.Assign(id, render_surface);
133 } 155 }
134 return BufferSyncInterface::PARSE_NO_ERROR; 156 return BufferSyncInterface::PARSE_NO_ERROR;
135 } 157 }
136 158
137 BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) { 159 BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) {
138 if (id == current_surface_id_) { 160 if (id == current_surface_id_) {
139 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 161 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
140 } 162 }
141 return render_surfaces_.Destroy(id) ? 163 return render_surfaces_.Destroy(id) ?
142 BufferSyncInterface::PARSE_NO_ERROR : 164 BufferSyncInterface::PARSE_NO_ERROR :
143 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 165 BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
144 } 166 }
145 167
146 BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface( 168 BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface(
147 ResourceID id, 169 ResourceID id,
148 unsigned int width, 170 unsigned int width,
149 unsigned int height) { 171 unsigned int height) {
150 if (id == current_depth_surface_id_) { 172 if (id == current_depth_surface_id_) {
151 // This will delete the current surface which would be bad. 173 // This will delete the current surface which would be bad.
152 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 174 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
153 } 175 }
154 RenderDepthStencilSurfaceD3D9* depth_surface = 176 RenderDepthStencilSurfaceD3D9 *depth_surface =
155 RenderDepthStencilSurfaceD3D9::Create(this, width, height); 177 RenderDepthStencilSurfaceD3D9::Create(this, width, height);
156 if (depth_surface == NULL) { 178 if (depth_surface == NULL) {
157 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 179 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
158 } 180 }
159 depth_surfaces_.Assign(id, depth_surface); 181 depth_surfaces_.Assign(id, depth_surface);
160 return BufferSyncInterface::PARSE_NO_ERROR; 182 return BufferSyncInterface::PARSE_NO_ERROR;
161 } 183 }
162 184
163 BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) { 185 BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) {
164 if (id == current_depth_surface_id_) { 186 if (id == current_depth_surface_id_) {
165 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 187 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
166 } 188 }
167 return depth_surfaces_.Destroy(id) ? 189 return depth_surfaces_.Destroy(id) ?
168 BufferSyncInterface::PARSE_NO_ERROR : 190 BufferSyncInterface::PARSE_NO_ERROR :
169 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 191 BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
170 } 192 }
171 193
172 BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface( 194 BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface(
173 ResourceID render_surface_id, 195 ResourceID render_surface_id,
174 ResourceID depth_stencil_id) { 196 ResourceID depth_stencil_id) {
175 RenderSurfaceD3D9 *d3d_render_surface = 197 RenderSurfaceD3D9 *d3d_render_surface =
176 render_surfaces_.Get(render_surface_id); 198 render_surfaces_.Get(render_surface_id);
177 RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface = 199 RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface =
178 depth_surfaces_.Get(depth_stencil_id); 200 depth_surfaces_.Get(depth_stencil_id);
179 201
180 if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) { 202 if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) {
181 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; 203 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
182 } 204 }
183 205
184 IDirect3DSurface9 *d3d_surface = 206 IDirect3DSurface9 *d3d_surface =
185 d3d_render_surface ? d3d_render_surface->GetSurfaceHandle() : NULL; 207 d3d_render_surface ? d3d_render_surface->direct3d_surface() : NULL;
186 IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ? 208 IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ?
187 d3d_render_depth_surface->GetSurfaceHandle() : NULL; 209 d3d_render_depth_surface->direct3d_surface() : NULL;
188 210
189 // Get the device and set the render target and the depth stencil surface. 211 // Get the device and set the render target and the depth stencil surface.
190 IDirect3DDevice9 *device = this->d3d_device(); 212 IDirect3DDevice9 *device = this->d3d_device();
191 213
192 HR(device->SetRenderTarget(0, d3d_surface)); 214 HR(device->SetRenderTarget(0, d3d_surface));
193 HR(device->SetDepthStencilSurface(d3d_depth_surface)); 215 HR(device->SetDepthStencilSurface(d3d_depth_surface));
194 current_surface_id_ = render_surface_id; 216 current_surface_id_ = render_surface_id;
195 current_depth_surface_id_ = depth_stencil_id; 217 current_depth_surface_id_ = depth_stencil_id;
196 return BufferSyncInterface::PARSE_NO_ERROR; 218 return BufferSyncInterface::PARSE_NO_ERROR;
197 } 219 }
198 220
199 void GAPID3D9::SetBackSurfaces() { 221 void GAPID3D9::SetBackSurfaces() {
200 // Get the device and set the render target and the depth stencil surface. 222 // Get the device and set the render target and the depth stencil surface.
201 IDirect3DDevice9 *device = this->d3d_device(); 223 IDirect3DDevice9 *device = this->d3d_device();
202 HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_)); 224 HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_));
203 HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_)); 225 HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_));
204 } 226 }
205 227
206 } // namespace command_buffer 228 } // namespace command_buffer
207 } // namespace o3d 229 } // namespace o3d
208 230
OLDNEW
« no previous file with comments | « command_buffer/service/win/d3d9/render_surface_d3d9.h ('k') | core/cross/command_buffer/render_surface_cb.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698