diff options
author | reed <reed@google.com> | 2015-09-16 12:53:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-16 12:53:29 -0700 |
commit | 746f31f18037c12f9fb79fbfb0cc0bbafc204484 (patch) | |
tree | 4f2e30299f4b3ab23dbdda0a4379fca7c4494c70 | |
parent | 34482bb79e45dd23dd05b268afc13e7c52b180af (diff) |
have raster-image return itself as a texture
This tickles skbug.com/4351, but we don't know how to fix that yet, so we think this CL is ok.
BUG=skia:
Review URL: https://codereview.chromium.org/1348023004
-rw-r--r-- | src/image/SkImage_Base.h | 8 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 34 |
2 files changed, 37 insertions, 5 deletions
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index d316267647..737b30d1db 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -56,7 +56,10 @@ public: // return a read-only copy of the pixels. We promise to not modify them, // but only inspect them (or encode them). - virtual bool getROPixels(SkBitmap*) const { return false; } + virtual bool getROPixels(SkBitmap*) const = 0; + + // Caller must call unref when they are done. + virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0; virtual SkShader* onNewShader(SkShader::TileMode, SkShader::TileMode, @@ -71,9 +74,6 @@ public: virtual bool onIsLazyGenerated() const { return false; } - // Caller must call unref when they are done. - virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const { return nullptr; } - private: const SkSurfaceProps fProps; diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 042107e3e3..67498f0e11 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -10,11 +10,16 @@ #include "SkCanvas.h" #include "SkColorTable.h" #include "SkData.h" -#include "SkImageGeneratorPriv.h" #include "SkImagePriv.h" #include "SkPixelRef.h" #include "SkSurface.h" +#if SK_SUPPORT_GPU +#include "GrContext.h" +#include "SkGr.h" +#include "SkGrPriv.h" +#endif + class SkImage_Raster : public SkImage_Base { public: static bool ValidArgs(const Info& info, size_t rowBytes, SkColorTable* ctable, @@ -67,6 +72,7 @@ public: const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; SkData* onRefEncoded() const override; bool getROPixels(SkBitmap*) const override; + GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; // exposed for SkSurface_Raster via SkNewImageFromPixelRef SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrigin, size_t rowBytes, @@ -180,6 +186,32 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst) const { return true; } +GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, SkImageUsageType usage) const { +#if SK_SUPPORT_GPU + if (!ctx) { + return nullptr; + } + + // textures (at least the texture-key) only support 16bit dimensions, so abort early + // if we're too big. + if (fBitmap.width() > 0xFFFF || fBitmap.height() > 0xFFFF) { + return nullptr; + } + + GrUniqueKey key; + GrMakeKeyFromImageID(&key, fBitmap.getGenerationID(), + SkIRect::MakeWH(fBitmap.width(), fBitmap.height()), + *ctx->caps(), usage); + + if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { + return tex; + } + return GrRefCachedBitmapTexture(ctx, fBitmap, usage); +#endif + + return nullptr; +} + /////////////////////////////////////////////////////////////////////////////// SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes, |