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

Side by Side Diff: tests/RecordTest.cpp

Issue 245853002: Refactor SkRecord opts, converting playback optimizations where possible. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: apply Created 6 years, 8 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 | « tests/RecordCullingTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 9
10 #include "SkRecord.h" 10 #include "SkRecord.h"
11 #include "SkRecords.h" 11 #include "SkRecords.h"
12 12
13 // Sums the area of any DrawRect command it sees. 13 // Sums the area of any DrawRect command it sees.
14 class AreaSummer { 14 class AreaSummer {
15 public: 15 public:
16 AreaSummer() : fArea(0) {} 16 AreaSummer() : fArea(0) {}
17 17
18 template <typename T> void operator()(const T&) { } 18 template <typename T> void operator()(const T&) { }
19 19
20 int area() const { return fArea; } 20 int area() const { return fArea; }
21 21
22 void apply(const SkRecord& record) {
23 for (unsigned i = 0; i < record.count(); i++) {
24 record.visit(i, *this);
25 }
26 }
27
22 private: 28 private:
23 int fArea; 29 int fArea;
24 }; 30 };
25 template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) { 31 template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) {
26 fArea += (int) (record.rect.width() * record.rect.height()); 32 fArea += (int) (record.rect.width() * record.rect.height());
27 } 33 }
28 34
29 // Scales out the bottom-right corner of any DrawRect command it sees by 2x. 35 // Scales out the bottom-right corner of any DrawRect command it sees by 2x.
30 struct Stretch { 36 struct Stretch {
31 template <typename T> void operator()(T*) {} 37 template <typename T> void operator()(T*) {}
38
39 void apply(SkRecord* record) {
40 for (unsigned i = 0; i < record->count(); i++) {
41 record->mutate(i, *this);
42 }
43 }
32 }; 44 };
33 template <> void Stretch::operator()(SkRecords::DrawRect* record) { 45 template <> void Stretch::operator()(SkRecords::DrawRect* record) {
34 record->rect.fRight *= 2; 46 record->rect.fRight *= 2;
35 record->rect.fBottom *= 2; 47 record->rect.fBottom *= 2;
36 } 48 }
37 49
38 // Basic tests for the low-level SkRecord code. 50 // Basic tests for the low-level SkRecord code.
39 DEF_TEST(Record, r) { 51 DEF_TEST(Record, r) {
40 SkRecord record; 52 SkRecord record;
41 53
42 // Add a simple DrawRect command. 54 // Add a simple DrawRect command.
43 SkRect rect = SkRect::MakeWH(10, 10); 55 SkRect rect = SkRect::MakeWH(10, 10);
44 SkPaint paint; 56 SkPaint paint;
45 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRe ct, (rect, paint)); 57 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRe ct, (rect, paint));
46 58
47 // Its area should be 100. 59 // Its area should be 100.
48 AreaSummer summer; 60 AreaSummer summer;
49 record.visit(summer); 61 summer.apply(record);
50 REPORTER_ASSERT(r, summer.area() == 100); 62 REPORTER_ASSERT(r, summer.area() == 100);
51 63
52 // Scale 2x. 64 // Scale 2x.
53 Stretch stretch; 65 Stretch stretch;
54 record.mutate(stretch); 66 stretch.apply(&record);
55 67
56 // Now its area should be 100 + 400. 68 // Now its area should be 100 + 400.
57 record.visit(summer); 69 summer.apply(record);
58 REPORTER_ASSERT(r, summer.area() == 500); 70 REPORTER_ASSERT(r, summer.area() == 500);
59 } 71 }
OLDNEW
« no previous file with comments | « tests/RecordCullingTest.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698