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 "SkDropShadowImageFilter.h" |
13 #include "SkRecord.h" | 14 #include "SkRecord.h" |
| 15 #include "SkRecordDraw.h" |
14 #include "SkRecordOpts.h" | 16 #include "SkRecordOpts.h" |
15 #include "SkRecordDraw.h" | |
16 #include "SkRecorder.h" | 17 #include "SkRecorder.h" |
17 #include "SkRecords.h" | 18 #include "SkRecords.h" |
18 | 19 |
19 static const int W = 1920, H = 1080; | 20 static const int W = 1920, H = 1080; |
20 | 21 |
21 class JustOneDraw : public SkDrawPictureCallback { | 22 class JustOneDraw : public SkDrawPictureCallback { |
22 public: | 23 public: |
23 JustOneDraw() : fCalls(0) {} | 24 JustOneDraw() : fCalls(0) {} |
24 | 25 |
25 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } | 26 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 218 |
218 REPORTER_ASSERT(r, 3 == rerecord.count()); | 219 REPORTER_ASSERT(r, 3 == rerecord.count()); |
219 assert_type<SkRecords::Save> (r, rerecord, 0); | 220 assert_type<SkRecords::Save> (r, rerecord, 0); |
220 assert_type<SkRecords::DrawRect>(r, rerecord, 1); | 221 assert_type<SkRecords::DrawRect>(r, rerecord, 1); |
221 assert_type<SkRecords::Restore> (r, rerecord, 2); | 222 assert_type<SkRecords::Restore> (r, rerecord, 2); |
222 | 223 |
223 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, 1); | 224 const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, re
record, 1); |
224 REPORTER_ASSERT(r, drawRect->rect == rect); | 225 REPORTER_ASSERT(r, drawRect->rect == rect); |
225 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED); | 226 REPORTER_ASSERT(r, drawRect->paint.getColor() == SK_ColorRED); |
226 } | 227 } |
| 228 |
| 229 // A regression test for crbug.com/415468 and skbug.com/2957. |
| 230 DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) { |
| 231 SkRecord record; |
| 232 SkRecorder recorder(&record, 50, 50); |
| 233 |
| 234 // We draw a rectangle with a long drop shadow. We used to not update the c
lip |
| 235 // bounds based on SaveLayer paints, so the drop shadow could be cut off. |
| 236 SkPaint paint; |
| 237 paint.setImageFilter(SkDropShadowImageFilter::Create(20, 0, 0, 0, SK_ColorBL
ACK))->unref(); |
| 238 |
| 239 recorder.saveLayer(NULL, &paint); |
| 240 recorder.clipRect(SkRect::MakeWH(20, 40)); |
| 241 recorder.drawRect(SkRect::MakeWH(20, 40), SkPaint()); |
| 242 recorder.restore(); |
| 243 |
| 244 // Under the original bug, all the right edge values would be 20 less than a
sserted here |
| 245 // because we intersected them with a clip that had not been adjusted for th
e drop shadow. |
| 246 TestBBH bbh; |
| 247 SkRecordFillBounds(record, &bbh); |
| 248 REPORTER_ASSERT(r, bbh.entries.count() == 4); |
| 249 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(0,
0, 70, 50))); |
| 250 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(0,
0, 70, 50))); |
| 251 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[2].bounds, SkRect::MakeLTRB(0,
0, 40, 40))); |
| 252 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[3].bounds, SkRect::MakeLTRB(0,
0, 70, 50))); |
| 253 } |
OLD | NEW |