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 "SkCommandLineFlags.h" 12 #include "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, const SkString& backend, 28 const SkTArray<SkString>& viaParts); 29 virtual ~SkCommandLineConfig(); asConfigGpu()30 virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; } asConfigSvg()31 virtual const SkCommandLineConfigSvg* asConfigSvg() const { return nullptr; } getTag()32 const SkString& getTag() const { return fTag; } getBackend()33 const SkString& getBackend() const { return fBackend; } getViaParts()34 const SkTArray<SkString>& getViaParts() const { return fViaParts; } 35 private: 36 SkString fTag; 37 SkString fBackend; 38 SkTArray<SkString> fViaParts; 39 }; 40 41 // SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend 42 // part of the tag. It is constructed tags that have: 43 // * backends of form "gpu[option=value,option2=value,...]" 44 // * backends that represent a shorthand of above (such as "glmsaa16" representing 45 // "gpu(api=gl,samples=16)") 46 class SkCommandLineConfigGpu : public SkCommandLineConfig { 47 public: 48 enum class SurfType { 49 kDefault, 50 kBackendTexture, 51 kBackendRenderTarget 52 }; 53 typedef sk_gpu_test::GrContextFactory::ContextType ContextType; 54 typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides; 55 56 SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts, 57 ContextType contextType, bool useNVPR, bool useDIText, int samples, 58 SkColorType colorType, SkAlphaType alphaType, 59 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, 60 bool testThreading, bool testPersistentCache, SurfType); 61 asConfigGpu()62 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } getContextType()63 ContextType getContextType() const { return fContextType; } getContextOverrides()64 ContextOverrides getContextOverrides() const { return fContextOverrides; } getUseNVPR()65 bool getUseNVPR() const { 66 SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) || 67 !(fContextOverrides & ContextOverrides::kDisableNVPR)); 68 return fContextOverrides & ContextOverrides::kRequireNVPRSupport; 69 } 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 bool 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 bool 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 SkCommandLineFlags::StringArray& configList, 108 SkCommandLineConfigArray* outResult); 109 110 #endif 111