backends/drm: move texture creation for gbm buffers into GbmBuffer
This commit is contained in:
parent
3d038b715f
commit
c30339cc82
4 changed files with 25 additions and 16 deletions
|
@ -11,6 +11,8 @@
|
|||
#include "gbm_surface.h"
|
||||
|
||||
#include "drm_gpu.h"
|
||||
#include "kwineglimagetexture.h"
|
||||
#include "kwineglutils_p.h"
|
||||
#include "logging.h"
|
||||
|
||||
// system
|
||||
|
@ -129,6 +131,19 @@ uint32_t GbmBuffer::stride() const
|
|||
return m_stride;
|
||||
}
|
||||
|
||||
QSharedPointer<GLTexture> GbmBuffer::createTexture(EGLDisplay eglDisplay) const
|
||||
{
|
||||
if (!m_bo) {
|
||||
return nullptr;
|
||||
}
|
||||
EGLImageKHR image = eglCreateImageKHR(eglDisplay, nullptr, EGL_NATIVE_PIXMAP_KHR, m_bo, nullptr);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << getEglErrorString();
|
||||
return nullptr;
|
||||
}
|
||||
return QSharedPointer<EGLImageTexture>::create(eglDisplay, image, GL_RGBA8, QSize(gbm_bo_get_width(m_bo), gbm_bo_get_height(m_bo)));
|
||||
}
|
||||
|
||||
DrmGbmBuffer::DrmGbmBuffer(DrmGpu *gpu, GbmSurface *surface, gbm_bo *bo)
|
||||
: DrmBuffer(gpu, gbm_bo_get_format(bo), gbm_bo_get_modifier(bo))
|
||||
, GbmBuffer(surface, bo)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "drm_buffer.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <epoxy/egl.h>
|
||||
|
||||
struct gbm_bo;
|
||||
|
||||
|
@ -26,6 +27,7 @@ namespace KWin
|
|||
{
|
||||
|
||||
class GbmSurface;
|
||||
class GLTexture;
|
||||
|
||||
class GbmBuffer : public QObject
|
||||
{
|
||||
|
@ -42,6 +44,7 @@ public:
|
|||
uint32_t stride() const;
|
||||
KWaylandServer::ClientBuffer *clientBuffer() const;
|
||||
gbm_bo *getBo() const;
|
||||
QSharedPointer<GLTexture> createTexture(EGLDisplay eglDisplay) const;
|
||||
|
||||
protected:
|
||||
GbmSurface *m_surface = nullptr;
|
||||
|
|
|
@ -294,26 +294,16 @@ bool EglGbmLayer::doesSwapchainFit(DumbSwapchain *swapchain) const
|
|||
|
||||
QSharedPointer<GLTexture> EglGbmLayer::texture() const
|
||||
{
|
||||
const auto createImage = [this](GbmBuffer *gbmBuffer) {
|
||||
EGLImageKHR image = eglCreateImageKHR(m_eglBackend->eglDisplay(), nullptr, EGL_NATIVE_PIXMAP_KHR, gbmBuffer->getBo(), nullptr);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << getEglErrorString();
|
||||
return QSharedPointer<EGLImageTexture>(nullptr);
|
||||
}
|
||||
return QSharedPointer<EGLImageTexture>::create(m_eglBackend->eglDisplay(), image, GL_RGBA8, m_pipeline->sourceSize());
|
||||
};
|
||||
if (m_scanoutBuffer) {
|
||||
return createImage(dynamic_cast<GbmBuffer *>(m_scanoutBuffer.data()));
|
||||
}
|
||||
if (m_shadowBuffer) {
|
||||
return m_scanoutBuffer->createTexture(m_eglBackend->eglDisplay());
|
||||
} else if (m_shadowBuffer) {
|
||||
return m_shadowBuffer->texture();
|
||||
}
|
||||
GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().data();
|
||||
if (!gbmBuffer) {
|
||||
} else if (GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().data()) {
|
||||
return gbmBuffer->createTexture(m_eglBackend->eglDisplay());
|
||||
} else {
|
||||
qCWarning(KWIN_DRM) << "Failed to record frame: No gbm buffer!";
|
||||
return nullptr;
|
||||
}
|
||||
return createImage(gbmBuffer);
|
||||
}
|
||||
|
||||
QSharedPointer<DrmBuffer> EglGbmLayer::importBuffer()
|
||||
|
|
|
@ -29,6 +29,7 @@ class GbmSurface;
|
|||
class DumbSwapchain;
|
||||
class ShadowBuffer;
|
||||
class EglGbmBackend;
|
||||
class DrmGbmBuffer;
|
||||
|
||||
class EglGbmLayer : public DrmPipelineLayer
|
||||
{
|
||||
|
@ -75,7 +76,7 @@ private:
|
|||
bool attemptedThisFrame = false;
|
||||
} m_scanoutCandidate;
|
||||
|
||||
QSharedPointer<DrmBuffer> m_scanoutBuffer;
|
||||
QSharedPointer<DrmGbmBuffer> m_scanoutBuffer;
|
||||
QSharedPointer<DrmBuffer> m_currentBuffer;
|
||||
QRegion m_currentDamage;
|
||||
QSharedPointer<GbmSurface> m_gbmSurface;
|
||||
|
|
Loading…
Reference in a new issue