diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-23 15:52:16 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-23 15:52:16 +0000 |
commit | dfec28d4a9e05d1d525f377b380b4df3c5e07c7b (patch) | |
tree | 495b005eba700d8eb59316017bd3569388683358 /src | |
parent | bcc6d7d390083c6c8ce04b2078ee2904399b8435 (diff) |
Add SkImage->draw() call with src and dst rects.
Committed: http://code.google.com/p/skia/source/detail?r=10237
R=junov@chromium.org, senorblanco@chromium.org, reed@google.com
Author: arbesfeld@chromium.org
Review URL: https://chromiumcodereview.appspot.com/19729007
git-svn-id: http://skia.googlecode.com/svn/trunk@10274 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/image/SkImage.cpp | 5 | ||||
-rw-r--r-- | src/image/SkImagePriv.cpp | 30 | ||||
-rw-r--r-- | src/image/SkImagePriv.h | 3 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 2 | ||||
-rw-r--r-- | src/image/SkImage_Codec.cpp | 12 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 6 | ||||
-rw-r--r-- | src/image/SkImage_Picture.cpp | 6 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 5 |
8 files changed, 69 insertions, 0 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 9c60f55aa7..39fd93acc6 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -36,6 +36,11 @@ void SkImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, as_IB(this)->onDraw(canvas, x, y, paint); } +void SkImage::draw(SkCanvas* canvas, const SkRect* src, const SkRect& dst, + const SkPaint* paint) { + as_IB(this)->onDrawRectToRect(canvas, src, dst, paint); +} + GrTexture* SkImage::getTexture() { return as_IB(this)->onGetTexture(); } diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp index c44e439b72..4ff1c92bff 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp @@ -141,3 +141,33 @@ void SkImagePrivDrawPicture(SkCanvas* canvas, SkPicture* picture, canvas->drawPicture(*picture); canvas->restoreToCount(saveCount); } + +void SkImagePrivDrawPicture(SkCanvas* canvas, SkPicture* picture, + const SkRect* src, const SkRect& dst, const SkPaint* paint) { + int saveCount = canvas->getSaveCount(); + + SkMatrix matrix; + SkRect tmpSrc; + + if (NULL != src) { + tmpSrc = *src; + } else { + tmpSrc.set(0, 0, + SkIntToScalar(picture->width()), + SkIntToScalar(picture->height())); + } + + matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); + if (paint && needs_layer(*paint)) { + canvas->saveLayer(&dst, paint); + } else { + canvas->save(); + } + canvas->concat(matrix); + if (!paint || !needs_layer(*paint)) { + canvas->clipRect(tmpSrc); + } + + canvas->drawPicture(*picture); + canvas->restoreToCount(saveCount); +} diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h index fc14f67c58..2af8bbea92 100644 --- a/src/image/SkImagePriv.h +++ b/src/image/SkImagePriv.h @@ -39,6 +39,9 @@ extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, SkScalar x, SkScalar y, const SkPaint*); +extern void SkImagePrivDrawPicture(SkCanvas*, SkPicture*, + const SkRect*, const SkRect&, const SkPaint*); + /** * Return an SkImage whose contents are those of the specified picture. Note: * The picture itself is unmodified, and may continue to be used for recording diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 9ae13de4ae..431444dadb 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -15,6 +15,8 @@ public: SkImage_Base(int width, int height) : INHERITED(width, height) {} virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) = 0; + virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, + const SkRect& dst, const SkPaint*) = 0; virtual GrTexture* onGetTexture() { return NULL; } // return a read-only copy of the pixels. We promise to not modify them, diff --git a/src/image/SkImage_Codec.cpp b/src/image/SkImage_Codec.cpp index 61661de356..b9a8990838 100644 --- a/src/image/SkImage_Codec.cpp +++ b/src/image/SkImage_Codec.cpp @@ -19,6 +19,7 @@ public: virtual ~SkImage_Codec(); virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; + virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; private: SkData* fEncodedData; @@ -48,6 +49,17 @@ void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPai canvas->drawBitmap(fBitmap, x, y, paint); } +void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, + const SkRect& dst, const SkPaint* paint) { + if (!fBitmap.pixelRef()) { + if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(), + &fBitmap)) { + return; + } + } + canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); +} + /////////////////////////////////////////////////////////////////////////////// SkImage* SkImage::NewEncodedData(SkData* data) { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index b6e4211d28..d19d2100c3 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -21,6 +21,7 @@ public: virtual ~SkImage_Gpu(); virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE; + virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) SK_OVERRIDE; virtual GrTexture* onGetTexture() SK_OVERRIDE; virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE { // TODO @@ -61,6 +62,11 @@ void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, canvas->drawBitmap(fBitmap, x, y, paint); } +void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, + const SkPaint* paint) { + canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); +} + GrTexture* SkImage_Gpu::onGetTexture() { return fTexture; } diff --git a/src/image/SkImage_Picture.cpp b/src/image/SkImage_Picture.cpp index be934fa238..87221de27b 100644 --- a/src/image/SkImage_Picture.cpp +++ b/src/image/SkImage_Picture.cpp @@ -15,6 +15,7 @@ public: virtual ~SkImage_Picture(); virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; + virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; SkPicture* getPicture() { return fPicture; } @@ -41,6 +42,11 @@ void SkImage_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, SkImagePrivDrawPicture(canvas, fPicture, x, y, paint); } +void SkImage_Picture::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, + const SkPaint* paint) { + SkImagePrivDrawPicture(canvas, fPicture, src, dst, paint); +} + SkImage* SkNewImageFromPicture(const SkPicture* srcPicture) { /** * We want to snapshot the playback status of the picture, w/o affecting diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 5e1e8a02f3..3e2685606d 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -55,6 +55,7 @@ public: virtual ~SkImage_Raster(); virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; + virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; // exposed for SkSurface_Raster via SkNewImageFromPixelRef @@ -109,6 +110,10 @@ void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa canvas->drawBitmap(fBitmap, x, y, paint); } +void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { + canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); +} + bool SkImage_Raster::getROPixels(SkBitmap* dst) const { *dst = fBitmap; return true; |