wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
This commit is contained in:
parent
c31d9ef417
commit
6967a31450
147 changed files with 5388 additions and 2226 deletions
41
src/protocols/types/Buffer.cpp
Normal file
41
src/protocols/types/Buffer.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "Buffer.hpp"
|
||||
#include "WLBuffer.hpp"
|
||||
|
||||
SDMABUFAttrs IWLBuffer::dmabuf() {
|
||||
return SDMABUFAttrs{};
|
||||
}
|
||||
|
||||
SSHMAttrs IWLBuffer::shm() {
|
||||
return SSHMAttrs{};
|
||||
}
|
||||
|
||||
std::tuple<uint8_t*, uint32_t, size_t> IWLBuffer::beginDataPtr(uint32_t flags) {
|
||||
return {nullptr, 0, 0};
|
||||
}
|
||||
|
||||
void IWLBuffer::endDataPtr() {
|
||||
; // empty
|
||||
}
|
||||
|
||||
void IWLBuffer::sendRelease() {
|
||||
if (!resource || !resource->resource)
|
||||
return;
|
||||
resource->resource->sendRelease();
|
||||
}
|
||||
|
||||
void IWLBuffer::lock() {
|
||||
locks++;
|
||||
}
|
||||
|
||||
void IWLBuffer::unlock() {
|
||||
locks--;
|
||||
|
||||
ASSERT(locks >= 0);
|
||||
|
||||
if (locks <= 0)
|
||||
sendRelease();
|
||||
}
|
||||
|
||||
bool IWLBuffer::locked() {
|
||||
return locks;
|
||||
}
|
||||
74
src/protocols/types/Buffer.hpp
Normal file
74
src/protocols/types/Buffer.hpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../defines.hpp"
|
||||
#include "../../helpers/signal/Signal.hpp"
|
||||
#include "../../render/Texture.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
|
||||
enum eBufferCapability {
|
||||
BUFFER_CAPABILITY_DATAPTR = (1 << 0),
|
||||
};
|
||||
|
||||
enum eBufferType {
|
||||
BUFFER_TYPE_DMABUF = 0,
|
||||
BUFFER_TYPE_SHM,
|
||||
BUFFER_TYPE_MISC,
|
||||
};
|
||||
|
||||
class CWLBufferResource;
|
||||
|
||||
struct SDMABUFAttrs {
|
||||
bool success = false;
|
||||
Vector2D size;
|
||||
uint32_t format = 0; // fourcc
|
||||
uint64_t modifier = 0;
|
||||
|
||||
int planes = 1;
|
||||
std::array<uint32_t, 4> offsets = {0};
|
||||
std::array<uint32_t, 4> strides = {0};
|
||||
std::array<int, 4> fds = {-1, -1, -1, -1};
|
||||
};
|
||||
|
||||
struct SSHMAttrs {
|
||||
bool success = false;
|
||||
int fd = 0;
|
||||
uint32_t format = 0;
|
||||
Vector2D size;
|
||||
int stride = 0;
|
||||
int64_t offset = 0;
|
||||
};
|
||||
|
||||
class IWLBuffer {
|
||||
public:
|
||||
virtual ~IWLBuffer() {
|
||||
;
|
||||
};
|
||||
|
||||
virtual eBufferCapability caps() = 0;
|
||||
virtual eBufferType type() = 0;
|
||||
virtual void update(const CRegion& damage) = 0;
|
||||
virtual SDMABUFAttrs dmabuf();
|
||||
virtual SSHMAttrs shm();
|
||||
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
|
||||
virtual void endDataPtr();
|
||||
virtual void sendRelease();
|
||||
virtual void lock();
|
||||
virtual void unlock();
|
||||
virtual bool locked();
|
||||
|
||||
Vector2D size;
|
||||
bool opaque = false;
|
||||
|
||||
SP<CWLBufferResource> resource;
|
||||
|
||||
SP<CTexture> texture;
|
||||
|
||||
struct {
|
||||
CSignal destroy;
|
||||
} events;
|
||||
|
||||
private:
|
||||
int locks = 0;
|
||||
};
|
||||
75
src/protocols/types/DMABuffer.cpp
Normal file
75
src/protocols/types/DMABuffer.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include "DMABuffer.hpp"
|
||||
#include "WLBuffer.hpp"
|
||||
#include "../../render/Renderer.hpp"
|
||||
#include "../../helpers/Format.hpp"
|
||||
|
||||
CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs attrs_) : attrs(attrs_) {
|
||||
g_pHyprRenderer->makeEGLCurrent();
|
||||
|
||||
listeners.resourceDestroy = events.destroy.registerListener([this](std::any d) {
|
||||
closeFDs();
|
||||
listeners.resourceDestroy.reset();
|
||||
});
|
||||
|
||||
size = attrs.size;
|
||||
resource = CWLBufferResource::create(makeShared<CWlBuffer>(client, 1, id));
|
||||
|
||||
auto eglImage = g_pHyprOpenGL->createEGLImage(attrs);
|
||||
|
||||
if (!eglImage)
|
||||
return;
|
||||
|
||||
texture = makeShared<CTexture>(attrs, eglImage); // texture takes ownership of the eglImage
|
||||
opaque = FormatUtils::isFormatOpaque(attrs.format);
|
||||
success = texture->m_iTexID;
|
||||
|
||||
if (!success)
|
||||
Debug::log(ERR, "Failed to create a dmabuf: texture is null");
|
||||
}
|
||||
|
||||
CDMABuffer::~CDMABuffer() {
|
||||
closeFDs();
|
||||
}
|
||||
|
||||
eBufferCapability CDMABuffer::caps() {
|
||||
return BUFFER_CAPABILITY_DATAPTR;
|
||||
}
|
||||
|
||||
eBufferType CDMABuffer::type() {
|
||||
return BUFFER_TYPE_DMABUF;
|
||||
}
|
||||
|
||||
void CDMABuffer::update(const CRegion& damage) {
|
||||
;
|
||||
}
|
||||
|
||||
SDMABUFAttrs CDMABuffer::dmabuf() {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
std::tuple<uint8_t*, uint32_t, size_t> CDMABuffer::beginDataPtr(uint32_t flags) {
|
||||
// FIXME:
|
||||
return {nullptr, 0, 0};
|
||||
}
|
||||
|
||||
void CDMABuffer::endDataPtr() {
|
||||
// FIXME:
|
||||
}
|
||||
|
||||
bool CDMABuffer::good() {
|
||||
return success;
|
||||
}
|
||||
|
||||
void CDMABuffer::updateTexture() {
|
||||
;
|
||||
}
|
||||
|
||||
void CDMABuffer::closeFDs() {
|
||||
for (int i = 0; i < attrs.planes; ++i) {
|
||||
if (attrs.fds[i] == -1)
|
||||
continue;
|
||||
close(attrs.fds[i]);
|
||||
attrs.fds[i] = -1;
|
||||
}
|
||||
attrs.planes = 0;
|
||||
}
|
||||
28
src/protocols/types/DMABuffer.hpp
Normal file
28
src/protocols/types/DMABuffer.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include "Buffer.hpp"
|
||||
|
||||
class CDMABuffer : public IWLBuffer {
|
||||
public:
|
||||
CDMABuffer(uint32_t id, wl_client* client, SDMABUFAttrs attrs_);
|
||||
virtual ~CDMABuffer();
|
||||
|
||||
virtual eBufferCapability caps();
|
||||
virtual eBufferType type();
|
||||
virtual void update(const CRegion& damage);
|
||||
virtual SDMABUFAttrs dmabuf();
|
||||
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
|
||||
virtual void endDataPtr();
|
||||
bool good();
|
||||
void updateTexture();
|
||||
void closeFDs();
|
||||
|
||||
bool success = false;
|
||||
|
||||
private:
|
||||
SDMABUFAttrs attrs;
|
||||
|
||||
struct {
|
||||
CHyprSignalListener resourceDestroy;
|
||||
} listeners;
|
||||
};
|
||||
14
src/protocols/types/SurfaceRole.hpp
Normal file
14
src/protocols/types/SurfaceRole.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
enum eSurfaceRole {
|
||||
SURFACE_ROLE_UNASSIGNED = 0,
|
||||
SURFACE_ROLE_XDG_SHELL,
|
||||
SURFACE_ROLE_LAYER_SHELL,
|
||||
SURFACE_ROLE_EASTER_EGG,
|
||||
SURFACE_ROLE_SUBSURFACE,
|
||||
};
|
||||
|
||||
class ISurfaceRole {
|
||||
public:
|
||||
virtual eSurfaceRole role() = 0;
|
||||
};
|
||||
43
src/protocols/types/WLBuffer.cpp
Normal file
43
src/protocols/types/WLBuffer.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "WLBuffer.hpp"
|
||||
#include "Buffer.hpp"
|
||||
|
||||
CWLBufferResource::CWLBufferResource(SP<CWlBuffer> resource_) : resource(resource_) {
|
||||
if (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CWlBuffer* r) {
|
||||
if (buffer.expired())
|
||||
return;
|
||||
buffer->events.destroy.emit();
|
||||
});
|
||||
resource->setDestroy([this](CWlBuffer* r) {
|
||||
if (buffer.expired())
|
||||
return;
|
||||
buffer->events.destroy.emit();
|
||||
});
|
||||
|
||||
resource->setData(this);
|
||||
}
|
||||
|
||||
bool CWLBufferResource::good() {
|
||||
return resource->resource();
|
||||
}
|
||||
|
||||
void CWLBufferResource::sendRelease() {
|
||||
resource->sendRelease();
|
||||
}
|
||||
|
||||
wl_resource* CWLBufferResource::getResource() {
|
||||
return resource->resource();
|
||||
}
|
||||
|
||||
SP<CWLBufferResource> CWLBufferResource::fromResource(wl_resource* res) {
|
||||
auto data = (CWLBufferResource*)(((CWlBuffer*)wl_resource_get_user_data(res))->data());
|
||||
return data ? data->self.lock() : nullptr;
|
||||
}
|
||||
|
||||
SP<CWLBufferResource> CWLBufferResource::create(SP<CWlBuffer> resource) {
|
||||
auto p = SP<CWLBufferResource>(new CWLBufferResource(resource));
|
||||
p->self = p;
|
||||
return p;
|
||||
}
|
||||
31
src/protocols/types/WLBuffer.hpp
Normal file
31
src/protocols/types/WLBuffer.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include "../WaylandProtocol.hpp"
|
||||
#include "wayland.hpp"
|
||||
#include "../../helpers/signal/Signal.hpp"
|
||||
|
||||
class IWLBuffer;
|
||||
|
||||
class CWLBufferResource {
|
||||
public:
|
||||
static SP<CWLBufferResource> create(SP<CWlBuffer> resource);
|
||||
static SP<CWLBufferResource> fromResource(wl_resource* res);
|
||||
|
||||
bool good();
|
||||
void sendRelease();
|
||||
wl_resource* getResource();
|
||||
|
||||
WP<IWLBuffer> buffer;
|
||||
|
||||
WP<CWLBufferResource> self;
|
||||
|
||||
private:
|
||||
CWLBufferResource(SP<CWlBuffer> resource_);
|
||||
|
||||
SP<CWlBuffer> resource;
|
||||
|
||||
friend class IWLBuffer;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue