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