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