/src/skia/src/gpu/GrProcessor.cpp
Line | Count | Source |
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. |
20 | | namespace { |
21 | | #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
22 | | static SkSpinlock gProcessorSpinlock; |
23 | | #endif |
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) |
29 | | MemoryPoolAccessor() {} |
30 | | ~MemoryPoolAccessor() {} |
31 | | #else |
32 | 1.50M | MemoryPoolAccessor() { gProcessorSpinlock.acquire(); } |
33 | 1.50M | ~MemoryPoolAccessor() { gProcessorSpinlock.release(); } |
34 | | #endif |
35 | | |
36 | 1.50M | GrMemoryPool* pool() const { |
37 | 1.50M | static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release(); |
38 | 1.50M | return gPool; |
39 | 1.50M | } |
40 | | }; |
41 | | } // namespace |
42 | | |
43 | | /////////////////////////////////////////////////////////////////////////////// |
44 | | |
45 | 694k | void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); } |
46 | | |
47 | 57.2k | void* GrProcessor::operator new(size_t object_size, size_t footer_size) { |
48 | 57.2k | return MemoryPoolAccessor().pool()->allocate(object_size + footer_size); |
49 | 57.2k | } |
50 | | |
51 | 751k | void GrProcessor::operator delete(void* target) { |
52 | 751k | return MemoryPoolAccessor().pool()->release(target); |
53 | 751k | } |