mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 15:45:59 +01:00
parent
5d100bdcbb
commit
68783d904d
4 changed files with 76 additions and 71 deletions
|
@ -457,12 +457,12 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb.m_iFb);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb.m_iFb);
|
||||||
|
|
||||||
GLint glf, glt;
|
const auto PFORMAT = g_pHyprOpenGL->getPixelFormatFromDRM(format);
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf);
|
if (!PFORMAT) {
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt);
|
g_pHyprRenderer->endRender();
|
||||||
if (glf == 0 || glt == 0) {
|
wlr_texture_destroy(sourceTex);
|
||||||
glf = drmFormatToGL(frame->pMonitor->drmFormat);
|
wlr_buffer_end_data_ptr_access(frame->buffer);
|
||||||
glt = glFormatToType(glf);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pHyprRenderer->endRender();
|
g_pHyprRenderer->endRender();
|
||||||
|
@ -473,16 +473,15 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec*
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
const auto FMT = g_pHyprOpenGL->getPreferredReadFormat(frame->pMonitor);
|
const wlr_pixel_format_info* drmFmtWlr = drm_get_pixel_format_info(format);
|
||||||
const wlr_pixel_format_info* drmFmtWlr = drm_get_pixel_format_info(FMT);
|
|
||||||
uint32_t packStride = pixel_format_info_min_stride(drmFmtWlr, frame->box.w);
|
uint32_t packStride = pixel_format_info_min_stride(drmFmtWlr, frame->box.w);
|
||||||
|
|
||||||
if (packStride == stride) {
|
if (packStride == stride) {
|
||||||
glReadPixels(frame->box.x, frame->box.y, frame->box.w, frame->box.h, glf, glt, data);
|
glReadPixels(frame->box.x, frame->box.y, frame->box.w, frame->box.h, PFORMAT->glFormat, PFORMAT->glType, data);
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < frame->box.h; ++i) {
|
for (size_t i = 0; i < frame->box.h; ++i) {
|
||||||
uint32_t y = frame->box.x + i;
|
uint32_t y = frame->box.x + i;
|
||||||
glReadPixels(frame->box.x, y, frame->box.w, 1, glf, glt, ((unsigned char*)data) + i * stride);
|
glReadPixels(frame->box.x, y, frame->box.w, 1, PFORMAT->glFormat, PFORMAT->glType, ((unsigned char*)data) + i * stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -387,19 +387,18 @@ bool CToplevelExportProtocolManager::copyFrameShm(SScreencopyFrame* frame, times
|
||||||
if (frame->overlayCursor)
|
if (frame->overlayCursor)
|
||||||
g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.vec());
|
g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.vec());
|
||||||
|
|
||||||
GLint glf, glt;
|
const auto PFORMAT = g_pHyprOpenGL->getPixelFormatFromDRM(format);
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf);
|
if (!PFORMAT) {
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt);
|
g_pHyprRenderer->endRender();
|
||||||
if (glf == 0 || glt == 0) {
|
wlr_buffer_end_data_ptr_access(frame->buffer);
|
||||||
glf = drmFormatToGL(frame->pMonitor->drmFormat);
|
return false;
|
||||||
glt = glFormatToType(glf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pHyprOpenGL->m_RenderData.mainFB->bind();
|
g_pHyprOpenGL->m_RenderData.mainFB->bind();
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
glReadPixels(0, 0, frame->box.width, frame->box.height, glf, glt, data);
|
glReadPixels(0, 0, frame->box.width, frame->box.height, PFORMAT->glFormat, PFORMAT->glType, data);
|
||||||
|
|
||||||
g_pHyprRenderer->endRender();
|
g_pHyprRenderer->endRender();
|
||||||
|
|
||||||
|
|
|
@ -2067,14 +2067,6 @@ void CHyprOpenGLImpl::setMonitorTransformEnabled(bool enabled) {
|
||||||
m_bEndFrame = !enabled;
|
m_bEndFrame = !enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SGLPixelFormat {
|
|
||||||
uint32_t drmFormat = DRM_FORMAT_INVALID;
|
|
||||||
GLint glInternalFormat = 0;
|
|
||||||
GLint glFormat = 0;
|
|
||||||
GLint glType = 0;
|
|
||||||
bool withAlpha = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline const SGLPixelFormat GLES2_FORMATS[] = {
|
inline const SGLPixelFormat GLES2_FORMATS[] = {
|
||||||
{
|
{
|
||||||
.drmFormat = DRM_FORMAT_ARGB8888,
|
.drmFormat = DRM_FORMAT_ARGB8888,
|
||||||
|
@ -2179,9 +2171,6 @@ inline const SGLPixelFormat GLES2_FORMATS[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) {
|
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) {
|
||||||
if (g_pHyprRenderer->isNvidia())
|
|
||||||
return DRM_FORMAT_XBGR8888;
|
|
||||||
|
|
||||||
GLint glf = -1, glt = -1, as = -1;
|
GLint glf = -1, glt = -1, as = -1;
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf);
|
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf);
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt);
|
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt);
|
||||||
|
@ -2202,3 +2191,12 @@ uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) {
|
||||||
|
|
||||||
return DRM_FORMAT_XBGR8888;
|
return DRM_FORMAT_XBGR8888;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SGLPixelFormat* CHyprOpenGLImpl::getPixelFormatFromDRM(uint32_t drmFormat) {
|
||||||
|
for (auto& fmt : GLES2_FORMATS) {
|
||||||
|
if (fmt.drmFormat == drmFormat)
|
||||||
|
return &fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
|
@ -41,6 +41,14 @@ struct SRenderModifData {
|
||||||
float scale = 1.f;
|
float scale = 1.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SGLPixelFormat {
|
||||||
|
uint32_t drmFormat = DRM_FORMAT_INVALID;
|
||||||
|
GLint glInternalFormat = 0;
|
||||||
|
GLint glFormat = 0;
|
||||||
|
GLint glType = 0;
|
||||||
|
bool withAlpha = false;
|
||||||
|
};
|
||||||
|
|
||||||
struct SMonitorRenderData {
|
struct SMonitorRenderData {
|
||||||
CFramebuffer offloadFB;
|
CFramebuffer offloadFB;
|
||||||
CFramebuffer mirrorFB; // these are used for some effects,
|
CFramebuffer mirrorFB; // these are used for some effects,
|
||||||
|
@ -159,6 +167,7 @@ class CHyprOpenGLImpl {
|
||||||
void bindBackOnMain();
|
void bindBackOnMain();
|
||||||
|
|
||||||
uint32_t getPreferredReadFormat(CMonitor* pMonitor);
|
uint32_t getPreferredReadFormat(CMonitor* pMonitor);
|
||||||
|
const SGLPixelFormat* getPixelFormatFromDRM(uint32_t drmFormat);
|
||||||
|
|
||||||
SCurrentRenderData m_RenderData;
|
SCurrentRenderData m_RenderData;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue