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