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