Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRM: Add a dumb allocator #104

Merged
merged 8 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/aquamarine/allocator/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Aquamarine {

enum eAllocatorType {
AQ_ALLOCATOR_TYPE_GBM = 0,
AQ_ALLOCATOR_TYPE_DRM_DUMB,
};

class IAllocator {
Expand Down
68 changes: 68 additions & 0 deletions include/aquamarine/allocator/DRMDumb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#include "Allocator.hpp"

namespace Aquamarine {
class CDRMDumbAllocator;
class CBackend;
class CSwapchain;

class CDRMDumbBuffer : public IBuffer {
public:
virtual ~CDRMDumbBuffer();

virtual eBufferCapability caps();
virtual eBufferType type();
virtual void update(const Hyprutils::Math::CRegion& damage);
virtual bool isSynchronous();
virtual bool good();
virtual SDMABUFAttrs dmabuf();
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
virtual void endDataPtr();

private:
CDRMDumbBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer<CDRMDumbAllocator> allocator_,
Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain);

Hyprutils::Memory::CWeakPointer<CDRMDumbAllocator> allocator;

//
Hyprutils::Math::Vector2D pixelSize;
uint32_t stride = 0, handle = 0;
uint64_t bufferLen = 0;
uint8_t* data = nullptr;
int primeFD = -1;

//
SDMABUFAttrs attrs{.success = false};

friend class CDRMDumbAllocator;
};

class CDRMDumbAllocator : public IAllocator {
public:
~CDRMDumbAllocator();
static Hyprutils::Memory::CSharedPointer<CDRMDumbAllocator> create(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_);

virtual Hyprutils::Memory::CSharedPointer<IBuffer> acquire(const SAllocatorBufferParams& params, Hyprutils::Memory::CSharedPointer<CSwapchain> swapchain_);
virtual Hyprutils::Memory::CSharedPointer<CBackend> getBackend();
virtual int drmFD();
virtual eAllocatorType type();

//
Hyprutils::Memory::CWeakPointer<CDRMDumbAllocator> self;

private:
CDRMDumbAllocator(int fd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_);

// a vector purely for tracking (debugging) the buffers and nothing more
std::vector<Hyprutils::Memory::CWeakPointer<CDRMDumbBuffer>> buffers;

Hyprutils::Memory::CWeakPointer<CBackend> backend;

int drmfd = -1;

friend class CDRMDumbBuffer;
friend class CDRMRenderer;
};
};
25 changes: 13 additions & 12 deletions include/aquamarine/backend/Backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ namespace Aquamarine {
AQ_BACKEND_CAPABILITY_POINTER = (1 << 0),
};

virtual eBackendType type() = 0;
virtual bool start() = 0;
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs() = 0;
virtual int drmFD() = 0;
virtual bool dispatchEvents() = 0;
virtual uint32_t capabilities() = 0;
virtual void onReady() = 0;
virtual std::vector<SDRMFormat> getRenderFormats() = 0;
virtual std::vector<SDRMFormat> getCursorFormats() = 0;
virtual bool createOutput(const std::string& name = "") = 0; // "" means auto
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator() = 0;
virtual std::vector<SDRMFormat> getRenderableFormats(); // empty = use getRenderFormats
virtual eBackendType type() = 0;
virtual bool start() = 0;
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs() = 0;
virtual int drmFD() = 0;
virtual bool dispatchEvents() = 0;
virtual uint32_t capabilities() = 0;
virtual void onReady() = 0;
virtual std::vector<SDRMFormat> getRenderFormats() = 0;
virtual std::vector<SDRMFormat> getCursorFormats() = 0;
virtual bool createOutput(const std::string& name = "") = 0; // "" means auto
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator() = 0;
virtual std::vector<SDRMFormat> getRenderableFormats(); // empty = use getRenderFormats
virtual std::vector<Hyprutils::Memory::CSharedPointer<IAllocator>> getAllocators() = 0;
};

class CBackend {
Expand Down
48 changes: 26 additions & 22 deletions include/aquamarine/backend/DRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Aquamarine {
class CDRMOutput;
struct SDRMConnector;
class CDRMRenderer;
class CDRMDumbAllocator;

typedef std::function<void(void)> FIdleCallback;

Expand Down Expand Up @@ -340,28 +341,29 @@ namespace Aquamarine {
class CDRMBackend : public IBackendImplementation {
public:
virtual ~CDRMBackend();
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();
virtual std::vector<SDRMFormat> getRenderableFormats();

Hyprutils::Memory::CWeakPointer<CDRMBackend> self;

void log(eBackendLogLevel, const std::string&);
bool sessionActive();
int getNonMasterFD();

std::vector<FIdleCallback> idleCallbacks;
std::string gpuName;
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();
virtual std::vector<SDRMFormat> getRenderableFormats();
virtual std::vector<Hyprutils::Memory::CSharedPointer<IAllocator>> getAllocators();

Hyprutils::Memory::CWeakPointer<CDRMBackend> self;

void log(eBackendLogLevel, const std::string&);
bool sessionActive();
int getNonMasterFD();

std::vector<FIdleCallback> idleCallbacks;
std::string gpuName;

private:
CDRMBackend(Hyprutils::Memory::CSharedPointer<CBackend> backend);
Expand Down Expand Up @@ -396,6 +398,8 @@ namespace Aquamarine {
std::vector<SDRMFormat> formats;
std::vector<SDRMFormat> glFormats;

Hyprutils::Memory::CSharedPointer<CDRMDumbAllocator> dumbAllocator;

bool atomic = false;

struct {
Expand Down
30 changes: 16 additions & 14 deletions include/aquamarine/backend/Headless.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Aquamarine {
class CBackend;
class CHeadlessBackend;
class IAllocator;

class CHeadlessOutput : public IOutput {
public:
Expand Down Expand Up @@ -35,20 +36,21 @@ namespace Aquamarine {
class CHeadlessBackend : public IBackendImplementation {
public:
virtual ~CHeadlessBackend();
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();

Hyprutils::Memory::CWeakPointer<CHeadlessBackend> self;
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();
virtual std::vector<Hyprutils::Memory::CSharedPointer<IAllocator>> getAllocators();

Hyprutils::Memory::CWeakPointer<CHeadlessBackend> self;

private:
CHeadlessBackend(Hyprutils::Memory::CSharedPointer<CBackend> backend_);
Expand Down
29 changes: 15 additions & 14 deletions include/aquamarine/backend/Wayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,21 @@ namespace Aquamarine {
class CWaylandBackend : public IBackendImplementation {
public:
virtual ~CWaylandBackend();
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();

Hyprutils::Memory::CWeakPointer<CWaylandBackend> self;
virtual eBackendType type();
virtual bool start();
virtual std::vector<Hyprutils::Memory::CSharedPointer<SPollFD>> pollFDs();
virtual int drmFD();
virtual bool dispatchEvents();
virtual uint32_t capabilities();
virtual bool setCursor(Hyprutils::Memory::CSharedPointer<IBuffer> buffer, const Hyprutils::Math::Vector2D& hotspot);
virtual void onReady();
virtual std::vector<SDRMFormat> getRenderFormats();
virtual std::vector<SDRMFormat> getCursorFormats();
virtual bool createOutput(const std::string& name = "");
virtual Hyprutils::Memory::CSharedPointer<IAllocator> preferredAllocator();
virtual std::vector<Hyprutils::Memory::CSharedPointer<IAllocator>> getAllocators();

Hyprutils::Memory::CWeakPointer<CWaylandBackend> self;

private:
CWaylandBackend(Hyprutils::Memory::CSharedPointer<CBackend> backend);
Expand Down
Loading
Loading