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 |
11 #include "SkDebugCanvas.h" | 11 #include "SkDebugCanvas.h" |
12 #include "SkDrawPictureCallback.h" | 12 #include "SkDrawPictureCallback.h" |
13 #include "SkRecord.h" | 13 #include "SkRecord.h" |
14 #include "SkRecordOpts.h" | 14 #include "SkRecordOpts.h" |
15 #include "SkRecordDraw.h" | 15 #include "SkRecordDraw.h" |
16 #include "SkRecorder.h" | 16 #include "SkRecorder.h" |
17 #include "SkRecords.h" | 17 #include "SkRecords.h" |
18 | 18 |
19 static const int W = 1920, H = 1080; | 19 static const int W = 1920, H = 1080; |
20 | 20 |
21 static void draw_pos_text_h(SkCanvas* canvas, const char* text, SkScalar y) { | |
22 const size_t len = strlen(text); | |
23 SkAutoTMalloc<SkScalar> xpos(len); | |
24 for (size_t i = 0; i < len; i++) { | |
25 xpos[i] = (SkScalar)i; | |
26 } | |
27 canvas->drawPosTextH(text, len, xpos, y, SkPaint()); | |
28 } | |
29 | |
30 class JustOneDraw : public SkDrawPictureCallback { | 21 class JustOneDraw : public SkDrawPictureCallback { |
31 public: | 22 public: |
32 JustOneDraw() : fCalls(0) {} | 23 JustOneDraw() : fCalls(0) {} |
33 | 24 |
34 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } | 25 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } |
35 private: | 26 private: |
36 int fCalls; | 27 int fCalls; |
37 }; | 28 }; |
38 | 29 |
39 DEF_TEST(RecordDraw_Abort, r) { | 30 DEF_TEST(RecordDraw_Abort, r) { |
(...skipping 24 matching lines...) Expand all Loading... |
64 SkRecorder canvas(&rerecord, W, H); | 55 SkRecorder canvas(&rerecord, W, H); |
65 SkRecordDraw(record, &canvas); | 56 SkRecordDraw(record, &canvas); |
66 | 57 |
67 REPORTER_ASSERT(r, 4 == rerecord.count()); | 58 REPORTER_ASSERT(r, 4 == rerecord.count()); |
68 assert_type<SkRecords::Save> (r, rerecord, 0); | 59 assert_type<SkRecords::Save> (r, rerecord, 0); |
69 assert_type<SkRecords::Save> (r, rerecord, 1); | 60 assert_type<SkRecords::Save> (r, rerecord, 1); |
70 assert_type<SkRecords::Restore> (r, rerecord, 2); | 61 assert_type<SkRecords::Restore> (r, rerecord, 2); |
71 assert_type<SkRecords::Restore> (r, rerecord, 3); | 62 assert_type<SkRecords::Restore> (r, rerecord, 3); |
72 } | 63 } |
73 | 64 |
74 // Rerecord into another SkRecord with a clip. | |
75 static void record_clipped(const SkRecord& record, SkRect clip, SkRecord* clippe
d) { | |
76 SkRecorder recorder(clipped, W, H); | |
77 recorder.clipRect(clip); | |
78 SkRecordDraw(record, &recorder); | |
79 } | |
80 | |
81 DEF_TEST(RecordDraw_PosTextHQuickReject, r) { | |
82 SkRecord record; | |
83 SkRecorder recorder(&record, W, H); | |
84 | |
85 draw_pos_text_h(&recorder, "This will draw.", 20); | |
86 draw_pos_text_h(&recorder, "This won't.", 5000); | |
87 | |
88 SkRecordBoundDrawPosTextH(&record); | |
89 | |
90 SkRecord clipped; | |
91 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); | |
92 | |
93 REPORTER_ASSERT(r, 4 == clipped.count()); | |
94 assert_type<SkRecords::ClipRect> (r, clipped, 0); | |
95 assert_type<SkRecords::Save> (r, clipped, 1); | |
96 assert_type<SkRecords::DrawPosTextH>(r, clipped, 2); | |
97 assert_type<SkRecords::Restore> (r, clipped, 3); | |
98 } | |
99 | |
100 DEF_TEST(RecordDraw_Culling, r) { | |
101 // Record these 7 drawing commands verbatim. | |
102 SkRecord record; | |
103 SkRecorder recorder(&record, W, H); | |
104 | |
105 recorder.pushCull(SkRect::MakeWH(100, 100)); | |
106 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint()); | |
107 recorder.drawRect(SkRect::MakeWH(30, 30), SkPaint()); | |
108 recorder.pushCull(SkRect::MakeWH(5, 5)); | |
109 recorder.drawRect(SkRect::MakeWH(1, 1), SkPaint()); | |
110 recorder.popCull(); | |
111 recorder.popCull(); | |
112 | |
113 // Take a pass over to match up pushCulls and popCulls. | |
114 SkRecordAnnotateCullingPairs(&record); | |
115 | |
116 // This clip intersects the outer cull, but allows us to quick reject the in
ner one. | |
117 SkRecord clipped; | |
118 record_clipped(record, SkRect::MakeLTRB(20, 20, 200, 200), &clipped); | |
119 | |
120 // If culling weren't working, we'd see 3 more commands recorded here. | |
121 REPORTER_ASSERT(r, 7 == clipped.count()); | |
122 assert_type<SkRecords::ClipRect>(r, clipped, 0); | |
123 assert_type<SkRecords::Save> (r, clipped, 1); | |
124 assert_type<SkRecords::PushCull>(r, clipped, 2); | |
125 assert_type<SkRecords::DrawRect>(r, clipped, 3); | |
126 assert_type<SkRecords::DrawRect>(r, clipped, 4); | |
127 assert_type<SkRecords::PopCull> (r, clipped, 5); | |
128 assert_type<SkRecords::Restore> (r, clipped, 6); | |
129 } | |
130 | |
131 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 65 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
132 // Set up an SkRecord that just scales by 2x,3x. | 66 // Set up an SkRecord that just scales by 2x,3x. |
133 SkRecord scaleRecord; | 67 SkRecord scaleRecord; |
134 SkRecorder scaleCanvas(&scaleRecord, W, H); | 68 SkRecorder scaleCanvas(&scaleRecord, W, H); |
135 SkMatrix scale; | 69 SkMatrix scale; |
136 scale.setScale(2, 3); | 70 scale.setScale(2, 3); |
137 scaleCanvas.setMatrix(scale); | 71 scaleCanvas.setMatrix(scale); |
138 | 72 |
139 // Set up an SkRecord with an initial +20, +20 translate. | 73 // Set up an SkRecord with an initial +20, +20 translate. |
140 SkRecord translateRecord; | 74 SkRecord translateRecord; |
(...skipping 13 matching lines...) Expand all Loading... |
154 // 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. |
155 const SkRecords::SetMatrix* setMatrix; | 89 const SkRecords::SetMatrix* setMatrix; |
156 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 90 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
157 REPORTER_ASSERT(r, setMatrix->matrix == translate); | 91 REPORTER_ASSERT(r, setMatrix->matrix == translate); |
158 | 92 |
159 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 93 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
160 SkMatrix expected = scale; | 94 SkMatrix expected = scale; |
161 expected.postConcat(translate); | 95 expected.postConcat(translate); |
162 REPORTER_ASSERT(r, setMatrix->matrix == expected); | 96 REPORTER_ASSERT(r, setMatrix->matrix == expected); |
163 } | 97 } |
OLD | NEW |