1 /*
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
13 #include "GrContextOptions.h"
14 #include "SkCommandLineFlags.h"
15 #include "SkTypes.h"
16
17 DECLARE_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 [~]small [~]tess [~]grdefault]")
24
get_named_pathrenderers_flags(const char * name)25 inline 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, "small")) {
42 return GpuPathRenderers::kSmall;
43 } else if (!strcmp(name, "tess")) {
44 return GpuPathRenderers::kTessellating;
45 } else if (!strcmp(name, "grdefault")) {
46 return GpuPathRenderers::kDefault;
47 }
48 SK_ABORT(SkStringPrintf("error: unknown named path renderer \"%s\"\n", name).c_str());
49 return GpuPathRenderers::kNone;
50 }
51
CollectGpuPathRenderersFromFlags()52 inline GrContextOptions::GpuPathRenderers CollectGpuPathRenderersFromFlags() {
53 using GpuPathRenderers = GrContextOptions::GpuPathRenderers;
54 if (FLAGS_pr.isEmpty()) {
55 return GpuPathRenderers::kAll;
56 }
57 GpuPathRenderers gpuPathRenderers = '~' == FLAGS_pr[0][0] ?
58 GpuPathRenderers::kAll : GpuPathRenderers::kNone;
59 for (int i = 0; i < FLAGS_pr.count(); ++i) {
60 const char* name = FLAGS_pr[i];
61 if (name[0] == '~') {
62 gpuPathRenderers &= ~get_named_pathrenderers_flags(&name[1]);
63 } else {
64 gpuPathRenderers |= get_named_pathrenderers_flags(name);
65 }
66 }
67 return gpuPathRenderers;
68 }
69
70 #endif // SK_SUPPORT_GPU
71
72 #endif
73