John Stiles | 23e6866 | 2020-10-29 10:17:15 -0400 | [diff] [blame] | 1 | /* |
John Stiles | e5d729c | 2020-10-29 10:26:28 -0400 | [diff] [blame] | 2 | * Copyright 2020 Google LLC |
John Stiles | 23e6866 | 2020-10-29 10:17:15 -0400 | [diff] [blame] | 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 | #ifndef SKSL_MEMORYPOOL |
| 9 | #define SKSL_MEMORYPOOL |
| 10 | |
| 11 | #include <memory> |
| 12 | |
| 13 | #include "include/core/SkTypes.h" |
| 14 | |
| 15 | #if SK_SUPPORT_GPU |
| 16 | |
| 17 | #include "src/gpu/GrMemoryPool.h" |
| 18 | |
| 19 | namespace SkSL { |
| 20 | using MemoryPool = ::GrMemoryPool; |
| 21 | } |
| 22 | |
| 23 | #else |
| 24 | |
| 25 | // When Ganesh is disabled, GrMemoryPool is not linked in. We include a minimal class which mimics |
| 26 | // the GrMemoryPool interface but simply redirects to the system allocator. |
| 27 | namespace SkSL { |
| 28 | |
| 29 | class MemoryPool { |
| 30 | public: |
| 31 | static std::unique_ptr<MemoryPool> Make(size_t, size_t) { |
| 32 | return std::make_unique<MemoryPool>(); |
| 33 | } |
John Stiles | e5d729c | 2020-10-29 10:26:28 -0400 | [diff] [blame] | 34 | void resetScratchSpace() {} |
John Stiles | 23e6866 | 2020-10-29 10:17:15 -0400 | [diff] [blame] | 35 | void reportLeaks() const {} |
| 36 | bool isEmpty() const { return true; } |
| 37 | void* allocate(size_t size) { return ::operator new(size); } |
| 38 | void release(void* p) { ::operator delete(p); } |
| 39 | }; |
| 40 | |
| 41 | } // namespace SkSL |
| 42 | |
| 43 | #endif // SK_SUPPORT_GPU |
| 44 | #endif // SKSL_MEMORYPOOL |