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
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
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 "glmsaa16" representing
51// "gpu(api=gl,samples=16)")
52class SkCommandLineConfigGpu : public SkCommandLineConfig {
53  public:
54    typedef sk_gpu_test::GrContextFactory::ContextType ContextType;
55    typedef sk_gpu_test::GrContextFactory::ContextOverrides ContextOverrides;
56    SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
57                           ContextType contextType, bool useNVPR, bool useInstanced, bool useDIText,
58                           int samples, SkColorType colorType, SkAlphaType alphaType,
59                           sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers);
60    const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
61    ContextType getContextType() const { return fContextType; }
62    ContextOverrides getContextOverrides() const { return fContextOverrides; }
63    bool getUseNVPR() const {
64        SkASSERT(!(fContextOverrides & ContextOverrides::kRequireNVPRSupport) ||
65                 !(fContextOverrides & ContextOverrides::kDisableNVPR));
66        return fContextOverrides & ContextOverrides::kRequireNVPRSupport;
67    }
68    bool getUseInstanced() const { return fContextOverrides & ContextOverrides::kUseInstanced; }
69    bool getUseDIText() const { return fUseDIText; }
70    int getSamples() const { return fSamples; }
71    SkColorType getColorType() const { return fColorType; }
72    SkAlphaType getAlphaType() const { return fAlphaType; }
73    SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
74
75  private:
76    ContextType fContextType;
77    ContextOverrides fContextOverrides;
78    bool fUseDIText;
79    int fSamples;
80    SkColorType fColorType;
81    SkAlphaType fAlphaType;
82    sk_sp<SkColorSpace> fColorSpace;
83};
84#endif
85
86typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray;
87void ParseConfigs(const SkCommandLineFlags::StringArray& configList,
88                  SkCommandLineConfigArray* outResult);
89
90#endif
91