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 #include "RecordTestUtils.h" |
9 | 10 |
10 #include "SkRecord.h" | 11 #include "SkRecord.h" |
11 #include "SkRecordOpts.h" | 12 #include "SkRecordOpts.h" |
12 #include "SkRecorder.h" | 13 #include "SkRecorder.h" |
13 #include "SkRecords.h" | 14 #include "SkRecords.h" |
14 | |
15 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
16 | 16 |
17 static const int W = 1920, H = 1080; | 17 static const int W = 1920, H = 1080; |
18 | 18 |
19 // If the command we're reading is a U, set ptr to it, otherwise set it to NULL. | |
20 template <typename U> | |
21 struct ReadAs { | |
22 ReadAs() : ptr(NULL), type(SkRecords::Type(~0)) {} | |
23 | |
24 const U* ptr; | |
25 SkRecords::Type type; | |
26 | |
27 void operator()(const U& r) { ptr = &r; type = U::kType; } | |
28 | |
29 template <typename T> | |
30 void operator()(const T&) { type = U::kType; } | |
31 }; | |
32 | |
33 // Assert that the ith command in record is of type T, and return it. | |
34 template <typename T> | |
35 static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsig
ned index) { | |
36 ReadAs<T> reader; | |
37 record.visit<void>(index, reader); | |
38 REPORTER_ASSERT(r, T::kType == reader.type); | |
39 REPORTER_ASSERT(r, NULL != reader.ptr); | |
40 return reader.ptr; | |
41 } | |
42 | |
43 DEF_TEST(RecordOpts_Culling, r) { | 19 DEF_TEST(RecordOpts_Culling, r) { |
44 SkRecord record; | 20 SkRecord record; |
45 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 21 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); |
46 | 22 |
47 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint()); | 23 recorder.drawRect(SkRect::MakeWH(1000, 10000), SkPaint()); |
48 | 24 |
49 recorder.pushCull(SkRect::MakeWH(100, 100)); | 25 recorder.pushCull(SkRect::MakeWH(100, 100)); |
50 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); | 26 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); |
51 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); | 27 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); |
52 recorder.pushCull(SkRect::MakeWH(5, 5)); | 28 recorder.pushCull(SkRect::MakeWH(5, 5)); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // SaveLayer/Restore removed: we can fold in the alpha! | 236 // SaveLayer/Restore removed: we can fold in the alpha! |
261 recorder.saveLayer(NULL, &goodLayerPaint); | 237 recorder.saveLayer(NULL, &goodLayerPaint); |
262 recorder.drawRect(draw, goodDrawPaint); | 238 recorder.drawRect(draw, goodDrawPaint); |
263 recorder.restore(); | 239 recorder.restore(); |
264 assert_savelayer_restore(r, &record, 15, true); | 240 assert_savelayer_restore(r, &record, 15, true); |
265 | 241 |
266 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); | 242 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
cord, 16); |
267 REPORTER_ASSERT(r, drawRect != NULL); | 243 REPORTER_ASSERT(r, drawRect != NULL); |
268 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); | 244 REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202); |
269 } | 245 } |
OLD | NEW |