• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, "ccpr")) {
44         return GpuPathRenderers::kCoverageCounting;
45     } else if (!strcmp(name, "tess")) {
46         return GpuPathRenderers::kTessellating;
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 
CollectGpuPathRenderersFromFlags()54 inline 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
75