From e4b97293f27135c34c758920915f9fc07d23add5 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Sun, 19 Jan 2025 22:47:47 +0500 Subject: [PATCH 01/14] clang-tidy --- .clang-tidy | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..f0dfdf1 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,101 @@ +WarningsAsErrors: '*' +HeaderFilterRegex: '.*\.hpp' +FormatStyle: file +Checks: > + -*, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-forward-declararion-namespace, + -bugprone-forward-declararion-namespace, + -bugprone-macro-parentheses, + -bugprone-narrowing-conversions, + -bugprone-branch-clone, + -bugprone-assignment-in-if-condition, + concurrency-*, + -concurrency-mt-unsafe, + cppcoreguidelines-*, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-avoid-const-or-ref-data-members, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-special-member-functions, + -cppcoreguidelines-explicit-virtual-functions, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-narrowing-conversions, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-macro-to-enum, + -cppcoreguidelines-init-variables, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-pro-type-reinterpret-cast, + google-global-names-in-headers, + -google-readability-casting, + google-runtime-operator, + misc-*, + -misc-unused-parameters, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-include-cleaner, + -misc-use-anonymous-namespace, + -misc-const-correctness, + modernize-*, + -modernize-return-braced-init-list, + -modernize-use-trailing-return-type, + -modernize-use-using, + -modernize-use-override, + -modernize-avoid-c-arrays, + -modernize-macro-to-enum, + -modernize-loop-convert, + -modernize-use-nodiscard, + -modernize-pass-by-value, + -modernize-use-auto, + performance-*, + -performance-avoid-endl, + -performance-unnecessary-value-param, + portability-std-allocator-const, + readability-*, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-magic-numbers, + -readability-uppercase-literal-suffix, + -readability-braces-around-statements, + -readability-redundant-access-specifiers, + -readability-else-after-return, + -readability-container-data-pointer, + -readability-implicit-bool-conversion, + -readability-avoid-nested-conditional-operator, + -readability-redundant-member-init, + -readability-redundant-string-init, + -readability-avoid-const-params-in-decls, + -readability-named-parameter, + -readability-convert-member-functions-to-static, + -readability-qualified-auto, + -readability-make-member-function-const, + -readability-isolate-declaration, + -readability-inconsistent-declaration-parameter-name, + -clang-diagnostic-error, + +CheckOptions: + performance-for-range-copy.WarnOnAllAutoCopies: true + performance-inefficient-string-concatenation.StrictMode: true + readability-braces-around-statements.ShortStatementLines: 0 + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ClassIgnoredRegexp: I.* + readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!? + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.EnumPrefix: e + readability-identifier-naming.EnumConstantCase: UPPER_CASE + readability-identifier-naming.FunctionCase: camelBack + readability-identifier-naming.NamespaceCase: CamelCase + readability-identifier-naming.NamespacePrefix: N + readability-identifier-naming.StructPrefix: S + readability-identifier-naming.StructCase: CamelCase From 78f81b4be8704912d4eef1e0b3806e2d43586906 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Mon, 20 Jan 2025 23:39:45 +0500 Subject: [PATCH 02/14] modernize-deprecated-includes & readability-duplicate-include --- src/backend/Backend.cpp | 4 ++-- src/backend/Headless.cpp | 4 ++-- src/backend/Wayland.cpp | 2 +- src/backend/drm/Renderer.cpp | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/Backend.cpp b/src/backend/Backend.cpp index 9f4b080..7873d84 100644 --- a/src/backend/Backend.cpp +++ b/src/backend/Backend.cpp @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/src/backend/Headless.cpp b/src/backend/Headless.cpp index b556a07..6dabb71 100644 --- a/src/backend/Headless.cpp +++ b/src/backend/Headless.cpp @@ -1,8 +1,8 @@ #include #include -#include +#include #include -#include +#include #include "Shared.hpp" using namespace Aquamarine; diff --git a/src/backend/Wayland.cpp b/src/backend/Wayland.cpp index ec81b07..f1e50a3 100644 --- a/src/backend/Wayland.cpp +++ b/src/backend/Wayland.cpp @@ -3,7 +3,7 @@ #include #include "Shared.hpp" #include "FormatUtils.hpp" -#include +#include #include #include #include diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 7d4d7d8..acd5d64 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -7,7 +7,6 @@ #include "Math.hpp" #include "Shared.hpp" #include "FormatUtils.hpp" -#include #include using namespace Aquamarine; From 45000c426ce8a934e097ac67f920d886da95cebb Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Mon, 20 Jan 2025 23:44:45 +0500 Subject: [PATCH 03/14] prefer-member-initializer --- src/allocator/GBM.cpp | 3 +-- src/backend/Backend.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp index a061111..a0b6287 100644 --- a/src/allocator/GBM.cpp +++ b/src/allocator/GBM.cpp @@ -322,8 +322,7 @@ SP Aquamarine::CGBMAllocator::create(int drmfd_, Hyprutils::Memor return allocator; } -Aquamarine::CGBMAllocator::CGBMAllocator(int fd_, Hyprutils::Memory::CWeakPointer backend_) : fd(fd_), backend(backend_) { - gbmDevice = gbm_create_device(fd_); +Aquamarine::CGBMAllocator::CGBMAllocator(int fd_, Hyprutils::Memory::CWeakPointer backend_) : fd(fd_), backend(backend_), gbmDevice(gbm_create_device(fd_)) { if (!gbmDevice) { backend->log(AQ_LOG_ERROR, std::format("Couldn't open a GBM device at fd {}", fd_)); return; diff --git a/src/backend/Backend.cpp b/src/backend/Backend.cpp index 7873d84..8bb9f47 100644 --- a/src/backend/Backend.cpp +++ b/src/backend/Backend.cpp @@ -44,13 +44,12 @@ Aquamarine::CBackend::CBackend() { ; } -Aquamarine::SBackendImplementationOptions::SBackendImplementationOptions() { - backendType = AQ_BACKEND_WAYLAND; - backendRequestMode = AQ_BACKEND_REQUEST_IF_AVAILABLE; +Aquamarine::SBackendImplementationOptions::SBackendImplementationOptions() : backendType(AQ_BACKEND_WAYLAND), backendRequestMode(AQ_BACKEND_REQUEST_IF_AVAILABLE) { + ; } -Aquamarine::SBackendOptions::SBackendOptions() { - logFunction = nullptr; +Aquamarine::SBackendOptions::SBackendOptions() : logFunction(nullptr) { + ; } Hyprutils::Memory::CSharedPointer Aquamarine::CBackend::create(const std::vector& backends, const SBackendOptions& options) { From 904fd5707d2667112b3d6abd751c93b26c33d89c Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Mon, 20 Jan 2025 23:47:00 +0500 Subject: [PATCH 04/14] readability-redundant-control-flow --- src/backend/Session.cpp | 1 - src/backend/Wayland.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/Session.cpp b/src/backend/Session.cpp index b2d37a2..dc83926 100644 --- a/src/backend/Session.cpp +++ b/src/backend/Session.cpp @@ -340,7 +340,6 @@ void Aquamarine::CSession::dispatchUdevEvents() { } udev_device_unref(device); - return; } void Aquamarine::CSession::dispatchLibinputEvents() { diff --git a/src/backend/Wayland.cpp b/src/backend/Wayland.cpp index f1e50a3..70dc71b 100644 --- a/src/backend/Wayland.cpp +++ b/src/backend/Wayland.cpp @@ -739,7 +739,7 @@ bool Aquamarine::CWaylandOutput::setCursor(Hyprutils::Memory::CSharedPointer pointer, uint32_t serial) { From 2e6d8b9013a8afc19d1a8e645c5ddebecc94edce Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Mon, 20 Jan 2025 23:59:06 +0500 Subject: [PATCH 05/14] modernize-use-designated-initializers --- src/backend/drm/DRM.cpp | 12 +++--- src/backend/drm/Props.cpp | 76 ++++++++++++++++++------------------ src/backend/drm/Renderer.cpp | 10 ++--- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 38222b4..ffe99fb 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -588,8 +588,8 @@ void Aquamarine::CDRMBackend::buildGlFormats(const std::vector& fmts) } result.emplace_back(SDRMFormat{ - fmt.drmFormat, - {fmt.modifier}, + .drmFormat = fmt.drmFormat, + .modifiers = {fmt.modifier}, }); } @@ -1250,10 +1250,10 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector d const auto chromaticity = di_edid_get_chromaticity_coords(edid); if (chromaticity) { parsed.chromaticityCoords = IOutput::SChromaticityCoords{ - IOutput::xy{chromaticity->red_x, chromaticity->red_y}, - IOutput::xy{chromaticity->green_x, chromaticity->green_y}, - IOutput::xy{chromaticity->blue_x, chromaticity->blue_y}, - IOutput::xy{chromaticity->white_x, chromaticity->white_y}, + .red = IOutput::xy{.x = chromaticity->red_x, .y = chromaticity->red_y}, + .green = IOutput::xy{.x = chromaticity->green_x, .y = chromaticity->green_y}, + .blue = IOutput::xy{.x = chromaticity->blue_x, .y = chromaticity->blue_y}, + .white = IOutput::xy{.x = chromaticity->white_x, .y = chromaticity->white_y}, }; TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("EDID: chromaticity coords {},{} {},{} {},{} {},{}", parsed.chromaticityCoords->red.x, parsed.chromaticityCoords->red.y, diff --git a/src/backend/drm/Props.cpp b/src/backend/drm/Props.cpp index 961e665..7f6ffc6 100644 --- a/src/backend/drm/Props.cpp +++ b/src/backend/drm/Props.cpp @@ -20,59 +20,59 @@ struct prop_info { static const struct prop_info connector_info[] = { #define INDEX(name) (offsetof(SDRMConnector::UDRMConnectorProps, name) / sizeof(uint32_t)) - {"CRTC_ID", INDEX(crtc_id)}, - {"Colorspace", INDEX(Colorspace)}, - {"DPMS", INDEX(dpms)}, - {"EDID", INDEX(edid)}, - {"HDR_OUTPUT_METADATA", INDEX(hdr_output_metadata)}, - {"PATH", INDEX(path)}, - {"content type", INDEX(content_type)}, - {"link-status", INDEX(link_status)}, - {"max bpc", INDEX(max_bpc)}, - {"non-desktop", INDEX(non_desktop)}, - {"panel orientation", INDEX(panel_orientation)}, - {"subconnector", INDEX(subconnector)}, - {"vrr_capable", INDEX(vrr_capable)}, + {.name = "CRTC_ID", .index = INDEX(crtc_id)}, + {.name = "Colorspace", .index = INDEX(Colorspace)}, + {.name = "DPMS", .index = INDEX(dpms)}, + {.name = "EDID", .index = INDEX(edid)}, + {.name = "HDR_OUTPUT_METADATA", .index = INDEX(hdr_output_metadata)}, + {.name = "PATH", .index = INDEX(path)}, + {.name = "content type", .index = INDEX(content_type)}, + {.name = "link-status", .index = INDEX(link_status)}, + {.name = "max bpc", .index = INDEX(max_bpc)}, + {.name = "non-desktop", .index = INDEX(non_desktop)}, + {.name = "panel orientation", .index = INDEX(panel_orientation)}, + {.name = "subconnector", .index = INDEX(subconnector)}, + {.name = "vrr_capable", .index = INDEX(vrr_capable)}, #undef INDEX }; static const struct prop_info colorspace_info[] = { #define INDEX(name) (offsetof(SDRMConnector::UDRMConnectorColorspace, name) / sizeof(uint32_t)) - {"BT2020_RGB", INDEX(BT2020_RGB)}, - {"BT2020_YCC", INDEX(BT2020_YCC)}, - {"Default", INDEX(Default)}, + {.name = "BT2020_RGB", .index = INDEX(BT2020_RGB)}, + {.name = "BT2020_YCC", .index = INDEX(BT2020_YCC)}, + {.name = "Default", .index = INDEX(Default)}, #undef INDEX }; static const struct prop_info crtc_info[] = { #define INDEX(name) (offsetof(SDRMCRTC::UDRMCRTCProps, name) / sizeof(uint32_t)) - {"ACTIVE", INDEX(active)}, {"CTM", INDEX(ctm)}, - {"DEGAMMA_LUT", INDEX(degamma_lut)}, {"DEGAMMA_LUT_SIZE", INDEX(degamma_lut_size)}, - {"GAMMA_LUT", INDEX(gamma_lut)}, {"GAMMA_LUT_SIZE", INDEX(gamma_lut_size)}, - {"MODE_ID", INDEX(mode_id)}, {"OUT_FENCE_PTR", INDEX(out_fence_ptr)}, - {"VRR_ENABLED", INDEX(vrr_enabled)}, + {.name = "ACTIVE", .index = INDEX(active)}, {.name = "CTM", .index = INDEX(ctm)}, + {.name = "DEGAMMA_LUT", .index = INDEX(degamma_lut)}, {.name = "DEGAMMA_LUT_SIZE", .index = INDEX(degamma_lut_size)}, + {.name = "GAMMA_LUT", .index = INDEX(gamma_lut)}, {.name = "GAMMA_LUT_SIZE", .index = INDEX(gamma_lut_size)}, + {.name = "MODE_ID", .index = INDEX(mode_id)}, {.name = "OUT_FENCE_PTR", .index = INDEX(out_fence_ptr)}, + {.name = "VRR_ENABLED", .index = INDEX(vrr_enabled)}, #undef INDEX }; static const struct prop_info plane_info[] = { #define INDEX(name) (offsetof(SDRMPlane::UDRMPlaneProps, name) / sizeof(uint32_t)) - {"CRTC_H", INDEX(crtc_h)}, - {"CRTC_ID", INDEX(crtc_id)}, - {"CRTC_W", INDEX(crtc_w)}, - {"CRTC_X", INDEX(crtc_x)}, - {"CRTC_Y", INDEX(crtc_y)}, - {"FB_DAMAGE_CLIPS", INDEX(fb_damage_clips)}, - {"FB_ID", INDEX(fb_id)}, - {"HOTSPOT_X", INDEX(hotspot_x)}, - {"HOTSPOT_Y", INDEX(hotspot_y)}, - {"IN_FENCE_FD", INDEX(in_fence_fd)}, - {"IN_FORMATS", INDEX(in_formats)}, - {"SRC_H", INDEX(src_h)}, - {"SRC_W", INDEX(src_w)}, - {"SRC_X", INDEX(src_x)}, - {"SRC_Y", INDEX(src_y)}, - {"rotation", INDEX(rotation)}, - {"type", INDEX(type)}, + {.name = "CRTC_H", .index = INDEX(crtc_h)}, + {.name = "CRTC_ID", .index = INDEX(crtc_id)}, + {.name = "CRTC_W", .index = INDEX(crtc_w)}, + {.name = "CRTC_X", .index = INDEX(crtc_x)}, + {.name = "CRTC_Y", .index = INDEX(crtc_y)}, + {.name = "FB_DAMAGE_CLIPS", .index = INDEX(fb_damage_clips)}, + {.name = "FB_ID", .index = INDEX(fb_id)}, + {.name = "HOTSPOT_X", .index = INDEX(hotspot_x)}, + {.name = "HOTSPOT_Y", .index = INDEX(hotspot_y)}, + {.name = "IN_FENCE_FD", .index = INDEX(in_fence_fd)}, + {.name = "IN_FORMATS", .index = INDEX(in_formats)}, + {.name = "SRC_H", .index = INDEX(src_h)}, + {.name = "SRC_W", .index = INDEX(src_w)}, + {.name = "SRC_X", .index = INDEX(src_x)}, + {.name = "SRC_Y", .index = INDEX(src_y)}, + {.name = "rotation", .index = INDEX(rotation)}, + {.name = "type", .index = INDEX(type)}, #undef INDEX }; diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index acd5d64..c23c495 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -406,10 +406,10 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) { EGLint modlo; EGLint modhi; } attrNames[4] = { - {EGL_DMA_BUF_PLANE0_FD_EXT, EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGL_DMA_BUF_PLANE0_PITCH_EXT, EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT}, - {EGL_DMA_BUF_PLANE1_FD_EXT, EGL_DMA_BUF_PLANE1_OFFSET_EXT, EGL_DMA_BUF_PLANE1_PITCH_EXT, EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT}, - {EGL_DMA_BUF_PLANE2_FD_EXT, EGL_DMA_BUF_PLANE2_OFFSET_EXT, EGL_DMA_BUF_PLANE2_PITCH_EXT, EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT}, - {EGL_DMA_BUF_PLANE3_FD_EXT, EGL_DMA_BUF_PLANE3_OFFSET_EXT, EGL_DMA_BUF_PLANE3_PITCH_EXT, EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}}; + {.fd = EGL_DMA_BUF_PLANE0_FD_EXT, .offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT}, + {.fd = EGL_DMA_BUF_PLANE1_FD_EXT, .offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT}, + {.fd = EGL_DMA_BUF_PLANE2_FD_EXT, .offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT}, + {.fd = EGL_DMA_BUF_PLANE3_FD_EXT, .offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}}; for (int i = 0; i < attrs.planes; i++) { attribs.push_back(attrNames[i].fd); @@ -786,7 +786,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP from, SP to, i restoreEGL(); - return {true, explicitFD == -1 ? std::nullopt : std::optional{explicitFD}}; + return {.success = true, .syncFD = explicitFD == -1 ? std::nullopt : std::optional{explicitFD}}; } void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachment) { From e6302a530d9cdf6edcc53abab28e413061789297 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:00:11 +0500 Subject: [PATCH 06/14] more member initializers!!!! --- src/backend/drm/impl/Atomic.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index b11ab3c..0784e42 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -13,8 +13,7 @@ using namespace Hyprutils::Memory; using namespace Hyprutils::Math; #define SP CSharedPointer -Aquamarine::CDRMAtomicRequest::CDRMAtomicRequest(Hyprutils::Memory::CWeakPointer backend_) : backend(backend_) { - req = drmModeAtomicAlloc(); +Aquamarine::CDRMAtomicRequest::CDRMAtomicRequest(Hyprutils::Memory::CWeakPointer backend_) : backend(backend_), req(drmModeAtomicAlloc()) { if (!req) failed = true; } From e225fa6f723a902b6635a2cdcceaa9114df3c7e0 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:08:30 +0500 Subject: [PATCH 07/14] modernize-use-ranges --- src/allocator/GBM.cpp | 11 ++++++----- src/allocator/Swapchain.cpp | 3 ++- src/backend/Wayland.cpp | 3 ++- src/backend/drm/DRM.cpp | 7 ++++--- src/backend/drm/Renderer.cpp | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp index a0b6287..aacd2eb 100644 --- a/src/allocator/GBM.cpp +++ b/src/allocator/GBM.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -24,23 +25,23 @@ static SDRMFormat guessFormatFrom(std::vector formats, bool cursor, */ if (!scanout) { if (auto it = - std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; }); + std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; }); it != formats.end()) return *it; } - if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB2101010 || f.drmFormat == DRM_FORMAT_XBGR2101010; }); + if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB2101010 || f.drmFormat == DRM_FORMAT_XBGR2101010; }); it != formats.end()) return *it; } if (!scanout || cursor /* don't set opaque for cursor plane */) { - if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; }); + if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; }); it != formats.end()) return *it; } - if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; }); + if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; }); it != formats.end()) return *it; @@ -119,7 +120,7 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Renderable has {} formats, clipping", RENDERABLE.size()))); if (params.scanout && !CURSOR && !MULTIGPU) { // regular scanout plane, check if the format is renderable - auto rformat = std::find_if(RENDERABLE.begin(), RENDERABLE.end(), [f](const auto& e) { return e.drmFormat == f.drmFormat; }); + auto rformat = std::ranges::find_if(RENDERABLE, [f](const auto& e) { return e.drmFormat == f.drmFormat; }); if (rformat == RENDERABLE.end()) { TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Dropping format {} as it's not renderable", fourccToName(f.drmFormat)))); diff --git a/src/allocator/Swapchain.cpp b/src/allocator/Swapchain.cpp index 32c224d..143542a 100644 --- a/src/allocator/Swapchain.cpp +++ b/src/allocator/Swapchain.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "FormatUtils.hpp" @@ -114,7 +115,7 @@ bool Aquamarine::CSwapchain::resize(size_t newSize) { } bool Aquamarine::CSwapchain::contains(SP buffer) { - return std::find(buffers.begin(), buffers.end(), buffer) != buffers.end(); + return std::ranges::find(buffers, buffer) != buffers.end(); } const SSwapchainOptions& Aquamarine::CSwapchain::currentOptions() { diff --git a/src/backend/Wayland.cpp b/src/backend/Wayland.cpp index 70dc71b..40e59e9 100644 --- a/src/backend/Wayland.cpp +++ b/src/backend/Wayland.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -403,7 +404,7 @@ bool Aquamarine::CWaylandBackend::initDmabuf() { backend->log(AQ_LOG_DEBUG, std::format("zwp_linux_dmabuf_v1: Got format {} with modifier {}", fourccToName(fmt.drmFormat), modName ? modName : "UNKNOWN")); free(modName); - auto it = std::find_if(dmabufFormats.begin(), dmabufFormats.end(), [&fmt](const auto& e) { return e.drmFormat == fmt.drmFormat; }); + auto it = std::ranges::find_if(dmabufFormats, [&fmt](const auto& e) { return e.drmFormat == fmt.drmFormat; }); if (it == dmabufFormats.end()) { dmabufFormats.emplace_back(SDRMFormat{.drmFormat = fmt.drmFormat, .modifiers = {fmt.modifier}}); continue; diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index ffe99fb..b7abde8 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1,4 +1,5 @@ #include "aquamarine/output/Output.hpp" +#include #include #include #include @@ -582,7 +583,7 @@ void Aquamarine::CDRMBackend::buildGlFormats(const std::vector& fmts) if (fmt.external && fmt.modifier != DRM_FORMAT_MOD_INVALID) continue; - if (auto it = std::find_if(result.begin(), result.end(), [fmt](const auto& e) { return fmt.drmFormat == e.drmFormat; }); it != result.end()) { + if (auto it = std::ranges::find_if(result, [fmt](const auto& e) { return fmt.drmFormat == e.drmFormat; }); it != result.end()) { it->modifiers.emplace_back(fmt.modifier); continue; } @@ -774,7 +775,7 @@ void Aquamarine::CDRMBackend::scanConnectors() { continue; } - auto it = std::find_if(connectors.begin(), connectors.end(), [connectorID](const auto& e) { return e->id == connectorID; }); + auto it = std::ranges::find_if(connectors, [connectorID](const auto& e) { return e->id == connectorID; }); if (it == connectors.end()) { backend->log(AQ_LOG_DEBUG, std::format("drm: Initializing connector id {}", connectorID)); conn = connectors.emplace_back(SP(new SDRMConnector())); @@ -1077,7 +1078,7 @@ bool Aquamarine::SDRMPlane::init(drmModePlane* plane) { drmModeFormatModifierIterator iter = {0}; while (drmModeFormatModifierBlobIterNext(blob, &iter)) { - auto it = std::find_if(formats.begin(), formats.end(), [iter](const auto& e) { return e.drmFormat == iter.fmt; }); + auto it = std::ranges::find_if(formats, [iter](const auto& e) { return e.drmFormat == iter.fmt; }); TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Modifier {} with format {}", iter.mod, fourccToName(iter.fmt)))); diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index c23c495..4413e7e 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -1,6 +1,7 @@ #include "Renderer.hpp" #include #include +#include #include #include #include @@ -132,7 +133,7 @@ std::optional>> CDRMRenderer::getModsForFo result.push_back({mods.at(i), external.at(i)}); } - if (std::find(mods.begin(), mods.end(), DRM_FORMAT_MOD_LINEAR) == mods.end() && mods.size() == 0) + if (std::ranges::find(mods, DRM_FORMAT_MOD_LINEAR) == mods.end() && mods.size() == 0) result.push_back({DRM_FORMAT_MOD_LINEAR, true}); return result; From cd0520b3dfa143b51cc9e338e196da20392a0c36 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:09:48 +0500 Subject: [PATCH 08/14] bugprone-suspicious-string-compare --- src/backend/drm/DRM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index b7abde8..0db9d9c 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1363,7 +1363,7 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) { output->modes.emplace_back(aqMode); - if (currentModeInfo && std::memcmp(&drmMode, currentModeInfo, sizeof(drmModeModeInfo))) { + if (currentModeInfo && std::memcmp(&drmMode, currentModeInfo, sizeof(drmModeModeInfo)) != 0) { output->state->setMode(aqMode); //uint64_t modeID = 0; From 7cda30272d3701e5370e478a651c844aec3ca032 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:11:53 +0500 Subject: [PATCH 09/14] modernize-use-nullptr --- src/backend/drm/Renderer.cpp | 2 +- src/backend/drm/impl/Atomic.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 4413e7e..5763bf3 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -99,7 +99,7 @@ void main() { inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); - if (proc == NULL) { + if (proc == nullptr) { gBackend->log(AQ_LOG_ERROR, std::format("eglGetProcAddress({}) failed", name)); abort(); } diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index 0784e42..c1075a2 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -298,7 +298,7 @@ bool Aquamarine::CDRMAtomicImpl::prepareConnector(Hyprutils::Memory::CSharedPoin if (!prop) // TODO: allow this with legacy gamma, perhaps. connector->backend->backend->log(AQ_LOG_ERROR, "atomic drm: failed to commit gamma: no gamma_lut prop"); else if (gammaLut.empty()) { - blobId = 0; + blobId = nullptr; return true; } else { std::vector lut; From e8cd43fccf6ec0e9dca67cef50a62c38315acd5c Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:16:50 +0500 Subject: [PATCH 10/14] modernize-use-emplace & reserve vector --- src/backend/drm/Renderer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 5763bf3..7400009 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -129,12 +129,13 @@ std::optional>> CDRMRenderer::getModsForFo egl.eglQueryDmaBufModifiersEXT(egl.display, format, len, mods.data(), external.data(), &len); std::vector> result; + result.reserve(mods.size()); for (size_t i = 0; i < mods.size(); ++i) { - result.push_back({mods.at(i), external.at(i)}); + result.emplace_back(mods.at(i), external.at(i)); } if (std::ranges::find(mods, DRM_FORMAT_MOD_LINEAR) == mods.end() && mods.size() == 0) - result.push_back({DRM_FORMAT_MOD_LINEAR, true}); + result.emplace_back(DRM_FORMAT_MOD_LINEAR, true); return result; } @@ -168,7 +169,7 @@ bool CDRMRenderer::initDRMFormats() { hasModifiers = hasModifiers || mods.size() > 0; // EGL can always do implicit modifiers. - mods.push_back({DRM_FORMAT_MOD_INVALID, true}); + mods.emplace_back(DRM_FORMAT_MOD_INVALID, true); for (auto const& [mod, external] : mods) { dmaFormats.push_back(SGLFormat{ From 5f47ff95efe7f256b7bba557e3778888fbcced49 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:19:17 +0500 Subject: [PATCH 11/14] redundant cast --- src/backend/drm/Renderer.cpp | 4 ++-- src/backend/drm/impl/Atomic.cpp | 2 +- src/backend/drm/impl/Legacy.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 7400009..6bce5e5 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -213,7 +213,7 @@ SP CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointerbackend = backend_; gBackend = backend_; - const std::string EGLEXTENSIONS = (const char*)eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); + const std::string EGLEXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); if (!EGLEXTENSIONS.contains("KHR_platform_gbm")) { backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no gbm support"); @@ -284,7 +284,7 @@ SP CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointeregl.display, EGL_EXTENSIONS); + const std::string EGLEXTENSIONS2 = eglQueryString(renderer->egl.display, EGL_EXTENSIONS); if (EGLEXTENSIONS2.contains("IMG_context_priority")) { attrs.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG); diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index c1075a2..ce98b61 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -283,7 +283,7 @@ bool Aquamarine::CDRMAtomicImpl::prepareConnector(Hyprutils::Memory::CSharedPoin if (!enable) data.atomic.modeBlob = 0; else { - if (drmModeCreatePropertyBlob(connector->backend->gpu->fd, (drmModeModeInfo*)&data.modeInfo, sizeof(drmModeModeInfo), &data.atomic.modeBlob)) { + if (drmModeCreatePropertyBlob(connector->backend->gpu->fd, (&data.modeInfo), sizeof(drmModeModeInfo), &data.atomic.modeBlob)) { connector->backend->backend->log(AQ_LOG_ERROR, "atomic drm: failed to create a modeset blob"); return false; } diff --git a/src/backend/drm/impl/Legacy.cpp b/src/backend/drm/impl/Legacy.cpp index 6dac7e5..e9ac9a2 100644 --- a/src/backend/drm/impl/Legacy.cpp +++ b/src/backend/drm/impl/Legacy.cpp @@ -49,7 +49,7 @@ bool Aquamarine::CDRMLegacyImpl::commitInternal(Hyprutils::Memory::CSharedPointe drmModeModeInfo* mode = nullptr; if (enable) { connectors.push_back(connector->id); - mode = (drmModeModeInfo*)&data.modeInfo; + mode = &data.modeInfo; } if (mode) { @@ -165,4 +165,4 @@ bool Aquamarine::CDRMLegacyImpl::reset() { } return ok; -} \ No newline at end of file +} From a85925882b3bf97486e7433865f6c2b932ba975a Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:20:06 +0500 Subject: [PATCH 12/14] performance-for-range-copy --- src/backend/drm/DRM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 0db9d9c..af4681f 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -307,7 +307,7 @@ std::vector> Aquamarine::CDRMBackend::attempt(SP backe } Aquamarine::CDRMBackend::~CDRMBackend() { - for (auto conn : connectors) { + for (auto& conn : connectors) { conn->disconnect(); conn.reset(); } From 6b12844b21b8a436fba48f7483467335dbe474d7 Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:17:53 +0500 Subject: [PATCH 13/14] bruh --- src/backend/drm/impl/Atomic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/drm/impl/Atomic.cpp b/src/backend/drm/impl/Atomic.cpp index ce98b61..da920a2 100644 --- a/src/backend/drm/impl/Atomic.cpp +++ b/src/backend/drm/impl/Atomic.cpp @@ -283,7 +283,7 @@ bool Aquamarine::CDRMAtomicImpl::prepareConnector(Hyprutils::Memory::CSharedPoin if (!enable) data.atomic.modeBlob = 0; else { - if (drmModeCreatePropertyBlob(connector->backend->gpu->fd, (&data.modeInfo), sizeof(drmModeModeInfo), &data.atomic.modeBlob)) { + if (drmModeCreatePropertyBlob(connector->backend->gpu->fd, &data.modeInfo, sizeof(drmModeModeInfo), &data.atomic.modeBlob)) { connector->backend->backend->log(AQ_LOG_ERROR, "atomic drm: failed to create a modeset blob"); return false; } From e2ef23c46a06791fa46de4ed296a18eac3293b2d Mon Sep 17 00:00:00 2001 From: Honkazel <169346573+Honkazel@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:37:25 +0500 Subject: [PATCH 14/14] oaoaoao --- src/backend/drm/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 6bce5e5..5388926 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -99,7 +99,7 @@ void main() { inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); - if (proc == nullptr) { + if (!proc) { gBackend->log(AQ_LOG_ERROR, std::format("eglGetProcAddress({}) failed", name)); abort(); }