aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-11-24 07:05:15 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-24 07:05:15 -0800
commit91175f19664a62851da4ca4e0984a7c7c45b258f (patch)
tree33d518c4804c733e825bccf94c749fd78cd3203e
parent52e74c6d848931e12d2ba634abc0aae881cd3be1 (diff)
Use scratch keys for stencil buffers.
-rw-r--r--bench/GrResourceCacheBench.cpp62
-rw-r--r--include/gpu/GrContext.h8
-rwxr-xr-xsrc/gpu/GrContext.cpp17
-rw-r--r--src/gpu/GrGpu.cpp9
-rw-r--r--src/gpu/GrStencilBuffer.cpp6
-rw-r--r--src/gpu/GrStencilBuffer.h4
-rw-r--r--src/gpu/gl/GrGpuGL.cpp4
7 files changed, 40 insertions, 70 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index e1ec90d511..272e7bf01e 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -14,9 +14,6 @@
#include "GrContext.h"
#include "GrGpu.h"
#include "GrResourceCache2.h"
-#include "GrStencilBuffer.h"
-#include "GrTexture.h"
-#include "GrTexturePriv.h"
#include "SkCanvas.h"
enum {
@@ -24,17 +21,24 @@ enum {
CACHE_SIZE_BYTES = 2 * 1024 * 1024,
};
-class StencilResource : public GrGpuResource {
+class FooResource : public GrGpuResource {
public:
- SK_DECLARE_INST_COUNT(StencilResource);
- StencilResource(GrGpu* gpu, int id)
+ SK_DECLARE_INST_COUNT(FooResource);
+ FooResource(GrGpu* gpu, int id)
: INHERITED(gpu, false)
, fID(id) {
this->registerWithCache();
}
static GrResourceKey ComputeKey(int width, int height, int sampleCnt) {
- return GrStencilBuffer::ComputeKey(width, height, sampleCnt);
+ GrCacheID::Key key;
+ memset(&key, 0, sizeof(key));
+ key.fData32[0] = width;
+ key.fData32[1] = height;
+ key.fData32[2] = sampleCnt;
+ static int gType = GrResourceKey::GenerateResourceType();
+ static int gDomain = GrCacheID::GenerateDomain();
+ return GrResourceKey(GrCacheID(gDomain, key), gType, 0);
}
int fID;
@@ -47,10 +51,10 @@ private:
typedef GrGpuResource INHERITED;
};
-class TextureResource : public GrGpuResource {
+class BarResource : public GrGpuResource {
public:
- SK_DECLARE_INST_COUNT(TextureResource);
- TextureResource(GrGpu* gpu, int id)
+ SK_DECLARE_INST_COUNT(BarResource);
+ BarResource(GrGpu* gpu, int id)
: INHERITED(gpu, false)
, fID(id) {
this->registerWithCache();
@@ -77,13 +81,13 @@ private:
typedef GrGpuResource INHERITED;
};
-static void get_stencil(int i, int* w, int* h, int* s) {
+static void get_foo_params(int i, int* w, int* h, int* s) {
*w = i % 1024;
*h = i * 2 % 1024;
- *s = i % 1 == 0 ? 0 : 4;
+ *s = i % 2 == 0 ? 0 : 4;
}
-static void get_texture_desc(int i, GrSurfaceDesc* desc) {
+static void get_bar_surf_desc(int i, GrSurfaceDesc* desc) {
desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
desc->fWidth = i % 1024;
desc->fHeight = i * 2 % 1024;
@@ -94,18 +98,18 @@ static void get_texture_desc(int i, GrSurfaceDesc* desc) {
static void populate_cache(GrGpu* gpu, int resourceCount) {
for (int i = 0; i < resourceCount; ++i) {
int w, h, s;
- get_stencil(i, &w, &h, &s);
- GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s);
- GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i));
+ get_foo_params(i, &w, &h, &s);
+ GrResourceKey key = FooResource::ComputeKey(w, h, s);
+ GrGpuResource* resource = SkNEW_ARGS(FooResource, (gpu, i));
resource->cacheAccess().setContentKey(key);
resource->unref();
}
for (int i = 0; i < resourceCount; ++i) {
GrSurfaceDesc desc;
- get_texture_desc(i, &desc);
- GrResourceKey key = TextureResource::ComputeKey(desc);
- GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i));
+ get_bar_surf_desc(i, &desc);
+ GrResourceKey key = BarResource::ComputeKey(desc);
+ GrGpuResource* resource = SkNEW_ARGS(BarResource, (gpu, i));
resource->cacheAccess().setContentKey(key);
resource->unref();
}
@@ -115,28 +119,28 @@ static void check_cache_contents_or_die(GrResourceCache2* cache, int k) {
// Benchmark find calls that succeed.
{
GrSurfaceDesc desc;
- get_texture_desc(k, &desc);
- GrResourceKey key = TextureResource::ComputeKey(desc);
+ get_bar_surf_desc(k, &desc);
+ GrResourceKey key = BarResource::ComputeKey(desc);
SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
if (!item) {
SkFAIL("cache add does not work as expected");
return;
}
- if (static_cast<TextureResource*>(item.get())->fID != k) {
+ if (static_cast<BarResource*>(item.get())->fID != k) {
SkFAIL("cache add does not work as expected");
return;
}
}
{
int w, h, s;
- get_stencil(k, &w, &h, &s);
- GrResourceKey key = StencilResource::ComputeKey(w, h, s);
+ get_foo_params(k, &w, &h, &s);
+ GrResourceKey key = FooResource::ComputeKey(w, h, s);
SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
if (!item) {
SkFAIL("cache add does not work as expected");
return;
}
- if (static_cast<TextureResource*>(item.get())->fID != k) {
+ if (static_cast<FooResource*>(item.get())->fID != k) {
SkFAIL("cache add does not work as expected");
return;
}
@@ -145,9 +149,9 @@ static void check_cache_contents_or_die(GrResourceCache2* cache, int k) {
// Benchmark also find calls that always fail.
{
GrSurfaceDesc desc;
- get_texture_desc(k, &desc);
+ get_bar_surf_desc(k, &desc);
desc.fHeight |= 1;
- GrResourceKey key = TextureResource::ComputeKey(desc);
+ GrResourceKey key = BarResource::ComputeKey(desc);
SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
if (item) {
SkFAIL("cache add does not work as expected");
@@ -156,9 +160,9 @@ static void check_cache_contents_or_die(GrResourceCache2* cache, int k) {
}
{
int w, h, s;
- get_stencil(k, &w, &h, &s);
+ get_foo_params(k, &w, &h, &s);
h |= 1;
- GrResourceKey key = StencilResource::ComputeKey(w, h, s);
+ GrResourceKey key = FooResource::ComputeKey(w, h, s);
SkAutoTUnref<GrGpuResource> item(cache->findAndRefContentResource(key));
if (item) {
SkFAIL("cache add does not work as expected");
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index b83df45743..c6dd2d7563 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -34,7 +34,6 @@ class GrPath;
class GrPathRenderer;
class GrResourceEntry;
class GrResourceCache2;
-class GrStencilBuffer;
class GrTestTarget;
class GrTextContext;
class GrTextureParams;
@@ -890,13 +889,6 @@ public:
void addGpuTraceMarker(const GrGpuTraceMarker* marker);
void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
- /**
- * Stencil buffers add themselves to the cache using addStencilBuffer. findStencilBuffer is
- * called to check the cache for a SB that matches an RT's criteria.
- */
- void addStencilBuffer(GrStencilBuffer* sb);
- GrStencilBuffer* findAndRefStencilBuffer(int width, int height, int sampleCnt);
-
GrPathRenderer* getPathRenderer(
const GrDrawTarget* target,
const GrDrawState*,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 657e57da33..607d3c3cc7 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -24,7 +24,6 @@
#include "GrPathUtils.h"
#include "GrResourceCache2.h"
#include "GrSoftwarePathRenderer.h"
-#include "GrStencilBuffer.h"
#include "GrStencilAndCoverTextContext.h"
#include "GrStrokeInfo.h"
#include "GrSurfacePriv.h"
@@ -252,22 +251,6 @@ bool GrContext::isTextureInCache(const GrSurfaceDesc& desc,
return fResourceCache2->hasContentKey(resourceKey);
}
-void GrContext::addStencilBuffer(GrStencilBuffer* sb) {
- // TODO: Make GrStencilBuffers use the scratch mechanism rather than content keys.
- ASSERT_OWNED_RESOURCE(sb);
-
- GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(),
- sb->height(),
- sb->numSamples());
- SkAssertResult(sb->cacheAccess().setContentKey(resourceKey));
-}
-
-GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int sampleCnt) {
- GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampleCnt);
- GrGpuResource* resource = this->findAndRefCachedResource(resourceKey);
- return static_cast<GrStencilBuffer*>(resource);
-}
-
static void stretch_image(void* dst,
int dstW,
int dstH,
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 2bda594b9a..6b742c4cc3 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -13,14 +13,12 @@
#include "GrContext.h"
#include "GrDrawTargetCaps.h"
#include "GrIndexBuffer.h"
+#include "GrResourceCache2.h"
#include "GrStencilBuffer.h"
#include "GrVertexBuffer.h"
////////////////////////////////////////////////////////////////////////////////
-#define DEBUG_INVAL_BUFFER 0xdeadcafe
-#define DEBUG_INVAL_START_IDX -1
-
GrGpu::GrGpu(GrContext* context)
: fResetTimestamp(kExpiredTimestamp+1)
, fResetBits(kAll_GrBackendState)
@@ -78,8 +76,9 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc,
bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
SkASSERT(NULL == rt->getStencilBuffer());
- SkAutoTUnref<GrStencilBuffer> sb(
- this->getContext()->findAndRefStencilBuffer(rt->width(), rt->height(), rt->numSamples()));
+ GrResourceKey sbKey = GrStencilBuffer::ComputeKey(rt->width(), rt->height(), rt->numSamples());
+ SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>(
+ this->getContext()->getResourceCache2()->findAndRefScratchResource(sbKey)));
if (sb) {
rt->setStencilBuffer(sb);
bool attached = this->attachStencilBufferToRenderTarget(sb, rt);
diff --git a/src/gpu/GrStencilBuffer.cpp b/src/gpu/GrStencilBuffer.cpp
index 16b0150a4d..5aa56e0717 100644
--- a/src/gpu/GrStencilBuffer.cpp
+++ b/src/gpu/GrStencilBuffer.cpp
@@ -12,14 +12,10 @@
#include "GrGpu.h"
#include "GrResourceCache2.h"
-void GrStencilBuffer::transferToCache() {
- this->getGpu()->getContext()->addStencilBuffer(this);
-}
-
namespace {
// we should never have more than one stencil buffer with same combo of (width,height,samplecount)
void gen_cache_id(int width, int height, int sampleCnt, GrCacheID* cacheID) {
- static const GrCacheID::Domain gStencilBufferDomain = GrCacheID::GenerateDomain();
+ static const GrCacheID::Domain gStencilBufferDomain = GrResourceKey::ScratchDomain();
GrCacheID::Key key;
uint32_t* keyData = key.fData32;
keyData[0] = width;
diff --git a/src/gpu/GrStencilBuffer.h b/src/gpu/GrStencilBuffer.h
index 86fef50225..187556bd4c 100644
--- a/src/gpu/GrStencilBuffer.h
+++ b/src/gpu/GrStencilBuffer.h
@@ -47,9 +47,6 @@ public:
!fLastClipStackRect.contains(clipSpaceRect);
}
- // Places the sb in the cache. The cache takes a ref of the stencil buffer.
- void transferToCache();
-
static GrResourceKey ComputeKey(int width, int height, int sampleCnt);
protected:
@@ -60,6 +57,7 @@ protected:
, fBits(bits)
, fSampleCnt(sampleCnt)
, fLastClipStackGenID(SkClipStack::kInvalidGenID) {
+ this->setScratchKey(ComputeKey(width, height, sampleCnt));
fLastClipStackRect.setEmpty();
}
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 9e1f754a82..c873c1d0df 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1121,8 +1121,7 @@ void inline get_stencil_rb_sizes(const GrGLInterface* gl,
}
}
-bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
- int width, int height) {
+bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, int width, int height) {
// All internally created RTs are also textures. We don't create
// SBs for a client's standalone RT (that is a RT that isn't also a texture).
@@ -1176,7 +1175,6 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
sbID = 0;
if (this->attachStencilBufferToRenderTarget(sb, rt)) {
fLastSuccessfulStencilFmtIdx = sIdx;
- sb->transferToCache();
rt->setStencilBuffer(sb);
return true;
}