blob: fa11cc622d13f0dd13825f47ed91294885bbd7cb [file] [log] [blame]
kkinnunen3e980c32015-12-23 01:33:00 -08001/*
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"
kkinnunen3e980c32015-12-23 01:33:00 -080012#include "GrContextFactory.h"
kkinnunen3e980c32015-12-23 01:33:00 -080013
14DECLARE_string(config);
15
kkinnunen3e980c32015-12-23 01:33:00 -080016class SkCommandLineConfigGpu;
Bryce Thomas95a7b762018-03-02 13:54:21 -080017class SkCommandLineConfigSvg;
kkinnunen3e980c32015-12-23 01:33:00 -080018
19// SkCommandLineConfig represents a Skia rendering configuration string.
20// The string has following form:
21// tag:
22// [via-]*backend
bsalomon11abd8d2016-10-14 08:13:48 -070023// where 'backend' consists of chars excluding hyphen
kkinnunen3e980c32015-12-23 01:33:00 -080024// and each 'via' consists of chars excluding hyphen.
25class SkCommandLineConfig {
26 public:
27 SkCommandLineConfig(const SkString& tag, const SkString& backend,
28 const SkTArray<SkString>& viaParts);
29 virtual ~SkCommandLineConfig();
kkinnunen3e980c32015-12-23 01:33:00 -080030 virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; }
Bryce Thomas95a7b762018-03-02 13:54:21 -080031 virtual const SkCommandLineConfigSvg* asConfigSvg() const { return nullptr; }
kkinnunen3e980c32015-12-23 01:33:00 -080032 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
kkinnunen3e980c32015-12-23 01:33:00 -080041// SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend
42// part of the tag. It is constructed tags that have:
Brian Salomon6405e712017-03-20 08:54:16 -040043// * backends of form "gpu[option=value,option2=value,...]"
Brian Salomon50f66d82017-03-17 14:32:05 -040044// * backends that represent a shorthand of above (such as "glmsaa16" representing
Brian Salomon6405e712017-03-20 08:54:16 -040045// "gpu(api=gl,samples=16)")
kkinnunen3e980c32015-12-23 01:33:00 -080046class SkCommandLineConfigGpu : public SkCommandLineConfig {
Brian Salomonf865b052018-03-09 09:01:53 -050047public:
48 enum class SurfType {
49 kDefault,
50 kBackendTexture,
51 kBackendRenderTarget
52 };
bsalomon85b4b532016-04-05 11:06:27 -070053 typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
csmartdaltone812d492017-02-21 12:36:05 -070054 typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides;
Brian Salomonf865b052018-03-09 09:01:53 -050055
kkinnunen3e980c32015-12-23 01:33:00 -080056 SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
Brian Salomonf865b052018-03-09 09:01:53 -050057 ContextType contextType, bool useNVPR, bool useDIText, int samples,
58 SkColorType colorType, SkAlphaType alphaType,
Brian Osmanf9810662017-08-30 10:02:10 -040059 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers,
Brian Salomon00a5eb82018-07-11 15:32:05 -040060 bool testThreading, bool testPersistentCache, SurfType);
Brian Salomonf865b052018-03-09 09:01:53 -050061
kkinnunen3e980c32015-12-23 01:33:00 -080062 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
63 ContextType getContextType() const { return fContextType; }
csmartdaltone812d492017-02-21 12:36:05 -070064 ContextOverrides getContextOverrides() const { return fContextOverrides; }
65 bool getUseNVPR() const {
66 SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) ||
67 !(fContextOverrides & ContextOverrides::kDisableNVPR));
68 return fContextOverrides & ContextOverrides::kRequireNVPRSupport;
69 }
kkinnunen3e980c32015-12-23 01:33:00 -080070 bool getUseDIText() const { return fUseDIText; }
71 int getSamples() const { return fSamples; }
brianosmand93c1202016-03-10 07:49:08 -080072 SkColorType getColorType() const { return fColorType; }
Brian Salomonce5ee602017-07-17 11:31:31 -040073 SkAlphaType getAlphaType() const { return fAlphaType; }
brianosmanb109b8c2016-06-16 13:03:24 -070074 SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
Brian Osmanf9810662017-08-30 10:02:10 -040075 bool getTestThreading() const { return fTestThreading; }
Brian Salomon00a5eb82018-07-11 15:32:05 -040076 bool getTestPersistentCache() const { return fTestPersistentCache; }
Brian Salomonf865b052018-03-09 09:01:53 -050077 SurfType getSurfType() const { return fSurfType; }
kkinnunen3e980c32015-12-23 01:33:00 -080078
Brian Salomonf865b052018-03-09 09:01:53 -050079private:
kkinnunen3e980c32015-12-23 01:33:00 -080080 ContextType fContextType;
csmartdaltone812d492017-02-21 12:36:05 -070081 ContextOverrides fContextOverrides;
kkinnunen3e980c32015-12-23 01:33:00 -080082 bool fUseDIText;
83 int fSamples;
brianosmand93c1202016-03-10 07:49:08 -080084 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -040085 SkAlphaType fAlphaType;
brianosmanb109b8c2016-06-16 13:03:24 -070086 sk_sp<SkColorSpace> fColorSpace;
Brian Osmanf9810662017-08-30 10:02:10 -040087 bool fTestThreading;
Brian Salomon00a5eb82018-07-11 15:32:05 -040088 bool fTestPersistentCache;
Brian Salomonf865b052018-03-09 09:01:53 -050089 SurfType fSurfType;
kkinnunen3e980c32015-12-23 01:33:00 -080090};
kkinnunen3e980c32015-12-23 01:33:00 -080091
Bryce Thomas95a7b762018-03-02 13:54:21 -080092// 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,...]"
95class SkCommandLineConfigSvg : public SkCommandLineConfig {
96public:
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
102private:
103 int fPageIndex;
104};
105
Ben Wagner145dbcd2016-11-03 14:40:50 -0400106typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray;
kkinnunen3e980c32015-12-23 01:33:00 -0800107void ParseConfigs(const SkCommandLineFlags::StringArray& configList,
108 SkCommandLineConfigArray* outResult);
109
110#endif