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

Side by Side Diff: cc/layer_tree_host_perftest.cc

Issue 11418235: Add perf tests based on json representation of layer tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update output to style expected by perf harness Created 8 years 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
« no previous file with comments | « no previous file | cc/test/data/10_10_layer_tree.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "base/base_paths.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/json/json_reader.h"
11 #include "base/path_service.h"
12 #include "base/string_piece.h"
7 #include "cc/content_layer.h" 13 #include "cc/content_layer.h"
8 #include "cc/nine_patch_layer.h" 14 #include "cc/nine_patch_layer.h"
9 #include "cc/solid_color_layer.h" 15 #include "cc/solid_color_layer.h"
10 #include "cc/test/fake_content_layer_client.h" 16 #include "cc/test/fake_content_layer_client.h"
11 #include "cc/test/layer_tree_test_common.h" 17 #include "cc/test/layer_tree_test_common.h"
12 18
13 namespace cc { 19 namespace cc {
14 namespace { 20 namespace {
15 21
16 class LayerTreeHostPerfTest : public WebKitTests::ThreadedTest {}; 22 static const int kMaxFrames = 120;
17 23
18 class LayerTreeHostPerfTestSevenTabSwitcher : public LayerTreeHostPerfTest { 24 class LayerTreeHostPerfTest : public WebKitTests::ThreadedTest {
19 public: 25 public:
20 LayerTreeHostPerfTestSevenTabSwitcher() : num_draws_(0) { 26 LayerTreeHostPerfTest()
27 : num_draws_(0) {
21 fake_delegate_.setPaintAllOpaque(true); 28 fake_delegate_.setPaintAllOpaque(true);
22 } 29 }
23 30
31 virtual void beginTest() OVERRIDE {
32 buildTree();
33 start_time_ = base::TimeTicks::HighResNow();
34 postSetNeedsCommitToMainThread();
35 }
36
37 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
38 impl->setNeedsRedraw();
danakj 2012/11/30 01:21:00 Probly won't matter, but this should be the else c
39 ++num_draws_;
40 if (num_draws_ > kMaxFrames)
41 endTest();
42 }
43
44 virtual void buildTree() {}
45
46 virtual void afterTest() OVERRIDE {
47 base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_;
48 // Format matches chrome/test/perf/perf_test.h:PrintResult
49 printf("*RESULT %s: t= %.2f ms\n", test_name_.c_str(),
50 elapsed.InMillisecondsF());
51 }
52
24 scoped_refptr<Layer> CreateLayer(float x, float y, int width, int height) { 53 scoped_refptr<Layer> CreateLayer(float x, float y, int width, int height) {
25 scoped_refptr<Layer> layer = Layer::create(); 54 scoped_refptr<Layer> layer = Layer::create();
26 layer->setAnchorPoint(gfx::Point()); 55 layer->setAnchorPoint(gfx::Point());
27 layer->setPosition(gfx::PointF(x, y)); 56 layer->setPosition(gfx::PointF(x, y));
28 layer->setBounds(gfx::Size(width, height)); 57 layer->setBounds(gfx::Size(width, height));
29 return layer; 58 return layer;
30 } 59 }
31 60
32 scoped_refptr<ContentLayer> CreateContentLayer(float x, float y, int width, in t height) { 61 scoped_refptr<ContentLayer> CreateContentLayer(float x, float y, int width, in t height) {
33 scoped_refptr<ContentLayer> layer = ContentLayer::create(&fake_delegate_); 62 scoped_refptr<ContentLayer> layer = ContentLayer::create(&fake_delegate_);
34 layer->setAnchorPoint(gfx::Point()); 63 layer->setAnchorPoint(gfx::Point());
35 layer->setPosition(gfx::PointF(x, y)); 64 layer->setPosition(gfx::PointF(x, y));
36 layer->setBounds(gfx::Size(width, height)); 65 layer->setBounds(gfx::Size(width, height));
37 layer->setIsDrawable(true); 66 layer->setIsDrawable(true);
38 return layer; 67 return layer;
39 } 68 }
40 69
41 scoped_refptr<SolidColorLayer> CreateColorLayer(float x, float y, int width, i nt height) { 70 scoped_refptr<SolidColorLayer> CreateColorLayer(float x, float y, int width, i nt height) {
42 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); 71 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create();
43 layer->setAnchorPoint(gfx::Point()); 72 layer->setAnchorPoint(gfx::Point());
44 layer->setPosition(gfx::PointF(x, y)); 73 layer->setPosition(gfx::PointF(x, y));
45 layer->setBounds(gfx::Size(width, height)); 74 layer->setBounds(gfx::Size(width, height));
46 layer->setIsDrawable(true); 75 layer->setIsDrawable(true);
47 return layer; 76 return layer;
48 } 77 }
49 78
50 scoped_refptr<NinePatchLayer> CreateDecorationLayer(float x, float y, int widt h, int height) { 79 scoped_refptr<NinePatchLayer> CreateDecorationLayer(float x, float y, int widt h, int height) {
80 return CreateDecorationLayer(x, y, width, height, gfx::Rect(0, 0, width, hei ght));
81 }
82
83 scoped_refptr<NinePatchLayer> CreateDecorationLayer(float x, float y, int widt h, int height, gfx::Rect aperture) {
51 scoped_refptr<NinePatchLayer> layer = NinePatchLayer::create(); 84 scoped_refptr<NinePatchLayer> layer = NinePatchLayer::create();
52 layer->setAnchorPoint(gfx::Point()); 85 layer->setAnchorPoint(gfx::Point());
53 layer->setPosition(gfx::PointF(x, y)); 86 layer->setPosition(gfx::PointF(x, y));
54 layer->setBounds(gfx::Size(width, height)); 87 layer->setBounds(gfx::Size(width, height));
55 layer->setIsDrawable(true); 88 layer->setIsDrawable(true);
56 89
57 SkBitmap bitmap; 90 SkBitmap bitmap;
58 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); 91 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
59 bitmap.allocPixels(NULL, NULL); 92 bitmap.allocPixels(NULL, NULL);
60 layer->setBitmap(bitmap, gfx::Rect(0, 0, width, height)); 93 layer->setBitmap(bitmap, aperture);
61 94
62 return layer; 95 return layer;
63 } 96 }
64 97
65 scoped_refptr<Layer> addChild(scoped_refptr<Layer> parent, scoped_refptr<Layer > child) { 98 scoped_refptr<Layer> addChild(scoped_refptr<Layer> parent, scoped_refptr<Layer > child) {
66 parent->addChild(child); 99 parent->addChild(child);
67 return child; 100 return child;
68 } 101 }
69 102
70 virtual void beginTest() OVERRIDE { 103 protected:
104 base::TimeTicks start_time_;
105 int num_draws_;
106 std::string test_name_;
107 WebKitTests::FakeContentLayerClient fake_delegate_;
108 };
109
110 class LayerTreeHostPerfTestSevenTabSwitcher : public LayerTreeHostPerfTest {
111 public:
112 LayerTreeHostPerfTestSevenTabSwitcher()
113 : LayerTreeHostPerfTest() {
114 test_name_ = "SevenTabSwitcher";
115 }
116
117 virtual void buildTree() OVERRIDE {
71 scoped_refptr<Layer> root = CreateLayer(0, 0, 720, 1038); // 1 118 scoped_refptr<Layer> root = CreateLayer(0, 0, 720, 1038); // 1
72 scoped_refptr<Layer> layer; 119 scoped_refptr<Layer> layer;
73 120
74 gfx::Transform down_scale_matrix; 121 gfx::Transform down_scale_matrix;
75 down_scale_matrix.Scale(0.747, 0.747); 122 down_scale_matrix.Scale(0.747, 0.747);
76 123
77 layer = addChild(root, CreateLayer(0, 0, 0, 0)); // 2 124 layer = addChild(root, CreateLayer(0, 0, 0, 0)); // 2
78 125
79 layer = addChild(root, CreateLayer(628, 15, 0, 0)); // 5 126 layer = addChild(root, CreateLayer(628, 15, 0, 0)); // 5
80 layer = addChild(root, CreateDecorationLayer(564, -49, 665, 274)); // 13 127 layer = addChild(root, CreateDecorationLayer(564, -49, 665, 274)); // 13
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 layer->setTransform(down_scale_matrix); 216 layer->setTransform(down_scale_matrix);
170 217
171 layer = addChild(root, CreateLayer(30, 617, 0, 0)); // 120 218 layer = addChild(root, CreateLayer(30, 617, 0, 0)); // 120
172 layer = addChild(root, CreateDecorationLayer(14, 601, 569, 807)); // 124 219 layer = addChild(root, CreateDecorationLayer(14, 601, 569, 807)); // 124
173 layer = addChild(root, CreateDecorationLayer(229.135986f, 601, 354, 96)); // 123 220 layer = addChild(root, CreateDecorationLayer(229.135986f, 601, 354, 96)); // 123
174 layer = addChild(root, CreateContentLayer(30, 617, 0, 0)); // 122 221 layer = addChild(root, CreateContentLayer(30, 617, 0, 0)); // 122
175 layer = addChild(root, CreateContentLayer(30, 617, 0, 0)); // 121 222 layer = addChild(root, CreateContentLayer(30, 617, 0, 0)); // 121
176 223
177 m_layerTreeHost->setViewportSize(gfx::Size(720, 1038), gfx::Size(720, 1038)) ; 224 m_layerTreeHost->setViewportSize(gfx::Size(720, 1038), gfx::Size(720, 1038)) ;
178 m_layerTreeHost->setRootLayer(root); 225 m_layerTreeHost->setRootLayer(root);
179 postSetNeedsCommitToMainThread(); 226 }
227 };
228
229 TEST_F(LayerTreeHostPerfTestSevenTabSwitcher, runSingleThread) {
230 runTest(false);
231 }
232
233 class LayerTreeHostPerfTestJsonReader : public LayerTreeHostPerfTest {
234 public:
235 LayerTreeHostPerfTestJsonReader()
236 : LayerTreeHostPerfTest() {
180 } 237 }
181 238
182 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 239 void readTestFile(std::string name) {
183 impl->setNeedsRedraw(); 240 test_name_ = name;
184 ++num_draws_; 241 FilePath filepath;
185 if (num_draws_ > 120) 242 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &filepath));
186 endTest(); 243 filepath = filepath.AppendASCII("cc").AppendASCII("test")
244 .AppendASCII("data").AppendASCII(name + ".json");
245 std::string json;
246 ASSERT_TRUE(file_util::ReadFileToString(filepath, &json));
247 tree_.reset(base::JSONReader::Read(json));
248 ASSERT_TRUE(tree_);
187 } 249 }
188 250
189 virtual void afterTest() OVERRIDE {} 251 scoped_refptr<Layer> parseLayer(base::Value* val) {
252 DictionaryValue* dict;
253 bool success = true;
254 success &= val->GetAsDictionary(&dict);
255 std::string layer_type;
256 success &= dict->GetString("LayerType", &layer_type);
257 ListValue* list;
258 success &= dict->GetList("Bounds", &list);
259 int width, height;
260 success &= list->GetInteger(0, &width);
261 success &= list->GetInteger(1, &height);
262 success &= dict->GetList("Position", &list);
263 double position_x, position_y;
264 success &= list->GetDouble(0, &position_x);
265 success &= list->GetDouble(1, &position_y);
266
267 scoped_refptr<Layer> new_layer;
268 if (layer_type == "SolidColorLayer") {
269 new_layer = CreateColorLayer(position_x, position_y, width, height);
270 } else if (layer_type == "ContentLayer") {
danakj 2012/11/30 01:21:00 aside: we should dump the opaque info for these an
271 new_layer = CreateContentLayer(position_x, position_y, width, height);
272 } else if (layer_type == "NinePatchLayer") {
273 success &= dict->GetList("ImageAperture", &list);
274 int aperture_x, aperture_y, aperture_width, aperture_height;
275 success &= list->GetInteger(0, &aperture_x);
276 success &= list->GetInteger(1, &aperture_y);
277 success &= list->GetInteger(2, &aperture_width);
278 success &= list->GetInteger(3, &aperture_height);
279
280 new_layer = CreateDecorationLayer(
281 position_x, position_y, width, height,
282 gfx::Rect(aperture_x, aperture_y, aperture_width, aperture_height));
283
284 } else { // Type "Layer" or unknown"
danakj 2012/11/30 01:21:00 mismatched "
285 new_layer = CreateLayer(position_x, position_y, width, height);
286 }
287
288 success &= dict->GetList("DrawTransform", &list);
289 double transform[16];
290 for (int i=0; i<16; ++i) {
danakj 2012/11/30 01:21:00 no {}
danakj 2012/11/30 01:21:00 spaces around operators
291 success &= list->GetDouble(i, &transform[i]);
292 }
293
294 gfx::Transform gfxTransform;
295 gfxTransform.matrix().setColMajord(transform);
296 new_layer->setTransform(gfxTransform);
297
298 success &= dict->GetList("Children", &list);
299 for (ListValue::const_iterator it = list->begin();
300 it != list->end(); ++it) {
301 new_layer->addChild(parseLayer(*it));
302 }
303
304 if (!success)
305 ADD_FAILURE();
danakj 2012/11/30 01:21:00 << "Unable to parse layer."
306
307 return new_layer;
308 }
309
310 virtual void buildTree() OVERRIDE {
311 gfx::Size viewport = gfx::Size(720, 1038);
danakj 2012/11/30 01:21:00 aside: maybe this should be in the json too, or be
312 m_layerTreeHost->setViewportSize(viewport, viewport);
313 m_layerTreeHost->setRootLayer(parseLayer(tree_.get()));
314 }
190 315
191 private: 316 private:
192 int num_draws_; 317 scoped_ptr<base::Value> tree_;
193 WebKitTests::FakeContentLayerClient fake_delegate_;
194 }; 318 };
195 319
196 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostPerfTestSevenTabSwitcher); 320 TEST_F(LayerTreeHostPerfTestJsonReader, tenTenSingleThread) {
321 readTestFile("10_10_layer_tree");
322 runTest(false);
323 }
197 324
198 } // namespace 325 } // namespace
199 } // namespace cc 326 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/test/data/10_10_layer_tree.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698