OLD | NEW |
---|---|
1 #include "GrBatch.h" | 1 #include "GrBatch.h" |
2 | 2 |
3 #include "GrMemoryPool.h" | 3 #include "GrMemoryPool.h" |
4 #include "SkTLS.h" | 4 #include "SkMutex.h" |
5 | 5 |
6 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small, | 6 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small, |
7 // but seems to be mostly consistent. There is a lot in flux right now, but we should really | 7 // but seems to be mostly consistent. There is a lot in flux right now, but we should really |
8 // revisit this when batch is everywhere | 8 // revisit this when batch is everywhere |
9 | 9 |
10 class GrBatch_Globals { | 10 |
11 // We use a global pool protected by a mutex. Chrome may use the same GrContext on different | |
12 // 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"
| |
13 // barrier between accesses of a context on different threads. Also, there may b e multiple | |
14 // GrContexts and those contexts may be in use concurrently on different threads . | |
15 namespace { | |
16 SK_DECLARE_STATIC_MUTEX(gBatchPoolMutex); | |
17 class MemoryPoolAccessor { | |
11 public: | 18 public: |
12 static GrMemoryPool* GetTLS() { | 19 MemoryPoolAccessor() { |
13 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); | 20 gBatchPoolMutex.acquire(); |
21 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.
| |
22 fPool = gPool; | |
14 } | 23 } |
15 | 24 |
25 ~MemoryPoolAccessor() { gBatchPoolMutex.release(); } | |
26 | |
27 GrMemoryPool* pool() const { return fPool; } | |
28 | |
16 private: | 29 private: |
17 static void* CreateTLS() { | 30 GrMemoryPool* fPool; |
18 return SkNEW_ARGS(GrMemoryPool, (16384, 16384)); | |
19 } | |
20 | 31 |
21 static void DeleteTLS(void* pool) { | |
22 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); | |
23 } | |
24 }; | 32 }; |
33 } | |
25 | 34 |
26 int32_t GrBatch::gCurrBatchClassID = | 35 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchClassID; |
27 GrBatch::kIllegalBatchClassID; | |
28 | 36 |
29 void* GrBatch::operator new(size_t size) { | 37 void* GrBatch::operator new(size_t size) { |
30 return GrBatch_Globals::GetTLS()->allocate(size); | 38 return MemoryPoolAccessor().pool()->allocate(size); |
31 } | 39 } |
32 | 40 |
33 void GrBatch::operator delete(void* target) { | 41 void GrBatch::operator delete(void* target) { |
34 GrBatch_Globals::GetTLS()->release(target); | 42 return MemoryPoolAccessor().pool()->release(target); |
35 } | 43 } |
OLD | NEW |