| 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 #include "RecordTestUtils.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // Record two commands. | 31 // Record two commands. |
| 32 SkRecord record; | 32 SkRecord record; |
| 33 SkRecorder recorder(&record, W, H); | 33 SkRecorder recorder(&record, W, H); |
| 34 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); | 34 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); |
| 35 recorder.clipRect(SkRect::MakeWH(100, 200)); | 35 recorder.clipRect(SkRect::MakeWH(100, 200)); |
| 36 | 36 |
| 37 SkRecord rerecord; | 37 SkRecord rerecord; |
| 38 SkRecorder canvas(&rerecord, W, H); | 38 SkRecorder canvas(&rerecord, W, H); |
| 39 | 39 |
| 40 JustOneDraw callback; | 40 JustOneDraw callback; |
| 41 SkRecordDraw(record, &canvas, &callback); | 41 SkRecordDraw(record, &canvas, NULL/*bbh*/, &callback); |
| 42 | 42 |
| 43 REPORTER_ASSERT(r, 3 == rerecord.count()); | 43 REPORTER_ASSERT(r, 3 == rerecord.count()); |
| 44 assert_type<SkRecords::Save> (r, rerecord, 0); | 44 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 45 assert_type<SkRecords::DrawRect>(r, rerecord, 1); | 45 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
| 46 assert_type<SkRecords::Restore> (r, rerecord, 2); | 46 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 47 } | 47 } |
| 48 | 48 |
| 49 DEF_TEST(RecordDraw_Unbalanced, r) { | 49 DEF_TEST(RecordDraw_Unbalanced, r) { |
| 50 SkRecord record; | 50 SkRecord record; |
| 51 SkRecorder recorder(&record, W, H); | 51 SkRecorder recorder(&record, W, H); |
| 52 recorder.save(); // We won't balance this, but SkRecordDraw will for us. | 52 recorder.save(); // We won't balance this, but SkRecordDraw will for us. |
| 53 | 53 |
| 54 SkRecord rerecord; | 54 SkRecord rerecord; |
| 55 SkRecorder canvas(&rerecord, W, H); | 55 SkRecorder canvas(&rerecord, W, H); |
| 56 SkRecordDraw(record, &canvas); | 56 SkRecordDraw(record, &canvas, NULL/*bbh*/, NULL/*callback*/); |
| 57 | 57 |
| 58 REPORTER_ASSERT(r, 4 == rerecord.count()); | 58 REPORTER_ASSERT(r, 4 == rerecord.count()); |
| 59 assert_type<SkRecords::Save> (r, rerecord, 0); | 59 assert_type<SkRecords::Save> (r, rerecord, 0); |
| 60 assert_type<SkRecords::Save> (r, rerecord, 1); | 60 assert_type<SkRecords::Save> (r, rerecord, 1); |
| 61 assert_type<SkRecords::Restore> (r, rerecord, 2); | 61 assert_type<SkRecords::Restore> (r, rerecord, 2); |
| 62 assert_type<SkRecords::Restore> (r, rerecord, 3); | 62 assert_type<SkRecords::Restore> (r, rerecord, 3); |
| 63 } | 63 } |
| 64 | 64 |
| 65 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 65 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
| 66 // Set up an SkRecord that just scales by 2x,3x. | 66 // Set up an SkRecord that just scales by 2x,3x. |
| 67 SkRecord scaleRecord; | 67 SkRecord scaleRecord; |
| 68 SkRecorder scaleCanvas(&scaleRecord, W, H); | 68 SkRecorder scaleCanvas(&scaleRecord, W, H); |
| 69 SkMatrix scale; | 69 SkMatrix scale; |
| 70 scale.setScale(2, 3); | 70 scale.setScale(2, 3); |
| 71 scaleCanvas.setMatrix(scale); | 71 scaleCanvas.setMatrix(scale); |
| 72 | 72 |
| 73 // Set up an SkRecord with an initial +20, +20 translate. | 73 // Set up an SkRecord with an initial +20, +20 translate. |
| 74 SkRecord translateRecord; | 74 SkRecord translateRecord; |
| 75 SkRecorder translateCanvas(&translateRecord, W, H); | 75 SkRecorder translateCanvas(&translateRecord, W, H); |
| 76 SkMatrix translate; | 76 SkMatrix translate; |
| 77 translate.setTranslate(20, 20); | 77 translate.setTranslate(20, 20); |
| 78 translateCanvas.setMatrix(translate); | 78 translateCanvas.setMatrix(translate); |
| 79 | 79 |
| 80 SkRecordDraw(scaleRecord, &translateCanvas); | 80 SkRecordDraw(scaleRecord, &translateCanvas, NULL/*bbh*/, NULL/*callback*/); |
| 81 REPORTER_ASSERT(r, 4 == translateRecord.count()); | 81 REPORTER_ASSERT(r, 4 == translateRecord.count()); |
| 82 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 82 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 83 assert_type<SkRecords::Save> (r, translateRecord, 1); | 83 assert_type<SkRecords::Save> (r, translateRecord, 1); |
| 84 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 84 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
| 85 assert_type<SkRecords::Restore> (r, translateRecord, 3); | 85 assert_type<SkRecords::Restore> (r, translateRecord, 3); |
| 86 | 86 |
| 87 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, | 87 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, |
| 88 // then a 2x,3x scale that's been concatted with that +20,+20 translate. | 88 // then a 2x,3x scale that's been concatted with that +20,+20 translate. |
| 89 const SkRecords::SetMatrix* setMatrix; | 89 const SkRecords::SetMatrix* setMatrix; |
| 90 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 90 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 91 REPORTER_ASSERT(r, setMatrix->matrix == translate); | 91 REPORTER_ASSERT(r, setMatrix->matrix == translate); |
| 92 | 92 |
| 93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
| 94 SkMatrix expected = scale; | 94 SkMatrix expected = scale; |
| 95 expected.postConcat(translate); | 95 expected.postConcat(translate); |
| 96 REPORTER_ASSERT(r, setMatrix->matrix == expected); | 96 REPORTER_ASSERT(r, setMatrix->matrix == expected); |
| 97 } | 97 } |
| OLD | NEW |