OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |