refactor: resolve Sonar cpp:S5945 findings (#5897)

This commit is contained in:
Dave Lane authored and GitHub committed 2026-10-11 10:12:57 -04:00
1 parent 88428ca4ee
commit 31392866b1
43 files changed
+858 -524

No files matched your search

+20 -19
View File
@@ -3,6 +3,7 @@
* @brief Definitions for graphics related functions.
*/
// standard includes
#include <array>
#include <fcntl.h>
#include <future>
#include <stdexcept>
@@ -85,7 +86,7 @@ namespace gl {
ctx.GenTextures(textures.size(), textures.begin());
float color[] = {0.0f, 0.0f, 0.0f, 1.0f};
std::array<float, 4> color = {0.0f, 0.0f, 0.0f, 1.0f};
for (auto tex : textures) {
gl::ctx.BindTexture(GL_TEXTURE_2D, tex);
@@ -93,7 +94,7 @@ namespace gl {
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // y
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl::ctx.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl::ctx.TexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
gl::ctx.TexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color.data());
}
return textures;
@@ -548,7 +549,7 @@ namespace egl {
BOOST_LOG(debug) << "EGL: ["sv << vendor << "]: version ["sv << version << ']';
BOOST_LOG(debug) << "API's supported: ["sv << apis << ']';
const char *extensions[] {
std::array<const char *, 4> extensions {
"EGL_KHR_create_context",
"EGL_KHR_surfaceless_context",
"EGL_EXT_image_dma_buf_import",
@@ -571,7 +572,7 @@ namespace egl {
std::optional<ctx_t> make_ctx(display_t::pointer display) {
bool nice_warning = false;
constexpr int conf_attr[] {
constexpr std::array<int, 3> conf_attr {
EGL_RENDERABLE_TYPE,
EGL_OPENGL_BIT,
EGL_NONE
@@ -579,7 +580,7 @@ namespace egl {
int count;
EGLConfig conf;
if (!eglChooseConfig(display, conf_attr, &conf, 1, &count)) {
if (!eglChooseConfig(display, conf_attr.data(), &conf, 1, &count)) {
BOOST_LOG(error) << "Couldn't set config attributes: ["sv << util::hex(eglGetError()).to_string_view() << ']';
return std::nullopt;
}
@@ -817,8 +818,8 @@ namespace egl {
GLenum attachment = GL_COLOR_ATTACHMENT0;
gl::ctx.DrawBuffers(1, &attachment);
const GLuint rgb_black[] = {0, 0, 0, 0};
gl::ctx.ClearBufferuiv(GL_COLOR, 0, rgb_black);
const std::array<GLuint, 4> rgb_black = {0, 0, 0, 0};
gl::ctx.ClearBufferuiv(GL_COLOR, 0, rgb_black.data());
gl_drain_errors;
@@ -826,8 +827,8 @@ namespace egl {
}
// Constants for clear black color Y, U, V. U & V are same so:
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f}; ///< Y black.
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f}; ///< Uv black.
const std::array<float, 4> y_black = {0.0f, 0.0f, 0.0f, 0.0f}; ///< Y black.
const std::array<float, 4> uv_black = {0.5f, 0.5f, 0.5f, 0.5f}; ///< Uv black.
/**
* @brief Bind NV12 target framebuffers to their Y and UV plane textures.
@@ -840,7 +841,7 @@ namespace egl {
for (size_t x = 0; x < attachments.size(); ++x) {
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, nv12->buf[x]);
gl::ctx.DrawBuffers(1, &attachments[x]);
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black.data() : uv_black.data());
}
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -859,7 +860,7 @@ namespace egl {
for (size_t x = 0; x < attachments.size(); ++x) {
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, yuv444->buf[x]);
gl::ctx.DrawBuffers(1, &attachments[x]);
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black.data() : uv_black.data());
}
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -1069,7 +1070,7 @@ namespace egl {
void sws_t::apply_colorspace(const video::sunshine_colorspace_t &colorspace, bool is_yuv444) {
auto color_p = video::color_vectors_from_colorspace(colorspace, true);
std::string_view members[] {
std::array<std::string_view, 5> members {
util::view(color_p->color_vec_y),
util::view(color_p->color_vec_u),
util::view(color_p->color_vec_v),
@@ -1077,7 +1078,7 @@ namespace egl {
util::view(color_p->range_uv),
};
color_matrix.update(members, sizeof(members) / sizeof(decltype(members[0])));
color_matrix.update(members.data(), members.size());
int planesCount = is_yuv444 ? 3 : 2;
@@ -1486,14 +1487,14 @@ namespace egl {
int sws_t::convert_nv12(gl::frame_buf_t &fb) {
gl::ctx.BindTexture(GL_TEXTURE_2D, loaded_texture);
GLenum attachments[] {
std::array<GLenum, 2> attachments {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1
};
int attachmentsCount = sizeof(attachments) / sizeof(decltype(attachments[0]));
int attachmentsCount = attachments.size();
int drawBuffers = draw_programs_to_buffers(attachments, fb, attachmentsCount, false);
int drawBuffers = draw_programs_to_buffers(attachments.data(), fb, attachmentsCount, false);
if (drawBuffers < 0) {
return -1;
}
@@ -1508,15 +1509,15 @@ namespace egl {
int sws_t::convert_yuv444(gl::frame_buf_t &fb) {
gl::ctx.BindTexture(GL_TEXTURE_2D, loaded_texture);
GLenum attachments[] {
std::array<GLenum, 3> attachments {
GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1,
GL_COLOR_ATTACHMENT2
};
int attachmentsCount = sizeof(attachments) / sizeof(decltype(attachments[0]));
int attachmentsCount = attachments.size();
int drawBuffers = draw_programs_to_buffers(attachments, fb, attachmentsCount, true);
int drawBuffers = draw_programs_to_buffers(attachments.data(), fb, attachmentsCount, true);
if (drawBuffers < 0) {
return -1;
}