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

Side by Side Diff: tests/RecordTest.cpp

Issue 228723003: Start on some unwritten SkRecord TODOs: (Closed) Base URL: https://skia.googlesource.com/skia.git@record-culling
Patch Set: rebase 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 | « src/record/SkRecorder.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
(Empty)
1 #include "Test.h"
2
3 #include "SkRecord.h"
4 #include "SkRecords.h"
5
6 // Adds the area of any DrawRect command it sees into area.
7 class AreaSummer {
8 public:
9 explicit AreaSummer(int* area) : fArea(area) {}
10
11 template <typename T> void operator()(const T&) { }
12
13 private:
14 int* fArea;
15 };
16 template <> void AreaSummer::operator()(const SkRecords::DrawRect& record) {
17 *fArea += (int) (record.rect.width() * record.rect.height());
18 }
19
20 // Scales out the bottom-right corner of any DrawRect command it sees by 2x.
21 struct Stretch {
22 template <typename T> void operator()(T*) {}
23 };
24 template <> void Stretch::operator()(SkRecords::DrawRect* record) {
25 record->rect.fRight *= 2;
26 record->rect.fBottom *= 2;
27 }
28
29 // Basic tests for the low-level SkRecord code.
30 DEF_TEST(Record, r) {
31 SkRecord record;
32
33 // Add a simple DrawRect command.
34 SkRect rect = SkRect::MakeWH(10, 10);
35 SkPaint paint;
36 SkNEW_PLACEMENT_ARGS(record.append<SkRecords::DrawRect>(), SkRecords::DrawRe ct, (rect, paint));
37
38 // Its area should be 100.
39 int area = 0;
40 record.visit(AreaSummer(&area));
41 REPORTER_ASSERT(r, area == 100);
42
43 // Scale 2x. Now it's area should be 400.
44 record.mutate(Stretch());
45 area = 0;
46 record.visit(AreaSummer(&area));
47 REPORTER_ASSERT(r, area == 400);
48 }
OLDNEW
« no previous file with comments | « src/record/SkRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698