blob: 641c68b3eeafe15d4c97ab8f696f58fccd685d22 [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"
12
13#if SK_SUPPORT_GPU
14#include "GrContextFactory.h"
15#endif
16
17DECLARE_string(config);
18
19#if SK_SUPPORT_GPU
20class SkCommandLineConfigGpu;
21#endif
22
23// SkCommandLineConfig represents a Skia rendering configuration string.
24// The string has following form:
25// tag:
26// [via-]*backend
27// where 'backend' consists of chars excluding hyphen or "angle-gl"
28// and each 'via' consists of chars excluding hyphen.
29class 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:
49// * backends of form "gpu(option=value,option2=value,...)"
50// * backends that represent a shorthand of above (such as "msaa16" representing "gpu(samples=16)")
51class SkCommandLineConfigGpu : public SkCommandLineConfig {
52 public:
bsalomon85b4b532016-04-05 11:06:27 -070053 typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -080054 SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
csmartdaltone0d36292016-07-29 08:14:20 -070055 ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText,
56 int samples, SkColorType colorType, sk_sp<SkColorSpace> colorSpace);
kkinnunen3e980c32015-12-23 01:33:00 -080057 const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
58 ContextType getContextType() const { return fContextType; }
59 bool getUseNVPR() const { return fUseNVPR; }
csmartdaltone0d36292016-07-29 08:14:20 -070060 bool getUseInstanced() const { return fUseInstanced; }
kkinnunen3e980c32015-12-23 01:33:00 -080061 bool getUseDIText() const { return fUseDIText; }
62 int getSamples() const { return fSamples; }
brianosmand93c1202016-03-10 07:49:08 -080063 SkColorType getColorType() const { return fColorType; }
brianosmanb109b8c2016-06-16 13:03:24 -070064 SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
kkinnunen3e980c32015-12-23 01:33:00 -080065
66 private:
67 ContextType fContextType;
68 bool fUseNVPR;
csmartdaltone0d36292016-07-29 08:14:20 -070069 bool fUseInstanced;
kkinnunen3e980c32015-12-23 01:33:00 -080070 bool fUseDIText;
71 int fSamples;
brianosmand93c1202016-03-10 07:49:08 -080072 SkColorType fColorType;
brianosmanb109b8c2016-06-16 13:03:24 -070073 sk_sp<SkColorSpace> fColorSpace;
kkinnunen3e980c32015-12-23 01:33:00 -080074};
75#endif
76
77typedef SkTArray<SkAutoTDelete<SkCommandLineConfig>, true> SkCommandLineConfigArray;
78void ParseConfigs(const SkCommandLineFlags::StringArray& configList,
79 SkCommandLineConfigArray* outResult);
80
81#endif