diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrImageIDTextureAdjuster.cpp | 31 | ||||
-rw-r--r-- | src/gpu/GrImageIDTextureAdjuster.h | 27 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 63 |
3 files changed, 94 insertions, 27 deletions
diff --git a/src/gpu/GrImageIDTextureAdjuster.cpp b/src/gpu/GrImageIDTextureAdjuster.cpp index c37c022775..a9189f63fa 100644 --- a/src/gpu/GrImageIDTextureAdjuster.cpp +++ b/src/gpu/GrImageIDTextureAdjuster.cpp @@ -12,6 +12,7 @@ #include "SkBitmap.h" #include "SkGrPriv.h" #include "SkImage_Base.h" +#include "SkImageCacherator.h" #include "SkPixelRef.h" GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) @@ -96,3 +97,33 @@ void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef()); } + +////////////////////////////////////////////////////////////////////////////// + +GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, + const SkImage* client, SkImage::CachingHint chint) + : INHERITED(context, cacher->info().width(), cacher->info().height()) + , fCacher(cacher) + , fClient(client) + , fCachingHint(chint) { + if (client) { + GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), + SkIRect::MakeWH(this->width(), this->height())); + } +} + +GrTexture* GrImageTextureMaker::refOriginalTexture() { + return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint); +} + +void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) { + if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { + MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); + } +} + +void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { + if (fClient) { + as_IB(fClient)->notifyAddedToCache(); + } +} diff --git a/src/gpu/GrImageIDTextureAdjuster.h b/src/gpu/GrImageIDTextureAdjuster.h index a20902ed58..d8510feeaa 100644 --- a/src/gpu/GrImageIDTextureAdjuster.h +++ b/src/gpu/GrImageIDTextureAdjuster.h @@ -9,9 +9,11 @@ #define GrImageIDTextureAdjuster_DEFINED #include "GrTextureParamsAdjuster.h" +#include "SkImage.h" class SkBitmap; class SkImage_Base; +class SkImageCacherator; /** Implementation for texture-backed SkBitmaps. The bitmap must stay in scope and unmodified while this object exists. */ @@ -66,4 +68,29 @@ private: typedef GrTextureMaker INHERITED; }; +/** This class manages the conversion of generator-backed images to GrTextures. If the caching hint + is kAllow the image's ID is used for the cache key. */ +class GrImageTextureMaker : public GrTextureMaker { +public: + GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client, + SkImage::CachingHint chint); + +protected: + // TODO: consider overriding this, for the case where the underlying generator might be + // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) + // GrTexture* generateTextureForParams(const CopyParams&) override; + + GrTexture* refOriginalTexture() override; + void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; + void didCacheCopy(const GrUniqueKey& copyKey) override; + +private: + SkImageCacherator* fCacher; + const SkImage* fClient; + GrUniqueKey fOriginalKey; + SkImage::CachingHint fCachingHint; + + typedef GrTextureMaker INHERITED; +}; + #endif diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 17e4468acb..2545313e92 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -27,6 +27,7 @@ #include "SkGr.h" #include "SkGrPriv.h" #include "SkImage_Base.h" +#include "SkImageCacherator.h" #include "SkImageFilter.h" #include "SkLayerInfo.h" #include "SkMaskFilter.h" @@ -1399,43 +1400,36 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, filter, ctx, result, offset); } -static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) { - // TODO: It is wrong to assume these texture params here. - SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams::ClampNoFilter())); - if (tex) { - GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), bm); - return true; - } else { - return as_IB(image)->getROPixels(bm); - } -} - void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y, const SkPaint& paint) { - SkBitmap bm; + SkMatrix viewMatrix = *draw.fMatrix; + viewMatrix.preTranslate(x, y); if (GrTexture* tex = as_IB(image)->peekTexture()) { CHECK_SHOULD_DRAW(draw); - SkMatrix viewMatrix = *draw.fMatrix; - viewMatrix.preTranslate(x, y); bool alphaOnly = GrPixelConfigIsAlphaOnly(tex->config()); GrImageTextureAdjuster adjuster(as_IB(image)); this->drawTextureProducer(&adjuster, alphaOnly, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint); return; } else { + SkBitmap bm; if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstraint, paint.getFilterQuality(), *draw.fMatrix)) { // only support tiling as bitmap at the moment, so force raster-version if (!as_IB(image)->getROPixels(&bm)) { return; } - } else { - if (!wrap_as_bm(this->context(), image, &bm)) { - return; - } + this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); + } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { + CHECK_SHOULD_DRAW(draw); + GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_CachingHint); + bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType(); + this->drawTextureProducer(&maker, alphaOnly, nullptr, nullptr, + SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint); + } else if (as_IB(image)->getROPixels(&bm)) { + this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); } } - this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); } void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, @@ -1450,20 +1444,35 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const return; } SkBitmap bm; - SkMatrix viewMatrix = *draw.fMatrix; - viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()), - dst.height() / (src ? src->height() : image->height())); - if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), viewMatrix)) { + SkMatrix totalMatrix = *draw.fMatrix; + totalMatrix.preScale(dst.width() / (src ? src->width() : image->width()), + dst.height() / (src ? src->height() : image->height())); + if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), totalMatrix)) { // only support tiling as bitmap at the moment, so force raster-version if (!as_IB(image)->getROPixels(&bm)) { return; } + this->drawBitmapRect(draw, bm, src, dst, paint, constraint); + } else if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { + CHECK_SHOULD_DRAW(draw); + GrImageTextureMaker maker(fContext, cacher, image, SkImage::kAllow_CachingHint); + bool alphaOnly = kAlpha_8_SkColorType == cacher->info().colorType(); + this->drawTextureProducer(&maker, alphaOnly, src, &dst, constraint, *draw.fMatrix, + fClip, paint); + } else if (as_IB(image)->getROPixels(&bm)) { + this->drawBitmapRect(draw, bm, src, dst, paint, constraint); + } +} + +static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) { + // TODO: It is wrong to assume these texture params here. + SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams::ClampNoFilter())); + if (tex) { + GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), bm); + return true; } else { - if (!wrap_as_bm(this->context(), image, &bm)) { - return; - } + return as_IB(image)->getROPixels(bm); } - this->drawBitmapRect(draw, bm, src, dst, paint, constraint); } void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, |