Flutter Engine
The Flutter Engine
SkSLPool.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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
10#include "src/sksl/SkSLPool.h"
11
12#define SkVLOG(...) // SkDEBUGF(__VA_ARGS__)
13
14namespace SkSL {
15
16static thread_local MemoryPool* sMemPool = nullptr;
17
19 return sMemPool;
20}
21
23 sMemPool = memPool;
24}
25
26Pool::Pool() = default;
27
29 if (get_thread_local_memory_pool() == fMemPool.get()) {
30 SkDEBUGFAIL("SkSL pool is being destroyed while it is still attached to the thread");
32 }
33
34 SkVLOG("DELETE Pool:0x%016llX\n", (uint64_t)fMemPool.get());
35}
36
37std::unique_ptr<Pool> Pool::Create() {
38 auto pool = std::unique_ptr<Pool>(new Pool);
39 pool->fMemPool = MemoryPool::Make();
40 SkVLOG("CREATE Pool:0x%016llX\n", (uint64_t)pool->fMemPool.get());
41 return pool;
42}
43
46}
47
49 SkVLOG("ATTACH Pool:0x%016llX\n", (uint64_t)fMemPool.get());
51 set_thread_local_memory_pool(fMemPool.get());
52}
53
55 SkVLOG("DETACH Pool:0x%016llX\n", (uint64_t)memPool);
56 SkASSERT(get_thread_local_memory_pool() == fMemPool.get());
58}
59
60void* Pool::AllocMemory(size_t size) {
61 // Is a pool attached?
63 if (memPool) {
64 void* ptr = memPool->allocate(size);
65 SkVLOG("ALLOC Pool:0x%016llX 0x%016llX\n", (uint64_t)memPool, (uint64_t)ptr);
66 return ptr;
67 }
68
69 // There's no pool attached. Allocate memory using the system allocator.
70 void* ptr = ::operator new(size);
71 SkVLOG("ALLOC Pool:__________________ 0x%016llX\n", (uint64_t)ptr);
72 return ptr;
73}
74
75void Pool::FreeMemory(void* ptr) {
76 // Is a pool attached?
78 if (memPool) {
79 SkVLOG("FREE Pool:0x%016llX 0x%016llX\n", (uint64_t)memPool, (uint64_t)ptr);
80 memPool->release(ptr);
81 return;
82 }
83
84 // There's no pool attached. Free it using the system allocator.
85 SkVLOG("FREE Pool:__________________ 0x%016llX\n", (uint64_t)ptr);
86 ::operator delete(ptr);
87}
88
89} // namespace SkSL
AutoreleasePool pool
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkVLOG(...)
Definition: SkSLPool.cpp:12
static std::unique_ptr< MemoryPool > Make()
void * allocate(size_t size)
static std::unique_ptr< Pool > Create()
Definition: SkSLPool.cpp:37
static void * AllocMemory(size_t size)
Definition: SkSLPool.cpp:60
static bool IsAttached()
Definition: SkSLPool.cpp:44
void attachToThread()
Definition: SkSLPool.cpp:48
void detachFromThread()
Definition: SkSLPool.cpp:54
static void FreeMemory(void *ptr)
Definition: SkSLPool.cpp:75
static thread_local MemoryPool * sMemPool
Definition: SkSLPool.cpp:16
static MemoryPool * get_thread_local_memory_pool()
Definition: SkSLPool.cpp:18
static void set_thread_local_memory_pool(MemoryPool *memPool)
Definition: SkSLPool.cpp:22
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259