Debian Codegraph @

tools/flags/CommonFlagsConfig.h

raw
1 /*
2 * Copyright 2015 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
8 #ifndef SK_COMMON_FLAGS_CONFIG_H
9 #define SK_COMMON_FLAGS_CONFIG_H
10
11 #include "include/core/SkAlphaType.h"
12 #include "include/core/SkColorSpace.h"
13 #include "include/core/SkColorType.h"
14 #include "tools/flags/CommandLineFlags.h"
15
16 #if defined(SK_GANESH)
17 #include "tools/ganesh/GrContextFactory.h"
18 #include "tools/gpu/ContextType.h"
19 #endif
20
21 DECLARE_string(config)
22
23 class SkCommandLineConfigGpu;
24 class SkCommandLineConfigGraphite;
25 class SkCommandLineConfigSvg;
26
27 // SkCommandLineConfig represents a Skia rendering configuration string.
28 // The string has following form:
29 // tag:
30 // [via-]*backend
31 // where 'backend' consists of chars excluding hyphen
32 // and each 'via' consists of chars excluding hyphen.
33 class SkCommandLineConfig {
34 public:
35 SkCommandLineConfig(const SkString& tag,
36 const SkString& backend,
37 const skia_private::TArray<SkString>& viaParts);
38 virtual ~SkCommandLineConfig();
39 virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; }
40 virtual const SkCommandLineConfigGraphite* asConfigGraphite() const { return nullptr; }
41 virtual const SkCommandLineConfigSvg* asConfigSvg() const { return nullptr; }
42 const SkString& getTag() const { return fTag; }
43 const SkString& getBackend() const { return fBackend; }
44 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
45 const skia_private::TArray<SkString>& getViaParts() const { return fViaParts; }
46
47 private:
48 SkString fTag;
49 SkString fBackend;
50 sk_sp<SkColorSpace> fColorSpace;
51 skia_private::TArray<SkString> fViaParts;
52 };
53
54 #if defined(SK_GANESH)
55
56 // TODO: This should be "Ganesh" not "Gpu".
57
58 // SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend
59 // part of the tag. It is constructed tags that have:
60 // * backends of form "gpu[option=value,option2=value,...]"
61 // * backends that represent a shorthand of above (such as "glmsaa16" representing
62 // "gpu(api=gl,samples=16)")
63 class SkCommandLineConfigGpu : public SkCommandLineConfig {
64 public:
65 enum class SurfType { kDefault, kBackendTexture, kBackendRenderTarget };
66 typedef skgpu::ContextType ContextType;
67 typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides;
68
69 SkCommandLineConfigGpu(const SkString& tag,
70 const skia_private::TArray<SkString>& viaParts,
71 ContextType contextType,
72 bool fakeGLESVer2,
73 uint32_t surfaceFlags,
74 int samples,
75 SkColorType colorType,
76 SkAlphaType alphaType,
77 bool useStencilBuffers,
78 int testPersistentCache,
79 bool testPrecompileGanesh,
80 bool useDDLSink,
81 bool slug,
82 bool serializedSlug,
83 bool remoteSlug,
84 bool reducedShaders,
85 SurfType);
86
87 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
88 ContextType getContextType() const { return fContextType; }
89 ContextOverrides getContextOverrides() const { return fContextOverrides; }
90 uint32_t getSurfaceFlags() const { return fSurfaceFlags; }
91 int getSamples() const { return fSamples; }
92 SkColorType getColorType() const { return fColorType; }
93 SkAlphaType getAlphaType() const { return fAlphaType; }
94 int getTestPersistentCache() const { return fTestPersistentCache; }
95 bool getTestPrecompileGanesh() const { return fTestPrecompileGanesh; }
96 bool getUseDDLSink() const { return fUseDDLSink; }
97 bool getSlug() const { return fSlug; }
98 bool getSerializedSlug() const { return fSerializeSlug; }
99 bool getRemoteSlug() const { return fRemoteSlug; }
100 bool getReducedShaders() const { return fReducedShaders; }
101 SurfType getSurfType() const { return fSurfType; }
102
103 private:
104 ContextType fContextType;
105 ContextOverrides fContextOverrides;
106 uint32_t fSurfaceFlags;
107 int fSamples;
108 SkColorType fColorType;
109 SkAlphaType fAlphaType;
110 int fTestPersistentCache;
111 bool fTestPrecompileGanesh;
112 bool fUseDDLSink;
113 bool fSlug;
114 bool fSerializeSlug;
115 bool fRemoteSlug;
116 bool fReducedShaders;
117 SurfType fSurfType;
118 };
119 #endif // SK_GANESH
120
121 #if defined(SK_GRAPHITE)
122
123 #include "tools/graphite/ContextFactory.h"
124
125 class SkCommandLineConfigGraphite : public SkCommandLineConfig {
126 public:
127 using ContextType = skgpu::ContextType;
128
129 SkCommandLineConfigGraphite(const SkString& tag,
130 const skia_private::TArray<SkString>& viaParts,
131 ContextType contextType,
132 SkColorType colorType,
133 SkAlphaType alphaType,
134 bool testPersistentStorage,
135 bool testPrecompileGraphite,
136 bool testPipelineTracking)
137 : SkCommandLineConfig(tag, SkString("graphite"), viaParts)
138 , fContextType(contextType)
139 , fColorType(colorType)
140 , fAlphaType(alphaType)
141 , fTestPersistentStorage(testPersistentStorage)
142 , fTestPrecompileGraphite(testPrecompileGraphite)
143 , fTestPipelineTracking(testPipelineTracking) {
144 }
145
146 const SkCommandLineConfigGraphite* asConfigGraphite() const override { return this; }
147
148 ContextType getContextType() const { return fContextType; }
149 SkColorType getColorType() const { return fColorType; }
150 SkAlphaType getAlphaType() const { return fAlphaType; }
151 bool getTestPersistentStorage() const { return fTestPersistentStorage; }
152 bool getTestPrecompileGraphite() const { return fTestPrecompileGraphite; }
153 bool getTestPipelineTracking() const { return fTestPipelineTracking; }
154
155 private:
156 ContextType fContextType;
157 SkColorType fColorType;
158 SkAlphaType fAlphaType;
159 bool fTestPersistentStorage;
160 bool fTestPrecompileGraphite;
161 bool fTestPipelineTracking;
162 };
163
164 #endif // SK_GRAPHITE
165
166 // SkCommandLineConfigSvg is a SkCommandLineConfig that extracts information out of the backend
167 // part of the tag. It is constructed tags that have:
168 // * backends of form "svg[option=value,option2=value,...]"
169 class SkCommandLineConfigSvg : public SkCommandLineConfig {
170 public:
171 SkCommandLineConfigSvg(const SkString& tag, const skia_private::TArray<SkString>& viaParts, int pageIndex);
172 const SkCommandLineConfigSvg* asConfigSvg() const override { return this; }
173
174 int getPageIndex() const { return fPageIndex; }
175
176 private:
177 int fPageIndex;
178 };
179
180 typedef skia_private::TArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray;
181 void ParseConfigs(const CommandLineFlags::StringArray& configList,
182 SkCommandLineConfigArray* outResult);
183
184 #endif