diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2025-07-07 23:44:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-07 23:44:35 +0200 |
| commit | 9856563f8966856871a95f70757362f694ff22a6 (patch) | |
| tree | d8049c383676917123ba4b006a219eabd5707e81 /src/render/OpenGL.cpp | |
| parent | bb958a9e139d6ae90d45fe360287d33e229f971e (diff) | |
opengl: avoid reallocations in EGLImage (#10960)
use a std::array instead of vector and avoid reallocations.
it should at most be 49 entries, so make the array 50. and RASSERT check
it incase more entries gets added in the future.
Diffstat (limited to 'src/render/OpenGL.cpp')
| -rw-r--r-- | src/render/OpenGL.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 6b311a25..de643485 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -517,14 +517,15 @@ void CHyprOpenGLImpl::initDRMFormats() { } EGLImageKHR CHyprOpenGLImpl::createEGLImage(const Aquamarine::SDMABUFAttrs& attrs) { - std::vector<uint32_t> attribs; + std::array<uint32_t, 50> attribs; + size_t idx = 0; - attribs.push_back(EGL_WIDTH); - attribs.push_back(attrs.size.x); - attribs.push_back(EGL_HEIGHT); - attribs.push_back(attrs.size.y); - attribs.push_back(EGL_LINUX_DRM_FOURCC_EXT); - attribs.push_back(attrs.format); + attribs[idx++] = EGL_WIDTH; + attribs[idx++] = attrs.size.x; + attribs[idx++] = EGL_HEIGHT; + attribs[idx++] = attrs.size.y; + attribs[idx++] = EGL_LINUX_DRM_FOURCC_EXT; + attribs[idx++] = attrs.format; struct { EGLint fd; @@ -538,25 +539,27 @@ EGLImageKHR CHyprOpenGLImpl::createEGLImage(const Aquamarine::SDMABUFAttrs& attr {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}}; - for (int i = 0; i < attrs.planes; i++) { - attribs.push_back(attrNames[i].fd); - attribs.push_back(attrs.fds[i]); - attribs.push_back(attrNames[i].offset); - attribs.push_back(attrs.offsets[i]); - attribs.push_back(attrNames[i].pitch); - attribs.push_back(attrs.strides[i]); + for (int i = 0; i < attrs.planes; ++i) { + attribs[idx++] = attrNames[i].fd; + attribs[idx++] = attrs.fds[i]; + attribs[idx++] = attrNames[i].offset; + attribs[idx++] = attrs.offsets[i]; + attribs[idx++] = attrNames[i].pitch; + attribs[idx++] = attrs.strides[i]; + if (m_hasModifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) { - attribs.push_back(attrNames[i].modlo); - attribs.push_back(attrs.modifier & 0xFFFFFFFF); - attribs.push_back(attrNames[i].modhi); - attribs.push_back(attrs.modifier >> 32); + attribs[idx++] = attrNames[i].modlo; + attribs[idx++] = static_cast<uint32_t>(attrs.modifier & 0xFFFFFFFF); + attribs[idx++] = attrNames[i].modhi; + attribs[idx++] = static_cast<uint32_t>(attrs.modifier >> 32); } } - attribs.push_back(EGL_IMAGE_PRESERVED_KHR); - attribs.push_back(EGL_TRUE); + attribs[idx++] = EGL_IMAGE_PRESERVED_KHR; + attribs[idx++] = EGL_TRUE; + attribs[idx++] = EGL_NONE; - attribs.push_back(EGL_NONE); + RASSERT(idx <= attribs.size(), "createEglImage: attribs array out of bounds."); EGLImageKHR image = m_proc.eglCreateImageKHR(m_eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, (int*)attribs.data()); if (image == EGL_NO_IMAGE_KHR) { |
