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 useDIText, 58 int samples, 59 SkColorType colorType, 60 SkAlphaType alphaType, 61 sk_sp<SkColorSpace> colorSpace, 62 bool useStencilBuffers, 63 bool testThreading, 64 int testPersistentCache, 65 bool testPrecompile, 66 bool useDDLSink, 67 SurfType); 68 asConfigGpu()69 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } getContextType()70 ContextType getContextType() const { return fContextType; } getContextOverrides()71 ContextOverrides getContextOverrides() const { return fContextOverrides; } getUseDIText()72 bool getUseDIText() const { return fUseDIText; } getSamples()73 int getSamples() const { return fSamples; } getColorType()74 SkColorType getColorType() const { return fColorType; } getAlphaType()75 SkAlphaType getAlphaType() const { return fAlphaType; } getColorSpace()76 SkColorSpace* getColorSpace() const { return fColorSpace.get(); } getTestThreading()77 bool getTestThreading() const { return fTestThreading; } getTestPersistentCache()78 int getTestPersistentCache() const { return fTestPersistentCache; } getTestPrecompile()79 bool getTestPrecompile() const { return fTestPrecompile; } getUseDDLSink()80 bool getUseDDLSink() const { return fUseDDLSink; } getSurfType()81 SurfType getSurfType() const { return fSurfType; } 82 83 private: 84 ContextType fContextType; 85 ContextOverrides fContextOverrides; 86 bool fUseDIText; 87 int fSamples; 88 SkColorType fColorType; 89 SkAlphaType fAlphaType; 90 sk_sp<SkColorSpace> fColorSpace; 91 bool fTestThreading; 92 int fTestPersistentCache; 93 bool fTestPrecompile; 94 bool fUseDDLSink; 95 SurfType fSurfType; 96 }; 97 98 // SkCommandLineConfigSvg is a SkCommandLineConfig that extracts information out of the backend 99 // part of the tag. It is constructed tags that have: 100 // * backends of form "svg[option=value,option2=value,...]" 101 class SkCommandLineConfigSvg : public SkCommandLineConfig { 102 public: 103 SkCommandLineConfigSvg(const SkString& tag, const SkTArray<SkString>& viaParts, int pageIndex); asConfigSvg()104 const SkCommandLineConfigSvg* asConfigSvg() const override { return this; } 105 getPageIndex()106 int getPageIndex() const { return fPageIndex; } 107 108 private: 109 int fPageIndex; 110 }; 111 112 typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray; 113 void ParseConfigs(const CommandLineFlags::StringArray& configList, 114 SkCommandLineConfigArray* outResult); 115 116 #endif 117