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 "GrOp.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 ops. Its very small, but 14 // seems to be mostly consistent. There is a lot in flux right now, but we should really revisit 15 // this. 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 static SkSpinlock gOpPoolSpinLock; 24 class MemoryPoolAccessor { 25 public: 26 27 // We know in the Android framework there is only one GrContext. 28 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) MemoryPoolAccessor()29 MemoryPoolAccessor() {} ~MemoryPoolAccessor()30 ~MemoryPoolAccessor() {} 31 #else 32 MemoryPoolAccessor() { gOpPoolSpinLock.acquire(); } 33 ~MemoryPoolAccessor() { gOpPoolSpinLock.release(); } 34 #endif 35 pool() const36 GrMemoryPool* pool() const { 37 static GrMemoryPool gPool(16384, 16384); 38 return &gPool; 39 } 40 }; 41 } 42 43 int32_t GrOp::gCurrOpClassID = GrOp::kIllegalOpID; 44 45 int32_t GrOp::gCurrOpUniqueID = GrOp::kIllegalOpID; 46 operator new(size_t size)47void* GrOp::operator new(size_t size) { 48 return MemoryPoolAccessor().pool()->allocate(size); 49 } 50 operator delete(void * target)51void GrOp::operator delete(void* target) { 52 return MemoryPoolAccessor().pool()->release(target); 53 } 54 GrOp(uint32_t classID)55GrOp::GrOp(uint32_t classID) 56 : fClassID(classID) 57 , fUniqueID(kIllegalOpID) { 58 SkASSERT(classID == SkToU32(fClassID)); 59 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); 60 } 61 ~GrOp()62GrOp::~GrOp() {} 63