Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 608883003: GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: remove todo Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index ad01a363f0d95122af9450c513cd41e98c71aa6b..6f4d1a6f99ea6b83fc5ac1ae99a78704678e8228 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -77,50 +77,37 @@ enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
///////////////////////////////////////////////////////////////////////////////
-
-class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable {
+// Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this
+// just accesses the backing GrTexture. Otherwise, it creates a cached texture
+// representation and releases it in the destructor.
+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;
};
///////////////////////////////////////////////////////////////////////////////
@@ -153,8 +140,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();
@@ -1299,7 +1285,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
bitmap.height() <= fContext->getMaxTextureSize());
GrTexture* texture;
- SkAutoCachedTexture act(this, bitmap, &params, &texture);
+ AutoBitmapTexture abt(fContext, bitmap, &params, &texture);
if (NULL == texture) {
return;
}
@@ -1394,7 +1380,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.
@@ -1571,7 +1557,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);
@@ -1802,7 +1788,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;
« no previous file with comments | « src/gpu/SkGpuDevice.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698