1/* 2 * Copyright 2012 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 "include/private/SkSpinlock.h" 9#include "src/gpu/GrGeometryProcessor.h" 10#include "src/gpu/GrMemoryPool.h" 11#include "src/gpu/GrProcessor.h" 12#include "src/gpu/GrSamplerState.h" 13#include "src/gpu/GrTextureProxy.h" 14#include "src/gpu/GrXferProcessor.h" 15 16// We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on 17// different threads. The GrContext is not used concurrently on different threads and there is a 18// memory barrier between accesses of a context on different threads. Also, there may be multiple 19// GrContexts and those contexts may be in use concurrently on different threads. 20namespace { 21#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 22static SkSpinlock gProcessorSpinlock; 23#endif 24class MemoryPoolAccessor { 25public: 26 27// We know in the Android framework there is only one GrContext. 28#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 29 MemoryPoolAccessor() {} 30 ~MemoryPoolAccessor() {} 31#else 32 MemoryPoolAccessor() { gProcessorSpinlock.acquire(); } 33 ~MemoryPoolAccessor() { gProcessorSpinlock.release(); } 34#endif 35 36 GrMemoryPool* pool() const { 37 static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release(); 38 return gPool; 39 } 40}; 41} // namespace 42 43/////////////////////////////////////////////////////////////////////////////// 44 45void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); } 46 47void* GrProcessor::operator new(size_t object_size, size_t footer_size) { 48 return MemoryPoolAccessor().pool()->allocate(object_size + footer_size); 49} 50 51void GrProcessor::operator delete(void* target) { 52 return MemoryPoolAccessor().pool()->release(target); 53} 54