Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrProcessor.cpp
Go to the documentation of this file.
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
11
12#include <memory>
13
14// We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
15// different threads. The GrContext is not used concurrently on different threads and there is a
16// memory barrier between accesses of a context on different threads. Also, there may be multiple
17// GrContexts and those contexts may be in use concurrently on different threads.
18namespace {
19#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
20static SkSpinlock gProcessorSpinlock;
21#endif
22class MemoryPoolAccessor {
23public:
24
25// We know in the Android framework there is only one GrContext.
26#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
27 MemoryPoolAccessor() {}
28 ~MemoryPoolAccessor() {}
29#else
30 MemoryPoolAccessor() { gProcessorSpinlock.acquire(); }
31 ~MemoryPoolAccessor() { gProcessorSpinlock.release(); }
32#endif
33
34 GrMemoryPool* pool() const {
35 static GrMemoryPool* gPool = GrMemoryPool::Make(4096, 4096).release();
36 return gPool;
37 }
38};
39} // namespace
40
41///////////////////////////////////////////////////////////////////////////////
42
43void* GrProcessor::operator new(size_t size) { return MemoryPoolAccessor().pool()->allocate(size); }
44
45void* GrProcessor::operator new(size_t object_size, size_t footer_size) {
46 return MemoryPoolAccessor().pool()->allocate(object_size + footer_size);
47}
48
49void GrProcessor::operator delete(void* target) {
50 return MemoryPoolAccessor().pool()->release(target);
51}
AutoreleasePool pool
static SkDiscardableMemoryPool * gPool
static std::unique_ptr< GrMemoryPool > Make(size_t preallocSize, size_t minAllocSize)
uint32_t * target