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 SkCommandLineConfigGraphite(const SkString & tag,const skia_private::TArray<SkString> & viaParts,ContextType contextType,SkColorType colorType,SkAlphaType alphaType,bool testPrecompile)118 SkCommandLineConfigGraphite(const SkString& tag, 119 const skia_private::TArray<SkString>& viaParts, 120 ContextType contextType, 121 SkColorType colorType, 122 SkAlphaType alphaType, 123 bool testPrecompile) 124 : SkCommandLineConfig(tag, SkString("graphite"), viaParts) 125 , fContextType(contextType) 126 , fColorType(colorType) 127 , fAlphaType(alphaType) 128 , fTestPrecompile(testPrecompile) { 129 } asConfigGraphite()130 const SkCommandLineConfigGraphite* asConfigGraphite() const override { return this; } 131 getContextType()132 ContextType getContextType() const { return fContextType; } getColorType()133 SkColorType getColorType() const { return fColorType; } getAlphaType()134 SkAlphaType getAlphaType() const { return fAlphaType; } getTestPrecompile()135 bool getTestPrecompile() const { return fTestPrecompile; } 136 137 private: 138 ContextType fContextType; 139 SkColorType fColorType; 140 SkAlphaType fAlphaType; 141 bool fTestPrecompile; 142 }; 143 144 #endif // SK_GRAPHITE 145 146 // SkCommandLineConfigSvg is a SkCommandLineConfig that extracts information out of the backend 147 // part of the tag. It is constructed tags that have: 148 // * backends of form "svg[option=value,option2=value,...]" 149 class SkCommandLineConfigSvg : public SkCommandLineConfig { 150 public: 151 SkCommandLineConfigSvg(const SkString& tag, const skia_private::TArray<SkString>& viaParts, int pageIndex); asConfigSvg()152 const SkCommandLineConfigSvg* asConfigSvg() const override { return this; } 153 getPageIndex()154 int getPageIndex() const { return fPageIndex; } 155 156 private: 157 int fPageIndex; 158 }; 159 160 typedef skia_private::TArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray; 161 void ParseConfigs(const CommandLineFlags::StringArray& configList, 162 SkCommandLineConfigArray* outResult); 163 164 #endif 165