kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 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" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 12 | #include "GrContextFactory.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 13 | |
| 14 | DECLARE_string(config); |
| 15 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 16 | class SkCommandLineConfigGpu; |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 17 | class SkCommandLineConfigSvg; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 18 | |
| 19 | // SkCommandLineConfig represents a Skia rendering configuration string. |
| 20 | // The string has following form: |
| 21 | // tag: |
| 22 | // [via-]*backend |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 23 | // where 'backend' consists of chars excluding hyphen |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 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(); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 30 | virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; } |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 31 | virtual const SkCommandLineConfigSvg* asConfigSvg() const { return nullptr; } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 32 | const SkString& getTag() const { return fTag; } |
| 33 | const SkString& getBackend() const { return fBackend; } |
| 34 | const SkTArray<SkString>& getViaParts() const { return fViaParts; } |
| 35 | private: |
| 36 | SkString fTag; |
| 37 | SkString fBackend; |
| 38 | SkTArray<SkString> fViaParts; |
| 39 | }; |
| 40 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 41 | // SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend |
| 42 | // part of the tag. It is constructed tags that have: |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 43 | // * backends of form "gpu[option=value,option2=value,...]" |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 44 | // * backends that represent a shorthand of above (such as "glmsaa16" representing |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 45 | // "gpu(api=gl,samples=16)") |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 46 | class SkCommandLineConfigGpu : public SkCommandLineConfig { |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 47 | public: |
| 48 | enum class SurfType { |
| 49 | kDefault, |
| 50 | kBackendTexture, |
| 51 | kBackendRenderTarget |
| 52 | }; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 53 | typedef sk_gpu_test::GrContextFactory::ContextType ContextType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 54 | typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 55 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 56 | SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts, |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 57 | ContextType contextType, bool useNVPR, bool useDIText, int samples, |
| 58 | SkColorType colorType, SkAlphaType alphaType, |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 59 | sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 60 | bool testThreading, bool testPersistentCache, SurfType); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 61 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 62 | const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } |
| 63 | ContextType getContextType() const { return fContextType; } |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 64 | ContextOverrides getContextOverrides() const { return fContextOverrides; } |
| 65 | bool getUseNVPR() const { |
| 66 | SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) || |
| 67 | !(fContextOverrides & ContextOverrides::kDisableNVPR)); |
| 68 | return fContextOverrides & ContextOverrides::kRequireNVPRSupport; |
| 69 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 70 | bool getUseDIText() const { return fUseDIText; } |
| 71 | int getSamples() const { return fSamples; } |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 72 | SkColorType getColorType() const { return fColorType; } |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 73 | SkAlphaType getAlphaType() const { return fAlphaType; } |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 74 | SkColorSpace* getColorSpace() const { return fColorSpace.get(); } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 75 | bool getTestThreading() const { return fTestThreading; } |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 76 | bool getTestPersistentCache() const { return fTestPersistentCache; } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 77 | SurfType getSurfType() const { return fSurfType; } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 78 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 79 | private: |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 80 | ContextType fContextType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 81 | ContextOverrides fContextOverrides; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 82 | bool fUseDIText; |
| 83 | int fSamples; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 84 | SkColorType fColorType; |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 85 | SkAlphaType fAlphaType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 86 | sk_sp<SkColorSpace> fColorSpace; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 87 | bool fTestThreading; |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 88 | bool fTestPersistentCache; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 89 | SurfType fSurfType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 90 | }; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 91 | |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 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); |
| 98 | const SkCommandLineConfigSvg* asConfigSvg() const override { return this; } |
| 99 | |
| 100 | int getPageIndex() const { return fPageIndex; } |
| 101 | |
| 102 | private: |
| 103 | int fPageIndex; |
| 104 | }; |
| 105 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 106 | typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 107 | void ParseConfigs(const SkCommandLineFlags::StringArray& configList, |
| 108 | SkCommandLineConfigArray* outResult); |
| 109 | |
| 110 | #endif |