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 namespace { | |
robertphillips
2015/03/09 17:54:23
Maybe a comment somewhere explaining why we're doi
bsalomon
2015/03/09 17:55:12
Will add
| |
12 SK_DECLARE_STATIC_MUTEX(gBatchPoolMutex); | |
13 class MemoryPoolAccessor { | |
11 public: | 14 public: |
12 static GrMemoryPool* GetTLS() { | 15 MemoryPoolAccessor() { |
13 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); | 16 gBatchPoolMutex.acquire(); |
robertphillips
2015/03/09 17:54:23
Why the change from 16384 to 4096?
bsalomon
2015/03/09 17:55:12
copy/paste error from other file. Will fix!
| |
17 static SkAutoTDelete<GrMemoryPool> gPool(SkNEW_ARGS(GrMemoryPool, (4096, 4096))); | |
18 fPool = gPool; | |
14 } | 19 } |
15 | 20 |
21 ~MemoryPoolAccessor() { gBatchPoolMutex.release(); } | |
22 | |
23 GrMemoryPool* pool() const { return fPool; } | |
24 | |
16 private: | 25 private: |
17 static void* CreateTLS() { | 26 GrMemoryPool* fPool; |
18 return SkNEW_ARGS(GrMemoryPool, (16384, 16384)); | |
19 } | |
20 | 27 |
21 static void DeleteTLS(void* pool) { | |
22 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); | |
23 } | |
24 }; | 28 }; |
29 } | |
25 | 30 |
26 int32_t GrBatch::gCurrBatchClassID = | 31 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchClassID; |
27 GrBatch::kIllegalBatchClassID; | |
28 | 32 |
29 void* GrBatch::operator new(size_t size) { | 33 void* GrBatch::operator new(size_t size) { |
30 return GrBatch_Globals::GetTLS()->allocate(size); | 34 return MemoryPoolAccessor().pool()->allocate(size); |
31 } | 35 } |
32 | 36 |
33 void GrBatch::operator delete(void* target) { | 37 void GrBatch::operator delete(void* target) { |
34 GrBatch_Globals::GetTLS()->release(target); | 38 return MemoryPoolAccessor().pool()->release(target); |
35 } | 39 } |
OLD | NEW |