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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 // Under the original bug, all the right edge values would be 20 less than a sserted here | 246 // 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. | 247 // because we intersected them with a clip that had not been adjusted for th e drop shadow. |
246 TestBBH bbh; | 248 TestBBH bbh; |
247 SkRecordFillBounds(record, &bbh); | 249 SkRecordFillBounds(record, &bbh); |
248 REPORTER_ASSERT(r, bbh.entries.count() == 4); | 250 REPORTER_ASSERT(r, bbh.entries.count() == 4); |
249 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(0, 0, 70, 50))); | 251 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))); | 252 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))); | 253 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))); | 254 REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[3].bounds, SkRect::MakeLTRB(0, 0, 70, 50))); |
253 } | 255 } |
256 | |
257 DEF_TEST(RecordDraw_drawImage, r){ | |
258 class SkCanvasMock : public SkCanvas { | |
259 public: | |
260 SkCanvasMock(int width, int height) : INHERITED(width, height) { | |
261 this->resetTestValues(); | |
262 } | |
263 virtual ~SkCanvasMock() {} | |
264 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top , | |
265 const SkPaint* paint = NULL) SK_OVERRIDE { | |
mtklein
2014/09/30 14:42:21
some funky indents on these methods
Rémi Piotaix
2014/09/30 15:48:09
Done.
| |
266 | |
267 fDrawImageCalled = true; | |
268 fDrawingImage = image; | |
mtklein
2014/09/30 14:42:21
fDrawingImage seems unused?
Rémi Piotaix
2014/09/30 15:48:09
Done.
| |
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 fDrawingImage = image; | |
276 } | |
277 | |
278 void resetTestValues() { | |
279 fDrawImageCalled = fDrawImageRectCalled = false; | |
280 } | |
281 | |
282 const SkImage* fDrawingImage; | |
283 bool fDrawImageCalled; | |
284 bool fDrawImageRectCalled; | |
285 private: | |
286 typedef SkCanvas INHERITED; | |
287 }; | |
288 | |
289 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10)); | |
290 surface->getCanvas()->clear(SK_ColorGREEN); | |
291 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | |
292 | |
293 SkCanvasMock canvas(10, 10); | |
294 | |
295 { | |
296 SkRecord record; | |
297 SkRecorder recorder(&record, 10, 10); | |
298 recorder.drawImage(image, 0, 0); | |
299 SkRecordDraw(record, &canvas, 0, 0); | |
300 } | |
301 REPORTER_ASSERT(r, canvas.fDrawImageCalled); | |
302 canvas.resetTestValues(); | |
303 | |
304 { | |
305 SkRecord record; | |
306 SkRecorder recorder(&record, 10, 10); | |
307 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10)); | |
308 SkRecordDraw(record, &canvas, 0, 0); | |
309 } | |
310 REPORTER_ASSERT(r, canvas.fDrawImageRectCalled); | |
311 | |
312 } | |
OLD | NEW |