Flutter Engine
The Flutter Engine
SkContainers.h
Go to the documentation of this file.
1// Copyright 2022 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
4#ifndef SkContainers_DEFINED
5#define SkContainers_DEFINED
6
10
11#include <cstddef>
12#include <cstdint>
13
15public:
16 SkContainerAllocator(size_t sizeOfT, int maxCapacity)
17 : fSizeOfT{sizeOfT}
18 , fMaxCapacity{maxCapacity} {}
19
20 // allocate will abort on failure. Given a capacity of 0, it will return the empty span.
21 // The bytes allocated are freed using sk_free().
22 SkSpan<std::byte> allocate(int capacity, double growthFactor = 1.0);
23
24 // Rounds a requested capacity up towards `kCapacityMultiple` in a constexpr-friendly fashion.
25 template <typename T>
26 static constexpr size_t RoundUp(size_t capacity) {
27 return SkAlignTo(capacity * sizeof(T), kCapacityMultiple) / sizeof(T);
28 }
29
30private:
32
33 // All capacity counts will be rounded up to kCapacityMultiple. This matches ASAN's shadow
34 // granularity, as well as our typical struct alignment on a 64-bit machine.
35 static constexpr int64_t kCapacityMultiple = 8;
36
37 // Rounds up capacity to next multiple of kCapacityMultiple and pin to fMaxCapacity.
38 size_t roundUpCapacity(int64_t capacity) const;
39
40 // Grows the capacity by growthFactor being sure to stay with in kMinBytes and fMaxCapacity.
41 size_t growthFactorCapacity(int capacity, double growthFactor) const;
42
43 const size_t fSizeOfT;
44 const int64_t fMaxCapacity;
45};
46
47// sk_allocate_canfail returns the empty span on failure. Parameter size must be > 0.
49
50// Returns the empty span if size is 0. sk_allocate_throw aborts on failure.
52
54#endif // SkContainers_DEFINED
#define SK_SPI
Definition: SkAPI.h:41
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
SK_SPI void sk_report_container_overflow_and_die()
SkSpan< std::byte > sk_allocate_throw(size_t size)
SkSpan< std::byte > sk_allocate_canfail(size_t size)
SkContainerAllocator(size_t sizeOfT, int maxCapacity)
Definition: SkContainers.h:16
static constexpr size_t RoundUp(size_t capacity)
Definition: SkContainers.h:26
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
#define T
Definition: precompiler.cc:65
static constexpr int64_t kCapacityMultiple