aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-15 14:10:09 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-15 14:10:09 +0000
commitc0af3173314e227611d8c5541ef2deee0052d412 (patch)
tree7d2afe69f9255764adb3bf261c085e164c1135eb
parentf69a11b5c5dc5ae02489dfe7ca6432d641b9f121 (diff)
TLS GrContext count
Review URL: http://codereview.appspot.com/6298077/ git-svn-id: http://skia.googlecode.com/svn/trunk@4262 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/gpu/GrContext.h5
-rw-r--r--src/gpu/GrContext.cpp22
2 files changed, 27 insertions, 0 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index ee6130b13d..0cd5116cff 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -42,6 +42,11 @@ public:
static GrContext* Create(GrEngine engine,
GrPlatform3DContext context3D);
+ /**
+ * Returns the number of GrContext instances for the current thread.
+ */
+ static int GetThreadInstanceCount();
+
virtual ~GrContext();
/**
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 3cc2c89bfb..5a0f68982b 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -24,6 +24,7 @@
#include "GrStencilBuffer.h"
#include "GrTextStrike.h"
#include "SkTLazy.h"
+#include "SkTLS.h"
#include "SkTrace.h"
#define DEFER_TEXT_RENDERING 1
@@ -68,6 +69,23 @@ GrContext* GrContext::Create(GrEngine engine,
return ctx;
}
+namespace {
+void* CreateThreadInstanceCount() {
+ return new int(0);
+}
+void DeleteThreadInstanceCount(void* v) {
+ delete reinterpret_cast<int*>(v);
+}
+#define THREAD_INSTANCE_COUNT \
+ (*reinterpret_cast<int*>(SkTLS::Get(CreateThreadInstanceCount, \
+ DeleteThreadInstanceCount)))
+
+}
+
+int GrContext::GetThreadInstanceCount() {
+ return THREAD_INSTANCE_COUNT;
+}
+
GrContext::~GrContext() {
this->flush();
@@ -87,6 +105,8 @@ GrContext::~GrContext() {
GrSafeUnref(fPathRendererChain);
GrSafeUnref(fSoftwarePathRenderer);
fDrawState->unref();
+
+ --THREAD_INSTANCE_COUNT;
}
void GrContext::contextLost() {
@@ -1699,6 +1719,8 @@ static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {
}
GrContext::GrContext(GrGpu* gpu) {
+ ++THREAD_INSTANCE_COUNT;
+
fGpu = gpu;
fGpu->ref();
fGpu->setContext(this);