OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/test/layer_tree_json_parser.h" | 5 #include "cc/test/layer_tree_json_parser.h" |
6 | 6 |
7 #include "base/test/values_test_util.h" | 7 #include "base/test/values_test_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "cc/layers/content_layer.h" | 9 #include "cc/layers/content_layer.h" |
10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
11 #include "cc/layers/nine_patch_layer.h" | 11 #include "cc/layers/nine_patch_layer.h" |
12 #include "cc/layers/picture_layer.h" | 12 #include "cc/layers/picture_layer.h" |
13 #include "cc/layers/solid_color_layer.h" | 13 #include "cc/layers/solid_color_layer.h" |
14 #include "cc/layers/texture_layer.h" | 14 #include "cc/layers/texture_layer.h" |
| 15 #include "cc/trees/layer_tree_settings.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 scoped_refptr<Layer> ParseTreeFromValue(base::Value* val, | 21 scoped_refptr<Layer> ParseTreeFromValue(base::Value* val, |
21 ContentLayerClient* content_client) { | 22 ContentLayerClient* content_client) { |
22 base::DictionaryValue* dict; | 23 base::DictionaryValue* dict; |
23 bool success = true; | 24 bool success = true; |
24 success &= val->GetAsDictionary(&dict); | 25 success &= val->GetAsDictionary(&dict); |
25 std::string layer_type; | 26 std::string layer_type; |
26 success &= dict->GetString("LayerType", &layer_type); | 27 success &= dict->GetString("LayerType", &layer_type); |
27 base::ListValue* list; | 28 base::ListValue* list; |
28 success &= dict->GetList("Bounds", &list); | 29 success &= dict->GetList("Bounds", &list); |
29 int width, height; | 30 int width, height; |
30 success &= list->GetInteger(0, &width); | 31 success &= list->GetInteger(0, &width); |
31 success &= list->GetInteger(1, &height); | 32 success &= list->GetInteger(1, &height); |
32 success &= dict->GetList("Position", &list); | 33 success &= dict->GetList("Position", &list); |
33 double position_x, position_y; | 34 double position_x, position_y; |
34 success &= list->GetDouble(0, &position_x); | 35 success &= list->GetDouble(0, &position_x); |
35 success &= list->GetDouble(1, &position_y); | 36 success &= list->GetDouble(1, &position_y); |
36 | 37 |
37 bool draws_content; | 38 bool draws_content; |
38 success &= dict->GetBoolean("DrawsContent", &draws_content); | 39 success &= dict->GetBoolean("DrawsContent", &draws_content); |
39 | 40 |
| 41 LayerSettings layer_settings; |
| 42 |
40 scoped_refptr<Layer> new_layer; | 43 scoped_refptr<Layer> new_layer; |
41 if (layer_type == "SolidColorLayer") { | 44 if (layer_type == "SolidColorLayer") { |
42 new_layer = SolidColorLayer::Create(); | 45 new_layer = SolidColorLayer::Create(layer_settings); |
43 } else if (layer_type == "ContentLayer") { | 46 } else if (layer_type == "ContentLayer") { |
44 new_layer = ContentLayer::Create(content_client); | 47 new_layer = ContentLayer::Create(layer_settings, content_client); |
45 } else if (layer_type == "NinePatchLayer") { | 48 } else if (layer_type == "NinePatchLayer") { |
46 success &= dict->GetList("ImageAperture", &list); | 49 success &= dict->GetList("ImageAperture", &list); |
47 int aperture_x, aperture_y, aperture_width, aperture_height; | 50 int aperture_x, aperture_y, aperture_width, aperture_height; |
48 success &= list->GetInteger(0, &aperture_x); | 51 success &= list->GetInteger(0, &aperture_x); |
49 success &= list->GetInteger(1, &aperture_y); | 52 success &= list->GetInteger(1, &aperture_y); |
50 success &= list->GetInteger(2, &aperture_width); | 53 success &= list->GetInteger(2, &aperture_width); |
51 success &= list->GetInteger(3, &aperture_height); | 54 success &= list->GetInteger(3, &aperture_height); |
52 | 55 |
53 base::ListValue* bounds; | 56 base::ListValue* bounds; |
54 success &= dict->GetList("ImageBounds", &bounds); | 57 success &= dict->GetList("ImageBounds", &bounds); |
55 double image_width, image_height; | 58 double image_width, image_height; |
56 success &= bounds->GetDouble(0, &image_width); | 59 success &= bounds->GetDouble(0, &image_width); |
57 success &= bounds->GetDouble(1, &image_height); | 60 success &= bounds->GetDouble(1, &image_height); |
58 | 61 |
59 success &= dict->GetList("Border", &list); | 62 success &= dict->GetList("Border", &list); |
60 int border_x, border_y, border_width, border_height; | 63 int border_x, border_y, border_width, border_height; |
61 success &= list->GetInteger(0, &border_x); | 64 success &= list->GetInteger(0, &border_x); |
62 success &= list->GetInteger(1, &border_y); | 65 success &= list->GetInteger(1, &border_y); |
63 success &= list->GetInteger(2, &border_width); | 66 success &= list->GetInteger(2, &border_width); |
64 success &= list->GetInteger(3, &border_height); | 67 success &= list->GetInteger(3, &border_height); |
65 | 68 |
66 bool fill_center; | 69 bool fill_center; |
67 success &= dict->GetBoolean("FillCenter", &fill_center); | 70 success &= dict->GetBoolean("FillCenter", &fill_center); |
68 | 71 |
69 scoped_refptr<NinePatchLayer> nine_patch_layer = NinePatchLayer::Create(); | 72 scoped_refptr<NinePatchLayer> nine_patch_layer = |
| 73 NinePatchLayer::Create(layer_settings); |
70 | 74 |
71 SkBitmap bitmap; | 75 SkBitmap bitmap; |
72 bitmap.allocN32Pixels(image_width, image_height); | 76 bitmap.allocN32Pixels(image_width, image_height); |
73 bitmap.setImmutable(); | 77 bitmap.setImmutable(); |
74 nine_patch_layer->SetBitmap(bitmap); | 78 nine_patch_layer->SetBitmap(bitmap); |
75 nine_patch_layer->SetAperture( | 79 nine_patch_layer->SetAperture( |
76 gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height)); | 80 gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height)); |
77 nine_patch_layer->SetBorder( | 81 nine_patch_layer->SetBorder( |
78 gfx::Rect(border_x, border_y, border_width, border_height)); | 82 gfx::Rect(border_x, border_y, border_width, border_height)); |
79 nine_patch_layer->SetFillCenter(fill_center); | 83 nine_patch_layer->SetFillCenter(fill_center); |
80 | 84 |
81 new_layer = nine_patch_layer; | 85 new_layer = nine_patch_layer; |
82 } else if (layer_type == "TextureLayer") { | 86 } else if (layer_type == "TextureLayer") { |
83 new_layer = TextureLayer::CreateForMailbox(NULL); | 87 new_layer = TextureLayer::CreateForMailbox(layer_settings, NULL); |
84 } else if (layer_type == "PictureLayer") { | 88 } else if (layer_type == "PictureLayer") { |
85 new_layer = PictureLayer::Create(content_client); | 89 new_layer = PictureLayer::Create(layer_settings, content_client); |
86 } else { // Type "Layer" or "unknown" | 90 } else { // Type "Layer" or "unknown" |
87 new_layer = Layer::Create(); | 91 new_layer = Layer::Create(layer_settings); |
88 } | 92 } |
89 new_layer->SetPosition(gfx::PointF(position_x, position_y)); | 93 new_layer->SetPosition(gfx::PointF(position_x, position_y)); |
90 new_layer->SetBounds(gfx::Size(width, height)); | 94 new_layer->SetBounds(gfx::Size(width, height)); |
91 new_layer->SetIsDrawable(draws_content); | 95 new_layer->SetIsDrawable(draws_content); |
92 | 96 |
93 double opacity; | 97 double opacity; |
94 if (dict->GetDouble("Opacity", &opacity)) | 98 if (dict->GetDouble("Opacity", &opacity)) |
95 new_layer->SetOpacity(opacity); | 99 new_layer->SetOpacity(opacity); |
96 | 100 |
97 bool contents_opaque; | 101 bool contents_opaque; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 193 |
190 } // namespace | 194 } // namespace |
191 | 195 |
192 scoped_refptr<Layer> ParseTreeFromJson(std::string json, | 196 scoped_refptr<Layer> ParseTreeFromJson(std::string json, |
193 ContentLayerClient* content_client) { | 197 ContentLayerClient* content_client) { |
194 scoped_ptr<base::Value> val = base::test::ParseJson(json); | 198 scoped_ptr<base::Value> val = base::test::ParseJson(json); |
195 return ParseTreeFromValue(val.get(), content_client); | 199 return ParseTreeFromValue(val.get(), content_client); |
196 } | 200 } |
197 | 201 |
198 } // namespace cc | 202 } // namespace cc |
OLD | NEW |