egl: move over to use hyprgraphics (#12988)

use the hyprgraphics helpers instead.
This commit is contained in:
Tom Englund 2026-04-05 20:37:07 +02:00 committed by GitHub
parent 5c5ba65ad3
commit 809b9b9e78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 47 additions and 321 deletions

View file

@ -6,223 +6,6 @@
#include <xf86drm.h>
#include <drm_fourcc.h>
inline const std::vector<SPixelFormat> GLES3_FORMATS = {
{
.drmFormat = DRM_FORMAT_ARGB8888,
.glInternalFormat = GL_RGBA8,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_BYTE,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XRGB8888,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_BGRA},
},
{
.drmFormat = DRM_FORMAT_XRGB8888,
.glInternalFormat = GL_RGBA8,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_BYTE,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XRGB8888,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_BGR1},
},
{
.drmFormat = DRM_FORMAT_XBGR8888,
.glInternalFormat = GL_RGBA8,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_BYTE,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XBGR8888,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_ABGR8888,
.glInternalFormat = GL_RGBA8,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_BYTE,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XBGR8888,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_BGR888,
.glInternalFormat = GL_RGB8,
.glFormat = GL_RGB,
.glType = GL_UNSIGNED_BYTE,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_BGR888,
.bytesPerBlock = 3,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_RGBX4444,
.glInternalFormat = GL_RGBA4,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_SHORT_4_4_4_4,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_RGBX4444,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_RGBA4444,
.glInternalFormat = GL_RGBA4,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_SHORT_4_4_4_4,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_RGBX4444,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_RGBX5551,
.glInternalFormat = GL_RGB5_A1,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_SHORT_5_5_5_1,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_RGBX5551,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_RGBA5551,
.glInternalFormat = GL_RGB5_A1,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_SHORT_5_5_5_1,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_RGBX5551,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_RGB565,
.glInternalFormat = GL_RGB565,
.glFormat = GL_RGB,
.glType = GL_UNSIGNED_SHORT_5_6_5,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_RGB565,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_XBGR2101010,
.glInternalFormat = GL_RGB10_A2,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_INT_2_10_10_10_REV,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XBGR2101010,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_ABGR2101010,
.glInternalFormat = GL_RGB10_A2,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_INT_2_10_10_10_REV,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XBGR2101010,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_XRGB2101010,
.glInternalFormat = GL_RGB10_A2,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_INT_2_10_10_10_REV,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XRGB2101010,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_BGR1},
},
{
.drmFormat = DRM_FORMAT_ARGB2101010,
.glInternalFormat = GL_RGB10_A2,
.glFormat = GL_RGBA,
.glType = GL_UNSIGNED_INT_2_10_10_10_REV,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XRGB2101010,
.bytesPerBlock = 4,
.swizzle = {SWIZZLE_BGRA},
},
{
.drmFormat = DRM_FORMAT_XBGR16161616F,
.glInternalFormat = GL_RGBA16F,
.glFormat = GL_RGBA,
.glType = GL_HALF_FLOAT,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XBGR16161616F,
.bytesPerBlock = 8,
.swizzle = {SWIZZLE_RGB1},
},
{
.drmFormat = DRM_FORMAT_ABGR16161616F,
.glInternalFormat = GL_RGBA16F,
.glFormat = GL_RGBA,
.glType = GL_HALF_FLOAT,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XBGR16161616F,
.bytesPerBlock = 8,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_XBGR16161616,
.glInternalFormat = GL_RGBA16UI,
.glFormat = GL_RGBA_INTEGER,
.glType = GL_UNSIGNED_SHORT,
.withAlpha = false,
.alphaStripped = DRM_FORMAT_XBGR16161616,
.bytesPerBlock = 8,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_ABGR16161616,
.glInternalFormat = GL_RGBA16UI,
.glFormat = GL_RGBA_INTEGER,
.glType = GL_UNSIGNED_SHORT,
.withAlpha = true,
.alphaStripped = DRM_FORMAT_XBGR16161616,
.bytesPerBlock = 8,
.swizzle = {SWIZZLE_RGBA},
},
{
.drmFormat = DRM_FORMAT_YVYU,
.bytesPerBlock = 4,
.blockSize = {2, 1},
},
{
.drmFormat = DRM_FORMAT_VYUY,
.bytesPerBlock = 4,
.blockSize = {2, 1},
},
{
.drmFormat = DRM_FORMAT_R8,
.glInternalFormat = GL_R8,
.glFormat = GL_RED,
.glType = GL_UNSIGNED_BYTE,
.bytesPerBlock = 1,
.swizzle = {SWIZZLE_R001},
},
{
.drmFormat = DRM_FORMAT_GR88,
.glInternalFormat = GL_RG8,
.glFormat = GL_RG,
.glType = GL_UNSIGNED_BYTE,
.bytesPerBlock = 2,
.swizzle = {SWIZZLE_RG01},
},
{
.drmFormat = DRM_FORMAT_RGB888,
.glInternalFormat = GL_RGB8,
.glFormat = GL_RGB,
.glType = GL_UNSIGNED_BYTE,
.bytesPerBlock = 3,
.swizzle = {SWIZZLE_BGR1},
},
};
SHMFormat NFormatUtils::drmToShm(DRMFormat drm) {
switch (drm) {
case DRM_FORMAT_XRGB8888: return WL_SHM_FORMAT_XRGB8888;
@ -243,24 +26,6 @@ DRMFormat NFormatUtils::shmToDRM(SHMFormat shm) {
return shm;
}
const SPixelFormat* NFormatUtils::getPixelFormatFromDRM(DRMFormat drm) {
for (auto const& fmt : GLES3_FORMATS) {
if (fmt.drmFormat == drm)
return &fmt;
}
return nullptr;
}
const SPixelFormat* NFormatUtils::getPixelFormatFromGL(uint32_t glFormat, uint32_t glType, bool alpha) {
for (auto const& fmt : GLES3_FORMATS) {
if (fmt.glFormat == sc<int>(glFormat) && fmt.glType == sc<int>(glType) && fmt.withAlpha == alpha)
return &fmt;
}
return nullptr;
}
bool NFormatUtils::isFormatYUV(uint32_t drmFormat) {
switch (drmFormat) {
case DRM_FORMAT_YUYV:
@ -281,22 +46,6 @@ bool NFormatUtils::isFormatYUV(uint32_t drmFormat) {
}
}
bool NFormatUtils::isFormatOpaque(DRMFormat drm) {
const auto FMT = NFormatUtils::getPixelFormatFromDRM(drm);
if (!FMT)
return false;
return !FMT->withAlpha;
}
int NFormatUtils::pixelsPerBlock(const SPixelFormat* const fmt) {
return fmt->blockSize.x * fmt->blockSize.y > 0 ? fmt->blockSize.x * fmt->blockSize.y : 1;
}
int NFormatUtils::minStride(const SPixelFormat* const fmt, int32_t width) {
return std::ceil((width * fmt->bytesPerBlock) / pixelsPerBlock(fmt));
}
std::string NFormatUtils::drmFormatName(DRMFormat drm) {
auto n = drmGetFormatName(drm);

View file

@ -9,51 +9,13 @@
using DRMFormat = uint32_t;
using SHMFormat = uint32_t;
#define SWIZZLE_A1GB {GL_ALPHA, GL_ONE, GL_GREEN, GL_BLUE}
#define SWIZZLE_ABG1 {GL_ALPHA, GL_BLUE, GL_GREEN, GL_ONE}
#define SWIZZLE_ABGR {GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED}
#define SWIZZLE_ARGB {GL_ALPHA, GL_RED, GL_GREEN, GL_BLUE}
#define SWIZZLE_B1RG {GL_BLUE, GL_ONE, GL_RED, GL_GREEN}
#define SWIZZLE_BARG {GL_BLUE, GL_ALPHA, GL_RED, GL_GREEN}
#define SWIZZLE_BGR1 {GL_BLUE, GL_GREEN, GL_RED, GL_ONE}
#define SWIZZLE_BGRA {GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA}
#define SWIZZLE_G1AB {GL_GREEN, GL_ONE, GL_ALPHA, GL_BLUE}
#define SWIZZLE_GBA1 {GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE}
#define SWIZZLE_GBAR {GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED}
#define SWIZZLE_GRAB {GL_GREEN, GL_RED, GL_ALPHA, GL_BLUE}
#define SWIZZLE_R001 {GL_RED, GL_ZERO, GL_ZERO, GL_ONE}
#define SWIZZLE_R1BG {GL_RED, GL_ONE, GL_BLUE, GL_GREEN}
#define SWIZZLE_RABG {GL_RED, GL_ALPHA, GL_BLUE, GL_GREEN}
#define SWIZZLE_RG01 {GL_RED, GL_GREEN, GL_ZERO, GL_ONE}
#define SWIZZLE_GR01 {GL_GREEN, GL_RED, GL_ZERO, GL_ONE}
#define SWIZZLE_RGB1 {GL_RED, GL_GREEN, GL_BLUE, GL_ONE}
#define SWIZZLE_RGBA {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}
struct SPixelFormat {
DRMFormat drmFormat = 0; /* DRM_FORMAT_INVALID */
int glInternalFormat = 0;
int glFormat = 0;
int glType = 0;
bool withAlpha = true;
DRMFormat alphaStripped = 0; /* DRM_FORMAT_INVALID */
uint32_t bytesPerBlock = 0;
Vector2D blockSize;
std::optional<std::array<GLint, 4>> swizzle = std::nullopt;
};
using SDRMFormat = Aquamarine::SDRMFormat;
namespace NFormatUtils {
SHMFormat drmToShm(DRMFormat drm);
DRMFormat shmToDRM(SHMFormat shm);
const SPixelFormat* getPixelFormatFromDRM(DRMFormat drm);
const SPixelFormat* getPixelFormatFromGL(uint32_t glFormat, uint32_t glType, bool alpha);
bool isFormatYUV(uint32_t drmFormat);
bool isFormatOpaque(DRMFormat drm);
int pixelsPerBlock(const SPixelFormat* const fmt);
int minStride(const SPixelFormat* const fmt, int32_t width);
std::string drmFormatName(DRMFormat drm);
std::string drmModifierName(uint64_t mod);
DRMFormat alphaFormat(DRMFormat prevFormat);
SHMFormat drmToShm(DRMFormat drm);
DRMFormat shmToDRM(SHMFormat shm);
bool isFormatYUV(uint32_t drmFormat);
std::string drmFormatName(DRMFormat drm);
std::string drmModifierName(uint64_t mod);
DRMFormat alphaFormat(DRMFormat prevFormat);
};

View file

@ -5,7 +5,9 @@
#include "../../render/Renderer.hpp"
#include "../../render/pass/ClearPassElement.hpp"
#include "../../render/pass/TexPassElement.hpp"
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Screenshare;
CCursorshareSession::CCursorshareSession(wl_client* client, WP<CWLPointerResource> pointer) : m_client(client), m_pointer(pointer) {
@ -164,7 +166,7 @@ bool CCursorshareSession::copy() {
callback(RESULT_COPIED);
});
} else if (auto attrs = m_pendingFrame.buffer->shm(); attrs.success) {
const auto PFORMAT = NFormatUtils::getPixelFormatFromDRM(m_format);
const auto PFORMAT = getPixelFormatFromDRM(m_format);
if (attrs.format != m_format || !PFORMAT) {
LOGM(Log::ERR, "Can't copy: invalid format");
@ -190,11 +192,9 @@ bool CCursorshareSession::copy() {
if (glFormat != GL_BGRA_EXT && glFormat != GL_RGB) {
if (PFORMAT->swizzle.has_value()) {
std::array<GLint, 4> RGBA = SWIZZLE_RGBA;
std::array<GLint, 4> BGRA = SWIZZLE_BGRA;
if (PFORMAT->swizzle == RGBA)
if (PFORMAT->swizzle == SWIZZLE_RGBA)
glFormat = GL_RGBA;
else if (PFORMAT->swizzle == BGRA)
else if (PFORMAT->swizzle == SWIZZLE_BGRA)
glFormat = GL_BGRA_EXT;
else {
LOGM(Log::ERR, "Copied frame via shm might be broken or color flipped");

View file

@ -14,7 +14,9 @@
#include "../../render/pass/RectPassElement.hpp"
#include "helpers/cm/ColorManagement.hpp"
#include <hyprutils/math/Region.hpp>
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Screenshare;
CScreenshareFrame::CScreenshareFrame(WP<CScreenshareSession> session, bool overlayCursor, bool isFirst) :
@ -395,7 +397,7 @@ bool CScreenshareFrame::copyShm() {
auto shm = m_buffer->shm();
const auto PFORMAT = NFormatUtils::getPixelFormatFromDRM(shm.format);
const auto PFORMAT = getPixelFormatFromDRM(shm.format);
if (!PFORMAT) {
LOGM(Log::ERR, "Can't copy: failed to find a pixel format");
return false;

View file

@ -5,7 +5,9 @@
#include "types/Buffer.hpp"
#include "../helpers/Format.hpp"
#include "../helpers/time/Time.hpp"
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Screenshare;
CScreencopyClient::CScreencopyClient(SP<CZwlrScreencopyManagerV1> resource_) : m_resource(resource_) {
@ -74,7 +76,7 @@ CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, WP<CScr
DRMFormat format = formats.at(0);
auto bufSize = m_frame->bufferSize();
const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(format);
const auto PSHMINFO = getPixelFormatFromDRM(format);
if (!PSHMINFO) {
LOGM(Log::ERR, "No pixel format for drm format");
@ -82,7 +84,7 @@ CScreencopyFrame::CScreencopyFrame(SP<CZwlrScreencopyFrameV1> resource_, WP<CScr
return;
}
const auto stride = NFormatUtils::minStride(PSHMINFO, bufSize.x);
const auto stride = minStride(PSHMINFO, bufSize.x);
m_resource->sendBuffer(NFormatUtils::drmToShm(format), bufSize.x, bufSize.y, stride);
if (m_resource->version() >= 3) {

View file

@ -6,7 +6,9 @@
#include "../render/Renderer.hpp"
#include <hyprutils/math/Vector2D.hpp>
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Screenshare;
CToplevelExportClient::CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1> resource_) : m_resource(resource_) {
@ -73,8 +75,8 @@ CToplevelExportFrame::CToplevelExportFrame(SP<CHyprlandToplevelExportFrameV1> re
DRMFormat format = formats.at(0);
auto bufSize = m_frame->bufferSize();
const auto PSHMINFO = NFormatUtils::getPixelFormatFromDRM(format);
const auto stride = NFormatUtils::minStride(PSHMINFO, bufSize.x);
const auto PSHMINFO = getPixelFormatFromDRM(format);
const auto stride = minStride(PSHMINFO, bufSize.x);
m_resource->sendBuffer(NFormatUtils::drmToShm(format), bufSize.x, bufSize.y, stride);
if LIKELY (format != DRM_FORMAT_INVALID)

View file

@ -7,6 +7,9 @@
#include "../types/WLBuffer.hpp"
#include "../../helpers/Format.hpp"
#include "../../render/Renderer.hpp"
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Hyprutils::OS;
CWLSHMBuffer::CWLSHMBuffer(WP<CWLSHMPoolResource> pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) {
@ -21,7 +24,7 @@ CWLSHMBuffer::CWLSHMBuffer(WP<CWLSHMPoolResource> pool_, uint32_t id, int32_t of
m_stride = stride_;
m_fmt = fmt_;
m_offset = offset_;
m_opaque = NFormatUtils::isFormatOpaque(NFormatUtils::shmToDRM(fmt_));
m_opaque = isDrmFormatOpaque(NFormatUtils::shmToDRM(fmt_));
m_resource = CWLBufferResource::create(makeShared<CWlBuffer>(pool_->m_resource->client(), 1, id));

View file

@ -3,6 +3,7 @@
#include "../../desktop/view/LayerSurface.hpp"
#include "../../render/Renderer.hpp"
#include "../../helpers/Format.hpp"
#include <hyprgraphics/egl/Egl.hpp>
#if defined(__linux__)
#include <linux/dma-buf.h>
@ -11,6 +12,7 @@
#include <sys/ioctl.h>
using namespace Hyprutils::OS;
using namespace Hyprgraphics::Egl;
CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs const& attrs_) : m_attrs(attrs_) {
m_listeners.resourceDestroy = events.destroy.listen([this] {
@ -20,7 +22,7 @@ CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs
size = m_attrs.size;
m_resource = CWLBufferResource::create(makeShared<CWlBuffer>(client, 1, id));
m_opaque = NFormatUtils::isFormatOpaque(m_attrs.format);
m_opaque = isDrmFormatOpaque(m_attrs.format);
m_texture = g_pHyprRenderer->createTexture(m_attrs, m_opaque); // texture takes ownership of the eglImage
if UNLIKELY (!m_texture) {

View file

@ -3,7 +3,9 @@
#include "../Renderer.hpp"
#include "macros.hpp"
#include "../Framebuffer.hpp"
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Render::GL;
CGLFramebuffer::CGLFramebuffer() : IFramebuffer() {}
@ -27,14 +29,14 @@ bool CGLFramebuffer::internalAlloc(int w, int h, uint32_t drmFormat) {
m_fbAllocated = true;
}
const auto format = NFormatUtils::getPixelFormatFromDRM(drmFormat);
const auto format = getPixelFormatFromDRM(drmFormat);
m_tex->bind();
glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, w, h, 0, format->glFormat, format->glType, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tex->m_texID, 0);
if (m_mirrorTex) {
const auto format = NFormatUtils::getPixelFormatFromDRM(m_mirrorTex->m_drmFormat);
const auto format = getPixelFormatFromDRM(m_mirrorTex->m_drmFormat);
m_mirrorTex->bind();
glTexImage2D(GL_TEXTURE_2D, 0, format->glInternalFormat ? format->glInternalFormat : format->glFormat, w, h, 0, format->glFormat, format->glType, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_fb);
@ -110,7 +112,7 @@ bool CGLFramebuffer::readPixels(CHLBufferReference buffer, uint32_t offsetX, uin
auto shm = buffer->shm();
auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); // no need for end, cuz it's shm
const auto PFORMAT = NFormatUtils::getPixelFormatFromDRM(shm.format);
const auto PFORMAT = getPixelFormatFromDRM(shm.format);
if (!PFORMAT) {
LOGM(Log::ERR, "Can't copy: failed to find a pixel format");
return false;
@ -122,7 +124,7 @@ bool CGLFramebuffer::readPixels(CHLBufferReference buffer, uint32_t offsetX, uin
glPixelStorei(GL_PACK_ALIGNMENT, 1);
uint32_t packStride = NFormatUtils::minStride(PFORMAT, m_size.x);
uint32_t packStride = minStride(PFORMAT, m_size.x);
int glFormat = PFORMAT->glFormat;
if (glFormat == GL_RGBA)
@ -130,11 +132,9 @@ bool CGLFramebuffer::readPixels(CHLBufferReference buffer, uint32_t offsetX, uin
if (glFormat != GL_BGRA_EXT && glFormat != GL_RGB) {
if (PFORMAT->swizzle.has_value()) {
std::array<GLint, 4> RGBA = SWIZZLE_RGBA;
std::array<GLint, 4> BGRA = SWIZZLE_BGRA;
if (PFORMAT->swizzle == RGBA)
if (PFORMAT->swizzle == SWIZZLE_RGBA)
glFormat = GL_RGBA;
else if (PFORMAT->swizzle == BGRA)
else if (PFORMAT->swizzle == SWIZZLE_BGRA)
glFormat = GL_BGRA_EXT;
else {
LOGM(Log::ERR, "Copied frame via shm might be broken or color flipped");

View file

@ -4,7 +4,9 @@
#include "../../helpers/Format.hpp"
#include "../Texture.hpp"
#include <cstring>
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace Render::GL;
CGLTexture::CGLTexture(bool opaque) {
@ -32,7 +34,7 @@ CGLTexture::CGLTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, con
g_pHyprOpenGL->makeEGLCurrent();
const auto format = NFormatUtils::getPixelFormatFromDRM(drmFormat);
const auto format = getPixelFormatFromDRM(drmFormat);
ASSERT(format);
m_type = format->withAlpha ? TEXTURE_RGBA : TEXTURE_RGBX;
@ -70,7 +72,7 @@ CGLTexture::CGLTexture(const Aquamarine::SDMABUFAttrs& attrs, void* image, bool
return;
}
m_opaque = NFormatUtils::isFormatOpaque(attrs.format);
m_opaque = isDrmFormatOpaque(attrs.format);
// #TODO external only formats should be external aswell.
// also needs a seperate color shader.
@ -79,7 +81,7 @@ CGLTexture::CGLTexture(const Aquamarine::SDMABUFAttrs& attrs, void* image, bool
m_type = TEXTURE_EXTERNAL;
} else {*/
m_target = GL_TEXTURE_2D;
m_type = NFormatUtils::isFormatOpaque(attrs.format) ? TEXTURE_RGBX : TEXTURE_RGBA;
m_type = isDrmFormatOpaque(attrs.format) ? TEXTURE_RGBX : TEXTURE_RGBA;
//}
allocate(attrs.size);
@ -124,7 +126,7 @@ void CGLTexture::update(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, co
g_pHyprOpenGL->makeEGLCurrent();
const auto format = NFormatUtils::getPixelFormatFromDRM(drmFormat);
const auto format = getPixelFormatFromDRM(drmFormat);
ASSERT(format);
bind();

View file

@ -4,7 +4,9 @@
#include <drm_fourcc.h>
#include <wayland-server-protocol.h>
#include <hyprgraphics/egl/Egl.hpp>
using namespace Hyprgraphics::Egl;
using namespace NFormatUtils;
TEST(Helpers, formatDrmToShm) {
@ -45,8 +47,8 @@ TEST(Helpers, formatGetPixelFormatFromDRM) {
}
TEST(Helpers, formatIsFormatOpaque) {
EXPECT_TRUE(isFormatOpaque(DRM_FORMAT_XRGB8888));
EXPECT_FALSE(isFormatOpaque(DRM_FORMAT_ARGB8888));
EXPECT_TRUE(isDrmFormatOpaque(DRM_FORMAT_XRGB8888));
EXPECT_FALSE(isDrmFormatOpaque(DRM_FORMAT_ARGB8888));
}
TEST(Helpers, formatPixelsPerBlock) {