summaryrefslogtreecommitdiff
path: root/src/render/Texture.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-07-21 13:09:54 +0200
committerGitHub <noreply@github.com>2024-07-21 13:09:54 +0200
commit016da234d0e852de3ef20eb2e89ac58d2a85f6e7 (patch)
tree496085987176551b0794fffc069877d44943e2f1 /src/render/Texture.cpp
parentf642fb97df5c69267a03452533de383ff8023570 (diff)
Core: Move to aquamarine (#6608)
Moves Hyprland from wlroots to aquamarine for the backend. --------- Signed-off-by: Vaxry <vaxry@vaxry.net> Co-authored-by: Mihai Fufezan <mihai@fufexan.net> Co-authored-by: Jan Beich <jbeich@FreeBSD.org> Co-authored-by: vaxerski <vaxerski@users.noreply.github.com> Co-authored-by: UjinT34 <41110182+UjinT34@users.noreply.github.com> Co-authored-by: Tom Englund <tomenglund26@gmail.com> Co-authored-by: Ikalco <73481042+ikalco@users.noreply.github.com> Co-authored-by: diniamo <diniamo53@gmail.com>
Diffstat (limited to 'src/render/Texture.cpp')
-rw-r--r--src/render/Texture.cpp62
1 files changed, 42 insertions, 20 deletions
diff --git a/src/render/Texture.cpp b/src/render/Texture.cpp
index 46c501a0..0f5b4c4c 100644
--- a/src/render/Texture.cpp
+++ b/src/render/Texture.cpp
@@ -9,7 +9,7 @@ CTexture::CTexture() {
}
CTexture::~CTexture() {
- if (m_bNonOwning || !g_pCompositor || g_pCompositor->m_bIsShuttingDown || !g_pHyprRenderer)
+ if (!g_pCompositor || g_pCompositor->m_bIsShuttingDown || !g_pHyprRenderer)
return;
g_pHyprRenderer->makeEGLCurrent();
@@ -17,6 +17,45 @@ CTexture::~CTexture() {
}
CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_) {
+ createFromShm(drmFormat, pixels, stride, size_);
+}
+
+CTexture::CTexture(const Aquamarine::SDMABUFAttrs& attrs, void* image) {
+ createFromDma(attrs, image);
+}
+
+CTexture::CTexture(const SP<Aquamarine::IBuffer> buffer) {
+ if (!buffer)
+ return;
+
+ auto attrs = buffer->dmabuf();
+
+ if (!attrs.success) {
+ // attempt shm
+ auto shm = buffer->shm();
+
+ if (!shm.success) {
+ Debug::log(ERR, "Cannot create a texture: buffer has no dmabuf or shm");
+ return;
+ }
+
+ auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0);
+
+ createFromShm(fmt, pixelData, bufLen, shm.size);
+ return;
+ }
+
+ auto image = g_pHyprOpenGL->createEGLImage(buffer->dmabuf());
+
+ if (!image) {
+ Debug::log(ERR, "Cannot create a texture: failed to create an EGLImage");
+ return;
+ }
+
+ createFromDma(attrs, image);
+}
+
+void CTexture::createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_) {
g_pHyprRenderer->makeEGLCurrent();
const auto format = FormatUtils::getPixelFormatFromDRM(drmFormat);
@@ -41,24 +80,7 @@ CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const V
GLCALL(glBindTexture(GL_TEXTURE_2D, 0));
}
-CTexture::CTexture(wlr_texture* tex) {
- RASSERT(wlr_texture_is_gles2(tex), "wlr_texture provided to CTexture that isn't GLES2!");
- wlr_gles2_texture_attribs attrs;
- wlr_gles2_texture_get_attribs(tex, &attrs);
-
- m_iTarget = attrs.target;
- m_iTexID = attrs.tex;
- m_bNonOwning = true;
-
- if (m_iTarget == GL_TEXTURE_2D)
- m_iType = attrs.has_alpha ? TEXTURE_RGBA : TEXTURE_RGBX;
- else
- m_iType = TEXTURE_EXTERNAL;
-
- m_vSize = Vector2D((int)tex->width, (int)tex->height);
-}
-
-CTexture::CTexture(const SDMABUFAttrs& attrs, void* image) {
+void CTexture::createFromDma(const Aquamarine::SDMABUFAttrs& attrs, void* image) {
if (!g_pHyprOpenGL->m_sProc.glEGLImageTargetTexture2DOES) {
Debug::log(ERR, "Cannot create a dmabuf texture: no glEGLImageTargetTexture2DOES");
return;
@@ -119,7 +141,7 @@ void CTexture::destroyTexture() {
}
if (m_pEglImage)
- g_pHyprOpenGL->m_sProc.eglDestroyImageKHR(wlr_egl_get_display(g_pCompositor->m_sWLREGL), m_pEglImage);
+ g_pHyprOpenGL->m_sProc.eglDestroyImageKHR(g_pHyprOpenGL->m_pEglDisplay, m_pEglImage);
m_pEglImage = nullptr;
}