blob: 47ad5e60a4432fcaf09c8756bf312b12651277ed [file] [log] [blame]
Mike Klein88544fb2019-03-20 10:50:33 -05001/*
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
Herb Derby3724b592022-12-05 17:08:03 -050011#include "include/core/SkColorSpace.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "tools/flags/CommandLineFlags.h"
13#include "tools/gpu/GrContextFactory.h"
Mike Klein88544fb2019-03-20 10:50:33 -050014
15DECLARE_string(config);
16
17class SkCommandLineConfigGpu;
Robert Phillips297d0962021-10-13 10:37:36 -040018class SkCommandLineConfigGraphite;
Mike Klein88544fb2019-03-20 10:50:33 -050019class SkCommandLineConfigSvg;
20
21// SkCommandLineConfig represents a Skia rendering configuration string.
22// The string has following form:
23// tag:
24// [via-]*backend
25// where 'backend' consists of chars excluding hyphen
26// and each 'via' consists of chars excluding hyphen.
27class SkCommandLineConfig {
28public:
29 SkCommandLineConfig(const SkString& tag,
30 const SkString& backend,
Herb Derbyd7a008392023-03-02 15:36:17 -050031 const skia_private::TArray<SkString>& viaParts);
Mike Klein88544fb2019-03-20 10:50:33 -050032 virtual ~SkCommandLineConfig();
33 virtual const SkCommandLineConfigGpu* asConfigGpu() const { return nullptr; }
Robert Phillips297d0962021-10-13 10:37:36 -040034 virtual const SkCommandLineConfigGraphite* asConfigGraphite() const { return nullptr; }
Mike Klein88544fb2019-03-20 10:50:33 -050035 virtual const SkCommandLineConfigSvg* asConfigSvg() const { return nullptr; }
36 const SkString& getTag() const { return fTag; }
37 const SkString& getBackend() const { return fBackend; }
Brian Osmanfcb50232021-08-12 10:51:48 -040038 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
Herb Derbyd7a008392023-03-02 15:36:17 -050039 const skia_private::TArray<SkString>& getViaParts() const { return fViaParts; }
Mike Klein88544fb2019-03-20 10:50:33 -050040
41private:
Herb Derbyd7a008392023-03-02 15:36:17 -050042 SkString fTag;
43 SkString fBackend;
44 sk_sp<SkColorSpace> fColorSpace;
45 skia_private::TArray<SkString> fViaParts;
Mike Klein88544fb2019-03-20 10:50:33 -050046};
47
48// SkCommandLineConfigGpu is a SkCommandLineConfig that extracts information out of the backend
49// part of the tag. It is constructed tags that have:
50// * backends of form "gpu[option=value,option2=value,...]"
51// * backends that represent a shorthand of above (such as "glmsaa16" representing
52// "gpu(api=gl,samples=16)")
53class SkCommandLineConfigGpu : public SkCommandLineConfig {
54public:
55 enum class SurfType { kDefault, kBackendTexture, kBackendRenderTarget };
John Stilesba7c5252023-08-25 10:50:10 -040056 typedef skgpu::ContextType ContextType;
Mike Klein88544fb2019-03-20 10:50:33 -050057 typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides;
58
59 SkCommandLineConfigGpu(const SkString& tag,
Herb Derbyd7a008392023-03-02 15:36:17 -050060 const skia_private::TArray<SkString>& viaParts,
Mike Klein88544fb2019-03-20 10:50:33 -050061 ContextType contextType,
Brian Salomonb2b7f802020-08-26 15:27:03 -040062 bool fakeGLESVer2,
Chris Dalton180b4a12021-03-16 20:49:15 -060063 uint32_t surfaceFlags,
Mike Klein88544fb2019-03-20 10:50:33 -050064 int samples,
65 SkColorType colorType,
66 SkAlphaType alphaType,
Mike Klein88544fb2019-03-20 10:50:33 -050067 bool useStencilBuffers,
Brian Osmanf71b0702019-04-03 13:04:16 -040068 int testPersistentCache,
Brian Osmaned58e002019-09-06 14:42:43 -040069 bool testPrecompile,
Robert Phillips291f3402020-02-19 14:14:47 -050070 bool useDDLSink,
Herb Derby6b49c542022-03-23 09:24:02 -040071 bool slug,
Herb Derbyd378c782022-11-29 14:03:16 -050072 bool serializedSlug,
Herb Derby3724b592022-12-05 17:08:03 -050073 bool remoteSlug,
Brian Salomon5a328282021-04-14 10:32:25 -040074 bool reducedShaders,
Mike Klein88544fb2019-03-20 10:50:33 -050075 SurfType);
76
77 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
78 ContextType getContextType() const { return fContextType; }
79 ContextOverrides getContextOverrides() const { return fContextOverrides; }
Chris Dalton180b4a12021-03-16 20:49:15 -060080 uint32_t getSurfaceFlags() const { return fSurfaceFlags; }
Mike Klein88544fb2019-03-20 10:50:33 -050081 int getSamples() const { return fSamples; }
82 SkColorType getColorType() const { return fColorType; }
83 SkAlphaType getAlphaType() const { return fAlphaType; }
Brian Osmanf71b0702019-04-03 13:04:16 -040084 int getTestPersistentCache() const { return fTestPersistentCache; }
Brian Osmaned58e002019-09-06 14:42:43 -040085 bool getTestPrecompile() const { return fTestPrecompile; }
Robert Phillips291f3402020-02-19 14:14:47 -050086 bool getUseDDLSink() const { return fUseDDLSink; }
Herb Derby6b49c542022-03-23 09:24:02 -040087 bool getSlug() const { return fSlug; }
Herb Derbyd378c782022-11-29 14:03:16 -050088 bool getSerializedSlug() const { return fSerializeSlug; }
Herb Derby3724b592022-12-05 17:08:03 -050089 bool getRemoteSlug() const { return fRemoteSlug; }
Brian Salomon91216d52021-04-09 11:57:59 -040090 bool getReducedShaders() const { return fReducedShaders; }
Mike Klein88544fb2019-03-20 10:50:33 -050091 SurfType getSurfType() const { return fSurfType; }
92
93private:
94 ContextType fContextType;
95 ContextOverrides fContextOverrides;
Chris Dalton180b4a12021-03-16 20:49:15 -060096 uint32_t fSurfaceFlags;
Mike Klein88544fb2019-03-20 10:50:33 -050097 int fSamples;
98 SkColorType fColorType;
99 SkAlphaType fAlphaType;
Brian Osmanf71b0702019-04-03 13:04:16 -0400100 int fTestPersistentCache;
Brian Osmaned58e002019-09-06 14:42:43 -0400101 bool fTestPrecompile;
Robert Phillips291f3402020-02-19 14:14:47 -0500102 bool fUseDDLSink;
Herb Derby6b49c542022-03-23 09:24:02 -0400103 bool fSlug;
Herb Derbyd378c782022-11-29 14:03:16 -0500104 bool fSerializeSlug;
Herb Derby3724b592022-12-05 17:08:03 -0500105 bool fRemoteSlug;
Brian Salomon91216d52021-04-09 11:57:59 -0400106 bool fReducedShaders;
Mike Klein88544fb2019-03-20 10:50:33 -0500107 SurfType fSurfType;
108};
109
Kevin Lubick0f7b44e2023-02-28 09:13:11 -0500110#if defined(SK_GRAPHITE)
Robert Phillips297d0962021-10-13 10:37:36 -0400111
112#include "tools/graphite/ContextFactory.h"
113
114class SkCommandLineConfigGraphite : public SkCommandLineConfig {
115public:
John Stilesba7c5252023-08-25 10:50:10 -0400116 using ContextType = skgpu::ContextType;
Robert Phillips297d0962021-10-13 10:37:36 -0400117
Brian Salomon0d5356a2023-12-14 11:39:05 -0500118 enum class SurfaceType {
119 // SkSurfaces::RenderTarget()
120 kDefault,
121 // BackendTexture around a WGPUTextureView passed to SkSurfaces::WrapBackendTexture()
122 kWrapTextureView,
123 };
124
John Stilesda3bb892023-08-21 11:31:03 -0400125 SkCommandLineConfigGraphite(const SkString& tag,
Herb Derbyd7a008392023-03-02 15:36:17 -0500126 const skia_private::TArray<SkString>& viaParts,
John Stilesda3bb892023-08-21 11:31:03 -0400127 ContextType contextType,
Brian Salomon0d5356a2023-12-14 11:39:05 -0500128 SurfaceType surfaceType,
Brian Salomon23e1cb22023-12-05 19:46:43 -0500129 const skiatest::graphite::TestOptions& options,
John Stilesda3bb892023-08-21 11:31:03 -0400130 SkColorType colorType,
Robert Phillips34ca4a42024-02-05 13:35:56 -0500131 SkAlphaType alphaType,
132 bool testPrecompile)
Robert Phillips297d0962021-10-13 10:37:36 -0400133 : SkCommandLineConfig(tag, SkString("graphite"), viaParts)
Brian Salomon23e1cb22023-12-05 19:46:43 -0500134 , fOptions(options)
Robert Phillips297d0962021-10-13 10:37:36 -0400135 , fContextType(contextType)
Brian Salomon0d5356a2023-12-14 11:39:05 -0500136 , fSurfaceType(surfaceType)
Robert Phillips297d0962021-10-13 10:37:36 -0400137 , fColorType(colorType)
Robert Phillips34ca4a42024-02-05 13:35:56 -0500138 , fAlphaType(alphaType)
139 , fTestPrecompile(testPrecompile) {
140 }
Robert Phillips297d0962021-10-13 10:37:36 -0400141 const SkCommandLineConfigGraphite* asConfigGraphite() const override { return this; }
142
Brian Salomon23e1cb22023-12-05 19:46:43 -0500143 const skiatest::graphite::TestOptions& getOptions() const { return fOptions; }
Robert Phillips297d0962021-10-13 10:37:36 -0400144 ContextType getContextType() const { return fContextType; }
Brian Salomon0d5356a2023-12-14 11:39:05 -0500145 SurfaceType getSurfaceType() const { return fSurfaceType; }
Robert Phillips297d0962021-10-13 10:37:36 -0400146 SkColorType getColorType() const { return fColorType; }
147 SkAlphaType getAlphaType() const { return fAlphaType; }
Robert Phillips34ca4a42024-02-05 13:35:56 -0500148 bool getTestPrecompile() const { return fTestPrecompile; }
Robert Phillips297d0962021-10-13 10:37:36 -0400149
150private:
Brian Salomon23e1cb22023-12-05 19:46:43 -0500151 skiatest::graphite::TestOptions fOptions;
Brian Salomonc759bbf2023-12-05 11:11:27 -0500152 ContextType fContextType;
Brian Salomon0d5356a2023-12-14 11:39:05 -0500153 SurfaceType fSurfaceType;
Brian Salomonc759bbf2023-12-05 11:11:27 -0500154 SkColorType fColorType;
155 SkAlphaType fAlphaType;
Robert Phillips34ca4a42024-02-05 13:35:56 -0500156 bool fTestPrecompile;
Robert Phillips297d0962021-10-13 10:37:36 -0400157};
158
Kevin Lubick0f7b44e2023-02-28 09:13:11 -0500159#endif // SK_GRAPHITE
Robert Phillips297d0962021-10-13 10:37:36 -0400160
Mike Klein88544fb2019-03-20 10:50:33 -0500161// SkCommandLineConfigSvg is a SkCommandLineConfig that extracts information out of the backend
162// part of the tag. It is constructed tags that have:
163// * backends of form "svg[option=value,option2=value,...]"
164class SkCommandLineConfigSvg : public SkCommandLineConfig {
165public:
Herb Derbyd7a008392023-03-02 15:36:17 -0500166 SkCommandLineConfigSvg(const SkString& tag, const skia_private::TArray<SkString>& viaParts, int pageIndex);
Mike Klein88544fb2019-03-20 10:50:33 -0500167 const SkCommandLineConfigSvg* asConfigSvg() const override { return this; }
168
169 int getPageIndex() const { return fPageIndex; }
170
171private:
172 int fPageIndex;
173};
174
Herb Derbyd7a008392023-03-02 15:36:17 -0500175typedef skia_private::TArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray;
Mike Klein88544fb2019-03-20 10:50:33 -0500176void ParseConfigs(const CommandLineFlags::StringArray& configList,
177 SkCommandLineConfigArray* outResult);
178
179#endif