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

Side by Side Diff: gpu/tools/compositor_model_bench/render_tree.cc

Issue 2145543002: Use base::FooValue::From() to simplify gpu code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
« no previous file with comments | « gpu/tools/compositor_model_bench/render_tree.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/tools/compositor_model_bench/render_tree.h" 5 #include "gpu/tools/compositor_model_bench/render_tree.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <sstream> 8 #include <sstream>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "gpu/tools/compositor_model_bench/shaders.h" 17 #include "gpu/tools/compositor_model_bench/shaders.h"
18 18
19 using base::JSONReader; 19 using base::JSONReader;
20 using base::JSONWriter; 20 using base::JSONWriter;
21 using base::ReadFileToString; 21 using base::ReadFileToString;
22 using std::string; 22 using base::Value;
23 using std::vector;
24 23
25 GLenum TextureFormatFromString(const std::string& format) { 24 GLenum TextureFormatFromString(const std::string& format) {
26 if (format == "RGBA") 25 if (format == "RGBA")
27 return GL_RGBA; 26 return GL_RGBA;
28 if (format == "RGB") 27 if (format == "RGB")
29 return GL_RGB; 28 return GL_RGB;
30 if (format == "LUMINANCE") 29 if (format == "LUMINANCE")
31 return GL_LUMINANCE; 30 return GL_LUMINANCE;
32 return GL_INVALID_ENUM; 31 return GL_INVALID_ENUM;
33 } 32 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 108 }
110 109
111 void RenderNodeVisitor::EndVisitContentLayerNode(ContentLayerNode* v) { 110 void RenderNodeVisitor::EndVisitContentLayerNode(ContentLayerNode* v) {
112 this->EndVisitRenderNode(v); 111 this->EndVisitRenderNode(v);
113 } 112 }
114 113
115 void RenderNodeVisitor::EndVisitCCNode(CCNode* v) { 114 void RenderNodeVisitor::EndVisitCCNode(CCNode* v) {
116 this->EndVisitRenderNode(v); 115 this->EndVisitRenderNode(v);
117 } 116 }
118 117
119 RenderNode* InterpretNode(base::DictionaryValue* node); 118 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node);
120 119
121 std::string ValueTypeAsString(base::Value::Type type) { 120 std::string ValueTypeAsString(Value::Type type) {
122 switch (type) { 121 switch (type) {
123 case base::Value::TYPE_NULL: 122 case Value::TYPE_NULL:
124 return "NULL"; 123 return "NULL";
125 case base::Value::TYPE_BOOLEAN: 124 case Value::TYPE_BOOLEAN:
126 return "BOOLEAN"; 125 return "BOOLEAN";
127 case base::Value::TYPE_INTEGER: 126 case Value::TYPE_INTEGER:
128 return "INTEGER"; 127 return "INTEGER";
129 case base::Value::TYPE_DOUBLE: 128 case Value::TYPE_DOUBLE:
130 return "DOUBLE"; 129 return "DOUBLE";
131 case base::Value::TYPE_STRING: 130 case Value::TYPE_STRING:
132 return "STRING"; 131 return "STRING";
133 case base::Value::TYPE_BINARY: 132 case Value::TYPE_BINARY:
134 return "BINARY"; 133 return "BINARY";
135 case base::Value::TYPE_DICTIONARY: 134 case Value::TYPE_DICTIONARY:
136 return "DICTIONARY"; 135 return "DICTIONARY";
137 case base::Value::TYPE_LIST: 136 case Value::TYPE_LIST:
138 return "LIST"; 137 return "LIST";
139 default: 138 default:
140 return "(UNKNOWN TYPE)"; 139 return "(UNKNOWN TYPE)";
141 } 140 }
142 } 141 }
143 142
144 // Makes sure that the key exists and has the type we expect. 143 // Makes sure that the key exists and has the type we expect.
145 bool VerifyDictionaryEntry(base::DictionaryValue* node, 144 bool VerifyDictionaryEntry(const base::DictionaryValue& node,
146 const std::string& key, 145 const std::string& key,
147 base::Value::Type type) { 146 Value::Type type) {
148 if (!node->HasKey(key)) { 147 if (!node.HasKey(key)) {
149 LOG(ERROR) << "Missing value for key: " << key; 148 LOG(ERROR) << "Missing value for key: " << key;
150 return false; 149 return false;
151 } 150 }
152 151
153 base::Value* child; 152 const Value* child;
154 node->Get(key, &child); 153 node.Get(key, &child);
155 if (!child->IsType(type)) { 154 if (!child->IsType(type)) {
156 LOG(ERROR) << key << " did not have the expected type " 155 LOG(ERROR) << key << " did not have the expected type "
157 "(expected " << ValueTypeAsString(type) << ")"; 156 "(expected " << ValueTypeAsString(type) << ")";
158 return false; 157 return false;
159 } 158 }
160 159
161 return true; 160 return true;
162 } 161 }
163 162
164 // Makes sure that the list entry has the type we expect. 163 // Makes sure that the list entry has the type we expect.
165 bool VerifyListEntry(base::ListValue* l, 164 bool VerifyListEntry(const base::ListValue& l,
166 int idx, 165 int idx,
167 base::Value::Type type, 166 Value::Type type,
168 const char* listName = 0) { 167 const char* listName = nullptr) {
169 // Assume the idx is valid (since we'll be able to generate a better 168 // Assume the idx is valid (since we'll be able to generate a better
170 // error message for this elsewhere.) 169 // error message for this elsewhere.)
171 base::Value* el; 170 const Value* el;
172 l->Get(idx, &el); 171 l.Get(idx, &el);
173 if (!el->IsType(type)) { 172 if (!el->IsType(type)) {
174 LOG(ERROR) << (listName ? listName : "List") << "element " << idx << 173 LOG(ERROR) << (listName ? listName : "List") << "element " << idx
175 " did not have the expected type (expected " << 174 << " did not have the expected type (expected "
176 ValueTypeAsString(type) << ")\n"; 175 << ValueTypeAsString(type) << ")\n";
177 return false; 176 return false;
178 } 177 }
179 178
180 return true; 179 return true;
181 } 180 }
182 181
183 bool InterpretCommonContents(base::DictionaryValue* node, RenderNode* c) { 182 bool InterpretCommonContents(const base::DictionaryValue& node, RenderNode* c) {
184 if (!VerifyDictionaryEntry(node, "layerID", base::Value::TYPE_INTEGER) || 183 if (!VerifyDictionaryEntry(node, "layerID", Value::TYPE_INTEGER) ||
185 !VerifyDictionaryEntry(node, "width", base::Value::TYPE_INTEGER) || 184 !VerifyDictionaryEntry(node, "width", Value::TYPE_INTEGER) ||
186 !VerifyDictionaryEntry(node, "height", base::Value::TYPE_INTEGER) || 185 !VerifyDictionaryEntry(node, "height", Value::TYPE_INTEGER) ||
187 !VerifyDictionaryEntry(node, "drawsContent", base::Value::TYPE_BOOLEAN) || 186 !VerifyDictionaryEntry(node, "drawsContent", Value::TYPE_BOOLEAN) ||
188 !VerifyDictionaryEntry(node, "targetSurfaceID", 187 !VerifyDictionaryEntry(node, "targetSurfaceID", Value::TYPE_INTEGER) ||
189 base::Value::TYPE_INTEGER) || 188 !VerifyDictionaryEntry(node, "transform", Value::TYPE_LIST)) {
190 !VerifyDictionaryEntry(node, "transform", base::Value::TYPE_LIST)
191 ) {
192 return false; 189 return false;
193 } 190 }
194 191
195 int layerID; 192 int layerID;
196 node->GetInteger("layerID", &layerID); 193 node.GetInteger("layerID", &layerID);
197 c->set_layerID(layerID); 194 c->set_layerID(layerID);
198 int width; 195 int width;
199 node->GetInteger("width", &width); 196 node.GetInteger("width", &width);
200 c->set_width(width); 197 c->set_width(width);
201 int height; 198 int height;
202 node->GetInteger("height", &height); 199 node.GetInteger("height", &height);
203 c->set_height(height); 200 c->set_height(height);
204 bool drawsContent; 201 bool drawsContent;
205 node->GetBoolean("drawsContent", &drawsContent); 202 node.GetBoolean("drawsContent", &drawsContent);
206 c->set_drawsContent(drawsContent); 203 c->set_drawsContent(drawsContent);
207 int targetSurface; 204 int targetSurface;
208 node->GetInteger("targetSurfaceID", &targetSurface); 205 node.GetInteger("targetSurfaceID", &targetSurface);
209 c->set_targetSurface(targetSurface); 206 c->set_targetSurface(targetSurface);
210 207
211 base::ListValue* transform; 208 const base::ListValue* transform;
212 node->GetList("transform", &transform); 209 node.GetList("transform", &transform);
213 if (transform->GetSize() != 16) { 210 if (transform->GetSize() != 16) {
214 LOG(ERROR) << "4x4 transform matrix did not have 16 elements"; 211 LOG(ERROR) << "4x4 transform matrix did not have 16 elements";
215 return false; 212 return false;
216 } 213 }
217 float transform_mat[16]; 214 float transform_mat[16];
218 for (int i = 0; i < 16; ++i) { 215 for (int i = 0; i < 16; ++i) {
219 if (!VerifyListEntry(transform, i, base::Value::TYPE_DOUBLE, "Transform")) 216 if (!VerifyListEntry(*transform, i, Value::TYPE_DOUBLE, "Transform"))
220 return false; 217 return false;
221 double el; 218 double el;
222 transform->GetDouble(i, &el); 219 transform->GetDouble(i, &el);
223 transform_mat[i] = el; 220 transform_mat[i] = el;
224 } 221 }
225 c->set_transform(transform_mat); 222 c->set_transform(transform_mat);
226 223
227 if (node->HasKey("tiles")) { 224 if (!node.HasKey("tiles"))
228 if (!VerifyDictionaryEntry(node, "tiles", base::Value::TYPE_DICTIONARY)) 225 return true;
226
227 if (!VerifyDictionaryEntry(node, "tiles", Value::TYPE_DICTIONARY))
228 return false;
229 const base::DictionaryValue* tiles_dict;
230 node.GetDictionary("tiles", &tiles_dict);
231 if (!VerifyDictionaryEntry(*tiles_dict, "dim", Value::TYPE_LIST))
232 return false;
233 const base::ListValue* dim;
234 tiles_dict->GetList("dim", &dim);
235 if (!VerifyListEntry(*dim, 0, Value::TYPE_INTEGER, "Tile dimension") ||
236 !VerifyListEntry(*dim, 1, Value::TYPE_INTEGER, "Tile dimension")) {
237 return false;
238 }
239 int tile_width;
240 dim->GetInteger(0, &tile_width);
241 c->set_tile_width(tile_width);
242 int tile_height;
243 dim->GetInteger(1, &tile_height);
244 c->set_tile_height(tile_height);
245
246 if (!VerifyDictionaryEntry(*tiles_dict, "info", Value::TYPE_LIST))
247 return false;
248 const base::ListValue* tiles;
249 tiles_dict->GetList("info", &tiles);
250 for (unsigned int i = 0; i < tiles->GetSize(); ++i) {
251 if (!VerifyListEntry(*tiles, i, Value::TYPE_DICTIONARY, "Tile info"))
229 return false; 252 return false;
230 base::DictionaryValue* tiles_dict; 253 const base::DictionaryValue* tdict;
231 node->GetDictionary("tiles", &tiles_dict); 254 tiles->GetDictionary(i, &tdict);
232 if (!VerifyDictionaryEntry(tiles_dict, "dim", base::Value::TYPE_LIST)) 255
233 return false; 256 if (!VerifyDictionaryEntry(*tdict, "x", Value::TYPE_INTEGER) ||
234 base::ListValue* dim; 257 !VerifyDictionaryEntry(*tdict, "y", Value::TYPE_INTEGER)) {
235 tiles_dict->GetList("dim", &dim);
236 if (!VerifyListEntry(dim, 0, base::Value::TYPE_INTEGER, "Tile dimension") ||
237 !VerifyListEntry(dim, 1, base::Value::TYPE_INTEGER, "Tile dimension")) {
238 return false; 258 return false;
239 } 259 }
240 int tile_width; 260 Tile t;
241 dim->GetInteger(0, &tile_width); 261 tdict->GetInteger("x", &t.x);
242 c->set_tile_width(tile_width); 262 tdict->GetInteger("y", &t.y);
243 int tile_height; 263 if (tdict->HasKey("texID")) {
244 dim->GetInteger(1, &tile_height); 264 if (!VerifyDictionaryEntry(*tdict, "texID", Value::TYPE_INTEGER))
245 c->set_tile_height(tile_height);
246
247 if (!VerifyDictionaryEntry(tiles_dict, "info", base::Value::TYPE_LIST))
248 return false;
249 base::ListValue* tiles;
250 tiles_dict->GetList("info", &tiles);
251 for (unsigned int i = 0; i < tiles->GetSize(); ++i) {
252 if (!VerifyListEntry(tiles, i, base::Value::TYPE_DICTIONARY, "Tile info"))
253 return false; 265 return false;
254 base::DictionaryValue* tdict; 266 tdict->GetInteger("texID", &t.texID);
255 tiles->GetDictionary(i, &tdict); 267 } else {
256 268 t.texID = -1;
257 if (!VerifyDictionaryEntry(tdict, "x", base::Value::TYPE_INTEGER) ||
258 !VerifyDictionaryEntry(tdict, "y", base::Value::TYPE_INTEGER)) {
259 return false;
260 }
261 Tile t;
262 tdict->GetInteger("x", &t.x);
263 tdict->GetInteger("y", &t.y);
264 if (tdict->HasKey("texID")) {
265 if (!VerifyDictionaryEntry(tdict, "texID", base::Value::TYPE_INTEGER))
266 return false;
267 tdict->GetInteger("texID", &t.texID);
268 } else {
269 t.texID = -1;
270 }
271 c->add_tile(t);
272 } 269 }
270 c->add_tile(t);
273 } 271 }
274 return true; 272 return true;
275 } 273 }
276 274
277 bool InterpretCCData(base::DictionaryValue* node, CCNode* c) { 275 bool InterpretCCData(const base::DictionaryValue& node, CCNode* c) {
278 if (!VerifyDictionaryEntry(node, "vertex_shader", base::Value::TYPE_STRING) || 276 if (!VerifyDictionaryEntry(node, "vertex_shader", Value::TYPE_STRING) ||
279 !VerifyDictionaryEntry(node, "fragment_shader", 277 !VerifyDictionaryEntry(node, "fragment_shader", Value::TYPE_STRING) ||
280 base::Value::TYPE_STRING) || 278 !VerifyDictionaryEntry(node, "textures", Value::TYPE_LIST)) {
281 !VerifyDictionaryEntry(node, "textures", base::Value::TYPE_LIST)) {
282 return false; 279 return false;
283 } 280 }
284 string vertex_shader_name, fragment_shader_name; 281 std::string vertex_shader_name, fragment_shader_name;
285 node->GetString("vertex_shader", &vertex_shader_name); 282 node.GetString("vertex_shader", &vertex_shader_name);
286 node->GetString("fragment_shader", &fragment_shader_name); 283 node.GetString("fragment_shader", &fragment_shader_name);
287 284
288 c->set_vertex_shader(ShaderIDFromString(vertex_shader_name)); 285 c->set_vertex_shader(ShaderIDFromString(vertex_shader_name));
289 c->set_fragment_shader(ShaderIDFromString(fragment_shader_name)); 286 c->set_fragment_shader(ShaderIDFromString(fragment_shader_name));
290 base::ListValue* textures; 287 const base::ListValue* textures;
291 node->GetList("textures", &textures); 288 node.GetList("textures", &textures);
292 for (unsigned int i = 0; i < textures->GetSize(); ++i) { 289 for (unsigned int i = 0; i < textures->GetSize(); ++i) {
293 if (!VerifyListEntry(textures, i, base::Value::TYPE_DICTIONARY, "Tex list")) 290 if (!VerifyListEntry(*textures, i, Value::TYPE_DICTIONARY, "Tex list"))
294 return false; 291 return false;
295 base::DictionaryValue* tex; 292 const base::DictionaryValue* tex;
296 textures->GetDictionary(i, &tex); 293 textures->GetDictionary(i, &tex);
297 294
298 if (!VerifyDictionaryEntry(tex, "texID", base::Value::TYPE_INTEGER) || 295 if (!VerifyDictionaryEntry(*tex, "texID", Value::TYPE_INTEGER) ||
299 !VerifyDictionaryEntry(tex, "height", base::Value::TYPE_INTEGER) || 296 !VerifyDictionaryEntry(*tex, "height", Value::TYPE_INTEGER) ||
300 !VerifyDictionaryEntry(tex, "width", base::Value::TYPE_INTEGER) || 297 !VerifyDictionaryEntry(*tex, "width", Value::TYPE_INTEGER) ||
301 !VerifyDictionaryEntry(tex, "format", base::Value::TYPE_STRING)) { 298 !VerifyDictionaryEntry(*tex, "format", Value::TYPE_STRING)) {
302 return false; 299 return false;
303 } 300 }
304 Texture t; 301 Texture t;
305 tex->GetInteger("texID", &t.texID); 302 tex->GetInteger("texID", &t.texID);
306 tex->GetInteger("height", &t.height); 303 tex->GetInteger("height", &t.height);
307 tex->GetInteger("width", &t.width); 304 tex->GetInteger("width", &t.width);
308 305
309 string formatName; 306 std::string formatName;
310 tex->GetString("format", &formatName); 307 tex->GetString("format", &formatName);
311 t.format = TextureFormatFromString(formatName); 308 t.format = TextureFormatFromString(formatName);
312 if (t.format == GL_INVALID_ENUM) { 309 if (t.format == GL_INVALID_ENUM) {
313 LOG(ERROR) << "Unrecognized texture format in layer " << c->layerID() << 310 LOG(ERROR) << "Unrecognized texture format in layer " << c->layerID()
314 " (format: " << formatName << ")\n" 311 << " (format: " << formatName << ")\n"
315 "The layer had " << textures->GetSize() << " children."; 312 "The layer had "
313 << textures->GetSize() << " children.";
316 return false; 314 return false;
317 } 315 }
318 316
319 c->add_texture(t); 317 c->add_texture(t);
320 } 318 }
321 319
322 if (c->vertex_shader() == SHADER_UNRECOGNIZED) { 320 if (c->vertex_shader() == SHADER_UNRECOGNIZED) {
323 LOG(ERROR) << "Unrecognized vertex shader name, layer " << c->layerID() << 321 LOG(ERROR) << "Unrecognized vertex shader name, layer " << c->layerID()
324 " (shader: " << vertex_shader_name << ")"; 322 << " (shader: " << vertex_shader_name << ")";
325 return false; 323 return false;
326 } 324 }
327 325
328 if (c->fragment_shader() == SHADER_UNRECOGNIZED) { 326 if (c->fragment_shader() == SHADER_UNRECOGNIZED) {
329 LOG(ERROR) << "Unrecognized fragment shader name, layer " << c->layerID() << 327 LOG(ERROR) << "Unrecognized fragment shader name, layer " << c->layerID()
330 " (shader: " << fragment_shader_name << ")"; 328 << " (shader: " << fragment_shader_name << ")";
331 return false; 329 return false;
332 } 330 }
333 331
334 return true; 332 return true;
335 } 333 }
336 334
337 RenderNode* InterpretContentLayer(base::DictionaryValue* node) { 335 std::unique_ptr<RenderNode> InterpretContentLayer(
338 ContentLayerNode* n = new ContentLayerNode; 336 const base::DictionaryValue& node) {
339 if (!InterpretCommonContents(node, n)) 337 auto n = base::MakeUnique<ContentLayerNode>();
340 return NULL; 338 if (!InterpretCommonContents(node, n.get()))
339 return nullptr;
341 340
342 if (!VerifyDictionaryEntry(node, "type", base::Value::TYPE_STRING) || 341 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING) ||
343 !VerifyDictionaryEntry(node, "skipsDraw", base::Value::TYPE_BOOLEAN) || 342 !VerifyDictionaryEntry(node, "skipsDraw", Value::TYPE_BOOLEAN) ||
344 !VerifyDictionaryEntry(node, "children", base::Value::TYPE_LIST)) { 343 !VerifyDictionaryEntry(node, "children", Value::TYPE_LIST)) {
345 return NULL; 344 return nullptr;
346 } 345 }
347 346
348 string type; 347 std::string type;
349 node->GetString("type", &type); 348 node.GetString("type", &type);
350 DCHECK_EQ(type, "ContentLayer"); 349 DCHECK_EQ(type, "ContentLayer");
351 bool skipsDraw; 350 bool skipsDraw;
352 node->GetBoolean("skipsDraw", &skipsDraw); 351 node.GetBoolean("skipsDraw", &skipsDraw);
353 n->set_skipsDraw(skipsDraw); 352 n->set_skipsDraw(skipsDraw);
354 353
355 base::ListValue* children; 354 const base::ListValue* children;
356 node->GetList("children", &children); 355 node.GetList("children", &children);
357 for (unsigned int i = 0; i < children->GetSize(); ++i) { 356 for (unsigned int i = 0; i < children->GetSize(); ++i) {
358 base::DictionaryValue* childNode; 357 const base::DictionaryValue* childNode;
359 children->GetDictionary(i, &childNode); 358 if (!children->GetDictionary(i, &childNode))
360 RenderNode* child = InterpretNode(childNode); 359 continue;
360 std::unique_ptr<RenderNode> child = InterpretNode(*childNode);
361 if (child) 361 if (child)
362 n->add_child(child); 362 n->add_child(child.release());
363 } 363 }
364 364
365 return n; 365 return n;
366 } 366 }
367 367
368 RenderNode* InterpretCanvasLayer(base::DictionaryValue* node) { 368 std::unique_ptr<RenderNode> InterpretCanvasLayer(
369 CCNode* n = new CCNode; 369 const base::DictionaryValue& node) {
370 if (!InterpretCommonContents(node, n)) 370 auto n = base::MakeUnique<CCNode>();
371 return NULL; 371 if (!InterpretCommonContents(node, n.get()))
372 return nullptr;
372 373
373 if (!VerifyDictionaryEntry(node, "type", base::Value::TYPE_STRING)) { 374 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING))
374 return NULL; 375 return nullptr;
375 }
376 376
377 string type; 377 std::string type;
378 node->GetString("type", &type); 378 node.GetString("type", &type);
379 assert(type == "CanvasLayer"); 379 assert(type == "CanvasLayer");
380 380
381 if (!InterpretCCData(node, n)) 381 if (!InterpretCCData(node, n.get()))
382 return NULL; 382 return nullptr;
383 383
384 return n; 384 return n;
385 } 385 }
386 386
387 RenderNode* InterpretVideoLayer(base::DictionaryValue* node) { 387 std::unique_ptr<RenderNode> InterpretVideoLayer(
388 CCNode* n = new CCNode; 388 const base::DictionaryValue& node) {
389 if (!InterpretCommonContents(node, n)) 389 auto n = base::MakeUnique<CCNode>();
390 return NULL; 390 if (!InterpretCommonContents(node, n.get()))
391 return nullptr;
391 392
392 if (!VerifyDictionaryEntry(node, "type", base::Value::TYPE_STRING)) { 393 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING))
393 return NULL; 394 return nullptr;
394 }
395 395
396 string type; 396 std::string type;
397 node->GetString("type", &type); 397 node.GetString("type", &type);
398 assert(type == "VideoLayer"); 398 assert(type == "VideoLayer");
399 399
400 if (!InterpretCCData(node, n)) 400 if (!InterpretCCData(node, n.get()))
401 return NULL; 401 return nullptr;
402 402
403 return n; 403 return n;
404 } 404 }
405 405
406 RenderNode* InterpretImageLayer(base::DictionaryValue* node) { 406 std::unique_ptr<RenderNode> InterpretImageLayer(
407 CCNode* n = new CCNode; 407 const base::DictionaryValue& node) {
408 if (!InterpretCommonContents(node, n)) 408 auto n = base::MakeUnique<CCNode>();
409 return NULL; 409 if (!InterpretCommonContents(node, n.get()))
410 return nullptr;
410 411
411 if (!VerifyDictionaryEntry(node, "type", base::Value::TYPE_STRING)) { 412 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING))
412 return NULL; 413 return nullptr;
413 }
414 414
415 string type; 415 std::string type;
416 node->GetString("type", &type); 416 node.GetString("type", &type);
417 assert(type == "ImageLayer"); 417 assert(type == "ImageLayer");
418 418
419 if (!InterpretCCData(node, n)) 419 if (!InterpretCCData(node, n.get()))
420 return NULL; 420 return nullptr;
421 421
422 return n; 422 return n;
423 } 423 }
424 424
425 RenderNode* InterpretNode(base::DictionaryValue* node) { 425 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node) {
426 if (!VerifyDictionaryEntry(node, "type", base::Value::TYPE_STRING)) { 426 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING))
427 return NULL; 427 return nullptr;
428 }
429 428
430 string type; 429 std::string type;
431 node->GetString("type", &type); 430 node.GetString("type", &type);
432 if (type == "ContentLayer") 431 if (type == "ContentLayer")
433 return InterpretContentLayer(node); 432 return InterpretContentLayer(node);
434 if (type == "CanvasLayer") 433 if (type == "CanvasLayer")
435 return InterpretCanvasLayer(node); 434 return InterpretCanvasLayer(node);
436 if (type == "VideoLayer") 435 if (type == "VideoLayer")
437 return InterpretVideoLayer(node); 436 return InterpretVideoLayer(node);
438 if (type == "ImageLayer") 437 if (type == "ImageLayer")
439 return InterpretImageLayer(node); 438 return InterpretImageLayer(node);
440 439
441 440 std::string outjson;
442 string outjson; 441 JSONWriter::WriteWithOptions(node, base::JSONWriter::OPTIONS_PRETTY_PRINT,
443 JSONWriter::WriteWithOptions(*node, base::JSONWriter::OPTIONS_PRETTY_PRINT,
444 &outjson); 442 &outjson);
445 LOG(ERROR) << "Unrecognized node type! JSON:\n\n" 443 LOG(ERROR) << "Unrecognized node type! JSON:\n\n"
446 "-----------------------\n" << 444 "-----------------------\n"
447 outjson << 445 << outjson << "-----------------------";
448 "-----------------------";
449 446
450 return NULL; 447 return nullptr;
451 } 448 }
452 449
453 RenderNode* BuildRenderTreeFromFile(const base::FilePath& path) { 450 std::unique_ptr<RenderNode> BuildRenderTreeFromFile(
451 const base::FilePath& path) {
454 LOG(INFO) << "Reading " << path.LossyDisplayName(); 452 LOG(INFO) << "Reading " << path.LossyDisplayName();
455 string contents; 453 std::string contents;
456 if (!ReadFileToString(path, &contents)) 454 if (!ReadFileToString(path, &contents))
457 return NULL; 455 return nullptr;
458 456
459 int error_code = 0; 457 int error_code = 0;
460 string error_message; 458 std::string error_message;
461 std::unique_ptr<base::Value> root = JSONReader::ReadAndReturnError( 459 std::unique_ptr<base::DictionaryValue> root = base::DictionaryValue::From(
462 contents, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_message); 460 JSONReader::ReadAndReturnError(contents, base::JSON_ALLOW_TRAILING_COMMAS,
461 &error_code, &error_message));
463 if (!root) { 462 if (!root) {
464 LOG(ERROR) << "Failed to parse JSON file " << path.LossyDisplayName() << 463 if (error_code) {
465 "\n(" << error_message << ")"; 464 LOG(ERROR) << "Failed to parse JSON file " << path.LossyDisplayName()
466 return NULL; 465 << "\n(" << error_message << ")";
466 } else {
467 LOG(ERROR) << path.LossyDisplayName()
468 << " doesn not encode a JSON dictionary.";
469 }
470 return nullptr;
467 } 471 }
468 472
469 if (root->IsType(base::Value::TYPE_DICTIONARY)) { 473 return InterpretContentLayer(*root);
470 base::DictionaryValue* v = static_cast<base::DictionaryValue*>(root.get());
471 RenderNode* tree = InterpretContentLayer(v);
472 return tree;
473 } else {
474 LOG(ERROR) << path.LossyDisplayName() <<
475 " doesn not encode a JSON dictionary.";
476 return NULL;
477 }
478 } 474 }
479 475
OLDNEW
« no previous file with comments | « gpu/tools/compositor_model_bench/render_tree.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698