OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 // This class contains the implementation of the GAPI decoder class, decoding | 33 // This class contains the implementation of the GAPI decoder class, decoding |
34 // GAPI commands into calls to a GAPIInterface class. | 34 // GAPI commands into calls to a GAPIInterface class. |
35 | 35 |
36 #include "base/cross/bits.h" | 36 #include "base/cross/bits.h" |
37 #include "command_buffer/common/cross/gapi_interface.h" | 37 #include "command_buffer/common/cross/gapi_interface.h" |
38 #include "command_buffer/service/cross/gapi_decoder.h" | 38 #include "command_buffer/service/cross/gapi_decoder.h" |
39 #include "command_buffer/service/cross/cmd_buffer_engine.h" | 39 #include "command_buffer/service/cross/cmd_buffer_engine.h" |
40 | 40 |
41 namespace o3d { | 41 namespace o3d { |
42 namespace command_buffer { | 42 namespace command_buffer { |
| 43 namespace o3d { |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 // Returns the address of the first byte after a struct. | 47 // Returns the address of the first byte after a struct. |
47 template <typename T> | 48 template <typename T> |
48 const void* AddressAfterStruct(const T& pod) { | 49 const void* AddressAfterStruct(const T& pod) { |
49 return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); | 50 return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
50 } | 51 } |
51 | 52 |
52 // Returns the size in bytes of the data of an Immediate command, a command with | 53 // Returns the size in bytes of the data of an Immediate command, a command with |
53 // its data inline in the command buffer. | 54 // its data inline in the command buffer. |
54 template <typename T> | 55 template <typename T> |
55 unsigned int ImmediateDataSize(uint32 arg_count, const T& pod) { | 56 unsigned int ImmediateDataSize(uint32 arg_count, const T& pod) { |
56 return static_cast<unsigned int>( | 57 return static_cast<unsigned int>( |
57 (arg_count + 1 - ComputeNumEntries(sizeof(pod))) * | 58 (arg_count + 1 - ComputeNumEntries(sizeof(pod))) * |
58 sizeof(CommandBufferEntry)); // NOLINT | 59 sizeof(CommandBufferEntry)); // NOLINT |
59 } | 60 } |
60 | 61 |
61 // A struct to hold info about each command. | 62 // A struct to hold info about each command. |
62 struct CommandInfo { | 63 struct CommandInfo { |
63 int arg_flags; // How to handle the arguments for this command | 64 int arg_flags; // How to handle the arguments for this command |
64 int arg_count; // How many arguments are expected for this command. | 65 int arg_count; // How many arguments are expected for this command. |
65 }; | 66 }; |
66 | 67 |
67 // A table of CommandInfo for all the commands. | 68 // A table of CommandInfo for all the commands. |
68 const CommandInfo g_command_info[] = { | 69 const CommandInfo g_command_info[] = { |
69 #define O3D_COMMAND_BUFFER_CMD_OP(name) { \ | 70 #define O3D_COMMAND_BUFFER_CMD_OP(name) { \ |
70 cmd::name::kArgFlags, \ | 71 name::kArgFlags, \ |
71 sizeof(cmd::name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ | 72 sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ |
72 | 73 |
73 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) | 74 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) |
74 | 75 |
75 #undef O3D_COMMAND_BUFFER_CMD_OP | 76 #undef O3D_COMMAND_BUFFER_CMD_OP |
76 }; | 77 }; |
77 | 78 |
78 } // anonymous namespace. | 79 } // anonymous namespace. |
79 | 80 |
80 // Decode command with its arguments, and call the corresponding GAPIInterface | 81 // Decode command with its arguments, and call the corresponding GAPIInterface |
81 // method. | 82 // method. |
82 // Note: args is a pointer to the command buffer. As such, it could be changed | 83 // Note: args is a pointer to the command buffer. As such, it could be changed |
83 // by a (malicious) client at any time, so if validation has to happen, it | 84 // by a (malicious) client at any time, so if validation has to happen, it |
84 // should operate on a copy of them. | 85 // should operate on a copy of them. |
85 parse_error::ParseError GAPIDecoder::DoCommand( | 86 parse_error::ParseError GAPIDecoder::DoCommand( |
86 unsigned int command, | 87 unsigned int command, |
87 unsigned int arg_count, | 88 unsigned int arg_count, |
88 const void* cmd_data) { | 89 const void* cmd_data) { |
89 if (command < arraysize(g_command_info)) { | 90 if (command < arraysize(g_command_info)) { |
90 const CommandInfo& info = g_command_info[command]; | 91 const CommandInfo& info = g_command_info[command]; |
91 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); | 92 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
92 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || | 93 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
93 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { | 94 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
94 switch (command) { | 95 switch (command) { |
95 #define O3D_COMMAND_BUFFER_CMD_OP(name) \ | 96 #define O3D_COMMAND_BUFFER_CMD_OP(name) \ |
96 case cmd::name::kCmdId: \ | 97 case name::kCmdId: \ |
97 return Handle ## name( \ | 98 return Handle ## name( \ |
98 arg_count, \ | 99 arg_count, \ |
99 *static_cast<const cmd::name*>(cmd_data)); \ | 100 *static_cast<const name*>(cmd_data)); \ |
100 | 101 |
101 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) | 102 O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) |
102 | 103 |
103 #undef O3D_COMMAND_BUFFER_CMD_OP | 104 #undef O3D_COMMAND_BUFFER_CMD_OP |
104 } | 105 } |
105 } else { | 106 } else { |
106 return parse_error::kParseInvalidArguments; | 107 return parse_error::kParseInvalidArguments; |
107 } | 108 } |
108 } | 109 } |
109 return parse_error::kParseUnknownCommand; | 110 return parse_error::kParseUnknownCommand; |
110 } | 111 } |
111 | 112 |
112 void *GAPIDecoder::GetAddressAndCheckSize(unsigned int shm_id, | 113 void *GAPIDecoder::GetAddressAndCheckSize(unsigned int shm_id, |
113 unsigned int offset, | 114 unsigned int offset, |
114 unsigned int size) { | 115 unsigned int size) { |
115 void * shm_addr = engine_->GetSharedMemoryAddress(shm_id); | 116 void * shm_addr = engine_->GetSharedMemoryAddress(shm_id); |
116 if (!shm_addr) return NULL; | 117 if (!shm_addr) return NULL; |
117 size_t shm_size = engine_->GetSharedMemorySize(shm_id); | 118 size_t shm_size = engine_->GetSharedMemorySize(shm_id); |
118 if (offset + size > shm_size) return NULL; | 119 if (offset + size > shm_size) return NULL; |
119 return static_cast<char *>(shm_addr) + offset; | 120 return static_cast<char *>(shm_addr) + offset; |
120 } | 121 } |
121 | 122 |
122 parse_error::ParseError GAPIDecoder::HandleNoop( | 123 parse_error::ParseError GAPIDecoder::HandleNoop( |
123 uint32 arg_count, | 124 uint32 arg_count, |
124 const cmd::Noop& args) { | 125 const Noop& args) { |
125 return parse_error::kParseNoError; | 126 return parse_error::kParseNoError; |
126 } | 127 } |
127 | 128 |
128 parse_error::ParseError GAPIDecoder::HandleSetToken( | 129 parse_error::ParseError GAPIDecoder::HandleSetToken( |
129 uint32 arg_count, | 130 uint32 arg_count, |
130 const cmd::SetToken& args) { | 131 const SetToken& args) { |
131 engine_->set_token(args.token); | 132 engine_->set_token(args.token); |
132 return parse_error::kParseNoError; | 133 return parse_error::kParseNoError; |
133 } | 134 } |
134 | 135 |
135 parse_error::ParseError GAPIDecoder::HandleBeginFrame( | 136 parse_error::ParseError GAPIDecoder::HandleBeginFrame( |
136 uint32 arg_count, | 137 uint32 arg_count, |
137 const cmd::BeginFrame& args) { | 138 const BeginFrame& args) { |
138 gapi_->BeginFrame(); | 139 gapi_->BeginFrame(); |
139 return parse_error::kParseNoError; | 140 return parse_error::kParseNoError; |
140 } | 141 } |
141 | 142 |
142 parse_error::ParseError GAPIDecoder::HandleEndFrame( | 143 parse_error::ParseError GAPIDecoder::HandleEndFrame( |
143 uint32 arg_count, | 144 uint32 arg_count, |
144 const cmd::EndFrame& args) { | 145 const EndFrame& args) { |
145 gapi_->EndFrame(); | 146 gapi_->EndFrame(); |
146 return parse_error::kParseNoError; | 147 return parse_error::kParseNoError; |
147 } | 148 } |
148 | 149 |
149 parse_error::ParseError GAPIDecoder::HandleClear( | 150 parse_error::ParseError GAPIDecoder::HandleClear( |
150 uint32 arg_count, | 151 uint32 arg_count, |
151 const cmd::Clear& args) { | 152 const Clear& args) { |
152 // Pull out some values so they can't be changed by another thread after we've | 153 // Pull out some values so they can't be changed by another thread after we've |
153 // validated them. | 154 // validated them. |
154 uint32 buffers = args.buffers; | 155 uint32 buffers = args.buffers; |
155 if (buffers & ~command_buffer::kAllBuffers) | 156 if (buffers & ~kAllBuffers) |
156 return parse_error::kParseInvalidArguments; | 157 return parse_error::kParseInvalidArguments; |
157 RGBA rgba; | 158 RGBA rgba; |
158 rgba.red = args.red; | 159 rgba.red = args.red; |
159 rgba.green = args.green; | 160 rgba.green = args.green; |
160 rgba.blue = args.blue; | 161 rgba.blue = args.blue; |
161 rgba.alpha = args.alpha; | 162 rgba.alpha = args.alpha; |
162 gapi_->Clear(buffers, rgba, args.depth, args.stencil); | 163 gapi_->Clear(buffers, rgba, args.depth, args.stencil); |
163 return parse_error::kParseNoError; | 164 return parse_error::kParseNoError; |
164 } | 165 } |
165 | 166 |
166 parse_error::ParseError GAPIDecoder::HandleSetViewport( | 167 parse_error::ParseError GAPIDecoder::HandleSetViewport( |
167 uint32 arg_count, | 168 uint32 arg_count, |
168 const cmd::SetViewport& args) { | 169 const SetViewport& args) { |
169 gapi_->SetViewport(args.left, | 170 gapi_->SetViewport(args.left, |
170 args.top, | 171 args.top, |
171 args.width, | 172 args.width, |
172 args.height, | 173 args.height, |
173 args.z_min, | 174 args.z_min, |
174 args.z_max); | 175 args.z_max); |
175 return parse_error::kParseNoError; | 176 return parse_error::kParseNoError; |
176 } | 177 } |
177 | 178 |
178 parse_error::ParseError GAPIDecoder::HandleCreateVertexBuffer( | 179 parse_error::ParseError GAPIDecoder::HandleCreateVertexBuffer( |
179 uint32 arg_count, | 180 uint32 arg_count, |
180 const cmd::CreateVertexBuffer& args) { | 181 const CreateVertexBuffer& args) { |
181 return gapi_->CreateVertexBuffer( | 182 return gapi_->CreateVertexBuffer( |
182 args.vertex_buffer_id, args.size, args.flags); | 183 args.vertex_buffer_id, args.size, args.flags); |
183 } | 184 } |
184 | 185 |
185 parse_error::ParseError GAPIDecoder::HandleDestroyVertexBuffer( | 186 parse_error::ParseError GAPIDecoder::HandleDestroyVertexBuffer( |
186 uint32 arg_count, | 187 uint32 arg_count, |
187 const cmd::DestroyVertexBuffer& args) { | 188 const DestroyVertexBuffer& args) { |
188 return gapi_->DestroyVertexBuffer(args.vertex_buffer_id); | 189 return gapi_->DestroyVertexBuffer(args.vertex_buffer_id); |
189 } | 190 } |
190 | 191 |
191 parse_error::ParseError GAPIDecoder::HandleSetVertexBufferDataImmediate( | 192 parse_error::ParseError GAPIDecoder::HandleSetVertexBufferDataImmediate( |
192 uint32 arg_count, | 193 uint32 arg_count, |
193 const cmd::SetVertexBufferDataImmediate& args) { | 194 const SetVertexBufferDataImmediate& args) { |
194 uint32 size = ImmediateDataSize(arg_count, args); | 195 uint32 size = ImmediateDataSize(arg_count, args); |
195 if (size == 0) { | 196 if (size == 0) { |
196 return parse_error::kParseNoError; | 197 return parse_error::kParseNoError; |
197 } | 198 } |
198 return gapi_->SetVertexBufferData(args.vertex_buffer_id, args.offset, | 199 return gapi_->SetVertexBufferData(args.vertex_buffer_id, args.offset, |
199 size, | 200 size, |
200 AddressAfterStruct(args)); | 201 AddressAfterStruct(args)); |
201 } | 202 } |
202 | 203 |
203 parse_error::ParseError GAPIDecoder::HandleSetVertexBufferData( | 204 parse_error::ParseError GAPIDecoder::HandleSetVertexBufferData( |
204 uint32 arg_count, | 205 uint32 arg_count, |
205 const cmd::SetVertexBufferData& args) { | 206 const SetVertexBufferData& args) { |
206 // Pull out some values so they can't be changed by another thread after we've | 207 // Pull out some values so they can't be changed by another thread after we've |
207 // validated them. | 208 // validated them. |
208 uint32 size = args.size; | 209 uint32 size = args.size; |
209 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 210 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
210 args.shared_memory.offset, | 211 args.shared_memory.offset, |
211 size); | 212 size); |
212 if (!data) return parse_error::kParseInvalidArguments; | 213 if (!data) return parse_error::kParseInvalidArguments; |
213 return gapi_->SetVertexBufferData( | 214 return gapi_->SetVertexBufferData( |
214 args.vertex_buffer_id, args.offset, size, data); | 215 args.vertex_buffer_id, args.offset, size, data); |
215 } | 216 } |
216 | 217 |
217 parse_error::ParseError GAPIDecoder::HandleGetVertexBufferData( | 218 parse_error::ParseError GAPIDecoder::HandleGetVertexBufferData( |
218 uint32 arg_count, | 219 uint32 arg_count, |
219 const cmd::GetVertexBufferData& args) { | 220 const GetVertexBufferData& args) { |
220 // Pull out some values so they can't be changed by another thread after we've | 221 // Pull out some values so they can't be changed by another thread after we've |
221 // validated them. | 222 // validated them. |
222 uint32 size = args.size; | 223 uint32 size = args.size; |
223 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 224 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
224 args.shared_memory.offset, | 225 args.shared_memory.offset, |
225 size); | 226 size); |
226 if (!data) return parse_error::kParseInvalidArguments; | 227 if (!data) return parse_error::kParseInvalidArguments; |
227 return gapi_->GetVertexBufferData( | 228 return gapi_->GetVertexBufferData( |
228 args.vertex_buffer_id, args.offset, size, data); | 229 args.vertex_buffer_id, args.offset, size, data); |
229 } | 230 } |
230 | 231 |
231 parse_error::ParseError GAPIDecoder::HandleCreateIndexBuffer( | 232 parse_error::ParseError GAPIDecoder::HandleCreateIndexBuffer( |
232 uint32 arg_count, | 233 uint32 arg_count, |
233 const cmd::CreateIndexBuffer& args) { | 234 const CreateIndexBuffer& args) { |
234 return gapi_->CreateIndexBuffer(args.index_buffer_id, args.size, args.flags); | 235 return gapi_->CreateIndexBuffer(args.index_buffer_id, args.size, args.flags); |
235 } | 236 } |
236 | 237 |
237 parse_error::ParseError GAPIDecoder::HandleDestroyIndexBuffer( | 238 parse_error::ParseError GAPIDecoder::HandleDestroyIndexBuffer( |
238 uint32 arg_count, | 239 uint32 arg_count, |
239 const cmd::DestroyIndexBuffer& args) { | 240 const DestroyIndexBuffer& args) { |
240 return gapi_->DestroyIndexBuffer(args.index_buffer_id); | 241 return gapi_->DestroyIndexBuffer(args.index_buffer_id); |
241 } | 242 } |
242 | 243 |
243 parse_error::ParseError GAPIDecoder::HandleSetIndexBufferDataImmediate( | 244 parse_error::ParseError GAPIDecoder::HandleSetIndexBufferDataImmediate( |
244 uint32 arg_count, | 245 uint32 arg_count, |
245 const cmd::SetIndexBufferDataImmediate& args) { | 246 const SetIndexBufferDataImmediate& args) { |
246 uint32 size = ImmediateDataSize(arg_count, args); | 247 uint32 size = ImmediateDataSize(arg_count, args); |
247 if (size == 0) { | 248 if (size == 0) { |
248 return parse_error::kParseNoError; | 249 return parse_error::kParseNoError; |
249 } | 250 } |
250 return gapi_->SetIndexBufferData(args.index_buffer_id, args.offset, size, | 251 return gapi_->SetIndexBufferData(args.index_buffer_id, args.offset, size, |
251 AddressAfterStruct(args)); | 252 AddressAfterStruct(args)); |
252 } | 253 } |
253 | 254 |
254 parse_error::ParseError GAPIDecoder::HandleSetIndexBufferData( | 255 parse_error::ParseError GAPIDecoder::HandleSetIndexBufferData( |
255 uint32 arg_count, | 256 uint32 arg_count, |
256 const cmd::SetIndexBufferData& args) { | 257 const SetIndexBufferData& args) { |
257 // Pull out some values so they can't be changed by another thread after we've | 258 // Pull out some values so they can't be changed by another thread after we've |
258 // validated them. | 259 // validated them. |
259 uint32 size = args.size; | 260 uint32 size = args.size; |
260 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 261 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
261 args.shared_memory.offset, | 262 args.shared_memory.offset, |
262 size); | 263 size); |
263 if (!data) return parse_error::kParseInvalidArguments; | 264 if (!data) return parse_error::kParseInvalidArguments; |
264 return gapi_->SetIndexBufferData( | 265 return gapi_->SetIndexBufferData( |
265 args.index_buffer_id, args.offset, size, data); | 266 args.index_buffer_id, args.offset, size, data); |
266 } | 267 } |
267 | 268 |
268 parse_error::ParseError GAPIDecoder::HandleGetIndexBufferData( | 269 parse_error::ParseError GAPIDecoder::HandleGetIndexBufferData( |
269 uint32 arg_count, | 270 uint32 arg_count, |
270 const cmd::GetIndexBufferData& args) { | 271 const GetIndexBufferData& args) { |
271 // Pull out some values so they can't be changed by another thread after we've | 272 // Pull out some values so they can't be changed by another thread after we've |
272 // validated them. | 273 // validated them. |
273 uint32 size = args.size; | 274 uint32 size = args.size; |
274 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 275 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
275 args.shared_memory.offset, | 276 args.shared_memory.offset, |
276 size); | 277 size); |
277 if (!data) return parse_error::kParseInvalidArguments; | 278 if (!data) return parse_error::kParseInvalidArguments; |
278 return gapi_->GetIndexBufferData( | 279 return gapi_->GetIndexBufferData( |
279 args.index_buffer_id, args.offset, size, data); | 280 args.index_buffer_id, args.offset, size, data); |
280 } | 281 } |
281 | 282 |
282 parse_error::ParseError GAPIDecoder::HandleCreateVertexStruct( | 283 parse_error::ParseError GAPIDecoder::HandleCreateVertexStruct( |
283 uint32 arg_count, | 284 uint32 arg_count, |
284 const cmd::CreateVertexStruct& args) { | 285 const CreateVertexStruct& args) { |
285 return gapi_->CreateVertexStruct(args.vertex_struct_id, args.input_count); | 286 return gapi_->CreateVertexStruct(args.vertex_struct_id, args.input_count); |
286 } | 287 } |
287 | 288 |
288 parse_error::ParseError GAPIDecoder::HandleDestroyVertexStruct( | 289 parse_error::ParseError GAPIDecoder::HandleDestroyVertexStruct( |
289 uint32 arg_count, | 290 uint32 arg_count, |
290 const cmd::DestroyVertexStruct& args) { | 291 const DestroyVertexStruct& args) { |
291 return gapi_->DestroyVertexStruct(args.vertex_struct_id); | 292 return gapi_->DestroyVertexStruct(args.vertex_struct_id); |
292 } | 293 } |
293 | 294 |
294 parse_error::ParseError GAPIDecoder::HandleSetVertexInput( | 295 parse_error::ParseError GAPIDecoder::HandleSetVertexInput( |
295 uint32 arg_count, | 296 uint32 arg_count, |
296 const cmd::SetVertexInput& args) { | 297 const SetVertexInput& args) { |
297 unsigned int type_stride_semantic = args.type_stride_semantic; | 298 unsigned int type_stride_semantic = args.type_stride_semantic; |
298 unsigned int semantic_index = | 299 unsigned int semantic_index = |
299 cmd::SetVertexInput::SemanticIndex::Get(type_stride_semantic); | 300 SetVertexInput::SemanticIndex::Get(type_stride_semantic); |
300 unsigned int semantic = | 301 unsigned int semantic = |
301 cmd::SetVertexInput::Semantic::Get(type_stride_semantic); | 302 SetVertexInput::Semantic::Get(type_stride_semantic); |
302 unsigned int type = | 303 unsigned int type = |
303 cmd::SetVertexInput::Type::Get(type_stride_semantic); | 304 SetVertexInput::Type::Get(type_stride_semantic); |
304 unsigned int stride = | 305 unsigned int stride = |
305 cmd::SetVertexInput::Stride::Get(type_stride_semantic); | 306 SetVertexInput::Stride::Get(type_stride_semantic); |
306 if (semantic >= vertex_struct::kNumSemantics || | 307 if (semantic >= vertex_struct::kNumSemantics || |
307 type >= vertex_struct::kNumTypes || stride == 0) | 308 type >= vertex_struct::kNumTypes || stride == 0) |
308 return parse_error::kParseInvalidArguments; | 309 return parse_error::kParseInvalidArguments; |
309 return gapi_->SetVertexInput( | 310 return gapi_->SetVertexInput( |
310 args.vertex_struct_id, args.input_index, args.vertex_buffer_id, | 311 args.vertex_struct_id, args.input_index, args.vertex_buffer_id, |
311 args.offset, stride, | 312 args.offset, stride, |
312 static_cast<vertex_struct::Type>(type), | 313 static_cast<vertex_struct::Type>(type), |
313 static_cast<vertex_struct::Semantic>(semantic), | 314 static_cast<vertex_struct::Semantic>(semantic), |
314 semantic_index); | 315 semantic_index); |
315 } | 316 } |
316 | 317 |
317 parse_error::ParseError GAPIDecoder::HandleSetVertexStruct( | 318 parse_error::ParseError GAPIDecoder::HandleSetVertexStruct( |
318 uint32 arg_count, | 319 uint32 arg_count, |
319 const cmd::SetVertexStruct& args) { | 320 const SetVertexStruct& args) { |
320 return gapi_->SetVertexStruct(args.vertex_struct_id); | 321 return gapi_->SetVertexStruct(args.vertex_struct_id); |
321 } | 322 } |
322 | 323 |
323 parse_error::ParseError GAPIDecoder::HandleDraw( | 324 parse_error::ParseError GAPIDecoder::HandleDraw( |
324 uint32 arg_count, | 325 uint32 arg_count, |
325 const cmd::Draw& args) { | 326 const Draw& args) { |
326 // Pull out some values so they can't be changed by another thread after we've | 327 // Pull out some values so they can't be changed by another thread after we've |
327 // validated them. | 328 // validated them. |
328 uint32 primitive_type = args.primitive_type; | 329 uint32 primitive_type = args.primitive_type; |
329 if (primitive_type >= command_buffer::kMaxPrimitiveType) | 330 if (primitive_type >= kMaxPrimitiveType) |
330 return parse_error::kParseInvalidArguments; | 331 return parse_error::kParseInvalidArguments; |
331 return gapi_->Draw( | 332 return gapi_->Draw( |
332 static_cast<command_buffer::PrimitiveType>(primitive_type), | 333 static_cast<PrimitiveType>(primitive_type), |
333 args.first, args.count); | 334 args.first, args.count); |
334 } | 335 } |
335 | 336 |
336 parse_error::ParseError GAPIDecoder::HandleDrawIndexed( | 337 parse_error::ParseError GAPIDecoder::HandleDrawIndexed( |
337 uint32 arg_count, | 338 uint32 arg_count, |
338 const cmd::DrawIndexed& args) { | 339 const DrawIndexed& args) { |
339 // Pull out some values so they can't be changed by another thread after we've | 340 // Pull out some values so they can't be changed by another thread after we've |
340 // validated them. | 341 // validated them. |
341 uint32 primitive_type = args.primitive_type; | 342 uint32 primitive_type = args.primitive_type; |
342 if (primitive_type >= command_buffer::kMaxPrimitiveType) | 343 if (primitive_type >= kMaxPrimitiveType) |
343 return parse_error::kParseInvalidArguments; | 344 return parse_error::kParseInvalidArguments; |
344 return gapi_->DrawIndexed( | 345 return gapi_->DrawIndexed( |
345 static_cast<command_buffer::PrimitiveType>(primitive_type), | 346 static_cast<PrimitiveType>(primitive_type), |
346 args.index_buffer_id, | 347 args.index_buffer_id, |
347 args.first, args.count, args.min_index, args.max_index); | 348 args.first, args.count, args.min_index, args.max_index); |
348 } | 349 } |
349 | 350 |
350 parse_error::ParseError GAPIDecoder::HandleCreateEffect( | 351 parse_error::ParseError GAPIDecoder::HandleCreateEffect( |
351 uint32 arg_count, | 352 uint32 arg_count, |
352 const cmd::CreateEffect& args) { | 353 const CreateEffect& args) { |
353 // Pull out some values so they can't be changed by another thread after we've | 354 // Pull out some values so they can't be changed by another thread after we've |
354 // validated them. | 355 // validated them. |
355 uint32 size = args.size; | 356 uint32 size = args.size; |
356 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 357 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
357 args.shared_memory.offset, | 358 args.shared_memory.offset, |
358 size); | 359 size); |
359 if (!data) return parse_error::kParseInvalidArguments; | 360 if (!data) return parse_error::kParseInvalidArguments; |
360 return gapi_->CreateEffect(args.effect_id, size, data); | 361 return gapi_->CreateEffect(args.effect_id, size, data); |
361 } | 362 } |
362 | 363 |
363 parse_error::ParseError GAPIDecoder::HandleCreateEffectImmediate( | 364 parse_error::ParseError GAPIDecoder::HandleCreateEffectImmediate( |
364 uint32 arg_count, | 365 uint32 arg_count, |
365 const cmd::CreateEffectImmediate& args) { | 366 const CreateEffectImmediate& args) { |
366 // Pull out some values so they can't be changed by another thread after we've | 367 // Pull out some values so they can't be changed by another thread after we've |
367 // validated them. | 368 // validated them. |
368 uint32 size = args.size; | 369 uint32 size = args.size; |
369 uint32 data_size = ImmediateDataSize(arg_count, args); | 370 uint32 data_size = ImmediateDataSize(arg_count, args); |
370 if (size > data_size) { | 371 if (size > data_size) { |
371 return parse_error::kParseInvalidArguments; | 372 return parse_error::kParseInvalidArguments; |
372 } | 373 } |
373 if (data_size == 0) { | 374 if (data_size == 0) { |
374 return parse_error::kParseNoError; | 375 return parse_error::kParseNoError; |
375 } | 376 } |
376 return gapi_->CreateEffect(args.effect_id, size, AddressAfterStruct(args)); | 377 return gapi_->CreateEffect(args.effect_id, size, AddressAfterStruct(args)); |
377 } | 378 } |
378 | 379 |
379 parse_error::ParseError GAPIDecoder::HandleDestroyEffect( | 380 parse_error::ParseError GAPIDecoder::HandleDestroyEffect( |
380 uint32 arg_count, | 381 uint32 arg_count, |
381 const cmd::DestroyEffect& args) { | 382 const DestroyEffect& args) { |
382 return gapi_->DestroyEffect(args.effect_id); | 383 return gapi_->DestroyEffect(args.effect_id); |
383 } | 384 } |
384 | 385 |
385 parse_error::ParseError GAPIDecoder::HandleSetEffect( | 386 parse_error::ParseError GAPIDecoder::HandleSetEffect( |
386 uint32 arg_count, | 387 uint32 arg_count, |
387 const cmd::SetEffect& args) { | 388 const SetEffect& args) { |
388 return gapi_->SetEffect(args.effect_id); | 389 return gapi_->SetEffect(args.effect_id); |
389 } | 390 } |
390 | 391 |
391 parse_error::ParseError GAPIDecoder::HandleGetParamCount( | 392 parse_error::ParseError GAPIDecoder::HandleGetParamCount( |
392 uint32 arg_count, | 393 uint32 arg_count, |
393 const cmd::GetParamCount& args) { | 394 const GetParamCount& args) { |
394 // Pull out some values so they can't be changed by another thread after we've | 395 // Pull out some values so they can't be changed by another thread after we've |
395 // validated them. | 396 // validated them. |
396 uint32 size = args.size; | 397 uint32 size = args.size; |
397 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 398 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
398 args.shared_memory.offset, | 399 args.shared_memory.offset, |
399 size); | 400 size); |
400 if (!data) return parse_error::kParseInvalidArguments; | 401 if (!data) return parse_error::kParseInvalidArguments; |
401 return gapi_->GetParamCount(args.effect_id, size, data); | 402 return gapi_->GetParamCount(args.effect_id, size, data); |
402 } | 403 } |
403 | 404 |
404 parse_error::ParseError GAPIDecoder::HandleCreateParam( | 405 parse_error::ParseError GAPIDecoder::HandleCreateParam( |
405 uint32 arg_count, | 406 uint32 arg_count, |
406 const cmd::CreateParam& args) { | 407 const CreateParam& args) { |
407 return gapi_->CreateParam(args.param_id, args.effect_id, args.index); | 408 return gapi_->CreateParam(args.param_id, args.effect_id, args.index); |
408 } | 409 } |
409 | 410 |
410 parse_error::ParseError GAPIDecoder::HandleCreateParamByName( | 411 parse_error::ParseError GAPIDecoder::HandleCreateParamByName( |
411 uint32 arg_count, | 412 uint32 arg_count, |
412 const cmd::CreateParamByName& args) { | 413 const CreateParamByName& args) { |
413 // Pull out some values so they can't be changed by another thread after we've | 414 // Pull out some values so they can't be changed by another thread after we've |
414 // validated them. | 415 // validated them. |
415 uint32 size = args.size; | 416 uint32 size = args.size; |
416 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 417 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
417 args.shared_memory.offset, | 418 args.shared_memory.offset, |
418 size); | 419 size); |
419 if (!data) return parse_error::kParseInvalidArguments; | 420 if (!data) return parse_error::kParseInvalidArguments; |
420 return gapi_->CreateParamByName(args.param_id, args.effect_id, size, | 421 return gapi_->CreateParamByName(args.param_id, args.effect_id, size, |
421 data); | 422 data); |
422 } | 423 } |
423 | 424 |
424 parse_error::ParseError GAPIDecoder::HandleCreateParamByNameImmediate( | 425 parse_error::ParseError GAPIDecoder::HandleCreateParamByNameImmediate( |
425 uint32 arg_count, | 426 uint32 arg_count, |
426 const cmd::CreateParamByNameImmediate& args) { | 427 const CreateParamByNameImmediate& args) { |
427 // Pull out some values so they can't be changed by another thread after we've | 428 // Pull out some values so they can't be changed by another thread after we've |
428 // validated them. | 429 // validated them. |
429 uint32 size = args.size; | 430 uint32 size = args.size; |
430 uint32 data_size = ImmediateDataSize(arg_count, args); | 431 uint32 data_size = ImmediateDataSize(arg_count, args); |
431 if (size > data_size) | 432 if (size > data_size) |
432 return parse_error::kParseInvalidArguments; | 433 return parse_error::kParseInvalidArguments; |
433 if (data_size == 0) { | 434 if (data_size == 0) { |
434 return parse_error::kParseNoError; | 435 return parse_error::kParseNoError; |
435 } | 436 } |
436 return gapi_->CreateParamByName(args.param_id, args.effect_id, size, | 437 return gapi_->CreateParamByName(args.param_id, args.effect_id, size, |
437 AddressAfterStruct(args)); | 438 AddressAfterStruct(args)); |
438 } | 439 } |
439 | 440 |
440 parse_error::ParseError GAPIDecoder::HandleDestroyParam( | 441 parse_error::ParseError GAPIDecoder::HandleDestroyParam( |
441 uint32 arg_count, | 442 uint32 arg_count, |
442 const cmd::DestroyParam& args) { | 443 const DestroyParam& args) { |
443 return gapi_->DestroyParam(args.param_id); | 444 return gapi_->DestroyParam(args.param_id); |
444 } | 445 } |
445 | 446 |
446 parse_error::ParseError GAPIDecoder::HandleSetParamData( | 447 parse_error::ParseError GAPIDecoder::HandleSetParamData( |
447 uint32 arg_count, | 448 uint32 arg_count, |
448 const cmd::SetParamData& args) { | 449 const SetParamData& args) { |
449 // Pull out some values so they can't be changed by another thread after we've | 450 // Pull out some values so they can't be changed by another thread after we've |
450 // validated them. | 451 // validated them. |
451 uint32 size = args.size; | 452 uint32 size = args.size; |
452 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 453 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
453 args.shared_memory.offset, | 454 args.shared_memory.offset, |
454 size); | 455 size); |
455 if (!data) return parse_error::kParseInvalidArguments; | 456 if (!data) return parse_error::kParseInvalidArguments; |
456 return gapi_->SetParamData(args.param_id, size, data); | 457 return gapi_->SetParamData(args.param_id, size, data); |
457 } | 458 } |
458 | 459 |
459 parse_error::ParseError GAPIDecoder::HandleSetParamDataImmediate( | 460 parse_error::ParseError GAPIDecoder::HandleSetParamDataImmediate( |
460 uint32 arg_count, | 461 uint32 arg_count, |
461 const cmd::SetParamDataImmediate& args) { | 462 const SetParamDataImmediate& args) { |
462 // Pull out some values so they can't be changed by another thread after we've | 463 // Pull out some values so they can't be changed by another thread after we've |
463 // validated them. | 464 // validated them. |
464 uint32 size = args.size; | 465 uint32 size = args.size; |
465 uint32 data_size = ImmediateDataSize(arg_count, args); | 466 uint32 data_size = ImmediateDataSize(arg_count, args); |
466 if (size > data_size) { | 467 if (size > data_size) { |
467 return parse_error::kParseInvalidArguments; | 468 return parse_error::kParseInvalidArguments; |
468 } | 469 } |
469 if (data_size == 0) { | 470 if (data_size == 0) { |
470 return parse_error::kParseNoError; | 471 return parse_error::kParseNoError; |
471 } | 472 } |
472 return gapi_->SetParamData(args.param_id, size, AddressAfterStruct(args)); | 473 return gapi_->SetParamData(args.param_id, size, AddressAfterStruct(args)); |
473 } | 474 } |
474 | 475 |
475 parse_error::ParseError GAPIDecoder::HandleGetParamDesc( | 476 parse_error::ParseError GAPIDecoder::HandleGetParamDesc( |
476 uint32 arg_count, | 477 uint32 arg_count, |
477 const cmd::GetParamDesc& args) { | 478 const GetParamDesc& args) { |
478 // Pull out some values so they can't be changed by another thread after we've | 479 // Pull out some values so they can't be changed by another thread after we've |
479 // validated them. | 480 // validated them. |
480 uint32 size = args.size; | 481 uint32 size = args.size; |
481 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 482 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
482 args.shared_memory.offset, | 483 args.shared_memory.offset, |
483 size); | 484 size); |
484 if (!data) return parse_error::kParseInvalidArguments; | 485 if (!data) return parse_error::kParseInvalidArguments; |
485 return gapi_->GetParamDesc(args.param_id, size, data); | 486 return gapi_->GetParamDesc(args.param_id, size, data); |
486 } | 487 } |
487 | 488 |
488 parse_error::ParseError GAPIDecoder::HandleGetStreamCount( | 489 parse_error::ParseError GAPIDecoder::HandleGetStreamCount( |
489 uint32 arg_count, | 490 uint32 arg_count, |
490 const cmd::GetStreamCount& args) { | 491 const GetStreamCount& args) { |
491 // Pull out some values so they can't be changed by another thread after we've | 492 // Pull out some values so they can't be changed by another thread after we've |
492 // validated them. | 493 // validated them. |
493 uint32 size = args.size; | 494 uint32 size = args.size; |
494 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 495 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
495 args.shared_memory.offset, | 496 args.shared_memory.offset, |
496 size); | 497 size); |
497 if (!data) return parse_error::kParseInvalidArguments; | 498 if (!data) return parse_error::kParseInvalidArguments; |
498 return gapi_->GetStreamCount(args.effect_id, size, data); | 499 return gapi_->GetStreamCount(args.effect_id, size, data); |
499 } | 500 } |
500 | 501 |
501 parse_error::ParseError GAPIDecoder::HandleGetStreamDesc( | 502 parse_error::ParseError GAPIDecoder::HandleGetStreamDesc( |
502 uint32 arg_count, | 503 uint32 arg_count, |
503 const cmd::GetStreamDesc& args) { | 504 const GetStreamDesc& args) { |
504 // Pull out some values so they can't be changed by another thread after we've | 505 // Pull out some values so they can't be changed by another thread after we've |
505 // validated them. | 506 // validated them. |
506 uint32 size = args.size; | 507 uint32 size = args.size; |
507 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 508 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
508 args.shared_memory.offset, | 509 args.shared_memory.offset, |
509 size); | 510 size); |
510 if (!data) return parse_error::kParseInvalidArguments; | 511 if (!data) return parse_error::kParseInvalidArguments; |
511 return gapi_->GetStreamDesc(args.effect_id, args.index, size, data); | 512 return gapi_->GetStreamDesc(args.effect_id, args.index, size, data); |
512 } | 513 } |
513 | 514 |
514 parse_error::ParseError GAPIDecoder::HandleDestroyTexture( | 515 parse_error::ParseError GAPIDecoder::HandleDestroyTexture( |
515 uint32 arg_count, | 516 uint32 arg_count, |
516 const cmd::DestroyTexture& args) { | 517 const DestroyTexture& args) { |
517 return gapi_->DestroyTexture(args.texture_id); | 518 return gapi_->DestroyTexture(args.texture_id); |
518 } | 519 } |
519 | 520 |
520 parse_error::ParseError GAPIDecoder::HandleCreateTexture2d( | 521 parse_error::ParseError GAPIDecoder::HandleCreateTexture2d( |
521 uint32 arg_count, | 522 uint32 arg_count, |
522 const cmd::CreateTexture2d& args) { | 523 const CreateTexture2d& args) { |
523 unsigned int width_height = args.width_height; | 524 unsigned int width_height = args.width_height; |
524 unsigned int levels_format_flags = args.levels_format_flags; | 525 unsigned int levels_format_flags = args.levels_format_flags; |
525 unsigned int width = cmd::CreateTexture2d::Width::Get(width_height); | 526 unsigned int width = CreateTexture2d::Width::Get(width_height); |
526 unsigned int height = cmd::CreateTexture2d::Height::Get(width_height); | 527 unsigned int height = CreateTexture2d::Height::Get(width_height); |
527 unsigned int levels = cmd::CreateTexture2d::Levels::Get(levels_format_flags); | 528 unsigned int levels = CreateTexture2d::Levels::Get(levels_format_flags); |
528 unsigned int unused = cmd::CreateTexture2d::Unused::Get(levels_format_flags); | 529 unsigned int unused = CreateTexture2d::Unused::Get(levels_format_flags); |
529 unsigned int format = cmd::CreateTexture2d::Format::Get(levels_format_flags); | 530 unsigned int format = CreateTexture2d::Format::Get(levels_format_flags); |
530 unsigned int flags = cmd::CreateTexture2d::Flags::Get(levels_format_flags); | 531 unsigned int flags = CreateTexture2d::Flags::Get(levels_format_flags); |
531 unsigned int max_levels = | 532 unsigned int max_levels = |
532 1 + base::bits::Log2Ceiling(std::max(width, height)); | 533 1 + base::bits::Log2Ceiling(std::max(width, height)); |
533 if ((width == 0) || (height == 0) || (levels > max_levels) || | 534 if ((width == 0) || (height == 0) || (levels > max_levels) || |
534 (unused != 0) || (format == texture::kUnknown) || (levels == 0)) | 535 (unused != 0) || (format == texture::kUnknown) || (levels == 0)) |
535 return parse_error::kParseInvalidArguments; | 536 return parse_error::kParseInvalidArguments; |
536 bool enable_render_surfaces = !!flags; | 537 bool enable_render_surfaces = !!flags; |
537 return gapi_->CreateTexture2D(args.texture_id, width, height, levels, | 538 return gapi_->CreateTexture2D(args.texture_id, width, height, levels, |
538 static_cast<texture::Format>(format), flags, | 539 static_cast<texture::Format>(format), flags, |
539 enable_render_surfaces); | 540 enable_render_surfaces); |
540 } | 541 } |
541 | 542 |
542 parse_error::ParseError GAPIDecoder::HandleCreateTexture3d( | 543 parse_error::ParseError GAPIDecoder::HandleCreateTexture3d( |
543 uint32 arg_count, | 544 uint32 arg_count, |
544 const cmd::CreateTexture3d& args) { | 545 const CreateTexture3d& args) { |
545 unsigned int width_height = args.width_height; | 546 unsigned int width_height = args.width_height; |
546 unsigned int depth_unused = args.depth_unused; | 547 unsigned int depth_unused = args.depth_unused; |
547 unsigned int levels_format_flags = args.levels_format_flags; | 548 unsigned int levels_format_flags = args.levels_format_flags; |
548 unsigned int width = cmd::CreateTexture3d::Width::Get(width_height); | 549 unsigned int width = CreateTexture3d::Width::Get(width_height); |
549 unsigned int height = cmd::CreateTexture3d::Height::Get(width_height); | 550 unsigned int height = CreateTexture3d::Height::Get(width_height); |
550 unsigned int depth = cmd::CreateTexture3d::Depth::Get(depth_unused); | 551 unsigned int depth = CreateTexture3d::Depth::Get(depth_unused); |
551 unsigned int unused1 = cmd::CreateTexture3d::Unused1::Get(depth_unused); | 552 unsigned int unused1 = CreateTexture3d::Unused1::Get(depth_unused); |
552 unsigned int levels = cmd::CreateTexture3d::Levels::Get(levels_format_flags); | 553 unsigned int levels = CreateTexture3d::Levels::Get(levels_format_flags); |
553 unsigned int unused2 = | 554 unsigned int unused2 = CreateTexture3d::Unused2::Get(levels_format_flags); |
554 cmd::CreateTexture3d::Unused2::Get(levels_format_flags); | 555 unsigned int format = CreateTexture3d::Format::Get(levels_format_flags); |
555 unsigned int format = cmd::CreateTexture3d::Format::Get(levels_format_flags); | 556 unsigned int flags = CreateTexture3d::Flags::Get(levels_format_flags); |
556 unsigned int flags = cmd::CreateTexture3d::Flags::Get(levels_format_flags); | |
557 unsigned int max_levels = | 557 unsigned int max_levels = |
558 1 + base::bits::Log2Ceiling(std::max(depth, std::max(width, height))); | 558 1 + base::bits::Log2Ceiling(std::max(depth, std::max(width, height))); |
559 if ((width == 0) || (height == 0) || (depth == 0) || | 559 if ((width == 0) || (height == 0) || (depth == 0) || |
560 (levels > max_levels) || (unused1 != 0) || (unused2 != 0) || | 560 (levels > max_levels) || (unused1 != 0) || (unused2 != 0) || |
561 (format == texture::kUnknown) || (levels == 0)) | 561 (format == texture::kUnknown) || (levels == 0)) |
562 return parse_error::kParseInvalidArguments; | 562 return parse_error::kParseInvalidArguments; |
563 bool enable_render_surfaces = !!flags; | 563 bool enable_render_surfaces = !!flags; |
564 return gapi_->CreateTexture3D(args.texture_id, width, height, depth, levels, | 564 return gapi_->CreateTexture3D(args.texture_id, width, height, depth, levels, |
565 static_cast<texture::Format>(format), flags, | 565 static_cast<texture::Format>(format), flags, |
566 enable_render_surfaces); | 566 enable_render_surfaces); |
567 } | 567 } |
568 | 568 |
569 parse_error::ParseError GAPIDecoder::HandleCreateTextureCube( | 569 parse_error::ParseError GAPIDecoder::HandleCreateTextureCube( |
570 uint32 arg_count, | 570 uint32 arg_count, |
571 const cmd::CreateTextureCube& args) { | 571 const CreateTextureCube& args) { |
572 unsigned int side_unused = args.edge_length; | 572 unsigned int side_unused = args.edge_length; |
573 unsigned int levels_format_flags = args.levels_format_flags; | 573 unsigned int levels_format_flags = args.levels_format_flags; |
574 unsigned int side = cmd::CreateTextureCube::Side::Get(side_unused); | 574 unsigned int side = CreateTextureCube::Side::Get(side_unused); |
575 unsigned int unused1 = cmd::CreateTextureCube::Unused1::Get(side_unused); | 575 unsigned int unused1 = CreateTextureCube::Unused1::Get(side_unused); |
576 unsigned int levels = | 576 unsigned int levels = CreateTextureCube::Levels::Get(levels_format_flags); |
577 cmd::CreateTextureCube::Levels::Get(levels_format_flags); | 577 unsigned int unused2 = CreateTextureCube::Unused2::Get(levels_format_flags); |
578 unsigned int unused2 = | 578 unsigned int format = CreateTextureCube::Format::Get(levels_format_flags); |
579 cmd::CreateTextureCube::Unused2::Get(levels_format_flags); | 579 unsigned int flags = CreateTextureCube::Flags::Get(levels_format_flags); |
580 unsigned int format = | |
581 cmd::CreateTextureCube::Format::Get(levels_format_flags); | |
582 unsigned int flags = cmd::CreateTextureCube::Flags::Get(levels_format_flags); | |
583 unsigned int max_levels = 1 + base::bits::Log2Ceiling(side); | 580 unsigned int max_levels = 1 + base::bits::Log2Ceiling(side); |
584 if ((side == 0) || (levels > max_levels) || (unused1 != 0) || | 581 if ((side == 0) || (levels > max_levels) || (unused1 != 0) || |
585 (unused2 != 0) || (format == texture::kUnknown) || (levels == 0)) | 582 (unused2 != 0) || (format == texture::kUnknown) || (levels == 0)) |
586 return parse_error::kParseInvalidArguments; | 583 return parse_error::kParseInvalidArguments; |
587 bool enable_render_surfaces = !!flags; | 584 bool enable_render_surfaces = !!flags; |
588 return gapi_->CreateTextureCube(args.texture_id, side, levels, | 585 return gapi_->CreateTextureCube(args.texture_id, side, levels, |
589 static_cast<texture::Format>(format), | 586 static_cast<texture::Format>(format), |
590 flags, enable_render_surfaces); | 587 flags, enable_render_surfaces); |
591 } | 588 } |
592 | 589 |
593 parse_error::ParseError GAPIDecoder::HandleSetTextureData( | 590 parse_error::ParseError GAPIDecoder::HandleSetTextureData( |
594 uint32 arg_count, | 591 uint32 arg_count, |
595 const cmd::SetTextureData& args) { | 592 const SetTextureData& args) { |
596 unsigned int x_y = args.x_y; | 593 unsigned int x_y = args.x_y; |
597 unsigned int width_height = args.width_height; | 594 unsigned int width_height = args.width_height; |
598 unsigned int z_depth = args.z_depth; | 595 unsigned int z_depth = args.z_depth; |
599 unsigned int level_face = args.level_face; | 596 unsigned int level_face = args.level_face; |
600 unsigned int size = args.size; | 597 unsigned int size = args.size; |
601 unsigned int x = cmd::SetTextureData::X::Get(x_y); | 598 unsigned int x = SetTextureData::X::Get(x_y); |
602 unsigned int y = cmd::SetTextureData::Y::Get(x_y); | 599 unsigned int y = SetTextureData::Y::Get(x_y); |
603 unsigned int width = cmd::SetTextureData::Width::Get(width_height); | 600 unsigned int width = SetTextureData::Width::Get(width_height); |
604 unsigned int height = cmd::SetTextureData::Height::Get(width_height); | 601 unsigned int height = SetTextureData::Height::Get(width_height); |
605 unsigned int z = cmd::SetTextureData::Z::Get(z_depth); | 602 unsigned int z = SetTextureData::Z::Get(z_depth); |
606 unsigned int depth = cmd::SetTextureData::Depth::Get(z_depth); | 603 unsigned int depth = SetTextureData::Depth::Get(z_depth); |
607 unsigned int level = cmd::SetTextureData::Level::Get(level_face); | 604 unsigned int level = SetTextureData::Level::Get(level_face); |
608 unsigned int face = cmd::SetTextureData::Face::Get(level_face); | 605 unsigned int face = SetTextureData::Face::Get(level_face); |
609 unsigned int unused = cmd::SetTextureData::Unused::Get(level_face); | 606 unsigned int unused = SetTextureData::Unused::Get(level_face); |
610 const void *data = GetAddressAndCheckSize(args.shared_memory.id, | 607 const void *data = GetAddressAndCheckSize(args.shared_memory.id, |
611 args.shared_memory.offset, size); | 608 args.shared_memory.offset, size); |
612 if (face >= 6 || unused != 0 || !data) | 609 if (face >= 6 || unused != 0 || !data) |
613 return parse_error::kParseInvalidArguments; | 610 return parse_error::kParseInvalidArguments; |
614 return gapi_->SetTextureData( | 611 return gapi_->SetTextureData( |
615 args.texture_id, x, y, z, width, height, depth, level, | 612 args.texture_id, x, y, z, width, height, depth, level, |
616 static_cast<texture::Face>(face), args.row_pitch, | 613 static_cast<texture::Face>(face), args.row_pitch, |
617 args.slice_pitch, size, data); | 614 args.slice_pitch, size, data); |
618 } | 615 } |
619 | 616 |
620 parse_error::ParseError GAPIDecoder::HandleSetTextureDataImmediate( | 617 parse_error::ParseError GAPIDecoder::HandleSetTextureDataImmediate( |
621 uint32 arg_count, | 618 uint32 arg_count, |
622 const cmd::SetTextureDataImmediate& args) { | 619 const SetTextureDataImmediate& args) { |
623 unsigned int x_y = args.x_y; | 620 unsigned int x_y = args.x_y; |
624 unsigned int width_height = args.width_height; | 621 unsigned int width_height = args.width_height; |
625 unsigned int z_depth = args.z_depth; | 622 unsigned int z_depth = args.z_depth; |
626 unsigned int level_face = args.level_face; | 623 unsigned int level_face = args.level_face; |
627 unsigned int size = args.size; | 624 unsigned int size = args.size; |
628 unsigned int x = cmd::SetTextureDataImmediate::X::Get(x_y); | 625 unsigned int x = SetTextureDataImmediate::X::Get(x_y); |
629 unsigned int y = cmd::SetTextureDataImmediate::Y::Get(x_y); | 626 unsigned int y = SetTextureDataImmediate::Y::Get(x_y); |
630 unsigned int width = cmd::SetTextureDataImmediate::Width::Get(width_height); | 627 unsigned int width = SetTextureDataImmediate::Width::Get(width_height); |
631 unsigned int height = cmd::SetTextureDataImmediate::Height::Get(width_height); | 628 unsigned int height = SetTextureDataImmediate::Height::Get(width_height); |
632 unsigned int z = cmd::SetTextureDataImmediate::Z::Get(z_depth); | 629 unsigned int z = SetTextureDataImmediate::Z::Get(z_depth); |
633 unsigned int depth = cmd::SetTextureDataImmediate::Depth::Get(z_depth); | 630 unsigned int depth = SetTextureDataImmediate::Depth::Get(z_depth); |
634 unsigned int level = cmd::SetTextureDataImmediate::Level::Get(level_face); | 631 unsigned int level = SetTextureDataImmediate::Level::Get(level_face); |
635 unsigned int face = cmd::SetTextureDataImmediate::Face::Get(level_face); | 632 unsigned int face = SetTextureDataImmediate::Face::Get(level_face); |
636 unsigned int unused = cmd::SetTextureDataImmediate::Unused::Get(level_face); | 633 unsigned int unused = SetTextureDataImmediate::Unused::Get(level_face); |
637 uint32 data_size = ImmediateDataSize(arg_count, args); | 634 uint32 data_size = ImmediateDataSize(arg_count, args); |
638 if (face >= 6 || unused != 0 || | 635 if (face >= 6 || unused != 0 || |
639 size > data_size) | 636 size > data_size) |
640 return parse_error::kParseInvalidArguments; | 637 return parse_error::kParseInvalidArguments; |
641 if (data_size == 0) { | 638 if (data_size == 0) { |
642 return parse_error::kParseNoError; | 639 return parse_error::kParseNoError; |
643 } | 640 } |
644 return gapi_->SetTextureData( | 641 return gapi_->SetTextureData( |
645 args.texture_id, x, y, z, width, height, depth, level, | 642 args.texture_id, x, y, z, width, height, depth, level, |
646 static_cast<texture::Face>(face), args.row_pitch, | 643 static_cast<texture::Face>(face), args.row_pitch, |
647 args.slice_pitch, size, AddressAfterStruct(args)); | 644 args.slice_pitch, size, AddressAfterStruct(args)); |
648 } | 645 } |
649 | 646 |
650 parse_error::ParseError GAPIDecoder::HandleGetTextureData( | 647 parse_error::ParseError GAPIDecoder::HandleGetTextureData( |
651 uint32 arg_count, | 648 uint32 arg_count, |
652 const cmd::GetTextureData& args) { | 649 const GetTextureData& args) { |
653 unsigned int x_y = args.x_y; | 650 unsigned int x_y = args.x_y; |
654 unsigned int width_height = args.width_height; | 651 unsigned int width_height = args.width_height; |
655 unsigned int z_depth = args.z_depth; | 652 unsigned int z_depth = args.z_depth; |
656 unsigned int level_face = args.level_face; | 653 unsigned int level_face = args.level_face; |
657 unsigned int size = args.size; | 654 unsigned int size = args.size; |
658 unsigned int x = cmd::GetTextureData::X::Get(x_y); | 655 unsigned int x = GetTextureData::X::Get(x_y); |
659 unsigned int y = cmd::GetTextureData::Y::Get(x_y); | 656 unsigned int y = GetTextureData::Y::Get(x_y); |
660 unsigned int width = cmd::GetTextureData::Width::Get(width_height); | 657 unsigned int width = GetTextureData::Width::Get(width_height); |
661 unsigned int height = cmd::GetTextureData::Height::Get(width_height); | 658 unsigned int height = GetTextureData::Height::Get(width_height); |
662 unsigned int z = cmd::GetTextureData::Z::Get(z_depth); | 659 unsigned int z = GetTextureData::Z::Get(z_depth); |
663 unsigned int depth = cmd::GetTextureData::Depth::Get(z_depth); | 660 unsigned int depth = GetTextureData::Depth::Get(z_depth); |
664 unsigned int level = cmd::GetTextureData::Level::Get(level_face); | 661 unsigned int level = GetTextureData::Level::Get(level_face); |
665 unsigned int face = cmd::GetTextureData::Face::Get(level_face); | 662 unsigned int face = GetTextureData::Face::Get(level_face); |
666 unsigned int unused = cmd::GetTextureData::Unused::Get(level_face); | 663 unsigned int unused = GetTextureData::Unused::Get(level_face); |
667 void *data = GetAddressAndCheckSize(args.shared_memory.id, | 664 void *data = GetAddressAndCheckSize(args.shared_memory.id, |
668 args.shared_memory.offset, size); | 665 args.shared_memory.offset, size); |
669 if (face >= 6 || unused != 0 || !data) | 666 if (face >= 6 || unused != 0 || !data) |
670 return parse_error::kParseInvalidArguments; | 667 return parse_error::kParseInvalidArguments; |
671 return gapi_->GetTextureData( | 668 return gapi_->GetTextureData( |
672 args.texture_id, x, y, z, width, height, depth, level, | 669 args.texture_id, x, y, z, width, height, depth, level, |
673 static_cast<texture::Face>(face), args.row_pitch, | 670 static_cast<texture::Face>(face), args.row_pitch, |
674 args.slice_pitch, size, data); | 671 args.slice_pitch, size, data); |
675 } | 672 } |
676 | 673 |
677 parse_error::ParseError GAPIDecoder::HandleCreateSampler( | 674 parse_error::ParseError GAPIDecoder::HandleCreateSampler( |
678 uint32 arg_count, | 675 uint32 arg_count, |
679 const cmd::CreateSampler& args) { | 676 const CreateSampler& args) { |
680 return gapi_->CreateSampler(args.sampler_id); | 677 return gapi_->CreateSampler(args.sampler_id); |
681 } | 678 } |
682 | 679 |
683 parse_error::ParseError GAPIDecoder::HandleDestroySampler( | 680 parse_error::ParseError GAPIDecoder::HandleDestroySampler( |
684 uint32 arg_count, | 681 uint32 arg_count, |
685 const cmd::DestroySampler& args) { | 682 const DestroySampler& args) { |
686 return gapi_->DestroySampler(args.sampler_id); | 683 return gapi_->DestroySampler(args.sampler_id); |
687 } | 684 } |
688 | 685 |
689 parse_error::ParseError GAPIDecoder::HandleSetSamplerStates( | 686 parse_error::ParseError GAPIDecoder::HandleSetSamplerStates( |
690 uint32 arg_count, | 687 uint32 arg_count, |
691 const cmd::SetSamplerStates& args) { | 688 const SetSamplerStates& args) { |
692 Uint32 arg = args.sampler_states; | 689 Uint32 arg = args.sampler_states; |
693 if (cmd::SetSamplerStates::Unused::Get(arg) != 0) | 690 if (SetSamplerStates::Unused::Get(arg) != 0) |
694 return parse_error::kParseInvalidArguments; | 691 return parse_error::kParseInvalidArguments; |
695 unsigned int address_u_value = cmd::SetSamplerStates::AddressingU::Get(arg); | 692 unsigned int address_u_value = SetSamplerStates::AddressingU::Get(arg); |
696 unsigned int address_v_value = cmd::SetSamplerStates::AddressingV::Get(arg); | 693 unsigned int address_v_value = SetSamplerStates::AddressingV::Get(arg); |
697 unsigned int address_w_value = cmd::SetSamplerStates::AddressingW::Get(arg); | 694 unsigned int address_w_value = SetSamplerStates::AddressingW::Get(arg); |
698 unsigned int mag_filter_value = cmd::SetSamplerStates::MagFilter::Get(arg); | 695 unsigned int mag_filter_value = SetSamplerStates::MagFilter::Get(arg); |
699 unsigned int min_filter_value = cmd::SetSamplerStates::MinFilter::Get(arg); | 696 unsigned int min_filter_value = SetSamplerStates::MinFilter::Get(arg); |
700 unsigned int mip_filter_value = cmd::SetSamplerStates::MipFilter::Get(arg); | 697 unsigned int mip_filter_value = SetSamplerStates::MipFilter::Get(arg); |
701 unsigned int max_anisotropy = cmd::SetSamplerStates::MaxAnisotropy::Get(arg); | 698 unsigned int max_anisotropy = SetSamplerStates::MaxAnisotropy::Get(arg); |
702 if (address_u_value >= sampler::kNumAddressingMode || | 699 if (address_u_value >= sampler::kNumAddressingMode || |
703 address_v_value >= sampler::kNumAddressingMode || | 700 address_v_value >= sampler::kNumAddressingMode || |
704 address_w_value >= sampler::kNumAddressingMode || | 701 address_w_value >= sampler::kNumAddressingMode || |
705 mag_filter_value >= sampler::kNumFilteringMode || | 702 mag_filter_value >= sampler::kNumFilteringMode || |
706 min_filter_value >= sampler::kNumFilteringMode || | 703 min_filter_value >= sampler::kNumFilteringMode || |
707 mip_filter_value >= sampler::kNumFilteringMode || | 704 mip_filter_value >= sampler::kNumFilteringMode || |
708 mag_filter_value == sampler::kNone || | 705 mag_filter_value == sampler::kNone || |
709 min_filter_value == sampler::kNone || | 706 min_filter_value == sampler::kNone || |
710 max_anisotropy == 0) { | 707 max_anisotropy == 0) { |
711 return parse_error::kParseInvalidArguments; | 708 return parse_error::kParseInvalidArguments; |
712 } | 709 } |
713 gapi_->SetSamplerStates( | 710 gapi_->SetSamplerStates( |
714 args.sampler_id, | 711 args.sampler_id, |
715 static_cast<sampler::AddressingMode>(address_u_value), | 712 static_cast<sampler::AddressingMode>(address_u_value), |
716 static_cast<sampler::AddressingMode>(address_v_value), | 713 static_cast<sampler::AddressingMode>(address_v_value), |
717 static_cast<sampler::AddressingMode>(address_w_value), | 714 static_cast<sampler::AddressingMode>(address_w_value), |
718 static_cast<sampler::FilteringMode>(mag_filter_value), | 715 static_cast<sampler::FilteringMode>(mag_filter_value), |
719 static_cast<sampler::FilteringMode>(min_filter_value), | 716 static_cast<sampler::FilteringMode>(min_filter_value), |
720 static_cast<sampler::FilteringMode>(mip_filter_value), | 717 static_cast<sampler::FilteringMode>(mip_filter_value), |
721 max_anisotropy); | 718 max_anisotropy); |
722 return parse_error::kParseNoError; | 719 return parse_error::kParseNoError; |
723 } | 720 } |
724 | 721 |
725 parse_error::ParseError GAPIDecoder::HandleSetSamplerBorderColor( | 722 parse_error::ParseError GAPIDecoder::HandleSetSamplerBorderColor( |
726 uint32 arg_count, | 723 uint32 arg_count, |
727 const cmd::SetSamplerBorderColor& args) { | 724 const SetSamplerBorderColor& args) { |
728 RGBA rgba; | 725 RGBA rgba; |
729 rgba.red = args.red; | 726 rgba.red = args.red; |
730 rgba.green = args.green; | 727 rgba.green = args.green; |
731 rgba.blue = args.blue; | 728 rgba.blue = args.blue; |
732 rgba.alpha = args.alpha; | 729 rgba.alpha = args.alpha; |
733 return gapi_->SetSamplerBorderColor(args.sampler_id, rgba); | 730 return gapi_->SetSamplerBorderColor(args.sampler_id, rgba); |
734 } | 731 } |
735 | 732 |
736 parse_error::ParseError GAPIDecoder::HandleSetSamplerTexture( | 733 parse_error::ParseError GAPIDecoder::HandleSetSamplerTexture( |
737 uint32 arg_count, | 734 uint32 arg_count, |
738 const cmd::SetSamplerTexture& args) { | 735 const SetSamplerTexture& args) { |
739 return gapi_->SetSamplerTexture(args.sampler_id, args.texture_id); | 736 return gapi_->SetSamplerTexture(args.sampler_id, args.texture_id); |
740 } | 737 } |
741 | 738 |
742 parse_error::ParseError GAPIDecoder::HandleSetScissor( | 739 parse_error::ParseError GAPIDecoder::HandleSetScissor( |
743 uint32 arg_count, | 740 uint32 arg_count, |
744 const cmd::SetScissor& args) { | 741 const SetScissor& args) { |
745 Uint32 x_y_enable = args.x_y_enable; | 742 Uint32 x_y_enable = args.x_y_enable; |
746 if (cmd::SetScissor::Unused::Get(x_y_enable) != 0) | 743 if (SetScissor::Unused::Get(x_y_enable) != 0) |
747 return parse_error::kParseInvalidArguments; | 744 return parse_error::kParseInvalidArguments; |
748 unsigned int x = cmd::SetScissor::X::Get(x_y_enable); | 745 unsigned int x = SetScissor::X::Get(x_y_enable); |
749 unsigned int y = cmd::SetScissor::Y::Get(x_y_enable); | 746 unsigned int y = SetScissor::Y::Get(x_y_enable); |
750 bool enable = cmd::SetScissor::Enable::Get(x_y_enable) != 0; | 747 bool enable = SetScissor::Enable::Get(x_y_enable) != 0; |
751 Uint32 width_height = args.width_height; | 748 Uint32 width_height = args.width_height; |
752 unsigned int width = cmd::SetScissor::Width::Get(width_height); | 749 unsigned int width = SetScissor::Width::Get(width_height); |
753 unsigned int height = cmd::SetScissor::Height::Get(width_height); | 750 unsigned int height = SetScissor::Height::Get(width_height); |
754 gapi_->SetScissor(enable, x, y, width, height); | 751 gapi_->SetScissor(enable, x, y, width, height); |
755 return parse_error::kParseNoError; | 752 return parse_error::kParseNoError; |
756 } | 753 } |
757 | 754 |
758 parse_error::ParseError GAPIDecoder::HandleSetPolygonOffset( | 755 parse_error::ParseError GAPIDecoder::HandleSetPolygonOffset( |
759 uint32 arg_count, | 756 uint32 arg_count, |
760 const cmd::SetPolygonOffset& args) { | 757 const SetPolygonOffset& args) { |
761 gapi_->SetPolygonOffset(args.slope_factor, args.units); | 758 gapi_->SetPolygonOffset(args.slope_factor, args.units); |
762 return parse_error::kParseNoError; | 759 return parse_error::kParseNoError; |
763 } | 760 } |
764 | 761 |
765 parse_error::ParseError GAPIDecoder::HandleSetPointLineRaster( | 762 parse_error::ParseError GAPIDecoder::HandleSetPointLineRaster( |
766 uint32 arg_count, | 763 uint32 arg_count, |
767 const cmd::SetPointLineRaster& args) { | 764 const SetPointLineRaster& args) { |
768 Uint32 enables = args.enables; | 765 Uint32 enables = args.enables; |
769 if (cmd::SetPointLineRaster::Unused::Get(enables) != 0) | 766 if (SetPointLineRaster::Unused::Get(enables) != 0) |
770 return parse_error::kParseInvalidArguments; | 767 return parse_error::kParseInvalidArguments; |
771 bool line_smooth = !!cmd::SetPointLineRaster::LineSmoothEnable::Get(enables); | 768 bool line_smooth = !!SetPointLineRaster::LineSmoothEnable::Get(enables); |
772 bool point_sprite = | 769 bool point_sprite = !!SetPointLineRaster::PointSpriteEnable::Get(enables); |
773 !!cmd::SetPointLineRaster::PointSpriteEnable::Get(enables); | |
774 gapi_->SetPointLineRaster(line_smooth, point_sprite, args.point_size); | 770 gapi_->SetPointLineRaster(line_smooth, point_sprite, args.point_size); |
775 return parse_error::kParseNoError; | 771 return parse_error::kParseNoError; |
776 } | 772 } |
777 | 773 |
778 parse_error::ParseError GAPIDecoder::HandleSetPolygonRaster( | 774 parse_error::ParseError GAPIDecoder::HandleSetPolygonRaster( |
779 uint32 arg_count, | 775 uint32 arg_count, |
780 const cmd::SetPolygonRaster& args) { | 776 const SetPolygonRaster& args) { |
781 Uint32 fill_cull = args.fill_cull; | 777 Uint32 fill_cull = args.fill_cull; |
782 unsigned int fill_value = cmd::SetPolygonRaster::FillMode::Get(fill_cull); | 778 unsigned int fill_value = SetPolygonRaster::FillMode::Get(fill_cull); |
783 unsigned int cull_value = cmd::SetPolygonRaster::CullMode::Get(fill_cull); | 779 unsigned int cull_value = SetPolygonRaster::CullMode::Get(fill_cull); |
784 if (cmd::SetPolygonRaster::Unused::Get(fill_cull) != 0 || | 780 if (SetPolygonRaster::Unused::Get(fill_cull) != 0 || |
785 fill_value >= command_buffer::kNumPolygonMode || | 781 fill_value >= kNumPolygonMode || |
786 cull_value >= command_buffer::kNumFaceCullMode) | 782 cull_value >= kNumFaceCullMode) |
787 return parse_error::kParseInvalidArguments; | 783 return parse_error::kParseInvalidArguments; |
788 gapi_->SetPolygonRaster( | 784 gapi_->SetPolygonRaster( |
789 static_cast<command_buffer::PolygonMode>(fill_value), | 785 static_cast<PolygonMode>(fill_value), |
790 static_cast<command_buffer::FaceCullMode>(cull_value)); | 786 static_cast<FaceCullMode>(cull_value)); |
791 return parse_error::kParseNoError; | 787 return parse_error::kParseNoError; |
792 } | 788 } |
793 | 789 |
794 parse_error::ParseError GAPIDecoder::HandleSetAlphaTest( | 790 parse_error::ParseError GAPIDecoder::HandleSetAlphaTest( |
795 uint32 arg_count, | 791 uint32 arg_count, |
796 const cmd::SetAlphaTest& args) { | 792 const SetAlphaTest& args) { |
797 Uint32 func_enable = args.func_enable; | 793 Uint32 func_enable = args.func_enable; |
798 if (cmd::SetAlphaTest::Unused::Get(func_enable) != 0) | 794 if (SetAlphaTest::Unused::Get(func_enable) != 0) |
799 return parse_error::kParseInvalidArguments; | 795 return parse_error::kParseInvalidArguments; |
800 // Check that the bitmask get cannot generate values outside of the | 796 // Check that the bitmask get cannot generate values outside of the |
801 // allowed range. | 797 // allowed range. |
802 COMPILE_ASSERT(cmd::SetAlphaTest::Func::kMask < | 798 COMPILE_ASSERT(SetAlphaTest::Func::kMask < |
803 command_buffer::kNumComparison, | 799 kNumComparison, |
804 set_alpha_test_Func_may_produce_invalid_values); | 800 set_alpha_test_Func_may_produce_invalid_values); |
805 command_buffer::Comparison comp = static_cast<command_buffer::Comparison>( | 801 Comparison comp = static_cast<Comparison>( |
806 cmd::SetAlphaTest::Func::Get(func_enable)); | 802 SetAlphaTest::Func::Get(func_enable)); |
807 bool enable = cmd::SetAlphaTest::Enable::Get(func_enable) != 0; | 803 bool enable = SetAlphaTest::Enable::Get(func_enable) != 0; |
808 gapi_->SetAlphaTest(enable, args.value, comp); | 804 gapi_->SetAlphaTest(enable, args.value, comp); |
809 return parse_error::kParseNoError; | 805 return parse_error::kParseNoError; |
810 } | 806 } |
811 | 807 |
812 parse_error::ParseError GAPIDecoder::HandleSetDepthTest( | 808 parse_error::ParseError GAPIDecoder::HandleSetDepthTest( |
813 uint32 arg_count, | 809 uint32 arg_count, |
814 const cmd::SetDepthTest& args) { | 810 const SetDepthTest& args) { |
815 Uint32 func_enable = args.func_enable; | 811 Uint32 func_enable = args.func_enable; |
816 if (cmd::SetDepthTest::Unused::Get(func_enable) != 0) | 812 if (SetDepthTest::Unused::Get(func_enable) != 0) |
817 return parse_error::kParseInvalidArguments; | 813 return parse_error::kParseInvalidArguments; |
818 // Check that the bitmask get cannot generate values outside of the | 814 // Check that the bitmask get cannot generate values outside of the |
819 // allowed range. | 815 // allowed range. |
820 COMPILE_ASSERT(cmd::SetDepthTest::Func::kMask < | 816 COMPILE_ASSERT(SetDepthTest::Func::kMask < |
821 command_buffer::kNumComparison, | 817 kNumComparison, |
822 set_alpha_test_Func_may_produce_invalid_values); | 818 set_alpha_test_Func_may_produce_invalid_values); |
823 command_buffer::Comparison comp = static_cast<command_buffer::Comparison>( | 819 Comparison comp = static_cast<Comparison>( |
824 cmd::SetDepthTest::Func::Get(func_enable)); | 820 SetDepthTest::Func::Get(func_enable)); |
825 bool write_enable = cmd::SetDepthTest::WriteEnable::Get(func_enable) != 0; | 821 bool write_enable = SetDepthTest::WriteEnable::Get(func_enable) != 0; |
826 bool enable = cmd::SetDepthTest::Enable::Get(func_enable) != 0; | 822 bool enable = SetDepthTest::Enable::Get(func_enable) != 0; |
827 gapi_->SetDepthTest(enable, write_enable, comp); | 823 gapi_->SetDepthTest(enable, write_enable, comp); |
828 return parse_error::kParseNoError; | 824 return parse_error::kParseNoError; |
829 } | 825 } |
830 | 826 |
831 parse_error::ParseError GAPIDecoder::HandleSetStencilTest( | 827 parse_error::ParseError GAPIDecoder::HandleSetStencilTest( |
832 uint32 arg_count, | 828 uint32 arg_count, |
833 const cmd::SetStencilTest& args) { | 829 const SetStencilTest& args) { |
834 Uint32 arg0 = args.stencil_args0; | 830 Uint32 arg0 = args.stencil_args0; |
835 Uint32 arg1 = args.stencil_args1; | 831 Uint32 arg1 = args.stencil_args1; |
836 if (cmd::SetStencilTest::Unused0::Get(arg0) != 0 || | 832 if (SetStencilTest::Unused0::Get(arg0) != 0 || |
837 cmd::SetStencilTest::Unused1::Get(arg1) != 0 || | 833 SetStencilTest::Unused1::Get(arg1) != 0 || |
838 cmd::SetStencilTest::Unused2::Get(arg1) != 0) | 834 SetStencilTest::Unused2::Get(arg1) != 0) |
839 return parse_error::kParseInvalidArguments; | 835 return parse_error::kParseInvalidArguments; |
840 unsigned int write_mask = cmd::SetStencilTest::WriteMask::Get(arg0); | 836 unsigned int write_mask = SetStencilTest::WriteMask::Get(arg0); |
841 unsigned int compare_mask = cmd::SetStencilTest::CompareMask::Get(arg0); | 837 unsigned int compare_mask = SetStencilTest::CompareMask::Get(arg0); |
842 unsigned int ref = cmd::SetStencilTest::ReferenceValue::Get(arg0); | 838 unsigned int ref = SetStencilTest::ReferenceValue::Get(arg0); |
843 bool enable = cmd::SetStencilTest::Enable::Get(arg0) != 0; | 839 bool enable = SetStencilTest::Enable::Get(arg0) != 0; |
844 bool separate_ccw = cmd::SetStencilTest::SeparateCCW::Get(arg0) != 0; | 840 bool separate_ccw = SetStencilTest::SeparateCCW::Get(arg0) != 0; |
845 gapi_->SetStencilTest(enable, separate_ccw, write_mask, compare_mask, ref, | 841 gapi_->SetStencilTest(enable, separate_ccw, write_mask, compare_mask, ref, |
846 arg1); | 842 arg1); |
847 return parse_error::kParseNoError; | 843 return parse_error::kParseNoError; |
848 } | 844 } |
849 | 845 |
850 parse_error::ParseError GAPIDecoder::HandleSetColorWrite( | 846 parse_error::ParseError GAPIDecoder::HandleSetColorWrite( |
851 uint32 arg_count, | 847 uint32 arg_count, |
852 const cmd::SetColorWrite& args) { | 848 const SetColorWrite& args) { |
853 Uint32 enables = args.flags; | 849 Uint32 enables = args.flags; |
854 if (cmd::SetColorWrite::Unused::Get(enables) != 0) | 850 if (SetColorWrite::Unused::Get(enables) != 0) |
855 return parse_error::kParseInvalidArguments; | 851 return parse_error::kParseInvalidArguments; |
856 bool red = cmd::SetColorWrite::RedMask::Get(enables) != 0; | 852 bool red = SetColorWrite::RedMask::Get(enables) != 0; |
857 bool green = cmd::SetColorWrite::GreenMask::Get(enables) != 0; | 853 bool green = SetColorWrite::GreenMask::Get(enables) != 0; |
858 bool blue = cmd::SetColorWrite::BlueMask::Get(enables) != 0; | 854 bool blue = SetColorWrite::BlueMask::Get(enables) != 0; |
859 bool alpha = cmd::SetColorWrite::AlphaMask::Get(enables) != 0; | 855 bool alpha = SetColorWrite::AlphaMask::Get(enables) != 0; |
860 bool dither = cmd::SetColorWrite::DitherEnable::Get(enables) != 0; | 856 bool dither = SetColorWrite::DitherEnable::Get(enables) != 0; |
861 gapi_->SetColorWrite(red, green, blue, alpha, dither); | 857 gapi_->SetColorWrite(red, green, blue, alpha, dither); |
862 return parse_error::kParseNoError; | 858 return parse_error::kParseNoError; |
863 } | 859 } |
864 | 860 |
865 parse_error::ParseError GAPIDecoder::HandleSetBlending( | 861 parse_error::ParseError GAPIDecoder::HandleSetBlending( |
866 uint32 arg_count, | 862 uint32 arg_count, |
867 const cmd::SetBlending& args) { | 863 const SetBlending& args) { |
868 Uint32 arg = args.blend_settings; | 864 Uint32 arg = args.blend_settings; |
869 bool enable = cmd::SetBlending::Enable::Get(arg) != 0; | 865 bool enable = SetBlending::Enable::Get(arg) != 0; |
870 bool separate_alpha = cmd::SetBlending::SeparateAlpha::Get(arg) != 0; | 866 bool separate_alpha = SetBlending::SeparateAlpha::Get(arg) != 0; |
871 unsigned int color_eq = cmd::SetBlending::ColorEq::Get(arg); | 867 unsigned int color_eq = SetBlending::ColorEq::Get(arg); |
872 unsigned int color_src = cmd::SetBlending::ColorSrcFunc::Get(arg); | 868 unsigned int color_src = SetBlending::ColorSrcFunc::Get(arg); |
873 unsigned int color_dst = cmd::SetBlending::ColorDstFunc::Get(arg); | 869 unsigned int color_dst = SetBlending::ColorDstFunc::Get(arg); |
874 unsigned int alpha_eq = cmd::SetBlending::AlphaEq::Get(arg); | 870 unsigned int alpha_eq = SetBlending::AlphaEq::Get(arg); |
875 unsigned int alpha_src = cmd::SetBlending::AlphaSrcFunc::Get(arg); | 871 unsigned int alpha_src = SetBlending::AlphaSrcFunc::Get(arg); |
876 unsigned int alpha_dst = cmd::SetBlending::AlphaDstFunc::Get(arg); | 872 unsigned int alpha_dst = SetBlending::AlphaDstFunc::Get(arg); |
877 if (cmd::SetBlending::Unused0::Get(arg) != 0 || | 873 if (SetBlending::Unused0::Get(arg) != 0 || |
878 cmd::SetBlending::Unused1::Get(arg) != 0 || | 874 SetBlending::Unused1::Get(arg) != 0 || |
879 color_eq >= command_buffer::kNumBlendEq || | 875 color_eq >= kNumBlendEq || |
880 color_src >= command_buffer::kNumBlendFunc || | 876 color_src >= kNumBlendFunc || |
881 color_dst >= command_buffer::kNumBlendFunc || | 877 color_dst >= kNumBlendFunc || |
882 alpha_eq >= command_buffer::kNumBlendEq || | 878 alpha_eq >= kNumBlendEq || |
883 alpha_src >= command_buffer::kNumBlendFunc || | 879 alpha_src >= kNumBlendFunc || |
884 alpha_dst >= command_buffer::kNumBlendFunc) | 880 alpha_dst >= kNumBlendFunc) |
885 return parse_error::kParseInvalidArguments; | 881 return parse_error::kParseInvalidArguments; |
886 gapi_->SetBlending(enable, | 882 gapi_->SetBlending(enable, |
887 separate_alpha, | 883 separate_alpha, |
888 static_cast<command_buffer::BlendEq>(color_eq), | 884 static_cast<BlendEq>(color_eq), |
889 static_cast<command_buffer::BlendFunc>(color_src), | 885 static_cast<BlendFunc>(color_src), |
890 static_cast<command_buffer::BlendFunc>(color_dst), | 886 static_cast<BlendFunc>(color_dst), |
891 static_cast<command_buffer::BlendEq>(alpha_eq), | 887 static_cast<BlendEq>(alpha_eq), |
892 static_cast<command_buffer::BlendFunc>(alpha_src), | 888 static_cast<BlendFunc>(alpha_src), |
893 static_cast<command_buffer::BlendFunc>(alpha_dst)); | 889 static_cast<BlendFunc>(alpha_dst)); |
894 return parse_error::kParseNoError; | 890 return parse_error::kParseNoError; |
895 } | 891 } |
896 | 892 |
897 parse_error::ParseError GAPIDecoder::HandleSetBlendingColor( | 893 parse_error::ParseError GAPIDecoder::HandleSetBlendingColor( |
898 uint32 arg_count, | 894 uint32 arg_count, |
899 const cmd::SetBlendingColor& args) { | 895 const SetBlendingColor& args) { |
900 RGBA rgba; | 896 RGBA rgba; |
901 rgba.red = args.red; | 897 rgba.red = args.red; |
902 rgba.green = args.green; | 898 rgba.green = args.green; |
903 rgba.blue = args.blue; | 899 rgba.blue = args.blue; |
904 rgba.alpha = args.alpha; | 900 rgba.alpha = args.alpha; |
905 gapi_->SetBlendingColor(rgba); | 901 gapi_->SetBlendingColor(rgba); |
906 return parse_error::kParseNoError; | 902 return parse_error::kParseNoError; |
907 } | 903 } |
908 | 904 |
909 parse_error::ParseError GAPIDecoder::HandleCreateRenderSurface( | 905 parse_error::ParseError GAPIDecoder::HandleCreateRenderSurface( |
910 uint32 arg_count, | 906 uint32 arg_count, |
911 const cmd::CreateRenderSurface& args) { | 907 const CreateRenderSurface& args) { |
912 unsigned int width_height = args.width_height; | 908 unsigned int width_height = args.width_height; |
913 unsigned int width = cmd::CreateRenderSurface::Width::Get(width_height); | 909 unsigned int width = CreateRenderSurface::Width::Get(width_height); |
914 unsigned int height = cmd::CreateRenderSurface::Height::Get(width_height); | 910 unsigned int height = CreateRenderSurface::Height::Get(width_height); |
915 unsigned int levels_side = args.levels_side; | 911 unsigned int levels_side = args.levels_side; |
916 unsigned int mip_level = cmd::CreateRenderSurface::Levels::Get(levels_side); | 912 unsigned int mip_level = CreateRenderSurface::Levels::Get(levels_side); |
917 unsigned int side = cmd::CreateRenderSurface::Side::Get(levels_side); | 913 unsigned int side = CreateRenderSurface::Side::Get(levels_side); |
918 return gapi_->CreateRenderSurface(args.render_surface_id, | 914 return gapi_->CreateRenderSurface(args.render_surface_id, |
919 width, height, mip_level, | 915 width, height, mip_level, |
920 side, args.texture_id); | 916 side, args.texture_id); |
921 } | 917 } |
922 | 918 |
923 parse_error::ParseError GAPIDecoder::HandleDestroyRenderSurface( | 919 parse_error::ParseError GAPIDecoder::HandleDestroyRenderSurface( |
924 uint32 arg_count, | 920 uint32 arg_count, |
925 const cmd::DestroyRenderSurface& args) { | 921 const DestroyRenderSurface& args) { |
926 return gapi_->DestroyRenderSurface(args.render_surface_id); | 922 return gapi_->DestroyRenderSurface(args.render_surface_id); |
927 } | 923 } |
928 | 924 |
929 parse_error::ParseError GAPIDecoder::HandleCreateDepthSurface( | 925 parse_error::ParseError GAPIDecoder::HandleCreateDepthSurface( |
930 uint32 arg_count, | 926 uint32 arg_count, |
931 const cmd::CreateDepthSurface& args) { | 927 const CreateDepthSurface& args) { |
932 unsigned int width_height = args.width_height; | 928 unsigned int width_height = args.width_height; |
933 unsigned int width = cmd::CreateDepthSurface::Width::Get(width_height); | 929 unsigned int width = CreateDepthSurface::Width::Get(width_height); |
934 unsigned int height = cmd::CreateDepthSurface::Height::Get(width_height); | 930 unsigned int height = CreateDepthSurface::Height::Get(width_height); |
935 return gapi_->CreateDepthSurface(args.depth_surface_id, width, height); | 931 return gapi_->CreateDepthSurface(args.depth_surface_id, width, height); |
936 } | 932 } |
937 | 933 |
938 parse_error::ParseError GAPIDecoder::HandleDestroyDepthSurface( | 934 parse_error::ParseError GAPIDecoder::HandleDestroyDepthSurface( |
939 uint32 arg_count, | 935 uint32 arg_count, |
940 const cmd::DestroyDepthSurface& args) { | 936 const DestroyDepthSurface& args) { |
941 return gapi_->DestroyDepthSurface(args.depth_surface_id); | 937 return gapi_->DestroyDepthSurface(args.depth_surface_id); |
942 } | 938 } |
943 | 939 |
944 parse_error::ParseError GAPIDecoder::HandleSetRenderSurface( | 940 parse_error::ParseError GAPIDecoder::HandleSetRenderSurface( |
945 uint32 arg_count, | 941 uint32 arg_count, |
946 const cmd::SetRenderSurface& args) { | 942 const SetRenderSurface& args) { |
947 return gapi_->SetRenderSurface(args.render_surface_id, args.depth_surface_id); | 943 return gapi_->SetRenderSurface(args.render_surface_id, args.depth_surface_id); |
948 } | 944 } |
949 | 945 |
950 parse_error::ParseError GAPIDecoder::HandleSetBackSurfaces( | 946 parse_error::ParseError GAPIDecoder::HandleSetBackSurfaces( |
951 uint32 arg_count, | 947 uint32 arg_count, |
952 const cmd::SetBackSurfaces& args) { | 948 const SetBackSurfaces& args) { |
953 gapi_->SetBackSurfaces(); | 949 gapi_->SetBackSurfaces(); |
954 return parse_error::kParseNoError; | 950 return parse_error::kParseNoError; |
955 } | 951 } |
956 | 952 |
| 953 } // namespace o3d |
957 } // namespace command_buffer | 954 } // namespace command_buffer |
958 } // namespace o3d | 955 } // namespace o3d |
OLD | NEW |