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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Record two commands. | 60 // Record two commands. |
61 SkRecord record; | 61 SkRecord record; |
62 SkRecorder recorder(&record, W, H); | 62 SkRecorder recorder(&record, W, H); |
63 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); | 63 recorder.drawRect(SkRect::MakeWH(200, 300), SkPaint()); |
64 recorder.clipRect(SkRect::MakeWH(100, 200)); | 64 recorder.clipRect(SkRect::MakeWH(100, 200)); |
65 | 65 |
66 SkRecord rerecord; | 66 SkRecord rerecord; |
67 SkRecorder canvas(&rerecord, W, H); | 67 SkRecorder canvas(&rerecord, W, H); |
68 | 68 |
69 JustOneDraw callback; | 69 JustOneDraw callback; |
70 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, &callback); | 70 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr/*bbh*/, &callback
); |
71 | 71 |
72 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); | 72 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); |
73 REPORTER_ASSERT(r, 0 == count_instances_of_type<SkRecords::ClipRect>(rerecor
d)); | 73 REPORTER_ASSERT(r, 0 == count_instances_of_type<SkRecords::ClipRect>(rerecor
d)); |
74 } | 74 } |
75 | 75 |
76 DEF_TEST(RecordDraw_Unbalanced, r) { | 76 DEF_TEST(RecordDraw_Unbalanced, r) { |
77 SkRecord record; | 77 SkRecord record; |
78 SkRecorder recorder(&record, W, H); | 78 SkRecorder recorder(&record, W, H); |
79 recorder.save(); // We won't balance this, but SkRecordDraw will for us. | 79 recorder.save(); // We won't balance this, but SkRecordDraw will for us. |
80 recorder.scale(2, 2); | 80 recorder.scale(2, 2); |
81 | 81 |
82 SkRecord rerecord; | 82 SkRecord rerecord; |
83 SkRecorder canvas(&rerecord, W, H); | 83 SkRecorder canvas(&rerecord, W, H); |
84 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL/*bbh*/, NULL/*callback*/); | 84 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr/*bbh*/, nullptr/*
callback*/); |
85 | 85 |
86 int save_count = count_instances_of_type<SkRecords::Save>(rerecord); | 86 int save_count = count_instances_of_type<SkRecords::Save>(rerecord); |
87 int restore_count = count_instances_of_type<SkRecords::Save>(rerecord); | 87 int restore_count = count_instances_of_type<SkRecords::Save>(rerecord); |
88 REPORTER_ASSERT(r, save_count == restore_count); | 88 REPORTER_ASSERT(r, save_count == restore_count); |
89 } | 89 } |
90 | 90 |
91 DEF_TEST(RecordDraw_SetMatrixClobber, r) { | 91 DEF_TEST(RecordDraw_SetMatrixClobber, r) { |
92 // Set up an SkRecord that just scales by 2x,3x. | 92 // Set up an SkRecord that just scales by 2x,3x. |
93 SkRecord scaleRecord; | 93 SkRecord scaleRecord; |
94 SkRecorder scaleCanvas(&scaleRecord, W, H); | 94 SkRecorder scaleCanvas(&scaleRecord, W, H); |
95 SkMatrix scale; | 95 SkMatrix scale; |
96 scale.setScale(2, 3); | 96 scale.setScale(2, 3); |
97 scaleCanvas.setMatrix(scale); | 97 scaleCanvas.setMatrix(scale); |
98 | 98 |
99 // Set up an SkRecord with an initial +20, +20 translate. | 99 // Set up an SkRecord with an initial +20, +20 translate. |
100 SkRecord translateRecord; | 100 SkRecord translateRecord; |
101 SkRecorder translateCanvas(&translateRecord, W, H); | 101 SkRecorder translateCanvas(&translateRecord, W, H); |
102 SkMatrix translate; | 102 SkMatrix translate; |
103 translate.setTranslate(20, 20); | 103 translate.setTranslate(20, 20); |
104 translateCanvas.setMatrix(translate); | 104 translateCanvas.setMatrix(translate); |
105 | 105 |
106 SkRecordDraw(scaleRecord, &translateCanvas, NULL, NULL, 0, NULL/*bbh*/, NULL
/*callback*/); | 106 SkRecordDraw(scaleRecord, &translateCanvas, nullptr, nullptr, 0, nullptr/*bb
h*/, nullptr/*callback*/); |
107 REPORTER_ASSERT(r, 4 == translateRecord.count()); | 107 REPORTER_ASSERT(r, 4 == translateRecord.count()); |
108 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 108 assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
109 assert_type<SkRecords::Save> (r, translateRecord, 1); | 109 assert_type<SkRecords::Save> (r, translateRecord, 1); |
110 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); | 110 assert_type<SkRecords::SetMatrix>(r, translateRecord, 2); |
111 assert_type<SkRecords::Restore> (r, translateRecord, 3); | 111 assert_type<SkRecords::Restore> (r, translateRecord, 3); |
112 | 112 |
113 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, | 113 // When we look at translateRecord now, it should have its first +20,+20 tra
nslate, |
114 // then a 2x,3x scale that's been concatted with that +20,+20 translate. | 114 // then a 2x,3x scale that's been concatted with that +20,+20 translate. |
115 const SkRecords::SetMatrix* setMatrix; | 115 const SkRecords::SetMatrix* setMatrix; |
116 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); | 116 setMatrix = assert_type<SkRecords::SetMatrix>(r, translateRecord, 0); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 SkPaint p; | 208 SkPaint p; |
209 | 209 |
210 SkRecord record; | 210 SkRecord record; |
211 SkRecorder recorder(&record, kWidth, kHeight); | 211 SkRecorder recorder(&record, kWidth, kHeight); |
212 recorder.drawRect(r1, p); | 212 recorder.drawRect(r1, p); |
213 recorder.drawRect(r2, p); | 213 recorder.drawRect(r2, p); |
214 recorder.drawRect(r3, p); | 214 recorder.drawRect(r3, p); |
215 | 215 |
216 SkRecord rerecord; | 216 SkRecord rerecord; |
217 SkRecorder canvas(&rerecord, kWidth, kHeight); | 217 SkRecorder canvas(&rerecord, kWidth, kHeight); |
218 SkRecordPartialDraw(record, &canvas, NULL, 0, 1, 2, SkMatrix::I()); // repla
y just drawRect of r2 | 218 SkRecordPartialDraw(record, &canvas, nullptr, 0, 1, 2, SkMatrix::I()); // re
play just drawRect of r2 |
219 | 219 |
220 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); | 220 REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecor
d)); |
221 int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord); | 221 int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord); |
222 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, index); | 222 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, index); |
223 REPORTER_ASSERT(r, drawRect->rect == r2); | 223 REPORTER_ASSERT(r, drawRect->rect == r2); |
224 } | 224 } |
225 | 225 |
226 // A regression test for crbug.com/415468 and skbug.com/2957. | 226 // A regression test for crbug.com/415468 and skbug.com/2957. |
227 // | 227 // |
228 // This also now serves as a regression test for crbug.com/418417. We used to a
djust the | 228 // This also now serves as a regression test for crbug.com/418417. We used to a
djust the |
229 // bounds for the saveLayer, clip, and restore to be greater than the bounds of
the picture. | 229 // bounds for the saveLayer, clip, and restore to be greater than the bounds of
the picture. |
230 // (We were applying the saveLayer paint to the bounds after restore, which make
s no sense.) | 230 // (We were applying the saveLayer paint to the bounds after restore, which make
s no sense.) |
231 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { | 231 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { |
232 SkRecord record; | 232 SkRecord record; |
233 SkRecorder recorder(&record, 50, 50); | 233 SkRecorder recorder(&record, 50, 50); |
234 | 234 |
235 // We draw a rectangle with a long drop shadow. We used to not update the c
lip | 235 // We draw a rectangle with a long drop shadow. We used to not update the c
lip |
236 // bounds based on SaveLayer paints, so the drop shadow could be cut off. | 236 // bounds based on SaveLayer paints, so the drop shadow could be cut off. |
237 SkPaint paint; | 237 SkPaint paint; |
238 paint.setImageFilter(SkDropShadowImageFilter::Create(20, 0, 0, 0, SK_ColorBL
ACK, | 238 paint.setImageFilter(SkDropShadowImageFilter::Create(20, 0, 0, 0, SK_ColorBL
ACK, |
239 SkDropShadowImageFilter::kDrawShadowAndForeground_Shado
wMode))->unref(); | 239 SkDropShadowImageFilter::kDrawShadowAndForeground_Shado
wMode))->unref(); |
240 | 240 |
241 recorder.saveLayer(NULL, &paint); | 241 recorder.saveLayer(nullptr, &paint); |
242 recorder.clipRect(SkRect::MakeWH(20, 40)); | 242 recorder.clipRect(SkRect::MakeWH(20, 40)); |
243 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); | 243 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); |
244 recorder.restore(); | 244 recorder.restore(); |
245 | 245 |
246 // Under the original bug, the right edge value of the drawRect would be 20
less than asserted | 246 // Under the original bug, the right edge value of the drawRect would be 20
less than asserted |
247 // here because we intersected it with a clip that had not been adjusted for
the drop shadow. | 247 // here because we intersected it with a clip that had not been adjusted for
the drop shadow. |
248 // | 248 // |
249 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t
he drop shadow too. | 249 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t
he drop shadow too. |
250 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). | 250 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). |
251 TestBBH bbh; | 251 TestBBH bbh; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); | 310 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); |
311 surface->getCanvas()->clear(SK_ColorGREEN); | 311 surface->getCanvas()->clear(SK_ColorGREEN); |
312 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 312 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
313 | 313 |
314 SkCanvasMock canvas(10, 10); | 314 SkCanvasMock canvas(10, 10); |
315 | 315 |
316 { | 316 { |
317 SkRecord record; | 317 SkRecord record; |
318 SkRecorder recorder(&record, 10, 10); | 318 SkRecorder recorder(&record, 10, 10); |
319 recorder.drawImage(image, 0, 0); | 319 recorder.drawImage(image, 0, 0); |
320 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); | 320 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr, 0); |
321 } | 321 } |
322 REPORTER_ASSERT(r, canvas.fDrawImageCalled); | 322 REPORTER_ASSERT(r, canvas.fDrawImageCalled); |
323 canvas.resetTestValues(); | 323 canvas.resetTestValues(); |
324 | 324 |
325 { | 325 { |
326 SkRecord record; | 326 SkRecord record; |
327 SkRecorder recorder(&record, 10, 10); | 327 SkRecorder recorder(&record, 10, 10); |
328 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr); | 328 recorder.drawImageRect(image, SkRect::MakeWH(10, 10), nullptr); |
329 SkRecordDraw(record, &canvas, NULL, NULL, 0, NULL, 0); | 329 SkRecordDraw(record, &canvas, nullptr, nullptr, 0, nullptr, 0); |
330 } | 330 } |
331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | 331 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); |
332 | 332 |
333 } | 333 } |
OLD | NEW |