| 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 11 matching lines...) Expand all Loading... |
| 22 SkAutoTMalloc<SkScalar> xpos(len); | 22 SkAutoTMalloc<SkScalar> xpos(len); |
| 23 for (size_t i = 0; i < len; i++) { | 23 for (size_t i = 0; i < len; i++) { |
| 24 xpos[i] = (SkScalar)i; | 24 xpos[i] = (SkScalar)i; |
| 25 } | 25 } |
| 26 canvas->drawPosTextH(text, len, xpos, y, SkPaint()); | 26 canvas->drawPosTextH(text, len, xpos, y, SkPaint()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Rerecord into another SkRecord using full SkCanvas semantics, | 29 // Rerecord into another SkRecord using full SkCanvas semantics, |
| 30 // tracking clips and allowing SkRecordDraw's quickReject() calls to work. | 30 // tracking clips and allowing SkRecordDraw's quickReject() calls to work. |
| 31 static void record_clipped(const SkRecord& record, SkRect clip, SkRecord* clippe
d) { | 31 static void record_clipped(const SkRecord& record, SkRect clip, SkRecord* clippe
d) { |
| 32 SkRecorder recorder(SkRecorder::kReadWrite_Mode, clipped, W, H); | 32 SkRecorder recorder(clipped, W, H); |
| 33 recorder.clipRect(clip); | 33 recorder.clipRect(clip); |
| 34 SkRecordDraw(record, &recorder); | 34 SkRecordDraw(record, &recorder); |
| 35 } | 35 } |
| 36 | 36 |
| 37 DEF_TEST(RecordDraw_PosTextHQuickReject, r) { | 37 DEF_TEST(RecordDraw_PosTextHQuickReject, r) { |
| 38 SkRecord record; | 38 SkRecord record; |
| 39 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 39 SkRecorder recorder(&record, W, H); |
| 40 | 40 |
| 41 draw_pos_text_h(&recorder, "This will draw.", 20); | 41 draw_pos_text_h(&recorder, "This will draw.", 20); |
| 42 draw_pos_text_h(&recorder, "This won't.", 5000); | 42 draw_pos_text_h(&recorder, "This won't.", 5000); |
| 43 | 43 |
| 44 SkRecordBoundDrawPosTextH(&record); | 44 SkRecordBoundDrawPosTextH(&record); |
| 45 | 45 |
| 46 SkRecord clipped; | 46 SkRecord clipped; |
| 47 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); | 47 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); |
| 48 | 48 |
| 49 // clipRect and the first drawPosTextH. | 49 // clipRect and the first drawPosTextH. |
| 50 REPORTER_ASSERT(r, 2 == clipped.count()); | 50 REPORTER_ASSERT(r, 2 == clipped.count()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 DEF_TEST(RecordDraw_Culling, r) { | 53 DEF_TEST(RecordDraw_Culling, r) { |
| 54 // Record these 7 drawing commands verbatim. | 54 // Record these 7 drawing commands verbatim. |
| 55 SkRecord record; | 55 SkRecord record; |
| 56 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H); | 56 SkRecorder recorder(&record, W, H); |
| 57 | 57 |
| 58 recorder.pushCull(SkRect::MakeWH(100, 100)); | 58 recorder.pushCull(SkRect::MakeWH(100, 100)); |
| 59 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); | 59 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); |
| 60 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); | 60 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); |
| 61 recorder.pushCull(SkRect::MakeWH(5, 5)); | 61 recorder.pushCull(SkRect::MakeWH(5, 5)); |
| 62 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); | 62 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); |
| 63 recorder.popCull(); | 63 recorder.popCull(); |
| 64 recorder.popCull(); | 64 recorder.popCull(); |
| 65 | 65 |
| 66 // Take a pass over to match up pushCulls and popCulls. | 66 // Take a pass over to match up pushCulls and popCulls. |
| 67 SkRecordAnnotateCullingPairs(&record); | 67 SkRecordAnnotateCullingPairs(&record); |
| 68 | 68 |
| 69 // This clip intersects the outer cull, but allows us to quick reject the in
ner one. | 69 // This clip intersects the outer cull, but allows us to quick reject the in
ner one. |
| 70 SkRecord clipped; | 70 SkRecord clipped; |
| 71 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); | 71 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); |
| 72 | 72 |
| 73 // We'll keep the clipRect call from above, and the outer two drawRects, and
the push/pop pair. | 73 // We'll keep the clipRect call from above, and the outer two drawRects, and
the push/pop pair. |
| 74 // If culling weren't working, we'd see 8 commands recorded here. | 74 // If culling weren't working, we'd see 8 commands recorded here. |
| 75 REPORTER_ASSERT(r, 5 == clipped.count()); | 75 REPORTER_ASSERT(r, 5 == clipped.count()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 78 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
| 79 // Set up an SkRecord that just scales by 2x,3x. | 79 // Set up an SkRecord that just scales by 2x,3x. |
| 80 SkRecord scaleRecord; | 80 SkRecord scaleRecord; |
| 81 SkRecorder scaleCanvas(SkRecorder::kReadWrite_Mode, &scaleRecord, W, H); | 81 SkRecorder scaleCanvas(&scaleRecord, W, H); |
| 82 SkMatrix scale; | 82 SkMatrix scale; |
| 83 scale.setScale(2, 3); | 83 scale.setScale(2, 3); |
| 84 scaleCanvas.setMatrix(scale); | 84 scaleCanvas.setMatrix(scale); |
| 85 | 85 |
| 86 // Set up an SkRecord with an initial +20, +20 translate. | 86 // Set up an SkRecord with an initial +20, +20 translate. |
| 87 SkRecord translateRecord; | 87 SkRecord translateRecord; |
| 88 SkRecorder translateCanvas(SkRecorder::kReadWrite_Mode, &translateRecord, W,
H); | 88 SkRecorder translateCanvas(&translateRecord, W, H); |
| 89 SkMatrix translate; | 89 SkMatrix translate; |
| 90 translate.setTranslate(20, 20); | 90 translate.setTranslate(20, 20); |
| 91 translateCanvas.setMatrix(translate); | 91 translateCanvas.setMatrix(translate); |
| 92 | 92 |
| 93 SkRecordDraw(scaleRecord, &translateCanvas); | 93 SkRecordDraw(scaleRecord, &translateCanvas); |
| 94 | 94 |
| 95 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, | 95 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, |
| 96 // then a 2x,3x scale that's been concatted with that +20,+20 translate. | 96 // then a 2x,3x scale that's been concatted with that +20,+20 translate. |
| 97 const SkRecords::SetMatrix* setMatrix; | 97 const SkRecords::SetMatrix* setMatrix; |
| 98 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 98 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
| 99 REPORTER_ASSERT(r, setMatrix->matrix == translate); | 99 REPORTER_ASSERT(r, setMatrix->matrix == translate); |
| 100 | 100 |
| 101 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 1); | 101 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 1); |
| 102 SkMatrix expected = scale; | 102 SkMatrix expected = scale; |
| 103 expected.postConcat(translate); | 103 expected.postConcat(translate); |
| 104 REPORTER_ASSERT(r, setMatrix->matrix == expected); | 104 REPORTER_ASSERT(r, setMatrix->matrix == expected); |
| 105 } | 105 } |
| OLD | NEW |