Flutter Engine
The Flutter Engine
SkDataTable.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
9
14
15#include <cstring>
16
17static void malloc_freeproc(void* context) {
18 sk_free(context);
19}
20
21// Makes empty table
22SkDataTable::SkDataTable() {
23 fCount = 0;
24 fElemSize = 0; // 0 signals that we use fDir instead of fElems
25 fU.fDir = nullptr;
26 fFreeProc = nullptr;
27 fFreeProcContext = nullptr;
28}
29
30SkDataTable::SkDataTable(const void* array, size_t elemSize, int count,
31 FreeProc proc, void* context) {
32 SkASSERT(count > 0);
33
34 fCount = count;
35 fElemSize = elemSize; // non-zero signals we use fElems instead of fDir
36 fU.fElems = (const char*)array;
37 fFreeProc = proc;
38 fFreeProcContext = context;
39}
40
41SkDataTable::SkDataTable(const Dir* dir, int count, FreeProc proc, void* ctx) {
42 SkASSERT(count > 0);
43
44 fCount = count;
45 fElemSize = 0; // 0 signals that we use fDir instead of fElems
46 fU.fDir = dir;
47 fFreeProc = proc;
48 fFreeProcContext = ctx;
49}
50
51SkDataTable::~SkDataTable() {
52 if (fFreeProc) {
53 fFreeProc(fFreeProcContext);
54 }
55}
56
57size_t SkDataTable::atSize(int index) const {
58 SkASSERT((unsigned)index < (unsigned)fCount);
59
60 if (fElemSize) {
61 return fElemSize;
62 } else {
63 return fU.fDir[index].fSize;
64 }
65}
66
67const void* SkDataTable::at(int index, size_t* size) const {
68 SkASSERT((unsigned)index < (unsigned)fCount);
69
70 if (fElemSize) {
71 if (size) {
72 *size = fElemSize;
73 }
74 return fU.fElems + index * fElemSize;
75 } else {
76 if (size) {
77 *size = fU.fDir[index].fSize;
78 }
79 return fU.fDir[index].fPtr;
80 }
81}
82
83///////////////////////////////////////////////////////////////////////////////
84
86 static SkDataTable* singleton;
87 static SkOnce once;
88 once([]{ singleton = new SkDataTable(); });
89 return sk_ref_sp(singleton);
90}
91
93 const size_t sizes[], int count) {
94 if (count <= 0) {
96 }
97
98 size_t dataSize = 0;
99 for (int i = 0; i < count; ++i) {
100 dataSize += sizes[i];
101 }
102
103 size_t bufferSize = count * sizeof(Dir) + dataSize;
104 void* buffer = sk_malloc_throw(bufferSize);
105
106 Dir* dir = (Dir*)buffer;
107 char* elem = (char*)(dir + count);
108 for (int i = 0; i < count; ++i) {
109 dir[i].fPtr = elem;
110 dir[i].fSize = sizes[i];
111 memcpy(elem, ptrs[i], sizes[i]);
112 elem += sizes[i];
113 }
114
116}
117
118sk_sp<SkDataTable> SkDataTable::MakeCopyArray(const void* array, size_t elemSize, int count) {
119 if (count <= 0) {
120 return SkDataTable::MakeEmpty();
121 }
122
123 size_t bufferSize = elemSize * count;
124 void* buffer = sk_malloc_throw(bufferSize);
125 memcpy(buffer, array, bufferSize);
126
128}
129
130sk_sp<SkDataTable> SkDataTable::MakeArrayProc(const void* array, size_t elemSize, int count,
131 FreeProc proc, void* ctx) {
132 if (count <= 0) {
133 return SkDataTable::MakeEmpty();
134 }
135 return sk_sp<SkDataTable>(new SkDataTable(array, elemSize, count, proc, ctx));
136}
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void malloc_freeproc(void *context)
Definition: SkDataTable.cpp:17
SK_API void sk_free(void *)
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
int count() const
Definition: SkDataTable.h:33
static sk_sp< SkDataTable > MakeCopyArray(const void *array, size_t elemSize, int count)
const void * at(int index, size_t *size=nullptr) const
Definition: SkDataTable.cpp:67
static sk_sp< SkDataTable > MakeArrayProc(const void *array, size_t elemSize, int count, FreeProc proc, void *context)
static sk_sp< SkDataTable > MakeEmpty()
Definition: SkDataTable.cpp:85
static sk_sp< SkDataTable > MakeCopyArrays(const void *const *ptrs, const size_t sizes[], int count)
Definition: SkDataTable.cpp:92
size_t atSize(int index) const
Definition: SkDataTable.cpp:57
Definition: SkOnce.h:22
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
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