diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2019-11-18 12:07:36 +0200 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2019-11-18 12:12:39 +0200 |
commit | f824cccac7311647a8bd22d193d3aac2b961a1dd (patch) | |
tree | 3fd742c256fe0acd92d4a21b0e06944fb2256e14 /kms++ | |
parent | 7a52c7d720398da7df242aeef7be652b54290e94 (diff) |
fbs: use std::array and .at()
Use std::array and .at() to get bounds checking.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'kms++')
-rw-r--r-- | kms++/inc/kms++/dmabufframebuffer.h | 10 | ||||
-rw-r--r-- | kms++/inc/kms++/dumbframebuffer.h | 10 | ||||
-rw-r--r-- | kms++/inc/kms++/extframebuffer.h | 10 | ||||
-rw-r--r-- | kms++/src/dmabufframebuffer.cpp | 6 | ||||
-rw-r--r-- | kms++/src/dumbframebuffer.cpp | 16 | ||||
-rw-r--r-- | kms++/src/extframebuffer.cpp | 3 |
6 files changed, 27 insertions, 28 deletions
diff --git a/kms++/inc/kms++/dmabufframebuffer.h b/kms++/inc/kms++/dmabufframebuffer.h index 73c6d21..2a9182d 100644 --- a/kms++/inc/kms++/dmabufframebuffer.h +++ b/kms++/inc/kms++/dmabufframebuffer.h @@ -20,10 +20,10 @@ public: PixelFormat format() const override { return m_format; } unsigned num_planes() const override { return m_num_planes; } - uint32_t handle(unsigned plane) const { return m_planes[plane].handle; } - uint32_t stride(unsigned plane) const override { return m_planes[plane].stride; } - uint32_t size(unsigned plane) const override { return m_planes[plane].size; } - uint32_t offset(unsigned plane) const override { return m_planes[plane].offset; } + uint32_t handle(unsigned plane) const { return m_planes.at(plane).handle; } + uint32_t stride(unsigned plane) const override { return m_planes.at(plane).stride; } + uint32_t size(unsigned plane) const override { return m_planes.at(plane).size; } + uint32_t offset(unsigned plane) const override { return m_planes.at(plane).offset; } uint8_t* map(unsigned plane) override; int prime_fd(unsigned plane) override; @@ -41,7 +41,7 @@ private: }; unsigned m_num_planes; - struct FramebufferPlane m_planes[4]; + std::array<FramebufferPlane, 4> m_planes; PixelFormat m_format; diff --git a/kms++/inc/kms++/dumbframebuffer.h b/kms++/inc/kms++/dumbframebuffer.h index b722615..f450b2c 100644 --- a/kms++/inc/kms++/dumbframebuffer.h +++ b/kms++/inc/kms++/dumbframebuffer.h @@ -19,10 +19,10 @@ public: PixelFormat format() const override { return m_format; } unsigned num_planes() const override { return m_num_planes; } - uint32_t handle(unsigned plane) const { return m_planes[plane].handle; } - uint32_t stride(unsigned plane) const override { return m_planes[plane].stride; } - uint32_t size(unsigned plane) const override { return m_planes[plane].size; } - uint32_t offset(unsigned plane) const override { return m_planes[plane].offset; } + uint32_t handle(unsigned plane) const { return m_planes.at(plane).handle; } + uint32_t stride(unsigned plane) const override { return m_planes.at(plane).stride; } + uint32_t size(unsigned plane) const override { return m_planes.at(plane).size; } + uint32_t offset(unsigned plane) const override { return m_planes.at(plane).offset; } uint8_t* map(unsigned plane) override; int prime_fd(unsigned plane) override; @@ -37,7 +37,7 @@ private: }; unsigned m_num_planes; - struct FramebufferPlane m_planes[4]; + std::array<FramebufferPlane, 4> m_planes; PixelFormat m_format; }; diff --git a/kms++/inc/kms++/extframebuffer.h b/kms++/inc/kms++/extframebuffer.h index 0b9d08a..5239a3d 100644 --- a/kms++/inc/kms++/extframebuffer.h +++ b/kms++/inc/kms++/extframebuffer.h @@ -20,10 +20,10 @@ public: PixelFormat format() const override { return m_format; } unsigned num_planes() const override { return m_num_planes; } - uint32_t handle(unsigned plane) const { return m_planes[plane].handle; } - uint32_t stride(unsigned plane) const override { return m_planes[plane].stride; } - uint32_t size(unsigned plane) const override { return m_planes[plane].size; } - uint32_t offset(unsigned plane) const override { return m_planes[plane].offset; } + uint32_t handle(unsigned plane) const { return m_planes.at(plane).handle; } + uint32_t stride(unsigned plane) const override { return m_planes.at(plane).stride; } + uint32_t size(unsigned plane) const override { return m_planes.at(plane).size; } + uint32_t offset(unsigned plane) const override { return m_planes.at(plane).offset; } private: struct FramebufferPlane { @@ -35,7 +35,7 @@ private: }; unsigned m_num_planes; - struct FramebufferPlane m_planes[4]; + std::array<FramebufferPlane, 4> m_planes; PixelFormat m_format; }; diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index feac116..d36eb89 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -32,7 +32,7 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height throw std::invalid_argument("the size of fds, pitches and offsets has to match number of planes"); for (int i = 0; i < format_info.num_planes; ++i) { - FramebufferPlane& plane = m_planes[i]; + FramebufferPlane& plane = m_planes.at(i); plane.prime_fd = fds[i]; @@ -65,7 +65,7 @@ DmabufFramebuffer::~DmabufFramebuffer() uint8_t* DmabufFramebuffer::map(unsigned plane) { - FramebufferPlane& p = m_planes[plane]; + FramebufferPlane& p = m_planes.at(plane); if (p.map) return p.map; @@ -80,7 +80,7 @@ uint8_t* DmabufFramebuffer::map(unsigned plane) int DmabufFramebuffer::prime_fd(unsigned plane) { - FramebufferPlane& p = m_planes[plane]; + FramebufferPlane& p = m_planes.at(plane); return p.prime_fd; } diff --git a/kms++/src/dumbframebuffer.cpp b/kms++/src/dumbframebuffer.cpp index 2b74c35..3448fb1 100644 --- a/kms++/src/dumbframebuffer.cpp +++ b/kms++/src/dumbframebuffer.cpp @@ -36,7 +36,7 @@ DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, Pi for (int i = 0; i < format_info.num_planes; ++i) { const PixelFormatPlaneInfo& pi = format_info.planes[i]; - FramebufferPlane& plane = m_planes[i]; + FramebufferPlane& plane = m_planes.at(i); /* create dumb buffer */ struct drm_mode_create_dumb creq = drm_mode_create_dumb(); @@ -74,7 +74,7 @@ DumbFramebuffer::~DumbFramebuffer() drmModeRmFB(card().fd(), id()); for (uint i = 0; i < m_num_planes; ++i) { - FramebufferPlane& plane = m_planes[i]; + FramebufferPlane& plane = m_planes.at(i); /* unmap buffer */ if (plane.map) @@ -91,7 +91,7 @@ DumbFramebuffer::~DumbFramebuffer() uint8_t* DumbFramebuffer::map(unsigned plane) { - FramebufferPlane& p = m_planes[plane]; + FramebufferPlane& p = m_planes.at(plane); if (p.map) return p.map; @@ -114,15 +114,15 @@ uint8_t* DumbFramebuffer::map(unsigned plane) int DumbFramebuffer::prime_fd(unsigned int plane) { - if (m_planes[plane].prime_fd >= 0) - return m_planes[plane].prime_fd; + if (m_planes.at(plane).prime_fd >= 0) + return m_planes.at(plane).prime_fd; - int r = drmPrimeHandleToFD(card().fd(), m_planes[plane].handle, - DRM_CLOEXEC | O_RDWR, &m_planes[plane].prime_fd); + int r = drmPrimeHandleToFD(card().fd(), m_planes.at(plane).handle, + DRM_CLOEXEC | O_RDWR, &m_planes.at(plane).prime_fd); if (r) throw std::runtime_error("drmPrimeHandleToFD failed"); - return m_planes[plane].prime_fd; + return m_planes.at(plane).prime_fd; } } diff --git a/kms++/src/extframebuffer.cpp b/kms++/src/extframebuffer.cpp index 9f7ab6c..23aed50 100644 --- a/kms++/src/extframebuffer.cpp +++ b/kms++/src/extframebuffer.cpp @@ -28,10 +28,9 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe throw std::invalid_argument("the size of handles, pitches and offsets has to match number of planes"); for (int i = 0; i < format_info.num_planes; ++i) { - FramebufferPlane& plane = m_planes[i]; + FramebufferPlane& plane = m_planes.at(i); plane.handle = handles[i]; - plane.stride = pitches[i]; plane.offset = offsets[i]; plane.size = plane.stride * height; |