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

Side by Side Diff: command_buffer/client/cross/effect_helper.cc

Issue 147237: Adding GetStreamInfo functionality (and passing corresponding unit test). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const std::vector<EffectParamDesc> &descs) { 200 const std::vector<EffectParamDesc> &descs) {
201 CommandBufferEntry args[1]; 201 CommandBufferEntry args[1];
202 for (unsigned int i = 0; i < descs.size(); ++i) { 202 for (unsigned int i = 0; i < descs.size(); ++i) {
203 const EffectParamDesc &desc = descs[i]; 203 const EffectParamDesc &desc = descs[i];
204 args[0].value_uint32 = desc.id; 204 args[0].value_uint32 = desc.id;
205 helper_->AddCommand(DESTROY_PARAM, 1, args); 205 helper_->AddCommand(DESTROY_PARAM, 1, args);
206 param_id_allocator_->FreeID(desc.id); 206 param_id_allocator_->FreeID(desc.id);
207 } 207 }
208 } 208 }
209 209
210 bool EffectHelper::GetEffectStreams(ResourceID effect_id,
211 std::vector<EffectStreamDesc> *descs) {
212 using effect_stream::Desc;
213 DCHECK_NE(effect_id, kInvalidResource);
214
215 // Get the param count.
216 Uint32 *retval = shm_allocator_->AllocTyped<Uint32>(1);
217 CommandBufferEntry args[5];
218 args[0].value_uint32 = effect_id;
219 args[1].value_uint32 = sizeof(*retval);
220 args[2].value_uint32 = shm_id_;
221 args[3].value_uint32 = shm_allocator_->GetOffset(retval);
222 helper_->AddCommand(GET_STREAM_COUNT, 4, args);
223 // Finish has to be called to get the result.
224 helper_->Finish();
225
226 // We could have failed if the effect_id is invalid.
227 if (helper_->interface()->GetParseError() !=
228 BufferSyncInterface::PARSE_NO_ERROR) {
229 shm_allocator_->Free(retval);
230 return false;
231 }
232 unsigned int stream_count = *retval;
233 shm_allocator_->Free(retval);
234 unsigned int max_buffer_size = shm_allocator_->GetLargestFreeOrPendingSize();
235 if (max_buffer_size < sizeof(Desc)) { // NOLINT
236 // Not enough memory to get at least 1 stream desc.
237 return false;
238 }
239 descs->resize(stream_count);
240
241 // Read stream descriptions in batches. We use as much shared memory as
242 // possible so that we only call Finish as little as possible.
243 unsigned int max_stream_per_batch =
244 std::min(stream_count, max_buffer_size / sizeof(Desc)); // NOLINT
245 Desc *raw_descs = shm_allocator_->AllocTyped<Desc>(max_stream_per_batch);
246 DCHECK(raw_descs);
247 for (unsigned int i = 0; i < stream_count; i += max_stream_per_batch) {
248 unsigned int count = std::min(stream_count - i, max_stream_per_batch);
249 for (unsigned int j = 0 ; j < count; ++j) {
250 EffectStreamDesc *desc = &((*descs)[i + j]);
251 Desc *raw_desc = raw_descs + j;
252 args[0].value_uint32 = effect_id;
253 args[1].value_uint32 = i+j;
254 args[2].value_uint32 = sizeof(*raw_desc);
255 args[3].value_uint32 = shm_id_;
256 args[4].value_uint32 = shm_allocator_->GetOffset(raw_desc);
257 helper_->AddCommand(GET_STREAM_DESC, 5, args);
258 }
259 // Finish to get the results.
260 helper_->Finish();
261 DCHECK_EQ(helper_->interface()->GetParseError(),
262 BufferSyncInterface::PARSE_NO_ERROR);
263 for (unsigned int j = 0 ; j < count; ++j) {
264 EffectStreamDesc *desc = &((*descs)[i + j]);
265 Desc *raw_desc = raw_descs + j;
266 desc->semantic = static_cast<vertex_struct::Semantic>(raw_desc->semantic);
267 desc->semantic_index = raw_desc->semantic_index;
268 }
269 }
270 shm_allocator_->Free(raw_descs);
271 return true;
272 }
210 } // namespace command_buffer 273 } // namespace command_buffer
211 } // namespace o3d 274 } // namespace o3d
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698