aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/SkGpuDevice.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-16 14:49:16 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-16 14:49:16 +0000
commit1f47f4f7325971dd53991e2bb02da94fa7c6d962 (patch)
treea5b5dc02a15a3f3d4edeb921bda4ea1895f4ce77 /src/gpu/SkGpuDevice.cpp
parent71329d809a42889af8d2cadc4e43c60488a739a1 (diff)
Replaced TextureCacheEntry with GrTexture* and a back pointer to GrResourceEntry (in GrTexture)
Diffstat (limited to 'src/gpu/SkGpuDevice.cpp')
-rw-r--r--src/gpu/SkGpuDevice.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 496c096de5..e3ce2dccdf 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -81,43 +81,47 @@ enum {
class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable {
public:
- SkAutoCachedTexture() { }
+ SkAutoCachedTexture()
+ : fDevice(NULL)
+ , fTexture(NULL) {
+ }
+
SkAutoCachedTexture(SkGpuDevice* device,
const SkBitmap& bitmap,
const GrTextureParams* params,
- GrTexture** texture) {
- GrAssert(texture);
+ GrTexture** texture)
+ : fDevice(NULL)
+ , fTexture(NULL) {
+ GrAssert(NULL != texture);
*texture = this->set(device, bitmap, params);
}
~SkAutoCachedTexture() {
- if (fTex.texture()) {
- GrUnlockCachedBitmapTexture(fDevice->context(), fTex);
+ if (NULL != fTexture) {
+ GrUnlockCachedBitmapTexture(fTexture);
}
}
GrTexture* set(SkGpuDevice* device,
const SkBitmap& bitmap,
const GrTextureParams* params) {
- if (fTex.texture()) {
- GrUnlockCachedBitmapTexture(fDevice->context(), fTex);
+ if (NULL != fTexture) {
+ GrUnlockCachedBitmapTexture(fTexture);
+ fTexture = NULL;
}
fDevice = device;
- GrTexture* texture = (GrTexture*)bitmap.getTexture();
- if (texture) {
- // return the native texture
- fTex.reset();
- } else {
- // look it up in our cache
- fTex = GrLockCachedBitmapTexture(device->context(), bitmap, params);
- texture = fTex.texture();
+ GrTexture* result = (GrTexture*)bitmap.getTexture();
+ if (NULL == result) {
+ // Cannot return the native texture so look it up in our cache
+ fTexture = GrLockCachedBitmapTexture(device->context(), bitmap, params);
+ result = fTexture;
}
- return texture;
+ return result;
}
private:
SkGpuDevice* fDevice;
- GrContext::TextureCacheEntry fTex;
+ GrTexture* fTexture;
};
///////////////////////////////////////////////////////////////////////////////
@@ -184,6 +188,7 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
fContext = context;
fContext->ref();
+ fCached = false;
fTexture = NULL;
fRenderTarget = NULL;
fNeedClear = false;
@@ -221,6 +226,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
fContext = context;
fContext->ref();
+ fCached = false;
fTexture = NULL;
fRenderTarget = NULL;
fNeedClear = false;
@@ -266,10 +272,9 @@ SkGpuDevice::~SkGpuDevice() {
SkSafeUnref(fTexture);
SkSafeUnref(fRenderTarget);
- if (fCache.texture()) {
- GrAssert(NULL != fTexture);
+ if (NULL != fTexture && fCached) {
GrAssert(fRenderTarget == fTexture->asRenderTarget());
- fContext->unlockTexture(fCache);
+ fContext->unlockTexture(fTexture);
}
fContext->unref();
}
@@ -1925,7 +1930,6 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
desc.fHeight = height;
desc.fSampleCnt = fRenderTarget->numSamples();
- GrContext::TextureCacheEntry cacheEntry;
GrTexture* texture;
SkAutoTUnref<GrTexture> tunref;
// Skia's convention is to only clear a device if it is non-opaque.
@@ -1937,8 +1941,7 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
GrContext::ScratchTexMatch matchType = (kSaveLayer_Usage == usage) ?
GrContext::kApprox_ScratchTexMatch :
GrContext::kExact_ScratchTexMatch;
- cacheEntry = fContext->lockScratchTexture(desc, matchType);
- texture = cacheEntry.texture();
+ texture = fContext->lockScratchTexture(desc, matchType);
#else
tunref.reset(fContext->createUncachedTexture(desc, NULL, 0));
texture = tunref.get();
@@ -1946,7 +1949,6 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
if (texture) {
return SkNEW_ARGS(SkGpuDevice,(fContext,
texture,
- cacheEntry,
needClear));
} else {
GrPrintf("---- failed to create compatible device texture [%d %d]\n",
@@ -1957,13 +1959,11 @@ SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
SkGpuDevice::SkGpuDevice(GrContext* context,
GrTexture* texture,
- TexCache cacheEntry,
bool needClear)
: SkDevice(make_bitmap(context, texture->asRenderTarget())) {
GrAssert(texture && texture->asRenderTarget());
- GrAssert(NULL == cacheEntry.texture() || texture == cacheEntry.texture());
this->initFromRenderTarget(context, texture->asRenderTarget());
- fCache = cacheEntry;
+ fCached = true;
fNeedClear = needClear;
}