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