mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 08:26:00 +01:00
e
This commit is contained in:
parent
d3b58683cc
commit
ce8047e19e
2 changed files with 46 additions and 37 deletions
|
@ -30,6 +30,7 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
|
|||
|
||||
attrs.size = pixelSize;
|
||||
attrs.strides.at(0) = stride;
|
||||
attrs.planes = 1;
|
||||
|
||||
uint64_t offset = 0;
|
||||
if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) {
|
||||
|
@ -69,10 +70,7 @@ Aquamarine::CDRMDumbBuffer::~CDRMDumbBuffer() {
|
|||
if (data)
|
||||
munmap(data, size);
|
||||
|
||||
drm_mode_destroy_dumb request = {
|
||||
.handle = handle,
|
||||
};
|
||||
drmIoctl(allocator->drmFD(), DRM_IOCTL_MODE_DESTROY_DUMB, &request);
|
||||
drmModeDestroyDumbBuffer(allocator->drmFD(), handle);
|
||||
}
|
||||
|
||||
eBufferCapability Aquamarine::CDRMDumbBuffer::caps() {
|
||||
|
@ -112,8 +110,27 @@ Aquamarine::CDRMDumbAllocator::~CDRMDumbAllocator() {
|
|||
}
|
||||
|
||||
SP<CDRMDumbAllocator> Aquamarine::CDRMDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_) {
|
||||
if (drmGetNodeTypeFromFd(drmfd_) != DRM_NODE_PRIMARY) {
|
||||
backend_->log(AQ_LOG_ERROR, "DRM Dumb: Cannot create allocator when drmfd is not the primary node");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint64_t hasDumb = 0;
|
||||
if (drmGetCap(drmfd_, DRM_CAP_DUMB_BUFFER, &hasDumb) < 0) {
|
||||
backend_->log(AQ_LOG_ERROR, "DRM Dumb: Failed to query hasDumb");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!hasDumb) {
|
||||
backend_->log(AQ_LOG_ERROR, "DRM Dumb: hasDumb is false, gpu driver doesn't support dumb buffers!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto a = SP<CDRMDumbAllocator>(new CDRMDumbAllocator(drmfd_, backend_));
|
||||
a->self = a;
|
||||
|
||||
backend_->log(AQ_LOG_DEBUG, "DRM Dumb: created a dumb allocator");
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
|
|
@ -1935,44 +1935,36 @@ void Aquamarine::CDRMFB::drop() {
|
|||
uint32_t Aquamarine::CDRMFB::submitBuffer() {
|
||||
uint32_t newID = 0;
|
||||
|
||||
if (buffer->type() == eBufferType::BUFFER_TYPE_DMABUF) {
|
||||
auto attrs = buffer->dmabuf();
|
||||
std::array<uint64_t, 4> mods = {0, 0, 0, 0};
|
||||
for (size_t i = 0; i < attrs.planes; ++i) {
|
||||
mods[i] = attrs.modifier;
|
||||
}
|
||||
if (!buffer->dmabuf().success)
|
||||
return 0;
|
||||
|
||||
if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) {
|
||||
TRACE(backend->backend->log(AQ_LOG_TRACE,
|
||||
std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size,
|
||||
fourccToName(attrs.format), attrs.modifier)));
|
||||
if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(),
|
||||
&newID, DRM_MODE_FB_MODIFIERS)) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (attrs.modifier != DRM_FORMAT_MOD_INVALID && attrs.modifier != DRM_FORMAT_MOD_LINEAR) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: drmModeAddFB2WithModifiers unsupported and buffer has explicit modifiers");
|
||||
return 0;
|
||||
}
|
||||
auto attrs = buffer->dmabuf();
|
||||
std::array<uint64_t, 4> mods = {0, 0, 0, 0};
|
||||
for (size_t i = 0; i < attrs.planes; ++i) {
|
||||
mods[i] = attrs.modifier;
|
||||
}
|
||||
|
||||
TRACE(backend->backend->log(
|
||||
AQ_LOG_TRACE,
|
||||
std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier)));
|
||||
|
||||
if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), &newID, 0)) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2");
|
||||
return 0;
|
||||
}
|
||||
if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) {
|
||||
TRACE(backend->backend->log(AQ_LOG_TRACE,
|
||||
std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size,
|
||||
fourccToName(attrs.format), attrs.modifier)));
|
||||
if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(),
|
||||
&newID, DRM_MODE_FB_MODIFIERS)) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
auto attrs = buffer->shm();
|
||||
const uint32_t strides[4] = {(uint32_t)attrs.stride, 0, 0, 0};
|
||||
const uint32_t offsets[4] = {0, 0, 0, 0};
|
||||
if (attrs.modifier != DRM_FORMAT_MOD_INVALID && attrs.modifier != DRM_FORMAT_MOD_LINEAR) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: drmModeAddFB2WithModifiers unsupported and buffer has explicit modifiers");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), strides, offsets, &newID, 0)) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a shm buffer with drmModeAddFB2");
|
||||
TRACE(backend->backend->log(
|
||||
AQ_LOG_TRACE,
|
||||
std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier)));
|
||||
|
||||
if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), &newID, 0)) {
|
||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue