aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-13 17:47:59 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-13 17:47:59 +0000
commit9c2ea846351a29208cb4a36301ee611e7fb384ea (patch)
treecf61ae05b74705a6ae7d579e50410dd026ec780a /src/gpu
parent62e41903a70e0bebf875cd0fa5c94f804fad582a (diff)
Split cache-specific fields out of GrTextureDesc
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp23
-rw-r--r--src/gpu/GrStencilBuffer.cpp2
-rw-r--r--src/gpu/GrTexture.cpp10
-rw-r--r--src/gpu/SkGpuDevice.cpp5
-rw-r--r--src/gpu/SkGr.cpp27
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp10
-rw-r--r--src/gpu/gl/GrGpuGL.cpp1
7 files changed, 47 insertions, 31 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 6ea8531b15..2dc43bb85c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -238,15 +238,17 @@ void convolve_gaussian(GrGpu* gpu,
}
GrContext::TextureCacheEntry GrContext::findAndLockTexture(const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
const GrTextureParams* params) {
- GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, false);
+ GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheData, false);
return TextureCacheEntry(fTextureCache->findAndLock(resourceKey,
GrResourceCache::kNested_LockType));
}
bool GrContext::isTextureInCache(const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
const GrTextureParams* params) const {
- GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, false);
+ GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheData, false);
return fTextureCache->hasKey(resourceKey);
}
@@ -309,6 +311,7 @@ static void stretchImage(void* dst,
GrContext::TextureCacheEntry GrContext::createAndLockTexture(
const GrTextureParams* params,
const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
void* srcData,
size_t rowBytes) {
SK_TRACE_EVENT0("GrContext::createAndLockTexture");
@@ -319,16 +322,16 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture(
TextureCacheEntry entry;
- GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, false);
+ GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, params, desc, cacheData, false);
if (GrTexture::NeedsResizing(resourceKey)) {
// The desired texture is NPOT and tiled but that isn't supported by
// the current hardware. Resize the texture to be a POT
GrAssert(NULL != params);
- TextureCacheEntry clampEntry = this->findAndLockTexture(desc, NULL);
+ TextureCacheEntry clampEntry = this->findAndLockTexture(desc, cacheData, NULL);
if (NULL == clampEntry.texture()) {
- clampEntry = this->createAndLockTexture(NULL, desc, srcData, rowBytes);
+ clampEntry = this->createAndLockTexture(NULL, desc, cacheData, srcData, rowBytes);
GrAssert(NULL != clampEntry.texture());
if (NULL == clampEntry.texture()) {
return entry;
@@ -411,7 +414,7 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture(
const GrTextureDesc& inDesc,
ScratchTexMatch match) {
GrTextureDesc desc = inDesc;
- desc.fClientCacheID = kScratch_CacheID;
+ GrCacheData cacheData(GrCacheData::kScratch_CacheID);
if (kExact_ScratchTexMatch != match) {
// bin by pow2 with a reasonable min
@@ -427,7 +430,7 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture(
bool doubledH = false;
do {
- GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, desc, true);
+ GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, desc, cacheData, true);
entry = fTextureCache->findAndLock(key,
GrResourceCache::kNested_LockType);
// if we miss, relax the fit of the flags...
@@ -462,6 +465,7 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture(
if (NULL != texture) {
GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL,
texture->desc(),
+ cacheData,
true);
entry = fTextureCache->createAndLock(key, texture);
}
@@ -482,8 +486,12 @@ void GrContext::addExistingTextureToCache(GrTexture* texture) {
return;
}
+ // 'texture' is a scratch texture returning to the fold
+ GrCacheData cacheData(GrCacheData::kScratch_CacheID);
+
GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL,
texture->desc(),
+ cacheData,
true);
fTextureCache->attach(key, texture);
}
@@ -510,7 +518,6 @@ GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn,
void* srcData,
size_t rowBytes) {
GrTextureDesc descCopy = descIn;
- descCopy.fClientCacheID = kUncached_CacheID;
return fGpu->createTexture(descCopy, srcData, rowBytes);
}
diff --git a/src/gpu/GrStencilBuffer.cpp b/src/gpu/GrStencilBuffer.cpp
index 07ee661d01..53a4a65b66 100644
--- a/src/gpu/GrStencilBuffer.cpp
+++ b/src/gpu/GrStencilBuffer.cpp
@@ -66,7 +66,7 @@ void gen_stencil_key_values(int width,
GrCacheID* cacheID) {
cacheID->fPublicID = GrCacheID::kDefaultPublicCacheID;
cacheID->fResourceSpecific32 = width | (height << 16);
- cacheID->fDomain = kUnrestricted_ResourceDomain;
+ cacheID->fDomain = GrCacheData::kScratch_ResourceDomain;
GrAssert(sampleCnt >= 0 && sampleCnt < 256);
cacheID->fResourceSpecific16 = sampleCnt << 8;
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 208bd2ed57..d2e27367df 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -138,20 +138,21 @@ namespace {
void gen_texture_key_values(const GrGpu* gpu,
const GrTextureParams* params,
const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
bool scratch,
GrCacheID* cacheID) {
- uint64_t clientKey = desc.fClientCacheID;
+ uint64_t clientKey = cacheData.fClientCacheID;
if (scratch) {
// Instead of a client-provided key of the texture contents
// we create a key from the descriptor.
- GrAssert(kScratch_CacheID == clientKey);
+ GrAssert(GrCacheData::kScratch_CacheID == clientKey);
clientKey = (desc.fFlags << 8) | ((uint64_t) desc.fConfig << 32);
}
cacheID->fPublicID = clientKey;
- cacheID->fDomain = desc.fResourceDomain;
+ cacheID->fDomain = cacheData.fResourceDomain;
// we assume we only need 16 bits of width and height
// assert that texture creation will fail anyway if this assumption
@@ -184,9 +185,10 @@ void gen_texture_key_values(const GrGpu* gpu,
GrResourceKey GrTexture::ComputeKey(const GrGpu* gpu,
const GrTextureParams* params,
const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
bool scratch) {
GrCacheID id(GrTexture::GetResourceType());
- gen_texture_key_values(gpu, params, desc, scratch, &id);
+ gen_texture_key_values(gpu, params, desc, cacheData, scratch, &id);
uint32_t v[4];
id.toRaw(v);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 2d6d3a2e0f..496c096de5 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1907,9 +1907,10 @@ bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap,
desc.fWidth = bitmap.width();
desc.fHeight = bitmap.height();
desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config());
- desc.fClientCacheID = key;
- return this->context()->isTextureInCache(desc, &params);
+ GrCacheData cacheData(key);
+
+ return this->context()->isTextureInCache(desc, cacheData, &params);
}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index f6ee7efb11..8240eb1ace 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -75,7 +75,8 @@ static GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
desc.fWidth = bitmap->width();
desc.fHeight = bitmap->height();
desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
- desc.fClientCacheID = key;
+
+ GrCacheData cacheData(key);
if (SkBitmap::kIndex8_Config == bitmap->config()) {
// build_compressed_data doesn't do npot->pot expansion
@@ -91,8 +92,9 @@ static GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
// our compressed data will be trimmed, so pass width() for its
// "rowBytes", since they are the same now.
- if (kUncached_CacheID != key) {
- return ctx->createAndLockTexture(params, desc, storage.get(),
+ if (GrCacheData::kScratch_CacheID != key) {
+ return ctx->createAndLockTexture(params, desc, cacheData,
+ storage.get(),
bitmap->width());
} else {
entry = ctx->lockScratchTexture(desc,
@@ -111,11 +113,18 @@ static GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
}
desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
- if (kUncached_CacheID != key) {
- return ctx->createAndLockTexture(params, desc,
+ if (GrCacheData::kScratch_CacheID != key) {
+ // This texture is likely to be used again so leave it in the cache
+ // but locked.
+ return ctx->createAndLockTexture(params, desc, cacheData,
bitmap->getPixels(),
bitmap->rowBytes());
} else {
+ // This texture is unlikely to be used again (in its present form) so
+ // just use a scratch texture. This will remove the texture from the
+ // cache so no one else can find it. Additionally, once unlocked, the
+ // scratch texture will go to the end of the list for purging so will
+ // likely be available for this volatile bitmap the next time around.
entry = ctx->lockScratchTexture(desc,
GrContext::kExact_ScratchTexMatch);
entry.texture()->writePixels(0, 0,
@@ -135,6 +144,7 @@ GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx,
GrContext::TextureCacheEntry entry;
if (!bitmap.isVolatile()) {
+ // If the bitmap isn't changing try to find a cached copy first
uint64_t key = bitmap.getGenerationID();
key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
@@ -142,14 +152,15 @@ GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx,
desc.fWidth = bitmap.width();
desc.fHeight = bitmap.height();
desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config());
- desc.fClientCacheID = key;
- entry = ctx->findAndLockTexture(desc, params);
+ GrCacheData cacheData(key);
+
+ entry = ctx->findAndLockTexture(desc, cacheData, params);
if (NULL == entry.texture()) {
entry = sk_gr_create_bitmap_texture(ctx, key, params, bitmap);
}
} else {
- entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID, params, bitmap);
+ entry = sk_gr_create_bitmap_texture(ctx, GrCacheData::kScratch_CacheID, params, bitmap);
}
if (NULL == entry.texture()) {
GrPrintf("---- failed to create texture for cache [%d %d]\n",
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 4193519357..16d7f1b0b2 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -28,15 +28,13 @@ void GrGLRenderTarget::init(const Desc& desc,
namespace {
GrTextureDesc MakeDesc(GrTextureFlags flags,
int width, int height,
- GrPixelConfig config, int sampleCnt,
- uint64_t clientCacheID) {
+ GrPixelConfig config, int sampleCnt) {
GrTextureDesc temp;
temp.fFlags = flags;
temp.fWidth = width;
temp.fHeight = height;
temp.fConfig = config;
temp.fSampleCnt = sampleCnt;
- temp.fClientCacheID = clientCacheID;
return temp;
}
@@ -51,8 +49,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
texture,
MakeDesc(kNone_GrTextureFlags,
viewport.fWidth, viewport.fHeight,
- desc.fConfig, desc.fSampleCnt,
- kDefault_CacheID)) {
+ desc.fConfig, desc.fSampleCnt)) {
GrAssert(NULL != texID);
GrAssert(NULL != texture);
// FBO 0 can't also be a texture, right?
@@ -73,8 +70,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
NULL,
MakeDesc(kNone_GrTextureFlags,
viewport.fWidth, viewport.fHeight,
- desc.fConfig, desc.fSampleCnt,
- kDefault_CacheID)) {
+ desc.fConfig, desc.fSampleCnt)) {
this->init(desc, viewport, NULL);
}
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 26018bf464..c13badea0b 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1014,7 +1014,6 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
glTexDesc.fHeight = desc.fHeight;
glTexDesc.fConfig = desc.fConfig;
glTexDesc.fSampleCnt = desc.fSampleCnt;
- glTexDesc.fClientCacheID = desc.fClientCacheID;
glTexDesc.fOwnsID = true;