aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkRecordDraw.cpp10
-rw-r--r--src/core/SkRecorder.cpp11
-rw-r--r--src/core/SkRecorder.h5
-rw-r--r--src/core/SkRecords.h10
-rw-r--r--src/image/SkImagePriv.h2
-rw-r--r--src/image/SkImage_Raster.cpp4
-rw-r--r--tests/RecordDrawTest.cpp56
-rw-r--r--tests/RecordReplaceDrawTest.cpp2
-rw-r--r--tests/RecorderTest.cpp39
9 files changed, 135 insertions, 4 deletions
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 577ffa125e..0c3347ec55 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -93,6 +93,8 @@ DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.p
DRAW(DrawBitmapRectToRect,
drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags));
DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
+DRAW(DrawImage, drawImage(r.image, r.left, r.top, r.paint));
+DRAW(DrawImageRect, drawImageRect(r.image, r.src, r.dst, r.paint));
DRAW(DrawOval, drawOval(r.oval, r.paint));
DRAW(DrawPaint, drawPaint(r.paint));
DRAW(DrawPath, drawPath(r.path, r.paint));
@@ -359,7 +361,15 @@ private:
Bounds bounds(const DrawDRRect& op) const {
return this->adjustAndMap(op.outer.rect(), &op.paint);
}
+ Bounds bounds(const DrawImage& op) const {
+ const SkImage* image = op.image;
+ SkRect rect = SkRect::MakeXYWH(op.left, op.top, image->width(), image->height());
+ return this->adjustAndMap(rect, op.paint);
+ }
+ Bounds bounds(const DrawImageRect& op) const {
+ return this->adjustAndMap(op.dst, op.paint);
+ }
Bounds bounds(const DrawBitmapRectToRect& op) const {
return this->adjustAndMap(op.dst, op.paint);
}
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index f6c16d1c30..8dfce7e7dd 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -155,6 +155,17 @@ void SkRecorder::drawBitmapNine(const SkBitmap& bitmap,
APPEND(DrawBitmapNine, this->copy(paint), delay_copy(bitmap), center, dst);
}
+void SkRecorder::drawImage(const SkImage* image, SkScalar left, SkScalar top,
+ const SkPaint* paint) {
+ APPEND(DrawImage, this->copy(paint), image, left, top);
+}
+
+void SkRecorder::drawImageRect(const SkImage* image, const SkRect* src,
+ const SkRect& dst,
+ const SkPaint* paint) {
+ APPEND(DrawImageRect, this->copy(paint), image, this->copy(src), dst);
+}
+
void SkRecorder::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint) {
APPEND(DrawSprite, this->copy(paint), delay_copy(bitmap), left, top);
}
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 9eb68319cb..6ac8a56475 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -49,6 +49,11 @@ public:
const SkIRect& center,
const SkRect& dst,
const SkPaint* paint = NULL) SK_OVERRIDE;
+ virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top,
+ const SkPaint* paint = NULL) SK_OVERRIDE;
+ virtual void drawImageRect(const SkImage* image, const SkRect* src,
+ const SkRect& dst,
+ const SkPaint* paint = NULL) SK_OVERRIDE;
void drawSprite(const SkBitmap& bitmap,
int left,
int top,
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index c06d276cfa..f6292d419b 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -44,6 +44,8 @@ namespace SkRecords {
M(DrawBitmapMatrix) \
M(DrawBitmapNine) \
M(DrawBitmapRectToRect) \
+ M(DrawImage) \
+ M(DrawImageRect) \
M(DrawDRRect) \
M(DrawOval) \
M(DrawPaint) \
@@ -234,6 +236,14 @@ RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint,
SkRect, dst,
SkCanvas::DrawBitmapRectFlags, flags);
RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner);
+RECORD4(DrawImage, Optional<SkPaint>, paint,
+ RefBox<const SkImage>, image,
+ SkScalar, left,
+ SkScalar, top);
+RECORD4(DrawImageRect, Optional<SkPaint>, paint,
+ RefBox<const SkImage>, image,
+ Optional<SkRect>, src,
+ SkRect, dst);
RECORD2(DrawOval, SkPaint, paint, SkRect, oval);
RECORD1(DrawPaint, SkPaint, paint);
RECORD2(DrawPath, SkPaint, paint, SkPath, path);
diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h
index 89900766b4..e9d1d83899 100644
--- a/src/image/SkImagePriv.h
+++ b/src/image/SkImagePriv.h
@@ -33,7 +33,7 @@ static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
// Given an image created from SkNewImageFromBitmap, return its pixelref. This
// may be called to see if the surface and the image share the same pixelref,
// in which case the surface may need to perform a copy-on-write.
-extern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage);
+extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
// Given an image created with NewTexture, return its GrTexture. This
// may be called to see if the surface and the image share the same GrTexture,
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index d13141c3c6..18d6a8cabb 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -217,8 +217,8 @@ SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes));
}
-SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
- return ((SkImage_Raster*)image)->getPixelRef();
+const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
+ return ((const SkImage_Raster*)image)->getPixelRef();
}
bool SkImage_Raster::isOpaque() const {
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index f1c3a8b644..51313de9a9 100644
--- a/tests/RecordDrawTest.cpp
+++ b/tests/RecordDrawTest.cpp
@@ -11,11 +11,13 @@
#include "SkDebugCanvas.h"
#include "SkDrawPictureCallback.h"
#include "SkDropShadowImageFilter.h"
+#include "SkImagePriv.h"
#include "SkRecord.h"
#include "SkRecordDraw.h"
#include "SkRecordOpts.h"
#include "SkRecorder.h"
#include "SkRecords.h"
+#include "SkSurface.h"
static const int W = 1920, H = 1080;
@@ -252,3 +254,57 @@ DEF_TEST(RecordDraw_SaveLayerAffectsClipBounds, r) {
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)));
}
+
+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);
+
+}
diff --git a/tests/RecordReplaceDrawTest.cpp b/tests/RecordReplaceDrawTest.cpp
index e93b622cde..6ce45e43d5 100644
--- a/tests/RecordReplaceDrawTest.cpp
+++ b/tests/RecordReplaceDrawTest.cpp
@@ -134,7 +134,7 @@ void test_replacements(skiatest::Reporter* r, bool useBBH) {
assert_type<SkRecords::Save>(r, rerecord, 0);
assert_type<SkRecords::Save>(r, rerecord, 1);
assert_type<SkRecords::SetMatrix>(r, rerecord, 2);
- assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, 3);
+ assert_type<SkRecords::DrawImageRect>(r, rerecord, 3);
assert_type<SkRecords::Restore>(r, rerecord, 4);
assert_type<SkRecords::DrawRect>(r, rerecord, 5);
assert_type<SkRecords::Restore>(r, rerecord, 6);
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index aced54f7a9..d81bf059ef 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -12,6 +12,7 @@
#include "SkRecorder.h"
#include "SkRecords.h"
#include "SkShader.h"
+#include "SkSurface.h"
#define COUNT(T) + 1
static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
@@ -150,3 +151,41 @@ DEF_TEST(Recorder_IsDrawingToLayer, r) {
REPORTER_ASSERT(r, !recorder.isDrawingToLayer());
}
+DEF_TEST(Recorder_drawImage_takeReference, reporter) {
+
+ SkAutoTUnref<SkImage> image;
+ {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+ surface->getCanvas()->clear(SK_ColorGREEN);
+ image.reset(surface->newImageSnapshot());
+ }
+ {
+ SkRecord record;
+ SkRecorder recorder(&record, 100, 100);
+
+ // DrawImage is supposed to take a reference
+ recorder.drawImage(image.get(), 0, 0);
+ REPORTER_ASSERT(reporter, !image->unique());
+
+ Tally tally;
+ tally.apply(record);
+
+ REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>());
+ }
+ REPORTER_ASSERT(reporter, image->unique());
+
+ {
+ SkRecord record;
+ SkRecorder recorder(&record, 100, 100);
+
+ // DrawImageRect is supposed to take a reference
+ recorder.drawImageRect(image.get(), 0, SkRect::MakeWH(100, 100));
+ REPORTER_ASSERT(reporter, !image->unique());
+
+ Tally tally;
+ tally.apply(record);
+
+ REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>());
+ }
+ REPORTER_ASSERT(reporter, image->unique());
+}