Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
GrPersistentCacheUtils Namespace Reference

Classes

struct  ShaderMetadata
 

Functions

int GetCurrentVersion ()
 
sk_sp< SkDataPackCachedShaders (SkFourByteTag shaderType, const std::string shaders[], const SkSL::Program::Interface interfaces[], int numInterfaces, const ShaderMetadata *meta)
 
SkFourByteTag GetType (SkReadBuffer *reader)
 
bool UnpackCachedShaders (SkReadBuffer *reader, std::string shaders[], SkSL::Program::Interface interfaces[], int numInterfaces, ShaderMetadata *meta)
 

Variables

static constexpr int kCurrentVersion = 12
 

Function Documentation

◆ GetCurrentVersion()

int GrPersistentCacheUtils::GetCurrentVersion ( )

Definition at line 19 of file GrPersistentCacheUtils.cpp.

19 {
20 // The persistent cache stores a copy of the SkSL::Program::Interface struct. If you alter the
21 // Program::Interface struct in any way, you must increment kCurrentVersion to invalidate the
22 // outdated persistent cache files. The KnownSkSLProgramInterface struct must also be updated
23 // to match the new contents of Program::Interface.
24 struct KnownSkSLProgramInterface {
25 bool useLastFragColor;
26 bool useRTFlipUniform;
27 bool outputSecondaryColor;
28 };
29 static_assert(sizeof(SkSL::Program::Interface) == sizeof(KnownSkSLProgramInterface));
30
31 return kCurrentVersion;
32}
ProgramInterface Interface

◆ GetType()

SkFourByteTag GrPersistentCacheUtils::GetType ( SkReadBuffer reader)

Definition at line 75 of file GrPersistentCacheUtils.cpp.

75 {
76 constexpr SkFourByteTag kInvalidTag = ~0;
77 int version = reader->readInt();
78 SkFourByteTag typeTag = reader->readUInt();
79 return reader->validate(version == kCurrentVersion) ? typeTag : kInvalidTag;
80}
uint32_t SkFourByteTag
Definition SkTypes.h:166
bool validate(bool isValid)
uint32_t readUInt()
int32_t readInt()
static const int kInvalidTag
Definition skpinfo.cpp:30

◆ PackCachedShaders()

sk_sp< SkData > GrPersistentCacheUtils::PackCachedShaders ( SkFourByteTag  shaderType,
const std::string  shaders[],
const SkSL::Program::Interface  interfaces[],
int  numInterfaces,
const ShaderMetadata meta 
)

Definition at line 34 of file GrPersistentCacheUtils.cpp.

38 {
39 // For consistency (so tools can blindly pack and unpack cached shaders), we always write
40 // kGrShaderTypeCount interfaces. If the backend gives us fewer, we just replicate the last one.
41 SkASSERT(numInterfaces >= 1 && numInterfaces <= kGrShaderTypeCount);
42
43 SkBinaryWriteBuffer writer({});
44 writer.writeInt(kCurrentVersion);
45 writer.writeUInt(shaderType);
46 for (int i = 0; i < kGrShaderTypeCount; ++i) {
47 writer.writeByteArray(shaders[i].c_str(), shaders[i].size());
48 writer.writePad32(&interfaces[std::min(i, numInterfaces - 1)],
50 }
51 writer.writeBool(SkToBool(meta));
52 if (meta) {
53 writer.writeBool(SkToBool(meta->fSettings));
54 if (meta->fSettings) {
55 writer.writeBool(meta->fSettings->fForceNoRTFlip);
56 writer.writeBool(meta->fSettings->fFragColorIsInOut);
57 writer.writeBool(meta->fSettings->fForceHighPrecision);
58 writer.writeBool(meta->fSettings->fUsePushConstants);
59 }
60
61 writer.writeInt(meta->fAttributeNames.size());
62 for (const auto& attr : meta->fAttributeNames) {
63 writer.writeByteArray(attr.c_str(), attr.size());
64 }
65
66 writer.writeBool(meta->fHasSecondaryColorOutput);
67
68 if (meta->fPlatformData) {
69 writer.writeByteArray(meta->fPlatformData->data(), meta->fPlatformData->size());
70 }
71 }
72 return writer.snapshotAsData();
73}
static const int kGrShaderTypeCount
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
void writeInt(int32_t value) override
const void * data() const
Definition SkData.h:37
size_t size() const
Definition SkData.h:30
int size() const
Definition SkTArray.h:416
skia_private::TArray< std::string > fAttributeNames

◆ UnpackCachedShaders()

bool GrPersistentCacheUtils::UnpackCachedShaders ( SkReadBuffer reader,
std::string  shaders[],
SkSL::Program::Interface  interfaces[],
int  numInterfaces,
ShaderMetadata meta 
)

Definition at line 82 of file GrPersistentCacheUtils.cpp.

86 {
87 for (int i = 0; i < kGrShaderTypeCount; ++i) {
88 size_t shaderLen = 0;
89 const char* shaderBuf = static_cast<const char*>(reader->skipByteArray(&shaderLen));
90 if (shaderBuf) {
91 shaders[i].assign(shaderBuf, shaderLen);
92 }
93
94 // GL, for example, only wants one Interface
95 if (i < numInterfaces) {
96 reader->readPad32(&interfaces[i], sizeof(interfaces[i]));
97 } else {
98 reader->skip(sizeof(SkSL::Program::Interface));
99 }
100 }
101 if (reader->readBool() && meta) {
102 SkASSERT(meta->fSettings != nullptr);
103
104 if (reader->readBool()) {
105 meta->fSettings->fForceNoRTFlip = reader->readBool();
106 meta->fSettings->fFragColorIsInOut = reader->readBool();
107 meta->fSettings->fForceHighPrecision = reader->readBool();
108 meta->fSettings->fUsePushConstants = reader->readBool();
109 }
110
111 meta->fAttributeNames.resize(reader->readInt());
112 for (auto& attr : meta->fAttributeNames) {
113 size_t attrLen = 0;
114 const char* attrName = static_cast<const char*>(reader->skipByteArray(&attrLen));
115 if (attrName) {
116 attr.assign(attrName, attrLen);
117 }
118 }
119
120 meta->fHasSecondaryColorOutput = reader->readBool();
121
122 // a given platform will be responsible for reading its data
123 }
124
125 if (!reader->isValid()) {
126 for (int i = 0; i < kGrShaderTypeCount; ++i) {
127 shaders[i].clear();
128 }
129 }
130 return reader->isValid();
131}
const void * skipByteArray(size_t *size)
bool isValid() const
const void * skip(size_t size)
bool readPad32(void *buffer, size_t bytes)
void resize(size_t count)
Definition SkTArray.h:418

Variable Documentation

◆ kCurrentVersion

constexpr int GrPersistentCacheUtils::kCurrentVersion = 12
staticconstexpr

Definition at line 17 of file GrPersistentCacheUtils.cpp.