csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 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 | |
csmartdalton | e2d78ec | 2017-02-22 14:29:48 -0700 | [diff] [blame] | 13 | #include "GrContextOptions.h" |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 14 | #include "SkCommandLineFlags.h" |
| 15 | #include "SkTypes.h" |
| 16 | |
| 17 | DECLARE_string(pr); |
| 18 | |
Brian Salomon | 42c456f | 2017-03-06 11:29:48 -0500 | [diff] [blame] | 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 " \ |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 23 | "[~]aalinearizing [~]small [~]tess [~]grdefault]") |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 24 | |
| 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; |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 41 | } else if (!strcmp(name, "small")) { |
| 42 | return GpuPathRenderers::kSmall; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 43 | } else if (!strcmp(name, "tess")) { |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 44 | return GpuPathRenderers::kTessellating; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 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 | |
| 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 |