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 |
| 22 | |
| 23 | // SkCommandLineConfig represents a Skia rendering configuration string. |
| 24 | // The string has following form: |
| 25 | // tag: |
| 26 | // [via-]*backend |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 27 | // where 'backend' consists of chars excluding hyphen |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 28 | // and each 'via' consists of chars excluding hyphen. |
| 29 | class SkCommandLineConfig { |
| 30 | public: |
| 31 | SkCommandLineConfig(const SkString& tag, const SkString& backend, |
| 32 | const SkTArray<SkString>& viaParts); |
| 33 | virtual ~SkCommandLineConfig(); |
| 34 | #if SK_SUPPORT_GPU |
| 35 | virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; } |
| 36 | #endif |
| 37 | const SkString& getTag() const { return fTag; } |
| 38 | const SkString& getBackend() const { return fBackend; } |
| 39 | const SkTArray<SkString>& getViaParts() const { return fViaParts; } |
| 40 | private: |
| 41 | SkString fTag; |
| 42 | SkString fBackend; |
| 43 | SkTArray<SkString> fViaParts; |
| 44 | }; |
| 45 | |
| 46 | #if SK_SUPPORT_GPU |
| 47 | // SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend |
| 48 | // part of the tag. It is constructed tags that have: |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 49 | // * backends of form "gpu[option=value,option2=value,...]" |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 50 | // * backends that represent a shorthand of above (such as "glmsaa16" representing |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 51 | // "gpu(api=gl,samples=16)") |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 52 | class SkCommandLineConfigGpu : public SkCommandLineConfig { |
| 53 | public: |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 54 | typedef sk_gpu_test::GrContextFactory::ContextType ContextType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 55 | typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 56 | SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts, |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 57 | ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText, |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 58 | int samples, SkColorType colorType, SkAlphaType alphaType, |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 59 | sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, |
| 60 | bool testThreading); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 61 | const SkCommandLineConfigGpu* asConfigGpu() const override { return this; } |
| 62 | ContextType getContextType() const { return fContextType; } |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 63 | ContextOverrides getContextOverrides() const { return fContextOverrides; } |
| 64 | bool getUseNVPR() const { |
| 65 | SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) || |
| 66 | !(fContextOverrides & ContextOverrides::kDisableNVPR)); |
| 67 | return fContextOverrides & ContextOverrides::kRequireNVPRSupport; |
| 68 | } |
| 69 | bool getUseInstanced() const { return fContextOverrides & ContextOverrides::kUseInstanced; } |
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; } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | ContextType fContextType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 79 | ContextOverrides fContextOverrides; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 80 | bool fUseDIText; |
| 81 | int fSamples; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 82 | SkColorType fColorType; |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 83 | SkAlphaType fAlphaType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 84 | sk_sp<SkColorSpace> fColorSpace; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 85 | bool fTestThreading; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 86 | }; |
| 87 | #endif |
| 88 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 89 | typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 90 | void ParseConfigs(const SkCommandLineFlags::StringArray& configList, |
| 91 | SkCommandLineConfigArray* outResult); |
| 92 | |
| 93 | #endif |