GrBatch.cpp revision 1b55a963a2374a14bb82eb887bb99ee91680f0eb
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. 22namespace { 23SK_DECLARE_STATIC_SPINLOCK(gBatchSpinlock); 24class MemoryPoolAccessor { 25public: 26 MemoryPoolAccessor() { gBatchSpinlock.acquire(); } 27 28 ~MemoryPoolAccessor() { gBatchSpinlock.release(); } 29 30 GrMemoryPool* pool() const { 31 static GrMemoryPool gPool(16384, 16384); 32 return &gPool; 33 } 34}; 35} 36 37int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID; 38 39GrBATCH_SPEW(int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;) 40 41void* GrBatch::operator new(size_t size) { 42 return MemoryPoolAccessor().pool()->allocate(size); 43} 44 45void GrBatch::operator delete(void* target) { 46 return MemoryPoolAccessor().pool()->release(target); 47} 48 49GrBatch::GrBatch(uint32_t classID) 50 : fClassID(classID) 51#if GR_BATCH_SPEW 52 , fUniqueID(GenBatchID()) 53#endif 54{ 55 SkDEBUGCODE(fUsed = false;) 56} 57 58GrBatch::~GrBatch() {} 59