13e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen/* 23e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * Copyright 2015 Google Inc. 33e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * 43e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * Use of this source code is governed by a BSD-style license that can be 53e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * found in the LICENSE file. 63e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen */ 73e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 83e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#include "SkCommonFlagsConfig.h" 93e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 103e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#include <stdlib.h> 113e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 123e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic const char defaultConfigs[] = 133e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "565 8888 gpu nonrendering" 143e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 153e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 163e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " angle" 173e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 183e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 193e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 203e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " hwui" 213e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 223e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen ; 233e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 243e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic const char configHelp[] = 253e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "Options: 565 8888 debug gpu gpudebug gpudft gpunull " 263e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 " 273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "pdf pdf_poppler skp svg xps" 283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 303e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " angle" 313e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 323e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " angle-gl" 333e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 343e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_COMMAND_BUFFER 353e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " commandbuffer" 363e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 373e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_MESA 383e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " mesa" 393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 403e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 413e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " hwui" 423e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 433e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen " or use extended form 'backend(option=value,...)'.\n"; 443e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 453e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic const char configExtendedHelp[] = 463e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "Extended form: 'backend(option=value,...)'\n\n" 473e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "Possible backends and options:\n" 483e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_SUPPORT_GPU 493e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\n" 503e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "gpu(api=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n" 513e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tapi\ttype: string\tdefault: native.\n" 523e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t Select graphics API to use with gpu backend.\n" 533e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t Options:\n" 543e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" 553e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tgl \t\t\tUse OpenGL.\n" 563e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tgles \t\t\tUse OpenGL ES.\n" 573e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tdebug \t\t\tUse debug OpenGL.\n" 583e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tnull \t\t\tUse null OpenGL.\n" 593e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 603e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 613e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tangle\t\t\tUse ANGLE DirectX.\n" 623e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 633e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n" 643e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 653e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_COMMAND_BUFFER 663e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tcommandbuffer\t\tUse command buffer.\n" 6745c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen "\t\tcommandbuffer3\t\tUse command buffer ES 3.0 (experimental).\n" 683e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 693e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_MESA 703e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t\tmesa\t\t\tUse MESA.\n" 713e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 723e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tdit\ttype: bool\tdefault: false.\n" 733e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t Use device independent text.\n" 743e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tnvpr\ttype: bool\tdefault: false.\n" 753e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" 763e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tsamples\ttype: int\tdefault: 0.\n" 773e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\t Use multisampling with N samples.\n" 783e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\n" 793e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "Predefined configs:\n\n" 803e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tgpu \t= gpu()\n" 813e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tmsaa4 \t= gpu(samples=4)\n" 823e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tmsaa16 \t= gpu(samples=16)\n" 833e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" 843e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" 853e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tgpudft \t= gpu(dit=true)\n" 863e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tgpudebug \t= gpu(api=debug)\n" 873e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tgpunull \t= gpu(api=null)\n" 883e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tdebug \t= gpu(api=debug)\n" 893e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tnullgpu \t= gpu(api=null)\n" 903e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 913e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 923e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tangle \t= gpu(api=angle)\n" 933e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 943e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tangle-gl \t= gpu(api=angle-gl)\n" 953e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 963e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_COMMAND_BUFFER 973e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tcommandbuffer\t= gpu(api=commandbuffer)\n" 983e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 993e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_MESA 1003e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen "\tmesa \t= gpu(api=mesa)\n" 1013e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1023e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1033e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen ; 1043e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 1053e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenDEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp); 1063e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 1073e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic const struct { 1083e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* predefinedConfig; 1093e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* backend; 1103e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* options; 1113e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} gPredefinedConfigs[] = { 1123e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_SUPPORT_GPU 1133e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "gpu", "gpu", "" }, 1143e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "msaa4", "gpu", "samples=4" }, 1153e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "msaa16", "gpu", "samples=16" }, 116e3c2f80006e766eb7e99bc64911243346b3ac6d0kkinnunen { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, 117e3c2f80006e766eb7e99bc64911243346b3ac6d0kkinnunen { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, 1183e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "gpudft", "gpu", "dit=true" }, 1193e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "gpudebug", "gpu", "api=debug" }, 1203e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "gpunull", "gpu", "api=null" }, 1213e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "debug", "gpu", "api=debug" }, 1223e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "nullgpu", "gpu", "api=null" } 1233e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 1243e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 1253e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , { "angle", "gpu", "api=angle" } 1263e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , { "angle-gl", "gpu", "api=angle-gl" } 1283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_COMMAND_BUFFER 1303e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , { "commandbuffer", "gpu", "api=commandbuffer" } 1313e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1323e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_MESA 1333e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , { "mesa", "gpu", "api=mesa" } 1343e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1353e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#else 1363e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen { "", "", "" } 1373e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 1383e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen}; 1393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 1403e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend, 1413e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkTArray<SkString>& viaParts) 1423e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen : fTag(tag) 1433e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fBackend(backend) 1443e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fViaParts(viaParts) { 1453e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 1463e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSkCommandLineConfig::~SkCommandLineConfig() { 1473e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 1483e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 1493e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_SUPPORT_GPU 1503e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSkCommandLineConfigGpu::SkCommandLineConfigGpu( 1513e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkString& tag, const SkTArray<SkString>& viaParts, 1523e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen ContextType contextType, bool useNVPR, bool useDIText, int samples) 1533e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen : SkCommandLineConfig(tag, SkString("gpu"), viaParts) 1543e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fContextType(contextType) 1553e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fUseNVPR(useNVPR) 1563e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fUseDIText(useDIText) 1573e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fSamples(samples) { 1583e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 1593e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic bool parse_option_int(const SkString& value, int* outInt) { 1603e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.isEmpty()) { 1613e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return false; 1623e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1633e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen char* endptr = nullptr; 1643e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen long intValue = strtol(value.c_str(), &endptr, 10); 1653e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (*endptr != '\0') { 1663e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return false; 1673e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1683e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outInt = static_cast<int>(intValue); 1693e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1703e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 1713e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic bool parse_option_bool(const SkString& value, bool* outBool) { 1723e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("true")) { 1733e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outBool = true; 1743e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1753e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1763e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("false")) { 1773e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outBool = false; 1783e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1793e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1803e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return false; 1813e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 1823e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenstatic bool parse_option_gpu_api(const SkString& value, 1833e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkCommandLineConfigGpu::ContextType* outContextType) { 1843e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("native")) { 1853e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kNative_GLContextType; 1863e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1873e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1883e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("gl")) { 1893e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kGL_GLContextType; 1903e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1913e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1923e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("gles")) { 1933e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kGLES_GLContextType; 1943e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1953e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 1963e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("debug")) { 1973e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kDebug_GLContextType; 1983e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 1993e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2003e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("null")) { 2013e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kNull_GLContextType; 2023e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 2033e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2043e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_ANGLE 2053e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#ifdef SK_BUILD_FOR_WIN 2063e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("angle")) { 2073e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kANGLE_GLContextType; 2083e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 2093e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2103e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 2113e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("angle-gl")) { 2123e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kANGLE_GL_GLContextType; 2133e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 2143e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2153e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 2163e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_COMMAND_BUFFER 2173e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("commandbuffer")) { 21845c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen *outContextType = GrContextFactory::kCommandBufferES2_GLContextType; 21945c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen return true; 22045c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen } 22145c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen if (value.equals("commandbuffer3")) { 22245c2c8166bbd84a87e29fdd344b39e36e8a28a3fkkinnunen *outContextType = GrContextFactory::kCommandBufferES3_GLContextType; 2233e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 2243e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2253e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 2263e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_MESA 2273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (value.equals("mesa")) { 2283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen *outContextType = GrContextFactory::kMESA_GLContextType; 2293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return true; 2303e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2313e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 2323e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return false; 2333e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 2343e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 2353e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, 2363e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkTArray<SkString>& vias, 2373e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkString& options) { 2383e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen // Defaults for GPU backend. 2393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool seenAPI = false; 2403e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_GLContextType; 2413e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool seenUseNVPR = false; 2423e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool useNVPR = false; 2433e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool seenUseDIText =false; 2443e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool useDIText = false; 2453e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool seenSamples = false; 2463e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen int samples = 0; 2473e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 2483e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkTArray<SkString> optionParts; 2493e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); 2503e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen for (int i = 0; i < optionParts.count(); ++i) { 2513e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkTArray<SkString> keyValueParts; 2523e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts); 2533e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (keyValueParts.count() != 2) { 2543e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return nullptr; 2553e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2563e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkString& key = keyValueParts[0]; 2573e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkString& value = keyValueParts[1]; 2583e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen bool valueOk = false; 2593e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (key.equals("api") && !seenAPI) { 2603e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen valueOk = parse_option_gpu_api(value, &contextType); 2613e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen seenAPI = true; 2623e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } else if (key.equals("nvpr") && !seenUseNVPR) { 2633e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen valueOk = parse_option_bool(value, &useNVPR); 2643e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen seenUseNVPR = true; 2653e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } else if (key.equals("dit") && !seenUseDIText) { 2663e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen valueOk = parse_option_bool(value, &useDIText); 2673e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen seenUseDIText = true; 2683e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } else if (key.equals("samples") && !seenSamples) { 2693e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen valueOk = parse_option_int(value, &samples); 2703e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen seenSamples = true; 2713e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2723e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (!valueOk) { 2733e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return nullptr; 2743e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2753e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 2763e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText, samples); 2773e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 2783e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 2793e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 2803e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenvoid ParseConfigs(const SkCommandLineFlags::StringArray& configs, 2813e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkCommandLineConfigArray* outResult) { 2823e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen outResult->reset(); 2833e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen for (int i = 0; i < configs.count(); ++i) { 2843e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkString extendedBackend; 2853e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkString extendedOptions; 2863e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkString simpleBackend; 2873e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkTArray<SkString> vias; 2883e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 2893e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkString tag(configs[i]); 2903e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkTArray<SkString> parts; 2913e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(tag.c_str(), "(", kStrict_SkStrSplitMode, &parts); 2923e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (parts.count() == 2) { 2933e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkTArray<SkString> parts2; 2943e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(parts[1].c_str(), ")", kStrict_SkStrSplitMode, &parts2); 2953e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (parts2.count() == 2 && parts2[1].isEmpty()) { 2963e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias); 2973e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (vias.count()) { 2983e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedBackend = vias[vias.count() - 1]; 2993e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen vias.pop_back(); 3003e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } else { 3013e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedBackend = parts[0]; 3023e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3033e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedOptions = parts2[0]; 3043e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen simpleBackend.printf("%s(%s)", extendedBackend.c_str(), extendedOptions.c_str()); 3053e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3063e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3073e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 3083e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (extendedBackend.isEmpty()) { 3093e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen simpleBackend = tag; 3103e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias); 3113e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (vias.count()) { 3123e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen simpleBackend = vias[vias.count() - 1]; 3133e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen vias.pop_back(); 3143e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3153e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen // Note: no #if SK_ANGLE: this is a special rule in the via-tag grammar. 3163e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (vias.count() && simpleBackend.equals("gl") && 3173e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen vias[vias.count() - 1].equals("angle")) { 3183e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen simpleBackend = "angle-gl"; 3193e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen vias.pop_back(); 3203e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3213e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen 3223e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen for (auto& predefinedConfig : gPredefinedConfigs) { 3233e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (simpleBackend.equals(predefinedConfig.predefinedConfig)) { 3243e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedBackend = predefinedConfig.backend; 3253e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedOptions = predefinedConfig.options; 3263e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen break; 3273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3303e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkCommandLineConfig* parsedConfig = nullptr; 3313e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#if SK_SUPPORT_GPU 3323e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (extendedBackend.equals("gpu")) { 3333e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions); 3343e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3353e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#endif 3363e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen if (!parsedConfig) { 3373e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); 3383e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen outResult->emplace_back(parsedConfig); 3403e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 3413e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen} 342