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/gpu/GrContext.h"
9#include "include/private/SkSpinlock.h"
10#include "src/gpu/GrContextPriv.h"
11#include "src/gpu/GrGeometryProcessor.h"
12#include "src/gpu/GrMemoryPool.h"
13#include "src/gpu/GrProcessor.h"
14#include "src/gpu/GrSamplerState.h"
15#include "src/gpu/GrTextureProxy.h"
16#include "src/gpu/GrXferProcessor.h"
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 {
23#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
24static SkSpinlock gProcessorSpinlock;
25#endif
26class MemoryPoolAccessor {
27public:
28
29// We know in the Android framework there is only one GrContext.
30#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
31 MemoryPoolAccessor() {}
32 ~MemoryPoolAccessor() {}
33#else
34 MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
35 ~MemoryPoolAccessor() { gProcessorSpinlock.release(); }
36#endif
37
38 GrMemoryPool* pool() const {
39 static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release();
40 return gPool;
41 }
42};
43}
44
45///////////////////////////////////////////////////////////////////////////////
46
47void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); }
48
49void GrProcessor::operator delete(void* target) {
50 return MemoryPoolAccessor().pool()->release(target);
51}
52