diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 43 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.h | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 13b00defe4..37f2e51e4a 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1743,6 +1743,49 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, filter, ctx, result, offset); } +#include "SkImage_Base.h" + +static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { + const GrPixelConfig config = tex->config(); + SkColorType ct; + SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; + if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { + ct = kUnknown_SkColorType; + } + return SkImageInfo::Make(w, h, ct, at); +} + +static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { + GrTexture* tex = image->getTexture(); + if (tex) { + // TODO: handle the GrTexture directly, and skip GrPixelRef + const SkImageInfo info = make_info(tex, image->width(), image->height(), image->isOpaque()); + bm->setInfo(info); + bm->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, tex)))->unref(); + } else { + if (!as_IB(image)->getROPixels(bm)) { + return false; + } + } + return true; +} + +void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y, + const SkPaint& paint) { + SkBitmap bm; + if (wrap_as_bm(image, &bm)) { + this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); + } +} + +void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, + const SkRect& dst, const SkPaint& paint) { + SkBitmap bm; + if (wrap_as_bm(image, &bm)) { + this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::DrawBitmapRectFlags(0)); + } +} + /////////////////////////////////////////////////////////////////////////////// // must be in SkCanvas::VertexMode order diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index 30cf68daa8..89959e1f9c 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -115,6 +115,9 @@ public: const SkPaint&) override; virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override; + void drawImage(const SkDraw&, const SkImage*, SkScalar x, SkScalar y, const SkPaint&) override; + void drawImageRect(const SkDraw&, const SkImage*, const SkRect* src, const SkRect& dst, + const SkPaint&) override; void flush() override; |