Flutter Engine
The Flutter Engine
SkWriter32.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
13
14#include <algorithm>
15
16class SkMatrix;
17
19 size_t size = SkMatrixPriv::WriteToMemory(matrix, nullptr);
22}
23
25 this->write32(sampling.maxAniso);
26 if (!sampling.isAniso()) {
27 this->writeBool(sampling.useCubic);
28 if (sampling.useCubic) {
29 this->writeScalar(sampling.cubic.B);
30 this->writeScalar(sampling.cubic.C);
31 } else {
32 this->write32((unsigned)sampling.filter);
33 this->write32((unsigned)sampling.mipmap);
34 }
35 }
36}
37
38void SkWriter32::writeString(const char str[], size_t len) {
39 if (nullptr == str) {
40 str = "";
41 len = 0;
42 }
43 if ((long)len < 0) {
44 len = strlen(str);
45 }
46
47 // [ 4 byte len ] [ str ... ] [1 - 4 \0s]
48 uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1);
49 *ptr = SkToU32(len);
50 char* chars = (char*)(ptr + 1);
51 memcpy(chars, str, len);
52 chars[len] = '\0';
53}
54
55size_t SkWriter32::WriteStringSize(const char* str, size_t len) {
56 if ((long)len < 0) {
57 SkASSERT(str);
58 len = strlen(str);
59 }
60 const size_t lenBytes = 4; // we use 4 bytes to record the length
61 // add 1 since we also write a terminating 0
62 return SkAlign4(lenBytes + len + 1);
63}
64
65void SkWriter32::growToAtLeast(size_t size) {
66 const bool wasExternal = (fExternal != nullptr) && (fData == fExternal);
67
68 fCapacity = 4096 + std::max(size, fCapacity + (fCapacity / 2));
69 fInternal.realloc(fCapacity);
70 fData = fInternal.get();
71
72 if (wasExternal) {
73 // we were external, so copy in the data
74 memcpy(fData, fExternal, fUsed);
75 }
76}
77
79 return SkData::MakeWithCopy(fData, fUsed);
80}
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
static size_t WriteToMemory(const SkMatrix &matrix, void *buffer)
Definition: SkMatrixPriv.h:30
void write32(int32_t value)
Definition: SkWriter32.h:117
void writeSampling(const SkSamplingOptions &sampling)
Definition: SkWriter32.cpp:24
uint32_t * reservePad(size_t size)
Definition: SkWriter32.h:179
void writeScalar(SkScalar value)
Definition: SkWriter32.h:121
void writeMatrix(const SkMatrix &matrix)
Definition: SkWriter32.cpp:18
uint32_t * reserve(size_t size)
Definition: SkWriter32.h:67
static size_t WriteStringSize(const char *str, size_t len=(size_t) -1)
Definition: SkWriter32.cpp:55
bool writeBool(bool value)
Definition: SkWriter32.h:100
sk_sp< SkData > snapshotAsData() const
Definition: SkWriter32.cpp:78
void writeString(const char *str, size_t len=(size_t) -1)
Definition: SkWriter32.cpp:38
void realloc(size_t count)
Definition: SkTemplates.h:291
static float max(float r, float g, float b)
Definition: hsl.cpp:49
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkSamplingOptions sampling
Definition: SkRecords.h:337
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
const SkCubicResampler cubic
const SkFilterMode filter
const SkMipmapMode mipmap