• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "GrBatch.h"
9 
10 #include "GrMemoryPool.h"
11 #include "SkSpinlock.h"
12 
13 // TODO I noticed a small benefit to using a larger exclusive pool for batches.  Its very small,
14 // but seems to be mostly consistent.  There is a lot in flux right now, but we should really
15 // revisit this when batch is everywhere
16 
17 
18 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
19 // different threads. The GrContext is not used concurrently on different threads and there is a
20 // memory barrier between accesses of a context on different threads. Also, there may be multiple
21 // GrContexts and those contexts may be in use concurrently on different threads.
22 namespace {
23 SK_DECLARE_STATIC_SPINLOCK(gBatchSpinlock);
24 class MemoryPoolAccessor {
25 public:
MemoryPoolAccessor()26     MemoryPoolAccessor() { gBatchSpinlock.acquire(); }
27 
~MemoryPoolAccessor()28     ~MemoryPoolAccessor() { gBatchSpinlock.release(); }
29 
pool() const30     GrMemoryPool* pool() const {
31         static GrMemoryPool gPool(16384, 16384);
32         return &gPool;
33     }
34 };
35 }
36 
37 int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID;
38 
GrBATCH_SPEW(int32_t GrBatch::gCurrBatchUniqueID=GrBatch::kIllegalBatchID;)39 GrBATCH_SPEW(int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;)
40 
41 void* GrBatch::operator new(size_t size) {
42     return MemoryPoolAccessor().pool()->allocate(size);
43 }
44 
operator delete(void * target)45 void GrBatch::operator delete(void* target) {
46     return MemoryPoolAccessor().pool()->release(target);
47 }
48 
GrBatch(uint32_t classID)49 GrBatch::GrBatch(uint32_t classID)
50     : fClassID(classID)
51 #if GR_BATCH_SPEW
52     , fUniqueID(GenBatchID())
53 #endif
54 {
55     SkDEBUGCODE(fUsed = false;)
56 }
57 
~GrBatch()58 GrBatch::~GrBatch() {}
59