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 "SkDropShadowImageFilter.h" |
14 #include "SkImagePriv.h" | |
14 #include "SkRecord.h" | 15 #include "SkRecord.h" |
15 #include "SkRecordDraw.h" | 16 #include "SkRecordDraw.h" |
16 #include "SkRecordOpts.h" | 17 #include "SkRecordOpts.h" |
17 #include "SkRecorder.h" | 18 #include "SkRecorder.h" |
18 #include "SkRecords.h" | 19 #include "SkRecords.h" |
20 #include "SkSurface.h" | |
19 | 21 |
20 static const int W = 1920, H = 1080; | 22 static const int W = 1920, H = 1080; |
21 | 23 |
22 class JustOneDraw : public SkDrawPictureCallback { | 24 class JustOneDraw : public SkDrawPictureCallback { |
23 public: | 25 public: |
24 JustOneDraw() : fCalls(0) {} | 26 JustOneDraw() : fCalls(0) {} |
25 | 27 |
26 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } | 28 virtual bool abortDrawing() SK_OVERRIDE { return fCalls++ > 0; } |
27 private: | 29 private: |
28 int fCalls; | 30 int fCalls; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. | 247 // The second bug showed up as adjusting the picture bounds (0,0,50,50) by t he drop shadow too. |
246 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). | 248 // The saveLayer, clipRect, and restore bounds were incorrectly (0,0,70,50). |
247 TestBBH bbh; | 249 TestBBH bbh; |
248 SkRecordFillBounds(record, &bbh); | 250 SkRecordFillBounds(record, &bbh); |
249 REPORTER_ASSERT(r, bbh.fEntries.count() == 4); | 251 REPORTER_ASSERT(r, bbh.fEntries.count() == 4); |
250 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); | 252 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); |
251 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); | 253 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); |
252 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0 , 0, 40, 40))); | 254 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0 , 0, 40, 40))); |
253 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); | 255 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0 , 0, 50, 50))); |
254 } | 256 } |
257 | |
258 DEF_TEST(RecordDraw_drawImage, r){ | |
259 class SkCanvasMock : public SkCanvas { | |
260 public: | |
261 SkCanvasMock(int width, int height) : INHERITED(width, height) { | |
262 this->resetTestValues(); | |
263 } | |
264 virtual ~SkCanvasMock() {} | |
265 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top , | |
266 const SkPaint* paint = NULL) SK_OVERRIDE { | |
267 | |
268 fDrawImageCalled = true; | |
269 } | |
270 | |
271 virtual void drawImageRect(const SkImage* image, const SkRect* src, | |
272 const SkRect& dst, | |
273 const SkPaint* paint = NULL) SK_OVERRIDE { | |
274 fDrawImageRectCalled = true; | |
275 } | |
276 | |
277 void resetTestValues() { | |
278 fDrawImageCalled = fDrawImageRectCalled = false; | |
279 } | |
280 | |
281 bool fDrawImageCalled; | |
282 bool fDrawImageRectCalled; | |
283 private: | |
284 typedef SkCanvas INHERITED; | |
tfarina
2014/10/24 00:52:15
Filed https://code.google.com/p/skia/issues/detail
| |
285 }; | |
286 | |
287 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10)); | |
288 surface->getCanvas()->clear(SK_ColorGREEN); | |
289 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | |
290 | |
291 SkCanvasMock canvas(10, 10); | |
292 | |
293 { | |
294 SkRecord record; | |
295 SkRecorder recorder(&record, 10, 10); | |
296 recorder.drawImage(image, 0, 0); | |
297 SkRecordDraw(record, &canvas, 0, 0); | |
298 } | |
299 REPORTER_ASSERT(r, canvas.fDrawImageCalled); | |
300 canvas.resetTestValues(); | |
301 | |
302 { | |
303 SkRecord record; | |
304 SkRecorder recorder(&record, 10, 10); | |
305 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); | |
306 SkRecordDraw(record, &canvas, 0, 0); | |
307 } | |
308 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | |
309 | |
310 } | |
OLD | NEW |