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

Side by Side Diff: tests/RecorderTest.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/RecordTest.cpp ('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
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"
(...skipping 10 matching lines...) Expand all
21 class Tally { 21 class Tally {
22 public: 22 public:
23 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); } 23 Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
24 24
25 template <typename T> 25 template <typename T>
26 void operator()(const T&) { ++fHistogram[T::kType]; } 26 void operator()(const T&) { ++fHistogram[T::kType]; }
27 27
28 template <typename T> 28 template <typename T>
29 int count() const { return fHistogram[T::kType]; } 29 int count() const { return fHistogram[T::kType]; }
30 30
31 void apply(const SkRecord& record) {
32 for (unsigned i = 0; i < record.count(); i++) {
33 record.visit(i, *this);
34 }
35 }
36
31 private: 37 private:
32 int fHistogram[kRecordTypes]; 38 int fHistogram[kRecordTypes];
33 }; 39 };
34 40
35 DEF_TEST(Recorder, r) { 41 DEF_TEST(Recorder, r) {
36 SkRecord record; 42 SkRecord record;
37 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080); 43 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
38 44
39 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); 45 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
40 46
41 Tally tally; 47 Tally tally;
42 record.visit(tally); 48 tally.apply(record);
43
44 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>()); 49 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
45 } 50 }
46 51
47 // Regression test for leaking refs held by optional arguments. 52 // Regression test for leaking refs held by optional arguments.
48 DEF_TEST(Recorder_RefLeaking, r) { 53 DEF_TEST(Recorder_RefLeaking, r) {
49 // We use SaveLayer to test: 54 // We use SaveLayer to test:
50 // - its SkRect argument is optional and SkRect is POD. Just testing that that works. 55 // - its SkRect argument is optional and SkRect is POD. Just testing that that works.
51 // - its SkPaint argument is optional and SkPaint is not POD. The bug was here. 56 // - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
52 57
53 SkRect bounds = SkRect::MakeWH(320, 240); 58 SkRect bounds = SkRect::MakeWH(320, 240);
54 SkPaint paint; 59 SkPaint paint;
55 paint.setShader(SkNEW(SkEmptyShader))->unref(); 60 paint.setShader(SkNEW(SkEmptyShader))->unref();
56 61
57 REPORTER_ASSERT(r, paint.getShader()->unique()); 62 REPORTER_ASSERT(r, paint.getShader()->unique());
58 { 63 {
59 SkRecord record; 64 SkRecord record;
60 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080); 65 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
61 recorder.saveLayer(&bounds, &paint); 66 recorder.saveLayer(&bounds, &paint);
62 REPORTER_ASSERT(r, !paint.getShader()->unique()); 67 REPORTER_ASSERT(r, !paint.getShader()->unique());
63 } 68 }
64 REPORTER_ASSERT(r, paint.getShader()->unique()); 69 REPORTER_ASSERT(r, paint.getShader()->unique());
65 } 70 }
OLDNEW
« no previous file with comments | « tests/RecordTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698