From a35d57fa9088fbccd468ad095c89aba096b2494e Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 5 Feb 2025 12:03:34 +0200 Subject: Use the fourcc helpers Signed-off-by: Tomi Valkeinen --- kms++/src/dmabufframebuffer.cpp | 4 ++-- kms++/src/dumbframebuffer.cpp | 2 +- kms++/src/extframebuffer.cpp | 4 ++-- kms++/src/framebuffer.cpp | 2 +- kms++/src/omap/omapframebuffer.cpp | 2 +- kms++/src/plane.cpp | 6 ++++-- kmscube/cube-gbm.cpp | 2 +- utils/kmscapture.cpp | 4 ++-- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index e5d06ed..f303799 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -58,13 +58,13 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height offsets.resize(4); if (modifiers.empty()) { - r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, + r = drmModeAddFB2(card.fd(), width, height, pixel_format_to_fourcc(format), bo_handles, pitches.data(), offsets.data(), &id, 0); if (r) throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno)); } else { modifiers.resize(4); - r = drmModeAddFB2WithModifiers(card.fd(), width, height, (uint32_t)format, + r = drmModeAddFB2WithModifiers(card.fd(), width, height, pixel_format_to_fourcc(format), bo_handles, pitches.data(), offsets.data(), modifiers.data(), &id, DRM_MODE_FB_MODIFIERS); if (r) throw invalid_argument(string("drmModeAddFB2WithModifiers failed: ") + strerror(errno)); diff --git a/kms++/src/dumbframebuffer.cpp b/kms++/src/dumbframebuffer.cpp index bdc584e..e035061 100644 --- a/kms++/src/dumbframebuffer.cpp +++ b/kms++/src/dumbframebuffer.cpp @@ -75,7 +75,7 @@ DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, Pi m_planes[3].offset, }; uint32_t id; - r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, + r = drmModeAddFB2(card.fd(), width, height, pixel_format_to_fourcc(format), bo_handles, pitches, offsets, &id, 0); if (r) throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno)); diff --git a/kms++/src/extframebuffer.cpp b/kms++/src/extframebuffer.cpp index 78b6fbb..d67cbad 100644 --- a/kms++/src/extframebuffer.cpp +++ b/kms++/src/extframebuffer.cpp @@ -44,10 +44,10 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe int r; if (modifiers.empty()) { - r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, handles.data(), pitches.data(), offsets.data(), &id, 0); + r = drmModeAddFB2(card.fd(), width, height, pixel_format_to_fourcc(format), handles.data(), pitches.data(), offsets.data(), &id, 0); } else { modifiers.resize(4); - r = drmModeAddFB2WithModifiers(card.fd(), width, height, (uint32_t)format, handles.data(), pitches.data(), offsets.data(), modifiers.data(), &id, DRM_MODE_FB_MODIFIERS); + r = drmModeAddFB2WithModifiers(card.fd(), width, height, pixel_format_to_fourcc(format), handles.data(), pitches.data(), offsets.data(), modifiers.data(), &id, DRM_MODE_FB_MODIFIERS); } if (r) diff --git a/kms++/src/framebuffer.cpp b/kms++/src/framebuffer.cpp index 3a76b73..773cf4b 100644 --- a/kms++/src/framebuffer.cpp +++ b/kms++/src/framebuffer.cpp @@ -25,7 +25,7 @@ Framebuffer::Framebuffer(Card& card, uint32_t id) if (fb) { m_width = fb->width; m_height = fb->height; - m_format = (PixelFormat)fb->pixel_format; + m_format = fourcc_to_pixel_format(fb->pixel_format); drmModeFreeFB2(fb); } else { diff --git a/kms++/src/omap/omapframebuffer.cpp b/kms++/src/omap/omapframebuffer.cpp index 35852bf..9f9d7c7 100644 --- a/kms++/src/omap/omapframebuffer.cpp +++ b/kms++/src/omap/omapframebuffer.cpp @@ -133,7 +133,7 @@ void OmapFramebuffer::Create(uint32_t width, uint32_t height, PixelFormat format uint32_t pitches[4] = { m_planes[0].stride, m_planes[1].stride }; uint32_t offsets[4] = { m_planes[0].offset, m_planes[1].offset }; uint32_t id; - int r = drmModeAddFB2(card().fd(), width, height, (uint32_t)format, + int r = drmModeAddFB2(card().fd(), width, height, pixel_format_to_fourcc(format), bo_handles, pitches, offsets, &id, 0); if (r) throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno)); diff --git a/kms++/src/plane.cpp b/kms++/src/plane.cpp index bd426dd..93b3479 100644 --- a/kms++/src/plane.cpp +++ b/kms++/src/plane.cpp @@ -40,8 +40,10 @@ bool Plane::supports_format(PixelFormat fmt) const { auto p = m_priv->drm_plane; + uint32_t fcc = pixel_format_to_fourcc(fmt); + for (unsigned i = 0; i < p->count_formats; ++i) - if ((uint32_t)fmt == p->formats[i]) + if (fcc == p->formats[i]) return true; return false; @@ -94,7 +96,7 @@ vector Plane::get_formats() const vector r; for (unsigned i = 0; i < p->count_formats; ++i) - r.push_back((PixelFormat)p->formats[i]); + r.push_back(fourcc_to_pixel_format(p->formats[i])); return r; } diff --git a/kmscube/cube-gbm.cpp b/kmscube/cube-gbm.cpp index 69930ee..5b0715a 100644 --- a/kmscube/cube-gbm.cpp +++ b/kmscube/cube-gbm.cpp @@ -133,7 +133,7 @@ public: uint32_t height = gbm_bo_get_height(bo); uint32_t stride = gbm_bo_get_stride(bo); uint32_t handle = gbm_bo_get_handle(bo).u32; - PixelFormat format = (PixelFormat)gbm_bo_get_format(bo); + PixelFormat format = fourcc_to_pixel_format(gbm_bo_get_format(bo)); vector handles{ handle }; vector strides{ stride }; diff --git a/utils/kmscapture.cpp b/utils/kmscapture.cpp index 9bcd75e..23941ca 100644 --- a/utils/kmscapture.cpp +++ b/utils/kmscapture.cpp @@ -107,7 +107,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc* crtc, Plane* plane, uint32_t best_h = 240; struct v4l2_frmsizeenum v4lfrms = {}; - v4lfrms.pixel_format = (uint32_t)pixfmt; + v4lfrms.pixel_format = pixel_format_to_fourcc(pixfmt); while (ioctl(m_fd, VIDIOC_ENUM_FRAMESIZES, &v4lfrms) == 0) { if (v4lfrms.type != V4L2_FRMSIZE_TYPE_DISCRETE) { v4lfrms.index++; @@ -142,7 +142,7 @@ CameraPipeline::CameraPipeline(int cam_fd, Card& card, Crtc* crtc, Plane* plane, r = ioctl(m_fd, VIDIOC_G_FMT, &v4lfmt); ASSERT(r == 0); - v4lfmt.fmt.pix.pixelformat = (uint32_t)pixfmt; + v4lfmt.fmt.pix.pixelformat = pixel_format_to_fourcc(pixfmt); v4lfmt.fmt.pix.width = m_in_width; v4lfmt.fmt.pix.height = m_in_height; -- cgit v1.2.3