blob: 87d52b4d82147e4a4286e90064c4f9ea7b62daf8 [file] [log] [blame]
csmartdalton008b9d82017-02-22 12:00:42 -07001/*
2 * Copyright 2017 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_PATH_RENDERER_H
9#define SK_COMMON_FLAGS_PATH_RENDERER_H
10
11#if SK_SUPPORT_GPU
12
csmartdaltone2d78ec2017-02-22 14:29:48 -070013#include "GrContextOptions.h"
csmartdalton008b9d82017-02-22 12:00:42 -070014#include "SkCommandLineFlags.h"
15#include "SkTypes.h"
16
17DECLARE_string(pr);
18
19#define DEFINE_pathrenderer_flag \
20 DEFINE_string(pr, "all", \
21 "Set of enabled gpu path renderers. Defined as a list of: " \
22 "[[~]all [~]dashline [~]nvpr [~]msaa [~]aahairline [~]aaconvex " \
23 "[~]aalinearizing [~]pls [~]sdf [~]tess [~]grdefault]")
24
25inline GrContextOptions::GpuPathRenderers get_named_pathrenderers_flags(const char* name) {
26 using GpuPathRenderers = GrContextOptions::GpuPathRenderers;
27 if (!strcmp(name, "all")) {
28 return GpuPathRenderers::kAll;
29 } else if (!strcmp(name, "dashline")) {
30 return GpuPathRenderers::kDashLine;
31 } else if (!strcmp(name, "nvpr")) {
32 return GpuPathRenderers::kStencilAndCover;
33 } else if (!strcmp(name, "msaa")) {
34 return GpuPathRenderers::kMSAA;
35 } else if (!strcmp(name, "aahairline")) {
36 return GpuPathRenderers::kAAHairline;
37 } else if (!strcmp(name, "aaconvex")) {
38 return GpuPathRenderers::kAAConvex;
39 } else if (!strcmp(name, "aalinearizing")) {
40 return GpuPathRenderers::kAALinearizing;
41 } else if (!strcmp(name, "pls")) {
42 return GpuPathRenderers::kPLS;
43 } else if (!strcmp(name, "sdf")) {
44 return GpuPathRenderers::kDistanceField;
45 } else if (!strcmp(name, "tess")) {
46 return GpuPathRenderers::kTesselating;
47 } else if (!strcmp(name, "grdefault")) {
48 return GpuPathRenderers::kDefault;
49 }
50 SK_ABORT(SkStringPrintf("error: unknown named path renderer \"%s\"\n", name).c_str());
51 return GpuPathRenderers::kNone;
52}
53
54inline GrContextOptions::GpuPathRenderers CollectGpuPathRenderersFromFlags() {
55 using GpuPathRenderers = GrContextOptions::GpuPathRenderers;
56 if (FLAGS_pr.isEmpty()) {
57 return GpuPathRenderers::kAll;
58 }
59 GpuPathRenderers gpuPathRenderers = '~' == FLAGS_pr[0][0] ?
60 GpuPathRenderers::kAll : GpuPathRenderers::kNone;
61 for (int i = 0; i < FLAGS_pr.count(); ++i) {
62 const char* name = FLAGS_pr[i];
63 if (name[0] == '~') {
64 gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]);
65 } else {
66 gpuPathRenderers |= get_named_pathrenderers_flags(name);
67 }
68 }
69 return gpuPathRenderers;
70}
71
72#endif // SK_SUPPORT_GPU
73
74#endif