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 SkTArray<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 SkTArray<SkString>& getViaParts() const { return fViaParts; } 40 41 private: 42 SkString fTag; 43 SkString fBackend; 44 sk_sp<SkColorSpace> fColorSpace; 45 SkTArray<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 sk_gpu_test::GrContextFactory::ContextType ContextType; 57 typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides; 58 59 SkCommandLineConfigGpu(const SkString& tag, 60 const SkTArray<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 bool testThreading, 69 int testPersistentCache, 70 bool testPrecompile, 71 bool useDDLSink, 72 bool slug, 73 bool serializedSlug, 74 bool remoteSlug, 75 bool reducedShaders, 76 SurfType); 77 asConfigGpu()78 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } getContextType()79 ContextType getContextType() const { return fContextType; } getContextOverrides()80 ContextOverrides getContextOverrides() const { return fContextOverrides; } getSurfaceFlags()81 uint32_t getSurfaceFlags() const { return fSurfaceFlags; } getSamples()82 int getSamples() const { return fSamples; } getColorType()83 SkColorType getColorType() const { return fColorType; } getAlphaType()84 SkAlphaType getAlphaType() const { return fAlphaType; } getTestThreading()85 bool getTestThreading() const { return fTestThreading; } getTestPersistentCache()86 int getTestPersistentCache() const { return fTestPersistentCache; } getTestPrecompile()87 bool getTestPrecompile() const { return fTestPrecompile; } getUseDDLSink()88 bool getUseDDLSink() const { return fUseDDLSink; } getSlug()89 bool getSlug() const { return fSlug; } getSerializedSlug()90 bool getSerializedSlug() const { return fSerializeSlug; } getRemoteSlug()91 bool getRemoteSlug() const { return fRemoteSlug; } getReducedShaders()92 bool getReducedShaders() const { return fReducedShaders; } getSurfType()93 SurfType getSurfType() const { return fSurfType; } 94 95 private: 96 ContextType fContextType; 97 ContextOverrides fContextOverrides; 98 uint32_t fSurfaceFlags; 99 int fSamples; 100 SkColorType fColorType; 101 SkAlphaType fAlphaType; 102 bool fTestThreading; 103 int fTestPersistentCache; 104 bool fTestPrecompile; 105 bool fUseDDLSink; 106 bool fSlug; 107 bool fSerializeSlug; 108 bool fRemoteSlug; 109 bool fReducedShaders; 110 SurfType fSurfType; 111 }; 112 113 #if defined(SK_GRAPHITE) 114 115 #include "tools/graphite/ContextFactory.h" 116 117 class SkCommandLineConfigGraphite : public SkCommandLineConfig { 118 public: 119 using ContextType = sk_gpu_test::GrContextFactory::ContextType; 120 SkCommandLineConfigGraphite(const SkString & tag,const SkTArray<SkString> & viaParts,ContextType contextType,SkColorType colorType,SkAlphaType alphaType)121 SkCommandLineConfigGraphite(const SkString& tag, 122 const SkTArray<SkString>& viaParts, 123 ContextType contextType, 124 SkColorType colorType, 125 SkAlphaType alphaType) 126 : SkCommandLineConfig(tag, SkString("graphite"), viaParts) 127 , fContextType(contextType) 128 , fColorType(colorType) 129 , fAlphaType(alphaType) { 130 } asConfigGraphite()131 const SkCommandLineConfigGraphite* asConfigGraphite() const override { return this; } 132 getContextType()133 ContextType getContextType() const { return fContextType; } getColorType()134 SkColorType getColorType() const { return fColorType; } getAlphaType()135 SkAlphaType getAlphaType() const { return fAlphaType; } 136 137 private: 138 ContextType fContextType; 139 SkColorType fColorType; 140 SkAlphaType fAlphaType; 141 }; 142 143 #endif // SK_GRAPHITE 144 145 // SkCommandLineConfigSvg is a SkCommandLineConfig that extracts information out of the backend 146 // part of the tag. It is constructed tags that have: 147 // * backends of form "svg[option=value,option2=value,...]" 148 class SkCommandLineConfigSvg : public SkCommandLineConfig { 149 public: 150 SkCommandLineConfigSvg(const SkString& tag, const SkTArray<SkString>& viaParts, int pageIndex); asConfigSvg()151 const SkCommandLineConfigSvg* asConfigSvg() const override { return this; } 152 getPageIndex()153 int getPageIndex() const { return fPageIndex; } 154 155 private: 156 int fPageIndex; 157 }; 158 159 typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray; 160 void ParseConfigs(const CommandLineFlags::StringArray& configList, 161 SkCommandLineConfigArray* outResult); 162 163 #endif 164