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

Unified Diff: src/gpu/GrBatch.cpp

Issue 991943002: Use global GrMemoryPools protected by mutex for GrProcessor/GrBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments Created 5 years, 9 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 | « no previous file | src/gpu/GrProcessor.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBatch.cpp
diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp
index e1650a6bd31af3d6a5bd188c28b0ee7979889785..09278a067b355d2c5f02cfcc9f1dda0d89689a60 100644
--- a/src/gpu/GrBatch.cpp
+++ b/src/gpu/GrBatch.cpp
@@ -1,35 +1,43 @@
#include "GrBatch.h"
#include "GrMemoryPool.h"
-#include "SkTLS.h"
+#include "SkMutex.h"
// TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small,
// but seems to be mostly consistent. There is a lot in flux right now, but we should really
// revisit this when batch is everywhere
-class GrBatch_Globals {
+
+// We use a global pool protected by a mutex. Chrome may use the same GrContext on different
+// threads. The GrContext is not used concurrently on different threads there is a memory
mtklein 2015/03/09 18:10:04 colon after "threads" (and the other file)?
bsalomon 2015/03/09 18:42:42 added "and"
+// barrier between accesses of a context on different threads. Also, there may be multiple
+// GrContexts and those contexts may be in use concurrently on different threads.
+namespace {
+SK_DECLARE_STATIC_MUTEX(gBatchPoolMutex);
+class MemoryPoolAccessor {
public:
- static GrMemoryPool* GetTLS() {
- return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
+ MemoryPoolAccessor() {
+ gBatchPoolMutex.acquire();
+ static SkAutoTDelete<GrMemoryPool> gPool(SkNEW_ARGS(GrMemoryPool, (16384, 16384)));
mtklein 2015/03/09 18:10:04 Perhaps you can just write static GrMemoryPool
bsalomon 2015/03/09 18:42:42 Done, moved it to pool(), and removed the member.
+ fPool = gPool;
}
+ ~MemoryPoolAccessor() { gBatchPoolMutex.release(); }
+
+ GrMemoryPool* pool() const { return fPool; }
+
private:
- static void* CreateTLS() {
- return SkNEW_ARGS(GrMemoryPool, (16384, 16384));
- }
+ GrMemoryPool* fPool;
- static void DeleteTLS(void* pool) {
- SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
- }
};
+}
-int32_t GrBatch::gCurrBatchClassID =
- GrBatch::kIllegalBatchClassID;
+int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchClassID;
void* GrBatch::operator new(size_t size) {
- return GrBatch_Globals::GetTLS()->allocate(size);
+ return MemoryPoolAccessor().pool()->allocate(size);
}
void GrBatch::operator delete(void* target) {
- GrBatch_Globals::GetTLS()->release(target);
+ return MemoryPoolAccessor().pool()->release(target);
}
« no previous file with comments | « no previous file | src/gpu/GrProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698