Chromium Code Reviews| Index: src/image/SkImage_Gpu.cpp |
| diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp |
| index 1a63a0d6ba3cf51af625d616d77cb27de4c459fb..2cc0241a48ee708c1a1674dcf8b41226e64746f4 100644 |
| --- a/src/image/SkImage_Gpu.cpp |
| +++ b/src/image/SkImage_Gpu.cpp |
| @@ -7,11 +7,14 @@ |
| #include "SkBitmapCache.h" |
| #include "SkImage_Gpu.h" |
| +#include "GrCaps.h" |
| #include "GrContext.h" |
| #include "GrDrawContext.h" |
| +#include "GrTextureMaker.h" |
| #include "effects/GrYUVtoRGBEffect.h" |
| #include "SkCanvas.h" |
| #include "SkGpuDevice.h" |
| +#include "SkGrPriv.h" |
| #include "SkPixelRef.h" |
| SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex, |
| @@ -35,13 +38,6 @@ extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
| } |
| } |
| -SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY, |
| - const SkMatrix* localMatrix) const { |
| - SkBitmap bm; |
| - GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &bm); |
| - return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix); |
| -} |
| - |
| bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
| if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
| SkASSERT(dst->getGenerationID() == this->uniqueID()); |
| @@ -65,9 +61,56 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
| return true; |
| } |
|
robertphillips
2015/09/30 19:25:56
It seems odd that this has a different domain from
|
| +static void make_raw_texture_stretched_key(uint32_t imageID, const SkGrStretch& stretch, |
| + GrUniqueKey* stretchedKey) { |
| + SkASSERT(SkGrStretch::kNone_Type != stretch.fType); |
| + |
| + uint32_t width = SkToU16(stretch.fWidth); |
| + uint32_t height = SkToU16(stretch.fHeight); |
| + |
| + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| + GrUniqueKey::Builder builder(stretchedKey, kDomain, 3); |
| + builder[0] = imageID; |
| + builder[1] = stretch.fType; |
| + builder[2] = width | (height << 16); |
| + builder.finish(); |
| +} |
| + |
| +class Texture_GrTextureMaker : public GrTextureMaker { |
| +public: |
|
robertphillips
2015/09/30 19:25:56
unstretched can't be const ?
|
| + Texture_GrTextureMaker(const SkImage* image, GrTexture* unstretched) |
| + : INHERITED(image->width(), image->height()) |
| + , fImage(image) |
| + , fUnstretched(unstretched) |
| + {} |
| + |
| +protected: |
| + GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { |
| + return SkRef(fUnstretched); |
| + } |
| + |
| + bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override { |
| + make_raw_texture_stretched_key(fImage->uniqueID(), stretch, stretchedKey); |
| + return stretchedKey->isValid(); |
| + } |
| + |
| + void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { |
| + as_IB(fImage)->notifyAddedToCache(); |
| + } |
| + |
| + bool onGetROBitmap(SkBitmap* bitmap) override { |
| + return as_IB(fImage)->getROPixels(bitmap); |
| + } |
| + |
| +private: |
| + const SkImage* fImage; |
| + GrTexture* fUnstretched; |
| + |
| + typedef GrTextureMaker INHERITED; |
| +}; |
| + |
| GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) const { |
| - fTexture->ref(); |
| - return fTexture; |
| + return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, usage); |
| } |
| bool SkImage_Gpu::isOpaque() const { |