1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2020 LunarG, Inc.
** Copyright (c) 2019-2021 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
** to deal in the Software without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Software, and to permit persons to whom the
** Software is furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
*/
#include "options.h"
#include "util/platform.h"
#include "util/logging.h"
#include <sstream>
#include <algorithm>
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(util)
std::vector<FrameRange> GetFrameRanges(const std::string& args)
{
std::vector<FrameRange> ranges;
std::istringstream value_input;
value_input.str(args);
for (std::string range; std::getline(value_input, range, ',');)
{
if (range.empty() || (std::count(range.begin(), range.end(), '-') > 1))
{
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\"", range.c_str());
continue;
}
// Remove whitespace.
range.erase(std::remove_if(range.begin(), range.end(), ::isspace), range.end());
// Split string on '-' delimiter.
bool invalid = false;
std::vector<std::string> values;
std::istringstream range_input;
range_input.str(range);
for (std::string value; std::getline(range_input, value, '-');)
{
if (value.empty())
{
break;
}
// Check that the value string only contains numbers.
size_t count = std::count_if(value.begin(), value.end(), ::isdigit);
if (count == value.length())
{
values.push_back(value);
}
else
{
GFXRECON_LOG_WARNING(
"Ignoring invalid screenshot frame range \"%s\", which contains non-numeric values", range.c_str());
invalid = true;
break;
}
}
if (!invalid)
{
FrameRange screenshot_range;
if (values.size() == 1)
{
if (std::count(range.begin(), range.end(), '-') == 0)
{
screenshot_range.first = std::stoi(values[0]);
screenshot_range.last = screenshot_range.first;
}
else
{
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\"", range.c_str());
continue;
}
}
else if (values.size() == 2)
{
screenshot_range.first = std::stoi(values[0]);
screenshot_range.last = std::stoi(values[1]);
if (screenshot_range.first > screenshot_range.last)
{
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\", where first frame is "
"greater than last frame",
range.c_str());
continue;
}
}
else
{
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\"", range.c_str());
continue;
}
// Check for invalid start frame of 0.
if (screenshot_range.first == 0)
{
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\", with first frame equal to zero",
range.c_str());
continue;
}
uint32_t next_allowed = 0;
// Check that first frame is outside the bounds of the previous range.
if (!ranges.empty())
{
// The number of the frame after the last frame of the last range.
next_allowed = ranges.back().last + 1;
}
if (screenshot_range.first >= next_allowed)
{
ranges.emplace_back(std::move(screenshot_range));
}
else
{
const auto& back = ranges.back();
GFXRECON_LOG_WARNING("Ignoring invalid screenshot frame range \"%s\", "
"where start frame precedes the end of the previous range \"%u-%u\"",
range.c_str(),
back.first,
back.last);
}
}
}
return ranges;
}
bool ParseBoolString(const std::string& value_string, bool default_value)
{
bool result = default_value;
// Checking for "false" or zero, or "true" or a non-zero number.
if ((gfxrecon::util::platform::StringCompareNoCase("true", value_string.c_str()) == 0) ||
(atoi(value_string.c_str()) != 0))
{
result = true;
}
else if ((gfxrecon::util::platform::StringCompareNoCase("false", value_string.c_str()) == 0) ||
(value_string == "0"))
{
result = false;
}
else
{
if (!value_string.empty())
{
GFXRECON_LOG_WARNING("Settings Loader: Ignoring unrecognized Boolean option value \"%s\"",
value_string.c_str());
}
}
return result;
}
uint32_t ParseUintString(const std::string& value_string, uint32_t default_value)
{
auto result = default_value;
try
{
if (!value_string.empty())
{
result = std::stoul(value_string);
}
}
catch (...)
{
result = default_value;
GFXRECON_LOG_WARNING("Settings Loader: Ignoring unrecognized unsigned int option value \"%s\"",
value_string.c_str());
}
return result;
}
GFXRECON_END_NAMESPACE(util)
GFXRECON_END_NAMESPACE(gfxrecon)
|