- SkRecordFillBounds(record, &bbh);
- REPORTER_ASSERT(r, bbh.entries.count() == 4);
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40)));
- REPORTER_ASSERT(r, sloppy_rect_eq(bbh.entries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
+ SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
+ REPORTER_ASSERT(r, bbh.fEntries.count() == 4);
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(0, 0, 40, 40)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[3].bounds, SkRect::MakeLTRB(0, 0, 50, 50)));
+}
+
+// When a saveLayer provides an explicit bound and has a complex paint (e.g., one that
+// affects transparent black), that bound should serve to shrink the area of the required
+// backing store.
+DEF_TEST(RecordDraw_SaveLayerBoundsAffectsClipBounds, r) {
+ SkRecord record;
+ SkRecorder recorder(&record, 50, 50);
+
+ SkPaint p;
+ p.setXfermodeMode(SkXfermode::kSrc_Mode);
+
+ SkRect bounds = SkRect::MakeLTRB(10, 10, 40, 40);
+ recorder.saveLayer(&bounds, &p);
+ recorder.drawRect(SkRect::MakeLTRB(20, 20, 30, 30), SkPaint());
+ recorder.restore();
+
+ TestBBH bbh;
+ SkRecordFillBounds(SkRect::MakeWH(50, 50), record, &bbh);
+ REPORTER_ASSERT(r, bbh.fEntries.count() == 3);
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[0].bounds, SkRect::MakeLTRB(10, 10, 40, 40)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[1].bounds, SkRect::MakeLTRB(20, 20, 30, 30)));
+ REPORTER_ASSERT(r, sloppy_rect_eq(bbh.fEntries[2].bounds, SkRect::MakeLTRB(10, 10, 40, 40)));
+}
+
+DEF_TEST(RecordDraw_drawImage, r){
+ class SkCanvasMock : public SkCanvas {
+ public:
+ SkCanvasMock(int width, int height) : INHERITED(width, height) {
+ this->resetTestValues();
+ }
+ virtual ~SkCanvasMock() {}
+ virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top,
+ const SkPaint* paint = NULL) SK_OVERRIDE {
+
+ fDrawImageCalled = true;
+ }
+
+ virtual void drawImageRect(const SkImage* image, const SkRect* src,
+ const SkRect& dst,
+ const SkPaint* paint = NULL) SK_OVERRIDE {
+ fDrawImageRectCalled = true;
+ }
+
+ void resetTestValues() {
+ fDrawImageCalled = fDrawImageRectCalled = false;
+ }
+
+ bool fDrawImageCalled;
+ bool fDrawImageRectCalled;
+ private:
+ typedef SkCanvas INHERITED;
+ };
+
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10));
+ surface->getCanvas()->clear(SK_ColorGREEN);
+ SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
+
+ SkCanvasMock canvas(10, 10);
+
+ {
+ SkRecord record;
+ SkRecorder recorder(&record, 10, 10);
+ recorder.drawImage(image, 0, 0);
+ SkRecordDraw(record, &canvas, 0, 0);
+ }
+ REPORTER_ASSERT(r, canvas.fDrawImageCalled);
+ canvas.resetTestValues();
+
+ {
+ SkRecord record;
+ SkRecorder recorder(&record, 10, 10);
+ recorder.drawImageRect(image, 0, SkRect::MakeWH(10, 10));
+ SkRecordDraw(record, &canvas, 0, 0);
+ }
+ REPORTER_ASSERT(r, canvas.fDrawImageRectCalled);
+