Replace SK_ARRAY_COUNT with std::size() for skia/tools

Change-Id: I7db855e675b2ece5d3cf6f237beae3294ffa1e72
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/553589
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-06-28 08:27:35 -04:00 committed by SkCQ
parent e0f153ee85
commit b780fc21c3
25 changed files with 48 additions and 46 deletions

View File

@ -9,6 +9,7 @@
#include "src/core/SkLeanWindows.h"
#include <array> // for std::size
#include <stdlib.h>
#if defined(SK_BUILD_FOR_GOOGLE3)
@ -101,7 +102,7 @@
backtrace_request();
#else
void* stack[64];
const int count = backtrace(stack, SK_ARRAY_COUNT(stack));
const int count = backtrace(stack, std::size(stack));
char** symbols = backtrace_symbols(stack, count);
SkDebugf("\nSignal %d [%s]:\n", sig, strsignal(sig));
@ -109,7 +110,7 @@
Dl_info info;
if (dladdr(stack[i], &info) && info.dli_sname) {
char demangled[256];
size_t len = SK_ARRAY_COUNT(demangled);
size_t len = std::size(demangled);
int ok;
abi::__cxa_demangle(info.dli_sname, demangled, &len, &ok);
@ -170,7 +171,7 @@
static LONG WINAPI handler(EXCEPTION_POINTERS* e) {
const DWORD code = e->ExceptionRecord->ExceptionCode;
SkDebugf("\nCaught exception %lu", code);
for (size_t i = 0; i < SK_ARRAY_COUNT(kExceptions); i++) {
for (size_t i = 0; i < std::size(kExceptions); i++) {
if (kExceptions[i].code == code) {
SkDebugf(" %s", kExceptions[i].name);
}

View File

@ -159,7 +159,7 @@ bool HashAndEncode::encodePNG(SkWStream* st,
text[1].key = (png_charp)"Description";
text[1].text = (png_charp)description.c_str();
text[1].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png, info, text, SK_ARRAY_COUNT(text));
png_set_text(png, info, text, std::size(text));
png_set_IHDR(png, info, (png_uint_32)fSize.width()
, (png_uint_32)fSize.height()

View File

@ -62,9 +62,9 @@ struct Stats {
double s = samples[i];
s -= min;
s /= (max - min);
s *= (SK_ARRAY_COUNT(kBars) - 1);
s *= (std::size(kBars) - 1);
const size_t bar = (size_t)(s + 0.5);
SkASSERT_RELEASE(bar < SK_ARRAY_COUNT(kBars));
SkASSERT_RELEASE(bar < std::size(kBars));
plot.append(kBars[bar]);
}
}

View File

@ -76,12 +76,12 @@ static bool string_is_in(const char* target, const char* set[], size_t len) {
*/
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))) {
if (string_is_in(string, trueValues, std::size(trueValues))) {
*result = true;
return true;
}
static const char* falseValues[] = {"0", "FALSE", "false"};
if (string_is_in(string, falseValues, SK_ARRAY_COUNT(falseValues))) {
if (string_is_in(string, falseValues, std::size(falseValues))) {
*result = false;
return true;
}

View File

@ -209,7 +209,7 @@ static void init(Source* source, sk_sp<skottie::Animation> animation) {
// Draw frames in a shuffled order to exercise nonlinear frame progression.
// The film strip will still be in time order, just drawn out of order.
const int order[] = { 4, 0, 3, 1, 2 };
const int tiles = SK_ARRAY_COUNT(order);
const int tiles = std::size(order);
const float dim = 1000.0f / tiles;
const float dt = 1.0f / (tiles*tiles - 1);

View File

@ -254,7 +254,7 @@ static void output_font(sk_sp<SkTypeface> face, const char* identifier, FILE* ou
widthsStr = strip_final(widthsStr);
fprintf(out, "%s\n};\n\n", widthsStr.c_str());
fprintf(out, "const size_t %sCharCodesCount = SK_ARRAY_COUNT(%sCharCodes);\n\n",
fprintf(out, "const size_t %sCharCodesCount = std::size(%sCharCodes);\n\n",
identifier, identifier);
SkFontMetrics metrics;

View File

@ -1190,7 +1190,7 @@ const SkFixed LiberationMonoNormalWidths[] = {
0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0
};
const size_t LiberationMonoNormalCharCodesCount = SK_ARRAY_COUNT(LiberationMonoNormalCharCodes);
const size_t LiberationMonoNormalCharCodesCount = std::size(LiberationMonoNormalCharCodes);
const SkFontMetrics LiberationMonoNormalMetrics = {
0x0000000f, -0.83252f, -0.83252f, 0.300293f, 0.300293f, 0, 0.600098f, 0.633301f, -0.0244141f,
@ -2340,7 +2340,7 @@ const SkFixed LiberationMonoBoldWidths[] = {
0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0
};
const size_t LiberationMonoBoldCharCodesCount = SK_ARRAY_COUNT(LiberationMonoBoldCharCodes);
const size_t LiberationMonoBoldCharCodesCount = std::size(LiberationMonoBoldCharCodes);
const SkFontMetrics LiberationMonoBoldMetrics = {
0x0000000f, -0.833496f, -0.833496f, 0.300293f, 0.300293f, 0, 0.600098f, 0.641602f, -0.0268555f,
@ -3606,7 +3606,7 @@ const SkFixed LiberationMonoItalicWidths[] = {
0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0
};
const size_t LiberationMonoItalicCharCodesCount = SK_ARRAY_COUNT(LiberationMonoItalicCharCodes);
const size_t LiberationMonoItalicCharCodesCount = std::size(LiberationMonoItalicCharCodes);
const SkFontMetrics LiberationMonoItalicMetrics = {
0x0000000f, -0.833496f, -0.833496f, 0.300293f, 0.300293f, 0, 0.600098f, 0.798828f, -0.0942383f,
@ -4839,7 +4839,7 @@ const SkFixed LiberationMonoBoldItalicWidths[] = {
0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0, 0x000099a0
};
const size_t LiberationMonoBoldItalicCharCodesCount = SK_ARRAY_COUNT(LiberationMonoBoldItalicCharCodes);
const size_t LiberationMonoBoldItalicCharCodesCount = std::size(LiberationMonoBoldItalicCharCodes);
const SkFontMetrics LiberationMonoBoldItalicMetrics = {
0x0000000f, -0.83252f, -0.83252f, 0.300293f, 0.300293f, 0, 0.600098f, 0.791992f, -0.0942383f,

View File

@ -1184,7 +1184,7 @@ const SkFixed LiberationSansNormalWidths[] = {
0x00008000, 0x00005580, 0x00004280, 0x00005580, 0x00009580
};
const size_t LiberationSansNormalCharCodesCount = SK_ARRAY_COUNT(LiberationSansNormalCharCodes);
const size_t LiberationSansNormalCharCodesCount = std::size(LiberationSansNormalCharCodes);
const SkFontMetrics LiberationSansNormalMetrics = {
0x0000000f, -0.910156f, -0.905273f, 0.211914f, 0.303223f, 0.0327148f, 0.589355f, 1.25342f,
@ -2348,7 +2348,7 @@ const SkFixed LiberationSansBoldWidths[] = {
0x00008000, 0x000063a0, 0x000047a0, 0x000063a0, 0x00009580
};
const size_t LiberationSansBoldCharCodesCount = SK_ARRAY_COUNT(LiberationSansBoldCharCodes);
const size_t LiberationSansBoldCharCodesCount = std::size(LiberationSansBoldCharCodes);
const SkFontMetrics LiberationSansBoldMetrics = {
0x0000000f, -1.0332f, -0.905273f, 0.211914f, 0.303223f, 0.0327148f, 0.612305f, 1.24609f,
@ -3589,7 +3589,7 @@ const SkFixed LiberationSansItalicWidths[] = {
0x00008000, 0x00005580, 0x00004280, 0x00005580, 0x00009580
};
const size_t LiberationSansItalicCharCodesCount = SK_ARRAY_COUNT(LiberationSansItalicCharCodes);
const size_t LiberationSansItalicCharCodesCount = std::size(LiberationSansItalicCharCodes);
const SkFontMetrics LiberationSansItalicMetrics = {
0x0000000f, -1.01416f, -0.905273f, 0.211914f, 0.303223f, 0.0327148f, 0.590332f, 1.33447f,
@ -4849,7 +4849,7 @@ const SkFixed LiberationSansBoldItalicWidths[] = {
0x00008000, 0x000063a0, 0x000047a0, 0x000063a0, 0x00009580
};
const size_t LiberationSansBoldItalicCharCodesCount = SK_ARRAY_COUNT(LiberationSansBoldItalicCharCodes);
const size_t LiberationSansBoldItalicCharCodesCount = std::size(LiberationSansBoldItalicCharCodes);
const SkFontMetrics LiberationSansBoldItalicMetrics = {
0x0000000f, -1.02979f, -0.905273f, 0.211914f, 0.303223f, 0.0327148f, 0.61377f, 1.3374f,

View File

@ -1261,7 +1261,7 @@ const SkFixed LiberationSerifNormalWidths[] = {
0x000071a0, 0x00007ae0, 0x00003340, 0x00007ae0, 0x00008a80
};
const size_t LiberationSerifNormalCharCodesCount = SK_ARRAY_COUNT(LiberationSerifNormalCharCodes);
const size_t LiberationSerifNormalCharCodesCount = std::size(LiberationSerifNormalCharCodes);
const SkFontMetrics LiberationSerifNormalMetrics = {
0x0000000f, -0.981445f, -0.891113f, 0.216309f, 0.303223f, 0.0424805f, 0.567383f, 1.18359f,
@ -2511,7 +2511,7 @@ const SkFixed LiberationSerifBoldWidths[] = {
0x000071a0, 0x000064e0, 0x00003860, 0x000064e0, 0x00008520
};
const size_t LiberationSerifBoldCharCodesCount = SK_ARRAY_COUNT(LiberationSerifBoldCharCodes);
const size_t LiberationSerifBoldCharCodesCount = std::size(LiberationSerifBoldCharCodes);
const SkFontMetrics LiberationSerifBoldMetrics = {
0x0000000f, -1.00781f, -0.891113f, 0.216309f, 0.303223f, 0.0424805f, 0.59375f, 1.26709f,
@ -3829,7 +3829,7 @@ const SkFixed LiberationSerifItalicWidths[] = {
0x000063a0, 0x00006660, 0x00004660, 0x00006660, 0x00008a80
};
const size_t LiberationSerifItalicCharCodesCount = SK_ARRAY_COUNT(LiberationSerifItalicCharCodes);
const size_t LiberationSerifItalicCharCodesCount = std::size(LiberationSerifItalicCharCodes);
const SkFontMetrics LiberationSerifItalicMetrics = {
0x0000000f, -0.980957f, -0.891113f, 0.216309f, 0.303223f, 0.0424805f, 0.559082f, 1.26465f,
@ -5141,7 +5141,8 @@ const SkFixed LiberationSerifBoldItalicWidths[] = {
0x000063a0, 0x00005920, 0x00003860, 0x00005920, 0x000091e0
};
const size_t LiberationSerifBoldItalicCharCodesCount = SK_ARRAY_COUNT(LiberationSerifBoldItalicCharCodes);
const size_t LiberationSerifBoldItalicCharCodesCount
= std::size(LiberationSerifBoldItalicCharCodes);
const SkFontMetrics LiberationSerifBoldItalicMetrics = {
0x0000000f, -0.980957f, -0.891113f, 0.216309f, 0.303223f, 0.0424805f, 0.578125f, 1.32861f,

View File

@ -94,7 +94,7 @@ void GrDrawRandomOp(SkRandom* random, skgpu::v1::SurfaceDrawContext* sdc, GrPain
DRAW_OP_TEST_ENTRY(TriangulatingPathOp),
};
static constexpr size_t kTotal = SK_ARRAY_COUNT(gFactories);
static constexpr size_t kTotal = std::size(gFactories);
uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
auto op = gFactories[index](std::move(paint),
random,

View File

@ -55,7 +55,7 @@ void TestContext::flushAndWaitOnSync(GrDirectContext* context) {
context->flush(flushInfo);
context->submit();
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers);
}
void TestContext::testAbandon() {

View File

@ -211,7 +211,7 @@ std::unique_ptr<LazyYUVImage> LazyYUVImage::Make(SkYUVAPixmaps pixmaps,
sk_sp<SkImage> LazyYUVImage::refImage(GrRecordingContext* rContext, Type type) {
if (this->ensureYUVImage(rContext, type)) {
size_t idx = static_cast<size_t>(type);
SkASSERT(idx < SK_ARRAY_COUNT(fYUVImage));
SkASSERT(idx < std::size(fYUVImage));
return fYUVImage[idx];
} else {
return nullptr;
@ -261,7 +261,7 @@ bool LazyYUVImage::reset(SkYUVAPixmaps pixmaps, GrMipmapped mipmapped, sk_sp<SkC
bool LazyYUVImage::ensureYUVImage(GrRecordingContext* rContext, Type type) {
size_t idx = static_cast<size_t>(type);
SkASSERT(idx < SK_ARRAY_COUNT(fYUVImage));
SkASSERT(idx < std::size(fYUVImage));
if (fYUVImage[idx] && fYUVImage[idx]->isValid(rContext)) {
return true; // Have already made a YUV image valid for this context.
}

View File

@ -83,7 +83,7 @@ EGLGLTestContext::EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext*
kGLES_GrGLStandard,
};
size_t apiLimit = SK_ARRAY_COUNT(kStandards);
size_t apiLimit = std::size(kStandards);
size_t api = 0;
if (forcedGpuAPI == kGL_GrGLStandard) {
apiLimit = 1;

View File

@ -105,7 +105,7 @@ static int should_include_debug_layer(const char* layerName,
static void print_backtrace() {
#if defined(SK_BUILD_FOR_UNIX)
void* stack[64];
int count = backtrace(stack, SK_ARRAY_COUNT(stack));
int count = backtrace(stack, std::size(stack));
backtrace_symbols_fd(stack, count, 2);
#else
// Please add implementations for other platforms.
@ -186,7 +186,7 @@ static bool init_instance_extensions_and_layers(PFN_vkGetInstanceProcAddr getIns
}
uint32_t nonPatchVersion = remove_patch_version(specVersion);
for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) {
for (size_t i = 0; i < std::size(kDebugLayerNames); ++i) {
int idx = should_include_debug_layer(kDebugLayerNames[i], layerCount, layers,
nonPatchVersion);
if (idx != -1) {
@ -275,7 +275,7 @@ static bool init_device_extensions_and_layers(GrVkGetProc getProc, uint32_t spec
}
uint32_t nonPatchVersion = remove_patch_version(specVersion);
for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) {
for (size_t i = 0; i < std::size(kDebugLayerNames); ++i) {
int idx = should_include_debug_layer(kDebugLayerNames[i], layerCount, layers,
nonPatchVersion);
if (idx != -1) {

View File

@ -43,7 +43,7 @@ void GraphiteTestContext::submitRecordingAndWaitOnSync(skgpu::graphite::Context*
context->submit(skgpu::graphite::SyncToCpu::kNo);
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers);
}
} // namespace skiatest::graphite

View File

@ -36,7 +36,7 @@ static void add_white(SkRandom* rand, SkString* atom) {
}
int reps = rand->nextRangeU(0, 2);
for (int rep = 0; rep < reps; ++rep) {
int index = rand->nextRangeU(0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1);
int index = rand->nextRangeU(0, (int) std::size(gWhiteSpace) - 1);
if (gWhiteSpace[index]) {
atom->append(&gWhiteSpace[index], 1);
}
@ -67,7 +67,7 @@ static void add_some_white(SkRandom* rand, SkString* atom) {
SkString MakeRandomParsePathPiece(SkRandom* rand) {
SkString atom;
int legalIndex = rand->nextRangeU(0, (int) SK_ARRAY_COUNT(gLegal) - 1);
int legalIndex = rand->nextRangeU(0, (int) std::size(gLegal) - 1);
const Legal& legal = gLegal[legalIndex];
gEasy ? atom.append("\n") : add_white(rand, &atom);
char symbol = legal.fSymbol | (rand->nextBool() ? 0x20 : 0);

View File

@ -33,7 +33,7 @@ void android_main(struct android_app* state) {
// "--atrace",
};
std::unique_ptr<Application> vkApp(Application::Create(SK_ARRAY_COUNT(gCmdLine),
std::unique_ptr<Application> vkApp(Application::Create(std::size(gCmdLine),
const_cast<char**>(gCmdLine),
state));

View File

@ -214,7 +214,7 @@ void* SkiaAndroidApp::pthread_main(void* arg) {
// "--atrace",
};
skiaAndroidApp->fApp = Application::Create(SK_ARRAY_COUNT(gCmdLine),
skiaAndroidApp->fApp = Application::Create(std::size(gCmdLine),
const_cast<char**>(gCmdLine),
skiaAndroidApp);

View File

@ -237,7 +237,7 @@ static skui::Key get_key(unsigned short vk) {
{ kVK_ANSI_Z, skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
for (size_t i = 0; i < std::size(gPair); i++) {
if (gPair[i].fVK == vk) {
return gPair[i].fKey;
}

View File

@ -74,7 +74,7 @@ bool Window_unix::initWindow(Display* display) {
};
SkASSERT(nullptr == fVisualInfo);
if (fRequestedDisplayParams.fMSAASampleCount > 1) {
static const GLint kChooseFBConifgAttCnt = SK_ARRAY_COUNT(kChooseFBConfigAtt);
static const GLint kChooseFBConifgAttCnt = std::size(kChooseFBConfigAtt);
GLint msaaChooseFBConfigAtt[kChooseFBConifgAttCnt + 4];
memcpy(msaaChooseFBConfigAtt, kChooseFBConfigAtt, sizeof(kChooseFBConfigAtt));
SkASSERT(None == msaaChooseFBConfigAtt[kChooseFBConifgAttCnt - 1]);
@ -88,7 +88,7 @@ bool Window_unix::initWindow(Display* display) {
if (n > 0) {
fVisualInfo = glXGetVisualFromFBConfig(fDisplay, *fFBConfig);
} else {
static const GLint kChooseVisualAttCnt = SK_ARRAY_COUNT(chooseVisualAtt);
static const GLint kChooseVisualAttCnt = std::size(chooseVisualAtt);
GLint msaaChooseVisualAtt[kChooseVisualAttCnt + 4];
memcpy(msaaChooseVisualAtt, chooseVisualAtt, sizeof(chooseVisualAtt));
SkASSERT(None == msaaChooseVisualAtt[kChooseVisualAttCnt - 1]);
@ -219,7 +219,7 @@ static skui::Key get_key(KeySym keysym) {
{ 'y', skui::Key::kY },
{ 'z', skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
for (size_t i = 0; i < std::size(gPair); i++) {
if (gPair[i].fXK == keysym) {
return gPair[i].fKey;
}
@ -238,7 +238,7 @@ static skui::ModifierKey get_modifiers(const XEvent& event) {
};
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
for (size_t i = 0; i < SK_ARRAY_COUNT(gModifiers); ++i) {
for (size_t i = 0; i < std::size(gModifiers); ++i) {
if (event.xkey.state & gModifiers[i].fXMask) {
modifiers |= gModifiers[i].fSkMask;
}

View File

@ -152,7 +152,7 @@ static skui::Key get_key(WPARAM vk) {
{ 'Y', skui::Key::kY },
{ 'Z', skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
for (size_t i = 0; i < std::size(gPair); i++) {
if (gPair[i].fVK == vk) {
return gPair[i].fKey;
}

View File

@ -38,7 +38,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
char* argv[4096];
int argc = 0;
TCHAR exename[1024], *next;
int exenameLen = GetModuleFileName(nullptr, exename, SK_ARRAY_COUNT(exename));
int exenameLen = GetModuleFileName(nullptr, exename, std::size(exename));
// we're ignoring the possibility that the exe name exceeds the exename buffer
(void)exenameLen;
argv[argc++] = tchar_to_utf8(exename);

View File

@ -760,6 +760,6 @@ sk_gpu_test::FlushFinishTracker* GpuSync::newFlushTracker(GrDirectContext* conte
// callback on the flush call. The finish callback will unref the tracker when called.
tracker->ref();
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers);
return tracker;
}

View File

@ -34,7 +34,7 @@ void SkSLDebuggerSlide::unload() {
}
void SkSLDebuggerSlide::showLoadTraceGUI() {
ImGui::InputText("Trace Path", fTraceFile, SK_ARRAY_COUNT(fTraceFile));
ImGui::InputText("Trace Path", fTraceFile, std::size(fTraceFile));
bool load = ImGui::Button("Load Debug Trace");
if (load) {

View File

@ -1075,7 +1075,7 @@ void Viewer::updateTitle() {
if (ColorMode::kLegacy != fColorMode) {
int curPrimaries = -1;
for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
for (size_t i = 0; i < std::size(gNamedPrimaries); ++i) {
if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
curPrimaries = i;
break;
@ -2467,7 +2467,7 @@ void Viewer::drawImGui() {
// Pick from common gamuts:
int primariesIdx = 4; // Default: Custom
for (size_t i = 0; i < SK_ARRAY_COUNT(gNamedPrimaries); ++i) {
for (size_t i = 0; i < std::size(gNamedPrimaries); ++i) {
if (primaries_equal(*gNamedPrimaries[i].fPrimaries, fColorSpacePrimaries)) {
primariesIdx = i;
break;