tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/SkSpinlock.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrGeometryProcessor.h" |
| 10 | #include "src/gpu/GrMemoryPool.h" |
| 11 | #include "src/gpu/GrProcessor.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrSamplerState.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrXferProcessor.h" |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 15 | |
joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 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 |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 19 | // GrContexts and those contexts may be in use concurrently on different threads. |
| 20 | namespace { |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 21 | #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 22 | static SkSpinlock gProcessorSpinlock; |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 23 | #endif |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 24 | class MemoryPoolAccessor { |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 25 | public: |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 26 | |
msarett | 68440f8 | 2016-08-29 14:52:24 -0700 | [diff] [blame] | 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(); } |
joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 33 | ~MemoryPoolAccessor() { gProcessorSpinlock.release(); } |
msarett | 68440f8 | 2016-08-29 14:52:24 -0700 | [diff] [blame] | 34 | #endif |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 35 | |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 36 | GrMemoryPool* pool() const { |
Brian Salomon | 6986c65 | 2019-12-12 10:58:47 -0500 | [diff] [blame] | 37 | static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release(); |
Brian Osman | fce27ad | 2019-11-13 14:46:53 -0500 | [diff] [blame] | 38 | return gPool; |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 39 | } |
| 40 | }; |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 41 | } // namespace |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 42 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 45 | void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); } |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 46 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 47 | void GrProcessor::operator delete(void* target) { |
| 48 | return MemoryPoolAccessor().pool()->release(target); |
| 49 | } |