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