Chromium Code Reviews| Index: src/image/SkImage_Raster.cpp |
| diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp |
| index 67d521e345ef26f46b442d9174c8844a1b54d686..3a3e55e1cecf70518135be114d744cc629f46df2 100644 |
| --- a/src/image/SkImage_Raster.cpp |
| +++ b/src/image/SkImage_Raster.cpp |
| @@ -115,9 +115,21 @@ public: |
| return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated(); |
| } |
| +#if SK_SUPPORT_GPU |
| + sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override; |
| + void onPinAsTexture(GrContext*) const override; |
| + void onUnpinAsTexture(GrContext*) const override; |
| +#endif |
| + |
| private: |
| SkBitmap fBitmap; |
| +#if SK_SUPPORT_GPU |
| + mutable sk_sp<GrTexture> fPinnedTexture; |
| + mutable int32_t fPinnedCount = 0; |
| + mutable uint32_t fPinnedUniqueID = 0; |
| +#endif |
| + |
| typedef SkImage_Base INHERITED; |
| }; |
| @@ -178,6 +190,10 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst, CachingHint) const { |
| return true; |
| } |
| +static SkMutex gRasterImageMutex; |
| + |
| +#include "GrImageIDTextureAdjuster.h" |
| + |
| GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrTextureParams& params, |
| SkSourceGammaTreatment gammaTreatment) const { |
| #if SK_SUPPORT_GPU |
| @@ -185,12 +201,68 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrTextureParams& p |
| return nullptr; |
| } |
| + uint32_t uniqueID; |
| + sk_sp<GrTexture> tex = this->refPinnedTexture(&uniqueID); |
|
bsalomon
2016/08/16 16:36:47
Doesn't #1 need to be checked here? i.e. that tex-
reed1
2016/08/16 16:41:33
Does this sort of check not already exist for all
|
| + if (tex) { |
| + GrTextureAdjuster adjuster(fPinnedTexture.get(), fBitmap.bounds(), |
| + fPinnedUniqueID, fBitmap.colorSpace()); |
| + return adjuster.refTextureSafeForParams(params, gammaTreatment, nullptr); |
| + } |
| + |
| return GrRefCachedBitmapTexture(ctx, fBitmap, params, gammaTreatment); |
| #endif |
| return nullptr; |
| } |
| +#if SK_SUPPORT_GPU |
| + |
| +sk_sp<GrTexture> SkImage_Raster::refPinnedTexture(uint32_t* uniqueID) const { |
| + SkAutoMutexAcquire ama(gRasterImageMutex); |
| + if (fPinnedTexture) { |
| + SkASSERT(fPinnedCount > 0); |
| + SkASSERT(fPinnedUniqueID != 0); |
| + *uniqueID = fPinnedUniqueID; |
| + return fPinnedTexture; |
| + } |
| + return nullptr; |
| +} |
| + |
| +void SkImage_Raster::onPinAsTexture(GrContext* ctx) const { |
| + SkAutoMutexAcquire ama(gRasterImageMutex); |
| + |
| + if (fPinnedTexture) { |
|
bsalomon
2016/08/16 16:36:47
What if fPinnedTexture's context is not ctx?
reed1
2016/08/16 16:41:33
Oops, missed it here. I was only looking at unpin.
|
| + SkASSERT(fPinnedCount > 0); |
| + SkASSERT(fPinnedUniqueID != 0); |
| + } else { |
| + SkASSERT(fPinnedCount == 0); |
| + SkASSERT(fPinnedUniqueID == 0); |
| + fPinnedTexture.reset(GrRefCachedBitmapTexture(ctx, fBitmap, |
| + GrTextureParams::ClampNoFilter(), |
| + SkSourceGammaTreatment::kRespect)); |
| + fPinnedUniqueID = fBitmap.getGenerationID(); |
| + } |
| + // Note: we always increment, even if we failed to create the pinned texture |
| + ++fPinnedCount; |
| +} |
| + |
| +void SkImage_Raster::onUnpinAsTexture(GrContext* ctx) const { |
| + SkAutoMutexAcquire ama(gRasterImageMutex); |
| + |
| + // Note: we always decrement, even if fPinnedTexture is null |
| + SkASSERT(fPinnedCount > 0); |
| + SkASSERT(fPinnedUniqueID != 0); |
| + if (fPinnedTexture) { |
| + SkASSERT(fPinnedTexture->getContext() == ctx); |
| + } |
| + |
| + if (0 == --fPinnedCount) { |
| + fPinnedTexture.reset(nullptr); |
| + fPinnedUniqueID = 0; |
| + } |
| +} |
| +#endif |
| + |
| sk_sp<SkImage> SkImage_Raster::onMakeSubset(const SkIRect& subset) const { |
| // TODO : could consider heurist of sharing pixels, if subset is pretty close to complete |