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

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 611383003: Revert of GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: Created 6 years, 3 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 888e97ac5a59881dd65a31e8e55f254d59ebed39..792ce6d30d59a42f4fdf66e62ad1b8f82e4dfa6c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -76,37 +76,50 @@
///////////////////////////////////////////////////////////////////////////////
-// 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 {
+
+class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable {
public:
- AutoBitmapTexture() {}
-
- AutoBitmapTexture(GrContext* context,
- const SkBitmap& bitmap,
- const GrTextureParams* params,
- GrTexture** texture) {
+ SkAutoCachedTexture()
+ : fDevice(NULL)
+ , fTexture(NULL) {
+ }
+
+ SkAutoCachedTexture(SkGpuDevice* device,
+ const SkBitmap& bitmap,
+ const GrTextureParams* params,
+ GrTexture** texture)
+ : fDevice(NULL)
+ , fTexture(NULL) {
SkASSERT(texture);
- *texture = this->set(context, bitmap, params);
- }
-
- GrTexture* set(GrContext* context,
+ *texture = this->set(device, bitmap, params);
+ }
+
+ ~SkAutoCachedTexture() {
+ if (fTexture) {
+ GrUnlockAndUnrefCachedBitmapTexture(fTexture);
+ }
+ }
+
+ GrTexture* set(SkGpuDevice* device,
const SkBitmap& bitmap,
const GrTextureParams* params) {
- // 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();
- }
+ 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;
+ }
+ return result;
}
private:
- SkAutoTUnref<GrTexture> fTexture;
+ SkGpuDevice* fDevice;
+ GrTexture* fTexture;
};
///////////////////////////////////////////////////////////////////////////////
@@ -139,7 +152,8 @@
fRenderTarget = SkRef(surface->asRenderTarget());
SkImageInfo info = surface->surfacePriv().info();
- SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface));
+ SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef,
+ (info, surface, SkToBool(flags & kCached_Flag)));
fLegacyBitmap.setInfo(info);
fLegacyBitmap.setPixelRef(pr)->unref();
@@ -1280,7 +1294,7 @@
bitmap.height() <= fContext->getMaxTextureSize());
GrTexture* texture;
- AutoBitmapTexture abt(fContext, bitmap, &params, &texture);
+ SkAutoCachedTexture act(this, bitmap, &params, &texture);
if (NULL == texture) {
return;
}
@@ -1375,7 +1389,7 @@
GrTexture* texture;
// draw sprite uses the default texture params
- AutoBitmapTexture abt(fContext, bitmap, NULL, &texture);
+ SkAutoCachedTexture act(this, bitmap, NULL, &texture);
SkImageFilter* filter = paint.getImageFilter();
// This bitmap will own the filtered result as a texture.
@@ -1552,7 +1566,7 @@
GrTexture* texture;
// We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup
// must be pushed upstack.
- AutoBitmapTexture abt(fContext, src, NULL, &texture);
+ SkAutoCachedTexture act(this, src, NULL, &texture);
return filter_texture(this, fContext, texture, filter, src.width(), src.height(), ctx,
result, offset);
@@ -1783,6 +1797,7 @@
#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