| OLD | NEW |
| 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 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 void RenderNodeVisitor::EndVisitCCNode(CCNode* v) { | 114 void RenderNodeVisitor::EndVisitCCNode(CCNode* v) { |
| 115 this->EndVisitRenderNode(v); | 115 this->EndVisitRenderNode(v); |
| 116 } | 116 } |
| 117 | 117 |
| 118 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node); | 118 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node); |
| 119 | 119 |
| 120 std::string ValueTypeAsString(Value::Type type) { | 120 std::string ValueTypeAsString(Value::Type type) { |
| 121 switch (type) { | 121 switch (type) { |
| 122 case Value::TYPE_NULL: | 122 case Value::Type::NONE: |
| 123 return "NULL"; | 123 return "NULL"; |
| 124 case Value::TYPE_BOOLEAN: | 124 case Value::Type::BOOLEAN: |
| 125 return "BOOLEAN"; | 125 return "BOOLEAN"; |
| 126 case Value::TYPE_INTEGER: | 126 case Value::Type::INTEGER: |
| 127 return "INTEGER"; | 127 return "INTEGER"; |
| 128 case Value::TYPE_DOUBLE: | 128 case Value::Type::DOUBLE: |
| 129 return "DOUBLE"; | 129 return "DOUBLE"; |
| 130 case Value::TYPE_STRING: | 130 case Value::Type::STRING: |
| 131 return "STRING"; | 131 return "STRING"; |
| 132 case Value::TYPE_BINARY: | 132 case Value::Type::BINARY: |
| 133 return "BINARY"; | 133 return "BINARY"; |
| 134 case Value::TYPE_DICTIONARY: | 134 case Value::Type::DICTIONARY: |
| 135 return "DICTIONARY"; | 135 return "DICTIONARY"; |
| 136 case Value::TYPE_LIST: | 136 case Value::Type::LIST: |
| 137 return "LIST"; | 137 return "LIST"; |
| 138 default: | 138 default: |
| 139 return "(UNKNOWN TYPE)"; | 139 return "(UNKNOWN TYPE)"; |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 // 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. |
| 144 bool VerifyDictionaryEntry(const base::DictionaryValue& node, | 144 bool VerifyDictionaryEntry(const base::DictionaryValue& node, |
| 145 const std::string& key, | 145 const std::string& key, |
| 146 Value::Type type) { | 146 Value::Type type) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 173 LOG(ERROR) << (listName ? listName : "List") << "element " << idx | 173 LOG(ERROR) << (listName ? listName : "List") << "element " << idx |
| 174 << " did not have the expected type (expected " | 174 << " did not have the expected type (expected " |
| 175 << ValueTypeAsString(type) << ")\n"; | 175 << ValueTypeAsString(type) << ")\n"; |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 return true; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool InterpretCommonContents(const base::DictionaryValue& node, RenderNode* c) { | 182 bool InterpretCommonContents(const base::DictionaryValue& node, RenderNode* c) { |
| 183 if (!VerifyDictionaryEntry(node, "layerID", Value::TYPE_INTEGER) || | 183 if (!VerifyDictionaryEntry(node, "layerID", Value::Type::INTEGER) || |
| 184 !VerifyDictionaryEntry(node, "width", Value::TYPE_INTEGER) || | 184 !VerifyDictionaryEntry(node, "width", Value::Type::INTEGER) || |
| 185 !VerifyDictionaryEntry(node, "height", Value::TYPE_INTEGER) || | 185 !VerifyDictionaryEntry(node, "height", Value::Type::INTEGER) || |
| 186 !VerifyDictionaryEntry(node, "drawsContent", Value::TYPE_BOOLEAN) || | 186 !VerifyDictionaryEntry(node, "drawsContent", Value::Type::BOOLEAN) || |
| 187 !VerifyDictionaryEntry(node, "targetSurfaceID", Value::TYPE_INTEGER) || | 187 !VerifyDictionaryEntry(node, "targetSurfaceID", Value::Type::INTEGER) || |
| 188 !VerifyDictionaryEntry(node, "transform", Value::TYPE_LIST)) { | 188 !VerifyDictionaryEntry(node, "transform", Value::Type::LIST)) { |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| 191 | 191 |
| 192 int layerID; | 192 int layerID; |
| 193 node.GetInteger("layerID", &layerID); | 193 node.GetInteger("layerID", &layerID); |
| 194 c->set_layerID(layerID); | 194 c->set_layerID(layerID); |
| 195 int width; | 195 int width; |
| 196 node.GetInteger("width", &width); | 196 node.GetInteger("width", &width); |
| 197 c->set_width(width); | 197 c->set_width(width); |
| 198 int height; | 198 int height; |
| 199 node.GetInteger("height", &height); | 199 node.GetInteger("height", &height); |
| 200 c->set_height(height); | 200 c->set_height(height); |
| 201 bool drawsContent; | 201 bool drawsContent; |
| 202 node.GetBoolean("drawsContent", &drawsContent); | 202 node.GetBoolean("drawsContent", &drawsContent); |
| 203 c->set_drawsContent(drawsContent); | 203 c->set_drawsContent(drawsContent); |
| 204 int targetSurface; | 204 int targetSurface; |
| 205 node.GetInteger("targetSurfaceID", &targetSurface); | 205 node.GetInteger("targetSurfaceID", &targetSurface); |
| 206 c->set_targetSurface(targetSurface); | 206 c->set_targetSurface(targetSurface); |
| 207 | 207 |
| 208 const base::ListValue* transform; | 208 const base::ListValue* transform; |
| 209 node.GetList("transform", &transform); | 209 node.GetList("transform", &transform); |
| 210 if (transform->GetSize() != 16) { | 210 if (transform->GetSize() != 16) { |
| 211 LOG(ERROR) << "4x4 transform matrix did not have 16 elements"; | 211 LOG(ERROR) << "4x4 transform matrix did not have 16 elements"; |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 float transform_mat[16]; | 214 float transform_mat[16]; |
| 215 for (int i = 0; i < 16; ++i) { | 215 for (int i = 0; i < 16; ++i) { |
| 216 if (!VerifyListEntry(*transform, i, Value::TYPE_DOUBLE, "Transform")) | 216 if (!VerifyListEntry(*transform, i, Value::Type::DOUBLE, "Transform")) |
| 217 return false; | 217 return false; |
| 218 double el; | 218 double el; |
| 219 transform->GetDouble(i, &el); | 219 transform->GetDouble(i, &el); |
| 220 transform_mat[i] = el; | 220 transform_mat[i] = el; |
| 221 } | 221 } |
| 222 c->set_transform(transform_mat); | 222 c->set_transform(transform_mat); |
| 223 | 223 |
| 224 if (!node.HasKey("tiles")) | 224 if (!node.HasKey("tiles")) |
| 225 return true; | 225 return true; |
| 226 | 226 |
| 227 if (!VerifyDictionaryEntry(node, "tiles", Value::TYPE_DICTIONARY)) | 227 if (!VerifyDictionaryEntry(node, "tiles", Value::Type::DICTIONARY)) |
| 228 return false; | 228 return false; |
| 229 const base::DictionaryValue* tiles_dict; | 229 const base::DictionaryValue* tiles_dict; |
| 230 node.GetDictionary("tiles", &tiles_dict); | 230 node.GetDictionary("tiles", &tiles_dict); |
| 231 if (!VerifyDictionaryEntry(*tiles_dict, "dim", Value::TYPE_LIST)) | 231 if (!VerifyDictionaryEntry(*tiles_dict, "dim", Value::Type::LIST)) |
| 232 return false; | 232 return false; |
| 233 const base::ListValue* dim; | 233 const base::ListValue* dim; |
| 234 tiles_dict->GetList("dim", &dim); | 234 tiles_dict->GetList("dim", &dim); |
| 235 if (!VerifyListEntry(*dim, 0, Value::TYPE_INTEGER, "Tile dimension") || | 235 if (!VerifyListEntry(*dim, 0, Value::Type::INTEGER, "Tile dimension") || |
| 236 !VerifyListEntry(*dim, 1, Value::TYPE_INTEGER, "Tile dimension")) { | 236 !VerifyListEntry(*dim, 1, Value::Type::INTEGER, "Tile dimension")) { |
| 237 return false; | 237 return false; |
| 238 } | 238 } |
| 239 int tile_width; | 239 int tile_width; |
| 240 dim->GetInteger(0, &tile_width); | 240 dim->GetInteger(0, &tile_width); |
| 241 c->set_tile_width(tile_width); | 241 c->set_tile_width(tile_width); |
| 242 int tile_height; | 242 int tile_height; |
| 243 dim->GetInteger(1, &tile_height); | 243 dim->GetInteger(1, &tile_height); |
| 244 c->set_tile_height(tile_height); | 244 c->set_tile_height(tile_height); |
| 245 | 245 |
| 246 if (!VerifyDictionaryEntry(*tiles_dict, "info", Value::TYPE_LIST)) | 246 if (!VerifyDictionaryEntry(*tiles_dict, "info", Value::Type::LIST)) |
| 247 return false; | 247 return false; |
| 248 const base::ListValue* tiles; | 248 const base::ListValue* tiles; |
| 249 tiles_dict->GetList("info", &tiles); | 249 tiles_dict->GetList("info", &tiles); |
| 250 for (unsigned int i = 0; i < tiles->GetSize(); ++i) { | 250 for (unsigned int i = 0; i < tiles->GetSize(); ++i) { |
| 251 if (!VerifyListEntry(*tiles, i, Value::TYPE_DICTIONARY, "Tile info")) | 251 if (!VerifyListEntry(*tiles, i, Value::Type::DICTIONARY, "Tile info")) |
| 252 return false; | 252 return false; |
| 253 const base::DictionaryValue* tdict; | 253 const base::DictionaryValue* tdict; |
| 254 tiles->GetDictionary(i, &tdict); | 254 tiles->GetDictionary(i, &tdict); |
| 255 | 255 |
| 256 if (!VerifyDictionaryEntry(*tdict, "x", Value::TYPE_INTEGER) || | 256 if (!VerifyDictionaryEntry(*tdict, "x", Value::Type::INTEGER) || |
| 257 !VerifyDictionaryEntry(*tdict, "y", Value::TYPE_INTEGER)) { | 257 !VerifyDictionaryEntry(*tdict, "y", Value::Type::INTEGER)) { |
| 258 return false; | 258 return false; |
| 259 } | 259 } |
| 260 Tile t; | 260 Tile t; |
| 261 tdict->GetInteger("x", &t.x); | 261 tdict->GetInteger("x", &t.x); |
| 262 tdict->GetInteger("y", &t.y); | 262 tdict->GetInteger("y", &t.y); |
| 263 if (tdict->HasKey("texID")) { | 263 if (tdict->HasKey("texID")) { |
| 264 if (!VerifyDictionaryEntry(*tdict, "texID", Value::TYPE_INTEGER)) | 264 if (!VerifyDictionaryEntry(*tdict, "texID", Value::Type::INTEGER)) |
| 265 return false; | 265 return false; |
| 266 tdict->GetInteger("texID", &t.texID); | 266 tdict->GetInteger("texID", &t.texID); |
| 267 } else { | 267 } else { |
| 268 t.texID = -1; | 268 t.texID = -1; |
| 269 } | 269 } |
| 270 c->add_tile(t); | 270 c->add_tile(t); |
| 271 } | 271 } |
| 272 return true; | 272 return true; |
| 273 } | 273 } |
| 274 | 274 |
| 275 bool InterpretCCData(const base::DictionaryValue& node, CCNode* c) { | 275 bool InterpretCCData(const base::DictionaryValue& node, CCNode* c) { |
| 276 if (!VerifyDictionaryEntry(node, "vertex_shader", Value::TYPE_STRING) || | 276 if (!VerifyDictionaryEntry(node, "vertex_shader", Value::Type::STRING) || |
| 277 !VerifyDictionaryEntry(node, "fragment_shader", Value::TYPE_STRING) || | 277 !VerifyDictionaryEntry(node, "fragment_shader", Value::Type::STRING) || |
| 278 !VerifyDictionaryEntry(node, "textures", Value::TYPE_LIST)) { | 278 !VerifyDictionaryEntry(node, "textures", Value::Type::LIST)) { |
| 279 return false; | 279 return false; |
| 280 } | 280 } |
| 281 std::string vertex_shader_name, fragment_shader_name; | 281 std::string vertex_shader_name, fragment_shader_name; |
| 282 node.GetString("vertex_shader", &vertex_shader_name); | 282 node.GetString("vertex_shader", &vertex_shader_name); |
| 283 node.GetString("fragment_shader", &fragment_shader_name); | 283 node.GetString("fragment_shader", &fragment_shader_name); |
| 284 | 284 |
| 285 c->set_vertex_shader(ShaderIDFromString(vertex_shader_name)); | 285 c->set_vertex_shader(ShaderIDFromString(vertex_shader_name)); |
| 286 c->set_fragment_shader(ShaderIDFromString(fragment_shader_name)); | 286 c->set_fragment_shader(ShaderIDFromString(fragment_shader_name)); |
| 287 const base::ListValue* textures; | 287 const base::ListValue* textures; |
| 288 node.GetList("textures", &textures); | 288 node.GetList("textures", &textures); |
| 289 for (unsigned int i = 0; i < textures->GetSize(); ++i) { | 289 for (unsigned int i = 0; i < textures->GetSize(); ++i) { |
| 290 if (!VerifyListEntry(*textures, i, Value::TYPE_DICTIONARY, "Tex list")) | 290 if (!VerifyListEntry(*textures, i, Value::Type::DICTIONARY, "Tex list")) |
| 291 return false; | 291 return false; |
| 292 const base::DictionaryValue* tex; | 292 const base::DictionaryValue* tex; |
| 293 textures->GetDictionary(i, &tex); | 293 textures->GetDictionary(i, &tex); |
| 294 | 294 |
| 295 if (!VerifyDictionaryEntry(*tex, "texID", Value::TYPE_INTEGER) || | 295 if (!VerifyDictionaryEntry(*tex, "texID", Value::Type::INTEGER) || |
| 296 !VerifyDictionaryEntry(*tex, "height", Value::TYPE_INTEGER) || | 296 !VerifyDictionaryEntry(*tex, "height", Value::Type::INTEGER) || |
| 297 !VerifyDictionaryEntry(*tex, "width", Value::TYPE_INTEGER) || | 297 !VerifyDictionaryEntry(*tex, "width", Value::Type::INTEGER) || |
| 298 !VerifyDictionaryEntry(*tex, "format", Value::TYPE_STRING)) { | 298 !VerifyDictionaryEntry(*tex, "format", Value::Type::STRING)) { |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 Texture t; | 301 Texture t; |
| 302 tex->GetInteger("texID", &t.texID); | 302 tex->GetInteger("texID", &t.texID); |
| 303 tex->GetInteger("height", &t.height); | 303 tex->GetInteger("height", &t.height); |
| 304 tex->GetInteger("width", &t.width); | 304 tex->GetInteger("width", &t.width); |
| 305 | 305 |
| 306 std::string formatName; | 306 std::string formatName; |
| 307 tex->GetString("format", &formatName); | 307 tex->GetString("format", &formatName); |
| 308 t.format = TextureFormatFromString(formatName); | 308 t.format = TextureFormatFromString(formatName); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 331 | 331 |
| 332 return true; | 332 return true; |
| 333 } | 333 } |
| 334 | 334 |
| 335 std::unique_ptr<RenderNode> InterpretContentLayer( | 335 std::unique_ptr<RenderNode> InterpretContentLayer( |
| 336 const base::DictionaryValue& node) { | 336 const base::DictionaryValue& node) { |
| 337 auto n = base::MakeUnique<ContentLayerNode>(); | 337 auto n = base::MakeUnique<ContentLayerNode>(); |
| 338 if (!InterpretCommonContents(node, n.get())) | 338 if (!InterpretCommonContents(node, n.get())) |
| 339 return nullptr; | 339 return nullptr; |
| 340 | 340 |
| 341 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING) || | 341 if (!VerifyDictionaryEntry(node, "type", Value::Type::STRING) || |
| 342 !VerifyDictionaryEntry(node, "skipsDraw", Value::TYPE_BOOLEAN) || | 342 !VerifyDictionaryEntry(node, "skipsDraw", Value::Type::BOOLEAN) || |
| 343 !VerifyDictionaryEntry(node, "children", Value::TYPE_LIST)) { | 343 !VerifyDictionaryEntry(node, "children", Value::Type::LIST)) { |
| 344 return nullptr; | 344 return nullptr; |
| 345 } | 345 } |
| 346 | 346 |
| 347 std::string type; | 347 std::string type; |
| 348 node.GetString("type", &type); | 348 node.GetString("type", &type); |
| 349 DCHECK_EQ(type, "ContentLayer"); | 349 DCHECK_EQ(type, "ContentLayer"); |
| 350 bool skipsDraw; | 350 bool skipsDraw; |
| 351 node.GetBoolean("skipsDraw", &skipsDraw); | 351 node.GetBoolean("skipsDraw", &skipsDraw); |
| 352 n->set_skipsDraw(skipsDraw); | 352 n->set_skipsDraw(skipsDraw); |
| 353 | 353 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 364 | 364 |
| 365 return n; | 365 return n; |
| 366 } | 366 } |
| 367 | 367 |
| 368 std::unique_ptr<RenderNode> InterpretCanvasLayer( | 368 std::unique_ptr<RenderNode> InterpretCanvasLayer( |
| 369 const base::DictionaryValue& node) { | 369 const base::DictionaryValue& node) { |
| 370 auto n = base::MakeUnique<CCNode>(); | 370 auto n = base::MakeUnique<CCNode>(); |
| 371 if (!InterpretCommonContents(node, n.get())) | 371 if (!InterpretCommonContents(node, n.get())) |
| 372 return nullptr; | 372 return nullptr; |
| 373 | 373 |
| 374 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING)) | 374 if (!VerifyDictionaryEntry(node, "type", Value::Type::STRING)) |
| 375 return nullptr; | 375 return nullptr; |
| 376 | 376 |
| 377 std::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.get())) | 381 if (!InterpretCCData(node, n.get())) |
| 382 return nullptr; | 382 return nullptr; |
| 383 | 383 |
| 384 return n; | 384 return n; |
| 385 } | 385 } |
| 386 | 386 |
| 387 std::unique_ptr<RenderNode> InterpretVideoLayer( | 387 std::unique_ptr<RenderNode> InterpretVideoLayer( |
| 388 const base::DictionaryValue& node) { | 388 const base::DictionaryValue& node) { |
| 389 auto n = base::MakeUnique<CCNode>(); | 389 auto n = base::MakeUnique<CCNode>(); |
| 390 if (!InterpretCommonContents(node, n.get())) | 390 if (!InterpretCommonContents(node, n.get())) |
| 391 return nullptr; | 391 return nullptr; |
| 392 | 392 |
| 393 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING)) | 393 if (!VerifyDictionaryEntry(node, "type", Value::Type::STRING)) |
| 394 return nullptr; | 394 return nullptr; |
| 395 | 395 |
| 396 std::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.get())) | 400 if (!InterpretCCData(node, n.get())) |
| 401 return nullptr; | 401 return nullptr; |
| 402 | 402 |
| 403 return n; | 403 return n; |
| 404 } | 404 } |
| 405 | 405 |
| 406 std::unique_ptr<RenderNode> InterpretImageLayer( | 406 std::unique_ptr<RenderNode> InterpretImageLayer( |
| 407 const base::DictionaryValue& node) { | 407 const base::DictionaryValue& node) { |
| 408 auto n = base::MakeUnique<CCNode>(); | 408 auto n = base::MakeUnique<CCNode>(); |
| 409 if (!InterpretCommonContents(node, n.get())) | 409 if (!InterpretCommonContents(node, n.get())) |
| 410 return nullptr; | 410 return nullptr; |
| 411 | 411 |
| 412 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING)) | 412 if (!VerifyDictionaryEntry(node, "type", Value::Type::STRING)) |
| 413 return nullptr; | 413 return nullptr; |
| 414 | 414 |
| 415 std::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.get())) | 419 if (!InterpretCCData(node, n.get())) |
| 420 return nullptr; | 420 return nullptr; |
| 421 | 421 |
| 422 return n; | 422 return n; |
| 423 } | 423 } |
| 424 | 424 |
| 425 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node) { | 425 std::unique_ptr<RenderNode> InterpretNode(const base::DictionaryValue& node) { |
| 426 if (!VerifyDictionaryEntry(node, "type", Value::TYPE_STRING)) | 426 if (!VerifyDictionaryEntry(node, "type", Value::Type::STRING)) |
| 427 return nullptr; | 427 return nullptr; |
| 428 | 428 |
| 429 std::string type; | 429 std::string type; |
| 430 node.GetString("type", &type); | 430 node.GetString("type", &type); |
| 431 if (type == "ContentLayer") | 431 if (type == "ContentLayer") |
| 432 return InterpretContentLayer(node); | 432 return InterpretContentLayer(node); |
| 433 if (type == "CanvasLayer") | 433 if (type == "CanvasLayer") |
| 434 return InterpretCanvasLayer(node); | 434 return InterpretCanvasLayer(node); |
| 435 if (type == "VideoLayer") | 435 if (type == "VideoLayer") |
| 436 return InterpretVideoLayer(node); | 436 return InterpretVideoLayer(node); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 466 } else { | 466 } else { |
| 467 LOG(ERROR) << path.LossyDisplayName() | 467 LOG(ERROR) << path.LossyDisplayName() |
| 468 << " doesn not encode a JSON dictionary."; | 468 << " doesn not encode a JSON dictionary."; |
| 469 } | 469 } |
| 470 return nullptr; | 470 return nullptr; |
| 471 } | 471 } |
| 472 | 472 |
| 473 return InterpretContentLayer(*root); | 473 return InterpretContentLayer(*root); |
| 474 } | 474 } |
| 475 | 475 |
| OLD | NEW |