Skip to content
Permalink
Browse files
[Linux] GBMBufferSwapchain should only conditionally create linear-fo…
…rmatted buffer objects

https://bugs.webkit.org/show_bug.cgi?id=240637

Reviewed by Adrian Perez de Castro.

Spawning new gbm_bo objects should not default to requesting linear-storage
buffers. Instead, these should only be created when necessary, e.g. when
copying software-decoded video data into these buffers.

By default, no GBM flags are used. When required, the linear-storage requirement
is enscribed in the new flags field of the GBMBufferSwapchain::BufferDescription
object and acted upon in the GBMBufferSwapchain::getBuffer() call, using the
GBM_BO_USE_LINEAR flag in the gbm_bo_create() call.

The DMABuf-specific sink in MediaPlayerPrivateGStreamer is the only place at the
moment where linear-storage buffers are used since software-decoded material
originates here and is stored in linear memory.

* Source/WebCore/platform/graphics/gbm/GBMBufferSwapchain.cpp:
(WebCore::GBMBufferSwapchain::getBuffer):
* Source/WebCore/platform/graphics/gbm/GBMBufferSwapchain.h:
* Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp:
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::pushDMABufToCompositor):

Canonical link: https://commits.webkit.org/250959@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294803 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
zan@falconsigh.net committed May 25, 2022
1 parent 2b4a6da commit 37942e7385f8ecc3f68248408af2d6ef7a3dbed5
Showing 4 changed files with 18 additions and 5 deletions.
@@ -48,7 +48,7 @@ RefPtr<GBMBufferSwapchain::Buffer> GBMBufferSwapchain::getBuffer(const BufferDes

// If the description of the requested buffers has changed, update the description to the new one and wreck the existing buffers.
// This should handle changes in format or dimension of the buffers.
if (description.format.fourcc != m_array.description.format.fourcc || description.width != m_array.description.width || description.height != m_array.description.height) {
if (description.format.fourcc != m_array.description.format.fourcc || description.width != m_array.description.width || description.height != m_array.description.height || description.flags != m_array.description.flags) {
m_array.description = description;
m_array.object = { };
}
@@ -95,12 +95,16 @@ RefPtr<GBMBufferSwapchain::Buffer> GBMBufferSwapchain::getBuffer(const BufferDes
return nullptr;
}

uint32_t boFlags = 0;
if (description.flags & BufferDescription::LinearStorage)
boFlags |= GBM_BO_USE_LINEAR;

// For each plane, we spawn a gbm_bo object of the appropriate size and format.
// TODO: GBM_BO_USE_LINEAR will be needed when transferring memory into the bo (e.g. copying
// over the software-decoded video data), but might not be required for backing e.g. ANGLE rendering.
for (unsigned i = 0; i < buffer->m_description.format.numPlanes; ++i) {
auto& plane = buffer->m_planes[i];
plane.bo = gbm_bo_create(device.device(), plane.width, plane.height, uint32_t(plane.fourcc), GBM_BO_USE_LINEAR);
plane.bo = gbm_bo_create(device.device(), plane.width, plane.height, uint32_t(plane.fourcc), boFlags);
plane.stride = gbm_bo_get_stride(plane.bo);
}

@@ -64,9 +64,15 @@ class GBMBufferSwapchain : public ThreadSafeRefCounted<GBMBufferSwapchain> {
~GBMBufferSwapchain();

struct BufferDescription {
enum Flags : uint32_t {
NoFlags = 0,
LinearStorage = 1 << 0,
};

DMABufFormat format { };
uint32_t width { 0 };
uint32_t height { 0 };
uint32_t flags { NoFlags };
};

class Buffer : public ThreadSafeRefCounted<Buffer> {
@@ -98,6 +98,7 @@ bool GraphicsContextGLANGLE::makeContextCurrent()
.format = DMABufFormat::create(uint32_t(contextAttributes().alpha ? DMABufFormat::FourCC::ARGB8888 : DMABufFormat::FourCC::XRGB8888)),
.width = std::clamp<uint32_t>(size.width(), 0, UINT_MAX),
.height = std::clamp<uint32_t>(size.height(), 0, UINT_MAX),
.flags = GBMBufferSwapchain::BufferDescription::NoFlags,
});

GLenum textureTarget = drawingBufferTextureTarget();
@@ -3140,10 +3140,12 @@ void MediaPlayerPrivateGStreamer::pushDMABufToCompositor()
}

// If the decoder is exporting raw memory, we have to use the swapchain to allocate appropriate buffers
// and copy over the data for each plane.
// and copy over the data for each plane. For that to work, linear-storage buffer is required.
GBMBufferSwapchain::BufferDescription bufferDescription {
DMABufFormat::create(fourccValue(GST_VIDEO_INFO_FORMAT(&videoInfo))),
static_cast<uint32_t>GST_VIDEO_INFO_WIDTH(&videoInfo), static_cast<uint32_t>GST_VIDEO_INFO_HEIGHT(&videoInfo),
.format = DMABufFormat::create(fourccValue(GST_VIDEO_INFO_FORMAT(&videoInfo))),
.width = static_cast<uint32_t>GST_VIDEO_INFO_WIDTH(&videoInfo),
.height = static_cast<uint32_t>GST_VIDEO_INFO_HEIGHT(&videoInfo),
.flags = GBMBufferSwapchain::BufferDescription::LinearStorage,
};
if (bufferDescription.format.fourcc == DMABufFormat::FourCC::Invalid)
return;

0 comments on commit 37942e7

Please sign in to comment.