Chromium Code Reviews| Index: src/gpu/SkGpuDevice.cpp |
| diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
| index dd44eb13899adf96f6e8fc9099435df3a6ae2466..43f23e3a4e873cc59ebd60482180854fc02161e9 100644 |
| --- a/src/gpu/SkGpuDevice.cpp |
| +++ b/src/gpu/SkGpuDevice.cpp |
| @@ -76,50 +76,34 @@ enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
| /////////////////////////////////////////////////////////////////////////////// |
|
robertphillips
2014/09/29 15:25:08
// If 'bitmap' is GrTexture backed, return the bac
bsalomon
2014/09/29 19:58:14
Done.
|
| - |
| -class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable { |
| +class AutoBitmapTexture : public SkNoncopyable { |
| public: |
| - SkAutoCachedTexture() |
| - : fDevice(NULL) |
| - , fTexture(NULL) { |
| - } |
| + AutoBitmapTexture() {} |
| - SkAutoCachedTexture(SkGpuDevice* device, |
| - const SkBitmap& bitmap, |
| - const GrTextureParams* params, |
| - GrTexture** texture) |
| - : fDevice(NULL) |
| - , fTexture(NULL) { |
| + AutoBitmapTexture(GrContext* context, |
| + const SkBitmap& bitmap, |
| + const GrTextureParams* params, |
| + GrTexture** texture) { |
| SkASSERT(texture); |
| - *texture = this->set(device, bitmap, params); |
| + *texture = this->set(context, bitmap, params); |
| } |
| - ~SkAutoCachedTexture() { |
| - if (fTexture) { |
| - GrUnlockAndUnrefCachedBitmapTexture(fTexture); |
| - } |
| - } |
| - |
| - GrTexture* set(SkGpuDevice* device, |
| + GrTexture* set(GrContext* context, |
| const SkBitmap& bitmap, |
| const GrTextureParams* params) { |
| - if (fTexture) { |
| - GrUnlockAndUnrefCachedBitmapTexture(fTexture); |
| - fTexture = NULL; |
| - } |
| - fDevice = device; |
| - GrTexture* result = (GrTexture*)bitmap.getTexture(); |
| - if (NULL == result) { |
| - // Cannot return the native texture so look it up in our cache |
| - fTexture = GrLockAndRefCachedBitmapTexture(device->context(), bitmap, params); |
| - result = fTexture; |
| + // Either get the texture directly from the bitmap, or else use the cache and |
| + // remember to unref it. |
| + if (GrTexture* bmpTexture = bitmap.getTexture()) { |
| + fTexture.reset(NULL); |
| + return bmpTexture; |
| + } else { |
| + fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); |
| + return fTexture.get(); |
| } |
| - return result; |
| } |
| private: |
| - SkGpuDevice* fDevice; |
| - GrTexture* fTexture; |
| + SkAutoTUnref<GrTexture> fTexture; |
| }; |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -152,8 +136,7 @@ SkGpuDevice::SkGpuDevice(GrSurface* surface, const SkSurfaceProps& props, unsign |
| fRenderTarget = SkRef(surface->asRenderTarget()); |
| SkImageInfo info = surface->surfacePriv().info(); |
| - SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
| - (info, surface, SkToBool(flags & kCached_Flag))); |
| + SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface)); |
| fLegacyBitmap.setInfo(info); |
| fLegacyBitmap.setPixelRef(pr)->unref(); |
| @@ -1294,7 +1277,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, |
| bitmap.height() <= fContext->getMaxTextureSize()); |
| GrTexture* texture; |
| - SkAutoCachedTexture act(this, bitmap, ¶ms, &texture); |
| + AutoBitmapTexture abt(fContext, bitmap, ¶ms, &texture); |
| if (NULL == texture) { |
| return; |
| } |
| @@ -1389,7 +1372,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| GrTexture* texture; |
| // draw sprite uses the default texture params |
| - SkAutoCachedTexture act(this, bitmap, NULL, &texture); |
| + AutoBitmapTexture abt(fContext, bitmap, NULL, &texture); |
| SkImageFilter* filter = paint.getImageFilter(); |
| // This bitmap will own the filtered result as a texture. |
| @@ -1566,7 +1549,7 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, |
| GrTexture* texture; |
| // We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup |
| // must be pushed upstack. |
| - SkAutoCachedTexture act(this, src, NULL, &texture); |
| + AutoBitmapTexture abt(fContext, src, NULL, &texture); |
| return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctx, |
| result, offset); |
| @@ -1797,7 +1780,6 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage) |
| #if CACHE_COMPATIBLE_DEVICE_TEXTURES |
| // layers are never draw in repeat modes, so we can request an approx |
| // match and ignore any padding. |
| - flags |= kCached_Flag; |
| const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? |
| GrContext::kApprox_ScratchTexMatch : |
| GrContext::kExact_ScratchTexMatch; |