8#include <QtOpenGL/QOpenGLTexture>
9#include <QtGui/QOpenGLContext>
10#include <QtGui/QOffscreenSurface>
11#include <QtGui/qopengl.h>
16#include <QtCore/QDebug>
21#define DECL_GL_FUNCTION(name, type) \
24#define FIND_GL_FUNCTION(name, type) \
26 name = reinterpret_cast<type>(glContext->getProcAddress(#name)); \
28 qWarning() << "ERROR in GL proc lookup. Could not find " #name; \
69 if (!offscreenSurface) {
72 offscreenSurface->
create();
75 localContextInUse =
true;
77 qCritical(
"VulkanServerBufferIntegration: no globalShareContext");
83 if (localContextInUse)
90 bool localContextInUse =
false;
111 , m_integration(integration)
112 , m_width(qimage.
width())
113 , m_height(qimage.
height())
124 qWarning(
"VulkanServerBuffer: unsupported format");
130 m_vImage = vulkanWrapper->createTextureImage(qimage);
132 m_fd = vulkanWrapper->getImageInfo(m_vImage, &m_memorySize);
137 , m_integration(integration)
141 , m_glInternalFormat(glInternalFormat)
144 m_fd = vulkanWrapper->getImageInfo(m_vImage, &m_memorySize);
156 auto *bufferResource = resourceMap().value(client);
157 if (!bufferResource) {
158 auto integrationResource = m_integration->resourceMap().value(client);
159 if (!integrationResource) {
160 qWarning(
"VulkanServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the vulkan interface");
163 struct ::wl_resource *shm_integration_resource = integrationResource->handle;
164 Resource *resource =
add(client, 1);
165 m_integration->send_server_buffer_created(shm_integration_resource, resource->handle, m_fd, m_width, m_height, m_memorySize, m_glInternalFormat);
166 return resource->handle;
168 return bufferResource->handle;
181 funcs->glCreateMemoryObjectsEXT(1, &m_memoryObject);
185 int dupfd = fcntl(m_fd, F_DUPFD_CLOEXEC, 0);
187 perror(
"VulkanServerBuffer::toOpenGlTexture() Could not dup fd:");
214 if (!m_texture || !m_texture->
isCreated())
219 funcs->glDeleteMemoryObjectsEXT(1, &m_memoryObject);
225 return (m_texture && m_texture->
isCreated()) || resourceMap().size() > 0;
230 qCDebug(qLcWaylandCompositorHardwareIntegration) <<
"server_buffer RELEASE resource" << resource->handle << wl_resource_get_id(resource->handle) <<
"for client" << resource->client();
231 wl_resource_destroy(resource->handle);
246 QtWaylandServer::zqt_vulkan_server_buffer_v1::init(
compositor->display(), 1);
264 if (!m_vulkanWrapper) {
273 uint glInternalFormat)
275 if (!m_vulkanWrapper) {
281 reinterpret_cast<const uchar *
>(
view.constData()),
view.size(),
size, glInternalFormat);
286 qCWarning(qLcWaylandCompositorHardwareIntegration) <<
"could not load compressed texture";
QOpenGLContext * context()
static QPlatformNativeInterface * platformNativeInterface()
void create()
Allocates the platform resources associated with the offscreen surface.
void setFormat(const QSurfaceFormat &format)
Sets the offscreen surface format.
bool create()
Attempts to create the OpenGL context with the current configuration.
bool makeCurrent(QSurface *surface)
Makes the context current in the current thread, against the given surface.
QSurfaceFormat format() const
Returns the format of the underlying platform context, if create() has been called.
void setShareContext(QOpenGLContext *shareContext)
Makes this context share textures, shaders, and other OpenGL resources with shareContext.
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
void doneCurrent()
Convenience function for calling makeCurrent with a 0 surface.
static QOpenGLContext * globalShareContext()
bool isCreated() const
Returns true if the underlying OpenGL texture object has been created.
void destroy()
Destroys the underlying OpenGL texture object.
bool create()
Creates the underlying OpenGL texture object.
void bind()
Binds this texture to the currently active texture unit ready for rendering.
GLuint textureId() const
Returns the name of the underlying OpenGL texture object or 0 if it has not yet been created.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
bool supportsFormat(QtWayland::ServerBuffer::Format format) const override
bool initializeHardware(QWaylandCompositor *) override
~VulkanServerBufferIntegration() override
VulkanServerBufferIntegration()
QtWayland::ServerBuffer * createServerBufferFromData(QByteArrayView view, const QSize &size, uint glInternalFormat) override
QtWayland::ServerBuffer * createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override
VulkanWrapper * vulkanWrapper() const
VulkanServerBuffer(VulkanServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format)
void server_buffer_release(Resource *resource) override
void releaseOpenGlTexture() override
QOpenGLTexture * toOpenGlTexture() override
bool bufferInUse() override
struct::wl_resource * resourceForClient(struct ::wl_client *) override
~VulkanServerBuffer() override
VulkanImageWrapper * createTextureImageFromData(const uchar *pixels, uint bufferSize, const QSize &size, uint glInternalFormat)
void freeTextureImage(VulkanImageWrapper *imageWrapper)
static QT_BEGIN_NAMESPACE constexpr bool vsbiExtraDebug
static VulkanServerBufferGlFunctions * funcs
#define FIND_GL_FUNCTION(name, type)
Combined button and popup list for selecting options.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
#define qCWarning(category,...)
#define qCDebug(category,...)
static QOpenGLCompositor * compositor
#define GL_HANDLE_TYPE_OPAQUE_FD_EXT
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
bool init(QOpenGLContext *glContext)
DECL_GL_FUNCTION(glDeleteMemoryObjectsEXT, PFNGLDELETEMEMORYOBJECTSEXTPROC)
DECL_GL_FUNCTION(glTexStorageMem2DEXT, PFNGLTEXSTORAGEMEM2DEXTPROC)
DECL_GL_FUNCTION(glImportMemoryFdEXT, PFNGLIMPORTMEMORYFDEXTPROC)
DECL_GL_FUNCTION(glCreateMemoryObjectsEXT, PFNGLCREATEMEMORYOBJECTSEXTPROC)
static bool create(QOpenGLContext *glContext)