Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: tests/RecordDrawTest.cpp

Issue 610003002: Override SkCanvas::drawImage() in SkRecorder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add tests Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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){
mtklein 2014/09/27 15:41:22 I feel like this test may be taking on a bit too m
Rémi Piotaix 2014/09/29 17:57:55 Yes, already done in RecorderTest.cpp, but this is
258 class SkCanvasMock : public SkCanvas {
259 public:
260 SkCanvasMock(int width, int height) : INHERITED(width, height) {
robertphillips 2014/09/29 17:07:56 this->
Rémi Piotaix 2014/09/29 17:57:55 Done.
261 resetTestValues();
262 }
263 virtual ~SkCanvasMock() {}
264 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top ,
265 const SkPaint* paint = NULL) SK_OVERRIDE {
266
robertphillips 2014/09/29 17:07:56 fDrawImageCalled
Rémi Piotaix 2014/09/29 17:57:55 Done.
267 fDrawImage_called = true;
268 fDrawingImage = image;
269 INHERITED::drawImage(image, left, top, paint);
270 }
271
272 virtual void drawImageRect(const SkImage* image, const SkRect* src,
273 const SkRect& dst,
274 const SkPaint* paint = NULL) SK_OVERRIDE {
275 fDrawImageRect_called = true;
276 fDrawingImage = image;
277 INHERITED::drawImageRect(image, src, dst, paint);
278 }
279
280 virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
281 const SkPaint* paint = NULL) SK_OVERRIDE {
282 fDrawBitmap_valid = bitmap.pixelRef() == SkBitmapImageGetPixelRef(fD rawingImage);
283 }
284
285 virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
286 const SkRect& dst,
287 const SkPaint* paint = NULL,
288 DrawBitmapRectFlags flags = kNone_Draw BitmapRectFlag)
289 SK_OVERRIDE {
290 fDrawBitmap_valid = bitmap.pixelRef() == SkBitmapImageGetPixelRef(fD rawingImage);
291 }
292
293 void resetTestValues() {
294 fDrawImage_called = fDrawBitmap_valid = fDrawImageRect_called = fals e;
295 }
296
297 const SkImage* fDrawingImage;
robertphillips 2014/09/29 17:07:56 No '_'s in the names.
Rémi Piotaix 2014/09/29 17:57:55 Done.
298 bool fDrawImage_called;
299 bool fDrawImageRect_called;
300 bool fDrawBitmap_valid;
301 private:
302 typedef SkCanvas INHERITED;
303 };
304
305 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10));
reed1 2014/09/29 18:08:26 1. Can we using an outer-loop or something to vary
Rémi Piotaix 2014/09/29 18:40:21 Yeah, sure.
306 surface->getCanvas()->clear(SK_ColorGREEN);
307 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
308
309 SkCanvasMock canvas(10, 10);
310
311 {
312 SkRecord record;
313 SkRecorder recorder(&record, 10, 10);
314 recorder.drawImage(image, 0, 0);
315 SkRecordDraw(record, &canvas, 0, 0);
316 }
317 REPORTER_ASSERT(r, canvas.fDrawImage_called && canvas.fDrawBitmap_valid);
318 canvas.resetTestValues();
319
320 {
321 SkRecord record;
322 SkRecorder recorder(&record, 10, 10);
323 recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
324 SkRecordDraw(record, &canvas, 0, 0);
325 }
326 REPORTER_ASSERT(r, canvas.fDrawImageRect_called && canvas.fDrawBitmap_valid) ;
327
328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698