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