2013-03-04 16:41:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2013-03-21 19:43:15 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2013-04-23 15:38:09 +00:00
|
|
|
#include "SkTDArray.h"
|
2015-01-18 18:39:25 +00:00
|
|
|
#include "SkTSort.h"
|
2013-03-04 16:41:06 +00:00
|
|
|
|
2015-08-26 12:15:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-08-15 17:13:59 +00:00
|
|
|
DEFINE_bool(undefok, false, "Silently ignore unknown flags instead of crashing.");
|
2014-03-25 21:00:02 +00:00
|
|
|
|
2015-05-04 17:54:48 +00:00
|
|
|
template <typename T> static void ignore_result(const T&) {}
|
|
|
|
|
2013-04-24 19:25:26 +00:00
|
|
|
bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName,
|
|
|
|
SkCommandLineFlags::StringArray* pStrings,
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
const char* defaultValue, const char* helpString,
|
|
|
|
const char* extendedHelpString) {
|
|
|
|
SkFlagInfo* info = new SkFlagInfo(name, shortName, kString_FlagType, helpString,
|
|
|
|
extendedHelpString);
|
2013-04-24 19:25:26 +00:00
|
|
|
info->fDefaultString.set(defaultValue);
|
|
|
|
|
|
|
|
info->fStrings = pStrings;
|
|
|
|
SetDefaultStrings(pStrings, defaultValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings,
|
|
|
|
const char* defaultValue) {
|
|
|
|
pStrings->reset();
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == defaultValue) {
|
2013-04-24 19:37:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-04-24 19:25:26 +00:00
|
|
|
// If default is "", leave the array empty.
|
|
|
|
size_t defaultLength = strlen(defaultValue);
|
|
|
|
if (defaultLength > 0) {
|
|
|
|
const char* const defaultEnd = defaultValue + defaultLength;
|
|
|
|
const char* begin = defaultValue;
|
|
|
|
while (true) {
|
|
|
|
while (begin < defaultEnd && ' ' == *begin) {
|
|
|
|
begin++;
|
|
|
|
}
|
|
|
|
if (begin < defaultEnd) {
|
|
|
|
const char* end = begin + 1;
|
|
|
|
while (end < defaultEnd && ' ' != *end) {
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
size_t length = end - begin;
|
|
|
|
pStrings->append(begin, length);
|
|
|
|
begin = end + 1;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 13:10:59 +00:00
|
|
|
static bool string_is_in(const char* target, const char* set[], size_t len) {
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
if (0 == strcmp(target, set[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see whether string represents a boolean value.
|
|
|
|
* @param string C style string to parse.
|
|
|
|
* @param result Pointer to a boolean which will be set to the value in the string, if the
|
|
|
|
* string represents a boolean.
|
|
|
|
* @param boolean True if the string represents a boolean, false otherwise.
|
|
|
|
*/
|
|
|
|
static bool parse_bool_arg(const char* string, bool* result) {
|
|
|
|
static const char* trueValues[] = { "1", "TRUE", "true" };
|
|
|
|
if (string_is_in(string, trueValues, SK_ARRAY_COUNT(trueValues))) {
|
|
|
|
*result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static const char* falseValues[] = { "0", "FALSE", "false" };
|
|
|
|
if (string_is_in(string, falseValues, SK_ARRAY_COUNT(falseValues))) {
|
|
|
|
*result = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkDebugf("Parameter \"%s\" not supported.\n", string);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkFlagInfo::match(const char* string) {
|
|
|
|
if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
|
|
|
|
string++;
|
2013-04-09 21:25:46 +00:00
|
|
|
const SkString* compareName;
|
2013-03-21 13:10:59 +00:00
|
|
|
if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
|
|
|
|
string++;
|
2013-04-09 21:25:46 +00:00
|
|
|
// There were two dashes. Compare against full name.
|
|
|
|
compareName = &fName;
|
|
|
|
} else {
|
|
|
|
// One dash. Compare against the short name.
|
|
|
|
compareName = &fShortName;
|
2013-03-21 13:10:59 +00:00
|
|
|
}
|
|
|
|
if (kBool_FlagType == fFlagType) {
|
|
|
|
// In this case, go ahead and set the value.
|
2013-04-09 21:25:46 +00:00
|
|
|
if (compareName->equals(string)) {
|
2013-03-21 13:10:59 +00:00
|
|
|
*fBoolValue = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkStrStartsWith(string, "no") && strlen(string) > 2) {
|
|
|
|
string += 2;
|
2013-04-09 21:25:46 +00:00
|
|
|
// Only allow "no" to be prepended to the full name.
|
|
|
|
if (fName.equals(string)) {
|
2013-03-21 13:10:59 +00:00
|
|
|
*fBoolValue = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int equalIndex = SkStrFind(string, "=");
|
|
|
|
if (equalIndex > 0) {
|
|
|
|
// The string has an equal sign. Check to see if the string matches.
|
|
|
|
SkString flag(string, equalIndex);
|
2013-04-09 21:25:46 +00:00
|
|
|
if (flag.equals(*compareName)) {
|
2013-03-21 13:10:59 +00:00
|
|
|
// Check to see if the remainder beyond the equal sign is true or false:
|
|
|
|
string += equalIndex + 1;
|
|
|
|
parse_bool_arg(string, fBoolValue);
|
|
|
|
return true;
|
2013-04-09 21:25:46 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2013-03-21 13:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 21:25:46 +00:00
|
|
|
return compareName->equals(string);
|
2013-03-21 13:10:59 +00:00
|
|
|
} else {
|
|
|
|
// Has no dash
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-21 19:43:15 +00:00
|
|
|
SkFlagInfo* SkCommandLineFlags::gHead;
|
|
|
|
SkString SkCommandLineFlags::gUsage;
|
2013-03-04 16:41:06 +00:00
|
|
|
|
2013-03-21 19:43:15 +00:00
|
|
|
void SkCommandLineFlags::SetUsage(const char* usage) {
|
2013-03-04 16:41:06 +00:00
|
|
|
gUsage.set(usage);
|
|
|
|
}
|
|
|
|
|
2016-02-12 22:47:09 +00:00
|
|
|
void SkCommandLineFlags::PrintUsage() {
|
|
|
|
SkDebugf("%s", gUsage.c_str());
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
// Maximum line length for the help message.
|
2015-04-27 13:41:35 +00:00
|
|
|
#define LINE_LENGTH 72
|
2013-03-04 16:41:06 +00:00
|
|
|
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
static void print_indented(const SkString& text) {
|
|
|
|
size_t length = text.size();
|
|
|
|
const char* currLine = text.c_str();
|
2013-03-20 19:50:41 +00:00
|
|
|
const char* stop = currLine + length;
|
|
|
|
while (currLine < stop) {
|
Revert of Add config options to run different GPU APIs to dm and nanobench (patchset #21 id:400001 of https://codereview.chromium.org/1490113005/ )
Reason for revert:
The Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug builder fails after this CL.
Links to specific builds:
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1689
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1690
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1691
Original issue's description:
> Add config options to run different GPU APIs to dm and nanobench
>
> Add extended config specification form that can be used to run different
> gpu backend with different APIs.
>
> The configs can be specified with the form:
> gpu(api=string,dit=bool,nvpr=bool,samples=int)
>
> This replaces and removes the --gpuAPI flag.
>
> All existing configs should still work.
>
> Adds following documentation:
>
> out/Debug/dm --help config
>
> Flags:
> --config: type: string default: 565 8888 gpu nonrendering
> Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
> nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
> xps or use extended form 'backend(option=value,...)'.
>
> Extended form: 'backend(option=value,...)'
>
> Possible backends and options:
>
> gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
> api type: string default: native.
> Select graphics API to use with gpu backend.
> Options:
> native Use platform default OpenGL or OpenGL ES backend.
> gl Use OpenGL.
> gles Use OpenGL ES.
> debug Use debug OpenGL.
> null Use null OpenGL.
> dit type: bool default: false.
> Use device independent text.
> nvpr type: bool default: false.
> Use NV_path_rendering OpenGL and OpenGL ES extension.
> samples type: int default: 0.
> Use multisampling with N samples.
>
> Predefined configs:
>
> gpu = gpu()
> msaa4 = gpu(samples=4)
> msaa16 = gpu(samples=16)
> nvprmsaa4 = gpu(nvpr=true,samples=4)
> nvprmsaa16 = gpu(nvpr=true,samples=16)
> gpudft = gpu(dit=true)
> gpudebug = gpu(api=debug)
> gpunull = gpu(api=null)
> debug = gpu(api=debug)
> nullgpu = gpu(api=null)
>
> BUG=skia:2992
>
> Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
>
> Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
>
> Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
TBR=mtklein@google.com,bsalomon@google.com,joshualitt@google.com,scroggo@google.com,kkinnunen@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:2992
Review URL: https://codereview.chromium.org/1548683002
2015-12-22 18:22:26 +00:00
|
|
|
int lineBreak = SkStrFind(currLine, "\n");
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
if (lineBreak < 0) {
|
|
|
|
lineBreak = static_cast<int>(strlen(currLine));
|
|
|
|
}
|
|
|
|
if (lineBreak > LINE_LENGTH) {
|
2013-03-20 19:50:41 +00:00
|
|
|
// No line break within line length. Will need to insert one.
|
|
|
|
// Find a space before the line break.
|
|
|
|
int spaceIndex = LINE_LENGTH - 1;
|
|
|
|
while (spaceIndex > 0 && currLine[spaceIndex] != ' ') {
|
|
|
|
spaceIndex--;
|
|
|
|
}
|
|
|
|
int gap;
|
|
|
|
if (0 == spaceIndex) {
|
|
|
|
// No spaces on the entire line. Go ahead and break mid word.
|
|
|
|
spaceIndex = LINE_LENGTH;
|
|
|
|
gap = 0;
|
|
|
|
} else {
|
|
|
|
// Skip the space on the next line
|
|
|
|
gap = 1;
|
|
|
|
}
|
2015-04-27 13:41:35 +00:00
|
|
|
SkDebugf(" %.*s\n", spaceIndex, currLine);
|
2013-03-20 19:50:41 +00:00
|
|
|
currLine += spaceIndex + gap;
|
|
|
|
} else {
|
|
|
|
// the line break is within the limit. Break there.
|
|
|
|
lineBreak++;
|
2015-04-27 13:41:35 +00:00
|
|
|
SkDebugf(" %.*s", lineBreak, currLine);
|
2013-03-20 19:50:41 +00:00
|
|
|
currLine += lineBreak;
|
|
|
|
}
|
|
|
|
}
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_help_for_flag(const SkFlagInfo* flag) {
|
|
|
|
SkDebugf(" --%s", flag->name().c_str());
|
|
|
|
const SkString& shortName = flag->shortName();
|
|
|
|
if (shortName.size() > 0) {
|
|
|
|
SkDebugf(" or -%s", shortName.c_str());
|
|
|
|
}
|
|
|
|
SkDebugf(":\ttype: %s", flag->typeAsString().c_str());
|
|
|
|
if (flag->defaultValue().size() > 0) {
|
|
|
|
SkDebugf("\tdefault: %s", flag->defaultValue().c_str());
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
const SkString& help = flag->help();
|
|
|
|
print_indented(help);
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
static void print_extended_help_for_flag(const SkFlagInfo* flag) {
|
|
|
|
print_help_for_flag(flag);
|
|
|
|
print_indented(flag->extendedHelp());
|
2013-03-20 19:50:41 +00:00
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
|
2015-01-18 18:39:25 +00:00
|
|
|
namespace {
|
|
|
|
struct CompareFlagsByName {
|
|
|
|
bool operator()(SkFlagInfo* a, SkFlagInfo* b) const {
|
|
|
|
return strcmp(a->name().c_str(), b->name().c_str()) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2017-09-14 16:12:32 +00:00
|
|
|
void SkCommandLineFlags::Parse(int argc, const char* const * argv) {
|
2013-03-04 16:41:06 +00:00
|
|
|
// Only allow calling this function once.
|
|
|
|
static bool gOnce;
|
|
|
|
if (gOnce) {
|
2013-04-09 21:25:46 +00:00
|
|
|
SkDebugf("Parse should only be called once at the beginning of main!\n");
|
2013-03-04 16:41:06 +00:00
|
|
|
SkASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gOnce = true;
|
|
|
|
|
|
|
|
bool helpPrinted = false;
|
2017-07-06 12:33:19 +00:00
|
|
|
bool flagsPrinted = false;
|
2013-03-04 16:41:06 +00:00
|
|
|
// Loop over argv, starting with 1, since the first is just the name of the program.
|
|
|
|
for (int i = 1; i < argc; i++) {
|
2013-04-09 21:25:46 +00:00
|
|
|
if (0 == strcmp("-h", argv[i]) || 0 == strcmp("--help", argv[i])) {
|
2013-03-04 16:41:06 +00:00
|
|
|
// Print help message.
|
2013-03-20 19:50:41 +00:00
|
|
|
SkTDArray<const char*> helpFlags;
|
|
|
|
for (int j = i + 1; j < argc; j++) {
|
|
|
|
if (SkStrStartsWith(argv[j], '-')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
helpFlags.append(1, &argv[j]);
|
|
|
|
}
|
|
|
|
if (0 == helpFlags.count()) {
|
|
|
|
// Only print general help message if help for specific flags is not requested.
|
|
|
|
SkDebugf("%s\n%s\n", argv[0], gUsage.c_str());
|
|
|
|
}
|
2017-07-06 12:33:19 +00:00
|
|
|
if (!flagsPrinted) {
|
|
|
|
SkDebugf("Flags:\n");
|
|
|
|
flagsPrinted = true;
|
|
|
|
}
|
2015-01-18 18:39:25 +00:00
|
|
|
if (0 == helpFlags.count()) {
|
2013-03-20 19:50:41 +00:00
|
|
|
// If no flags followed --help, print them all
|
2015-01-18 18:39:25 +00:00
|
|
|
SkTDArray<SkFlagInfo*> allFlags;
|
|
|
|
for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
|
|
|
|
flag = flag->next()) {
|
|
|
|
allFlags.push(flag);
|
|
|
|
}
|
|
|
|
SkTQSort(&allFlags[0], &allFlags[allFlags.count() - 1],
|
|
|
|
CompareFlagsByName());
|
|
|
|
for (int i = 0; i < allFlags.count(); ++i) {
|
|
|
|
print_help_for_flag(allFlags[i]);
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
if (allFlags[i]->extendedHelp().size() > 0) {
|
|
|
|
SkDebugf(" Use '--help %s' for more information.\n",
|
|
|
|
allFlags[i]->name().c_str());
|
|
|
|
}
|
2015-01-18 18:39:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
|
|
|
|
flag = flag->next()) {
|
2013-03-20 19:50:41 +00:00
|
|
|
for (int k = 0; k < helpFlags.count(); k++) {
|
|
|
|
if (flag->name().equals(helpFlags[k]) ||
|
|
|
|
flag->shortName().equals(helpFlags[k])) {
|
Add config options to run different GPU APIs to dm and nanobench
Add extended config specification form that can be used to run different
gpu backend with different APIs.
The configs can be specified with the form:
gpu(api=string,dit=bool,nvpr=bool,samples=int)
This replaces and removes the --gpuAPI flag.
All existing configs should still work.
Adds following documentation:
out/Debug/dm --help config
Flags:
--config: type: string default: 565 8888 gpu nonrendering
Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
xps or use extended form 'backend(option=value,...)'.
Extended form: 'backend(option=value,...)'
Possible backends and options:
gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
api type: string default: native.
Select graphics API to use with gpu backend.
Options:
native Use platform default OpenGL or OpenGL ES backend.
gl Use OpenGL.
gles Use OpenGL ES.
debug Use debug OpenGL.
null Use null OpenGL.
dit type: bool default: false.
Use device independent text.
nvpr type: bool default: false.
Use NV_path_rendering OpenGL and OpenGL ES extension.
samples type: int default: 0.
Use multisampling with N samples.
Predefined configs:
gpu = gpu()
msaa4 = gpu(samples=4)
msaa16 = gpu(samples=16)
nvprmsaa4 = gpu(nvpr=true,samples=4)
nvprmsaa16 = gpu(nvpr=true,samples=16)
gpudft = gpu(dit=true)
gpudebug = gpu(api=debug)
gpunull = gpu(api=null)
debug = gpu(api=debug)
nullgpu = gpu(api=null)
BUG=skia:2992
Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
Review URL: https://codereview.chromium.org/1490113005
2015-12-23 09:33:00 +00:00
|
|
|
print_extended_help_for_flag(flag);
|
2013-03-20 19:50:41 +00:00
|
|
|
helpFlags.remove(k);
|
|
|
|
break;
|
2013-03-04 16:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 19:50:41 +00:00
|
|
|
if (helpFlags.count() > 0) {
|
|
|
|
SkDebugf("Requested help for unrecognized flags:\n");
|
|
|
|
for (int k = 0; k < helpFlags.count(); k++) {
|
2015-04-27 13:41:35 +00:00
|
|
|
SkDebugf(" --%s\n", helpFlags[k]);
|
2013-03-20 19:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-04 16:41:06 +00:00
|
|
|
helpPrinted = true;
|
|
|
|
}
|
|
|
|
if (!helpPrinted) {
|
2016-10-24 18:53:08 +00:00
|
|
|
SkFlagInfo* matchedFlag = nullptr;
|
2013-03-04 16:41:06 +00:00
|
|
|
SkFlagInfo* flag = gHead;
|
2016-10-24 18:53:08 +00:00
|
|
|
int startI = i;
|
2015-08-27 14:41:13 +00:00
|
|
|
while (flag != nullptr) {
|
2016-10-24 18:53:08 +00:00
|
|
|
if (flag->match(argv[startI])) {
|
|
|
|
i = startI;
|
|
|
|
if (matchedFlag) {
|
|
|
|
// Don't redefine the same flag with different types.
|
|
|
|
SkASSERT(matchedFlag->getFlagType() == flag->getFlagType());
|
|
|
|
} else {
|
|
|
|
matchedFlag = flag;
|
|
|
|
}
|
2013-03-04 16:41:06 +00:00
|
|
|
switch (flag->getFlagType()) {
|
|
|
|
case SkFlagInfo::kBool_FlagType:
|
2013-03-21 13:10:59 +00:00
|
|
|
// Can be handled by match, above, but can also be set by the next
|
|
|
|
// string.
|
|
|
|
if (i+1 < argc && !SkStrStartsWith(argv[i+1], '-')) {
|
|
|
|
i++;
|
|
|
|
bool value;
|
|
|
|
if (parse_bool_arg(argv[i], &value)) {
|
|
|
|
flag->setBool(value);
|
|
|
|
}
|
|
|
|
}
|
2013-03-04 16:41:06 +00:00
|
|
|
break;
|
|
|
|
case SkFlagInfo::kString_FlagType:
|
|
|
|
flag->resetStrings();
|
|
|
|
// Add all arguments until another flag is reached.
|
2015-02-15 02:56:31 +00:00
|
|
|
while (i+1 < argc) {
|
2015-08-27 14:41:13 +00:00
|
|
|
char* end = nullptr;
|
2015-05-04 17:54:48 +00:00
|
|
|
// Negative numbers aren't flags.
|
|
|
|
ignore_result(strtod(argv[i+1], &end));
|
2015-02-15 02:56:31 +00:00
|
|
|
if (end == argv[i+1] && SkStrStartsWith(argv[i+1], '-')) {
|
|
|
|
break;
|
|
|
|
}
|
2013-03-04 16:41:06 +00:00
|
|
|
i++;
|
|
|
|
flag->append(argv[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SkFlagInfo::kInt_FlagType:
|
|
|
|
i++;
|
|
|
|
flag->setInt(atoi(argv[i]));
|
|
|
|
break;
|
|
|
|
case SkFlagInfo::kDouble_FlagType:
|
|
|
|
i++;
|
|
|
|
flag->setDouble(atof(argv[i]));
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-22 15:37:26 +00:00
|
|
|
SkDEBUGFAIL("Invalid flag type");
|
2013-03-04 16:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
flag = flag->next();
|
|
|
|
}
|
2016-10-24 18:53:08 +00:00
|
|
|
if (!matchedFlag) {
|
2016-07-28 16:58:44 +00:00
|
|
|
#if defined(SK_BUILD_FOR_MAC)
|
2015-06-10 16:31:09 +00:00
|
|
|
if (SkStrStartsWith(argv[i], "NSDocumentRevisions")
|
|
|
|
|| SkStrStartsWith(argv[i], "-NSDocumentRevisions")) {
|
|
|
|
i++; // skip YES
|
2015-01-30 20:37:02 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2015-04-08 15:30:38 +00:00
|
|
|
if (FLAGS_undefok) {
|
|
|
|
SkDebugf("FYI: ignoring unknown flag '%s'.\n", argv[i]);
|
|
|
|
} else {
|
|
|
|
SkDebugf("Got unknown flag '%s'. Exiting.\n", argv[i]);
|
2014-03-25 21:00:02 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2013-03-04 16:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Since all of the flags have been set, release the memory used by each
|
|
|
|
// flag. FLAGS_x can still be used after this.
|
|
|
|
SkFlagInfo* flag = gHead;
|
2015-08-27 14:41:13 +00:00
|
|
|
gHead = nullptr;
|
|
|
|
while (flag != nullptr) {
|
2013-03-04 16:41:06 +00:00
|
|
|
SkFlagInfo* next = flag->next();
|
2015-08-26 20:07:48 +00:00
|
|
|
delete flag;
|
2013-03-04 16:41:06 +00:00
|
|
|
flag = next;
|
|
|
|
}
|
|
|
|
if (helpPrinted) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2013-07-24 17:24:23 +00:00
|
|
|
|
2013-08-30 15:52:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename Strings>
|
|
|
|
bool ShouldSkipImpl(const Strings& strings, const char* name) {
|
2013-07-24 17:24:23 +00:00
|
|
|
int count = strings.count();
|
|
|
|
size_t testLen = strlen(name);
|
|
|
|
bool anyExclude = count == 0;
|
|
|
|
for (int i = 0; i < strings.count(); ++i) {
|
|
|
|
const char* matchName = strings[i];
|
|
|
|
size_t matchLen = strlen(matchName);
|
|
|
|
bool matchExclude, matchStart, matchEnd;
|
|
|
|
if ((matchExclude = matchName[0] == '~')) {
|
|
|
|
anyExclude = true;
|
|
|
|
matchName++;
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if ((matchStart = matchName[0] == '^')) {
|
|
|
|
matchName++;
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if ((matchEnd = matchName[matchLen - 1] == '$')) {
|
|
|
|
matchLen--;
|
|
|
|
}
|
|
|
|
if (matchStart ? (!matchEnd || matchLen == testLen)
|
|
|
|
&& strncmp(name, matchName, matchLen) == 0
|
|
|
|
: matchEnd ? matchLen <= testLen
|
|
|
|
&& strncmp(name + testLen - matchLen, matchName, matchLen) == 0
|
2017-08-28 14:34:05 +00:00
|
|
|
: strstr(name, matchName) != nullptr) {
|
2013-07-24 17:24:23 +00:00
|
|
|
return matchExclude;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !anyExclude;
|
|
|
|
}
|
2013-08-30 15:52:46 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) {
|
|
|
|
return ShouldSkipImpl(strings, name);
|
|
|
|
}
|
|
|
|
bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name) {
|
|
|
|
return ShouldSkipImpl(strings, name);
|
|
|
|
}
|