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