Skip to content

Commit

Permalink
[WPE] WPE Platform: change the API to get the preferred DMA-BUF formats
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=272667

Reviewed by Alejandro G. Castro.

The initial API we added was very simple, just providing a single list
of formats, usages and modifiers, but it turned out it was not so simple
to iterate the formats, since we always want to iterate by tranche.
Also, we want to handle the main and target devices in the future, so we
need a new API that simplifies the iteration by tranche and includes the
devices.

* Source/WebKit/Shared/glib/DMABufRendererBufferFormat.h:
(WebKit::DMABufRendererBufferFormat::operator== const): Deleted.
* Source/WebKit/Shared/glib/DMABufRendererBufferFormat.serialization.in:
* Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp:
(WebKit::WebPageProxy::preferredBufferFormats const):
* Source/WebKit/WPEPlatform/CMakeLists.txt:
* Source/WebKit/WPEPlatform/wpe/WPEBufferDMABufFormat.cpp: Removed.
* Source/WebKit/WPEPlatform/wpe/WPEBufferDMABufFormat.h: Removed.
* Source/WebKit/WPEPlatform/wpe/WPEBufferDMABufFormats.cpp: Added.
(DMABufFormat::DMABufFormat):
(DMABufFormatsGroup::DMABufFormatsGroup):
(wpe_buffer_dma_buf_formats_class_init):
(wpe_buffer_dma_buf_formats_get_device):
(wpe_buffer_dma_buf_formats_get_n_groups):
(wpe_buffer_dma_buf_formats_get_group_usage):
(wpe_buffer_dma_buf_formats_get_group_device):
(wpe_buffer_dma_buf_formats_get_group_n_formats):
(wpe_buffer_dma_buf_formats_get_format_fourcc):
(wpe_buffer_dma_buf_formats_get_format_modifiers):
(_WPEBufferDMABufFormatsBuilder::_WPEBufferDMABufFormatsBuilder):
(wpe_buffer_dma_buf_formats_builder_new):
(wpe_buffer_dma_buf_formats_builder_ref):
(wpe_buffer_dma_buf_formats_builder_unref):
(wpe_buffer_dma_buf_formats_builder_append_group):
(wpe_buffer_dma_buf_formats_builder_append_format):
(wpe_buffer_dma_buf_formats_builder_end):
* Source/WebKit/WPEPlatform/wpe/WPEDisplay.cpp:
(wpeDisplayDispose):
(wpeDisplayPreferredDMABufFormats):
(wpe_display_get_preferred_dma_buf_formats):
* Source/WebKit/WPEPlatform/wpe/WPEDisplay.h:
* Source/WebKit/WPEPlatform/wpe/WPEView.cpp:
(wpe_view_class_init):
(wpe_view_get_preferred_dma_buf_formats):
(wpeViewDispose): Deleted.
* Source/WebKit/WPEPlatform/wpe/WPEView.h:
* Source/WebKit/WPEPlatform/wpe/drm/WPEDisplayDRM.cpp:
(wpeDisplayDRMGetPreferredDMABufFormats):
* Source/WebKit/WPEPlatform/wpe/headless/WPEDisplayHeadless.cpp:
(wpeDisplayHeadlessGetPreferredDMABufFormats):
* Source/WebKit/WPEPlatform/wpe/wayland/WPEDisplayWayland.cpp:
(wpeDisplayWaylandGetPreferredDMABufFormats):
* Source/WebKit/WPEPlatform/wpe/wayland/WPEViewWayland.cpp:
(DMABufFeedback::DMABufFeedback):
(DMABufFeedback::drmDeviceForUsage):
(DMABufFeedback::drmDevice const):
(DMABufFeedback::Tranche::Tranche):
(DMABufFeedback::Tranche::drmDevice const):
(wpeViewWaylandGetPreferredDMABufFormats):
* Source/WebKit/WPEPlatform/wpe/wpe-platform.h:
* Source/WebKit/WebProcess/WebPage/dmabuf/AcceleratedSurfaceDMABuf.cpp:
(WebKit::AcceleratedSurfaceDMABuf::RenderTargetEGLImage::create):
(WebKit::AcceleratedSurfaceDMABuf::SwapChain::setupBufferFormat):
* Source/WebKit/WebProcess/WebPage/dmabuf/AcceleratedSurfaceDMABuf.h:

Canonical link: https://commits.webkit.org/277538@main
  • Loading branch information
carlosgcampos committed Apr 16, 2024
1 parent 51f2745 commit f78822d
Show file tree
Hide file tree
Showing 20 changed files with 816 additions and 473 deletions.
13 changes: 7 additions & 6 deletions Source/WebKit/Shared/glib/DMABufRendererBufferFormat.h
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include <wtf/Vector.h>
#include <wtf/text/CString.h>

namespace WebKit {

Expand All @@ -36,15 +37,15 @@ enum class DMABufRendererBufferFormatUsage : uint8_t {
};

struct DMABufRendererBufferFormat {
bool operator==(const DMABufRendererBufferFormat& other) const
{
return usage == other.usage && fourcc == other.fourcc && modifiers == other.modifiers;
}
struct Format {
uint32_t fourcc { 0 };
Vector<uint64_t, 1> modifiers;
};

using Usage = DMABufRendererBufferFormatUsage;
Usage usage { Usage::Rendering };
uint32_t fourcc { 0 };
Vector<uint64_t, 1> modifiers;
CString drmDevice;
Vector<Format> formats;
};

} // namespace WebKit
Expand Up @@ -24,12 +24,17 @@

struct WebKit::DMABufRendererBufferFormat {
WebKit::DMABufRendererBufferFormat::Usage usage;
uint32_t fourcc;
Vector<uint64_t, 1> modifiers;
CString drmDevice;
Vector<WebKit::DMABufRendererBufferFormat::Format> formats;
}

enum class WebKit::DMABufRendererBufferFormatUsage : uint8_t {
Rendering,
Mapping,
Scanout
}

[Nested] struct WebKit::DMABufRendererBufferFormat::Format {
uint32_t fourcc;
Vector<uint64_t, 1> modifiers;
}
26 changes: 18 additions & 8 deletions Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreDMABuf.cpp
Expand Up @@ -103,24 +103,34 @@ Vector<DMABufRendererBufferFormat> AcceleratedBackingStoreDMABuf::preferredBuffe
if (formatString && *formatString) {
auto tokens = String::fromUTF8(formatString).split(':');
if (!tokens.isEmpty() && tokens[0].length() >= 2 && tokens[0].length() <= 4) {
uint32_t format = fourcc_code(tokens[0][0], tokens[0][1], tokens[0].length() > 2 ? tokens[0][2] : ' ', tokens[0].length() > 3 ? tokens[0][3] : ' ');
DMABufRendererBufferFormat format;
format.usage = display.gtkEGLDisplay() ? DMABufRendererBufferFormat::Usage::Rendering : DMABufRendererBufferFormat::Usage::Mapping;
format.drmDevice = display.drmRenderNodeFile().utf8();
uint32_t fourcc = fourcc_code(tokens[0][0], tokens[0][1], tokens[0].length() > 2 ? tokens[0][2] : ' ', tokens[0].length() > 3 ? tokens[0][3] : ' ');
uint64_t modifier = tokens.size() > 1 ? g_ascii_strtoull(tokens[1].ascii().data(), nullptr, 10) : DRM_FORMAT_MOD_INVALID;
return { { display.gtkEGLDisplay() ? DMABufRendererBufferFormat::Usage::Rendering : DMABufRendererBufferFormat::Usage::Mapping, format, { modifier } } };
format.formats.append({ fourcc, { modifier } });
return { WTFMove(format) };
}

WTFLogAlways("Invalid format %s set in WEBKIT_DMABUF_RENDERER_BUFFER_FORMAT, ignoring...", formatString);
}

if (!display.gtkEGLDisplay()) {
return {
{ DMABufRendererBufferFormat::Usage::Mapping, DRM_FORMAT_ARGB8888, { DRM_FORMAT_MOD_LINEAR } },
{ DMABufRendererBufferFormat::Usage::Mapping, DRM_FORMAT_XRGB8888, { DRM_FORMAT_MOD_LINEAR } }
};
DMABufRendererBufferFormat format;
format.usage = DMABufRendererBufferFormat::Usage::Mapping;
format.drmDevice = display.drmRenderNodeFile().utf8();
format.formats.append({ DRM_FORMAT_XRGB8888, { DRM_FORMAT_MOD_LINEAR } });
format.formats.append({ DRM_FORMAT_ARGB8888, { DRM_FORMAT_MOD_LINEAR } });
return { WTFMove(format) };
}

return display.dmabufFormats().map([](const auto& format) -> DMABufRendererBufferFormat {
return { DMABufRendererBufferFormat::Usage::Rendering, format.fourcc, format.modifiers };
DMABufRendererBufferFormat format;
format.usage = DMABufRendererBufferFormat::Usage::Rendering;
format.drmDevice = display.drmRenderNodeFile().utf8();
format.formats = display.dmabufFormats().map([](const auto& format) -> DMABufRendererBufferFormat::Format {
return { format.fourcc, format.modifiers };
});
return { WTFMove(format) };
}
#endif

Expand Down
31 changes: 20 additions & 11 deletions Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp
Expand Up @@ -106,16 +106,16 @@ Vector<DMABufRendererBufferFormat> WebPageProxy::preferredBufferFormats() const
if (!view)
return { };

GList* formats = wpe_view_get_preferred_dma_buf_formats(view);
auto* formats = wpe_view_get_preferred_dma_buf_formats(view);
if (!formats)
return { };

Vector<DMABufRendererBufferFormat> dmabufFormats;
dmabufFormats.reserveInitialCapacity(g_list_length(formats));
for (GList* i = formats; i; i = g_list_next(i)) {
auto* format = static_cast<WPEBufferDMABufFormat*>(i->data);
const char* mainDevice = wpe_buffer_dma_buf_formats_get_device(formats);
auto groupCount = wpe_buffer_dma_buf_formats_get_n_groups(formats);
for (unsigned i = 0; i < groupCount; ++i) {
DMABufRendererBufferFormat dmabufFormat;
switch (wpe_buffer_dma_buf_format_get_usage(format)) {
switch (wpe_buffer_dma_buf_formats_get_group_usage(formats, i)) {
case WPE_BUFFER_DMA_BUF_FORMAT_USAGE_RENDERING:
dmabufFormat.usage = DMABufRendererBufferFormat::Usage::Rendering;
break;
Expand All @@ -126,15 +126,24 @@ Vector<DMABufRendererBufferFormat> WebPageProxy::preferredBufferFormats() const
dmabufFormat.usage = DMABufRendererBufferFormat::Usage::Scanout;
break;
}
dmabufFormat.fourcc = wpe_buffer_dma_buf_format_get_fourcc(format);
auto* modifiers = wpe_buffer_dma_buf_format_get_modifiers(format);
dmabufFormat.modifiers.reserveInitialCapacity(modifiers->len);
for (guint i = 0; i < modifiers->len; ++i) {
guint64* mod = &g_array_index(modifiers, guint64, i);
dmabufFormat.modifiers.append(*mod);
const char* targetDevice = wpe_buffer_dma_buf_formats_get_group_device(formats, i);
dmabufFormat.drmDevice = targetDevice ? targetDevice : mainDevice;
auto formatsCount = wpe_buffer_dma_buf_formats_get_group_n_formats(formats, i);
dmabufFormat.formats.reserveInitialCapacity(formatsCount);
for (unsigned j = 0; j < formatsCount; ++j) {
DMABufRendererBufferFormat::Format format;
format.fourcc = wpe_buffer_dma_buf_formats_get_format_fourcc(formats, i, j);
auto* modifiers = wpe_buffer_dma_buf_formats_get_format_modifiers(formats, i, j);
format.modifiers.reserveInitialCapacity(modifiers->len);
for (unsigned k = 0; k < modifiers->len; ++k) {
auto* modifier = &g_array_index(modifiers, guint64, k);
format.modifiers.append(*modifier);
}
dmabufFormat.formats.append(WTFMove(format));
}
dmabufFormats.append(WTFMove(dmabufFormat));
}

return dmabufFormats;
#else
return { };
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WPEPlatform/CMakeLists.txt
Expand Up @@ -11,7 +11,7 @@ set(WPEPlatform_SOURCES
${WEBKIT_DIR}/WPEPlatform/wpe/WPEEvent.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBuffer.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABuf.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABufFormat.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABufFormats.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferSHM.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPECursorTheme.cpp
${WEBKIT_DIR}/WPEPlatform/wpe/WPEDisplay.cpp
Expand All @@ -31,7 +31,7 @@ set(WPEPlatform_INSTALLED_HEADERS
${WEBKIT_DIR}/WPEPlatform/wpe/WPEEvent.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBuffer.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABuf.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABufFormat.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferDMABufFormats.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEBufferSHM.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEDefines.h
${WEBKIT_DIR}/WPEPlatform/wpe/WPEDisplay.h
Expand Down
132 changes: 0 additions & 132 deletions Source/WebKit/WPEPlatform/wpe/WPEBufferDMABufFormat.cpp

This file was deleted.

68 changes: 0 additions & 68 deletions Source/WebKit/WPEPlatform/wpe/WPEBufferDMABufFormat.h

This file was deleted.

0 comments on commit f78822d

Please sign in to comment.