1 /*
2  * Copyright 2019 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 
8 #ifndef GrPersistentCacheEntry_DEFINED
9 #define GrPersistentCacheEntry_DEFINED
10 
11 #include "include/core/SkData.h"
12 #include "include/private/GrTypesPriv.h"
13 #include "src/sksl/ir/SkSLProgram.h"
14 
15 class SkReadBuffer;
16 
17 // The GrPersistentCache stores opaque blobs, as far as clients are concerned. It's helpful to
18 // inspect certain kinds of cached data within our tools, so for those cases (GLSL, SPIR-V), we
19 // put the serialization logic here, to be shared by the backend code and the tool code.
20 namespace GrPersistentCacheUtils {
21 
22 struct ShaderMetadata {
23     SkSL::Program::Settings* fSettings = nullptr;
24     SkTArray<SkSL::String> fAttributeNames;
25     bool fHasCustomColorOutput = false;
26     bool fHasSecondaryColorOutput = false;
27     sk_sp<SkData> fPlatformData;
28 };
29 
30 int GetCurrentVersion();
31 
32 sk_sp<SkData> PackCachedShaders(SkFourByteTag shaderType,
33                                 const SkSL::String shaders[],
34                                 const SkSL::Program::Inputs inputs[],
35                                 int numInputs,
36                                 const ShaderMetadata* meta = nullptr);
37 
38 SkFourByteTag GetType(SkReadBuffer* reader);
39 
40 bool UnpackCachedShaders(SkReadBuffer* reader,
41                          SkSL::String shaders[],
42                          SkSL::Program::Inputs inputs[],
43                          int numInputs,
44                          ShaderMetadata* meta = nullptr);
45 
46 }  // namespace GrPersistentCacheUtils
47 
48 #endif
49