- Revision
- 294100
- Author
- [email protected]
- Date
- 2022-05-12 06:30:17 -0700 (Thu, 12 May 2022)
Log Message
[GTK][WPE] Respect and use the DMABuf modifier values
https://bugs.webkit.org/show_bug.cgi?id=240276
Reviewed by Chris Lord.
When wrapping DMABuf objects in EGLImages, the modifier values should be
respected and used to properly and completely describe the DMABuf.
This should be applied in two places. First one is GraphicsContextGLGBM
where the DMABuf is used to back the ANGLE-handled EGLImage. Second one
is TextureMapperPlatformLayerProxyDMABuf, during construction of the
DMABufLayer object used to present the DMABuf inside the composition
engine.
In both cases this primarily relies on the presence of the
EGL_EXT_image_dma_buf_import_modifiers extension. For the first case
detection of this extension is done through ANGLE and its state stored
on the GraphicsContextGLGBM object during context initialization. For
the second case this state is stored on the PlatformDisplay object
after it's retrieved during the EGLDisplay initialization.
If detected, the DMABuf modifier value is included in the attributes
array used for the EGLImage creation call. The actual modifier value is
retrieved from the gbm_bo object, leaving it to libgbm to assess the
best possible formatting of the DMAbuf resource.
* platform/graphics/PlatformDisplay.cpp:
(WebCore::PlatformDisplay::initializeEGLDisplay):
* platform/graphics/PlatformDisplay.h:
(WebCore::PlatformDisplay::eglExtensions const):
* platform/graphics/gbm/GBMBufferSwapchain.cpp:
(WebCore::GBMBufferSwapchain::Buffer::createDMABufObject const):
* platform/graphics/gbm/GraphicsContextGLGBM.cpp:
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):
(WebCore::GraphicsContextGLGBM::platformInitializeContext):
* platform/graphics/gbm/GraphicsContextGLGBM.h:
(WebCore::GraphicsContextGLGBM::eglExtensions):
* platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp:
(WebCore::TextureMapperPlatformLayerProxyDMABuf::DMABufLayer::createEGLImageData):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (294099 => 294100)
--- trunk/Source/WebCore/ChangeLog 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/ChangeLog 2022-05-12 13:30:17 UTC (rev 294100)
@@ -1,3 +1,45 @@
+2022-05-12 Zan Dobersek <[email protected]>
+
+ [GTK][WPE] Respect and use the DMABuf modifier values
+ https://bugs.webkit.org/show_bug.cgi?id=240276
+
+ Reviewed by Chris Lord.
+
+ When wrapping DMABuf objects in EGLImages, the modifier values should be
+ respected and used to properly and completely describe the DMABuf.
+
+ This should be applied in two places. First one is GraphicsContextGLGBM
+ where the DMABuf is used to back the ANGLE-handled EGLImage. Second one
+ is TextureMapperPlatformLayerProxyDMABuf, during construction of the
+ DMABufLayer object used to present the DMABuf inside the composition
+ engine.
+
+ In both cases this primarily relies on the presence of the
+ EGL_EXT_image_dma_buf_import_modifiers extension. For the first case
+ detection of this extension is done through ANGLE and its state stored
+ on the GraphicsContextGLGBM object during context initialization. For
+ the second case this state is stored on the PlatformDisplay object
+ after it's retrieved during the EGLDisplay initialization.
+
+ If detected, the DMABuf modifier value is included in the attributes
+ array used for the EGLImage creation call. The actual modifier value is
+ retrieved from the gbm_bo object, leaving it to libgbm to assess the
+ best possible formatting of the DMAbuf resource.
+
+ * platform/graphics/PlatformDisplay.cpp:
+ (WebCore::PlatformDisplay::initializeEGLDisplay):
+ * platform/graphics/PlatformDisplay.h:
+ (WebCore::PlatformDisplay::eglExtensions const):
+ * platform/graphics/gbm/GBMBufferSwapchain.cpp:
+ (WebCore::GBMBufferSwapchain::Buffer::createDMABufObject const):
+ * platform/graphics/gbm/GraphicsContextGLGBM.cpp:
+ (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+ (WebCore::GraphicsContextGLGBM::platformInitializeContext):
+ * platform/graphics/gbm/GraphicsContextGLGBM.h:
+ (WebCore::GraphicsContextGLGBM::eglExtensions):
+ * platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp:
+ (WebCore::TextureMapperPlatformLayerProxyDMABuf::DMABufLayer::createEGLImageData):
+
2022-05-12 Alan Bujtas <[email protected]>
TextBoxPainter::paintBackground should bail out early when nothing to paint
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2022-05-12 13:30:17 UTC (rev 294100)
@@ -269,6 +269,20 @@
m_eglMajorVersion = majorVersion;
m_eglMinorVersion = minorVersion;
+ {
+ const char* extensionsString = eglQueryString(m_eglDisplay, EGL_EXTENSIONS);
+ auto displayExtensions = StringView { extensionsString }.split(' ');
+ auto findExtension =
+ [&](auto extensionName) {
+ return std::any_of(displayExtensions.begin(), displayExtensions.end(),
+ [&](auto extensionEntry) {
+ return extensionEntry == extensionName;
+ });
+ };
+
+ m_eglExtensions.EXT_image_dma_buf_import_modifiers = findExtension("EGL_EXT_image_dma_buf_import_modifiers"_s);
+ }
+
eglDisplays().add(this);
#if !PLATFORM(WIN)
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.h (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2022-05-12 13:30:17 UTC (rev 294100)
@@ -86,6 +86,11 @@
#if USE(EGL)
EGLDisplay eglDisplay() const;
bool eglCheckVersion(int major, int minor) const;
+
+ struct EGLExtensions {
+ bool EXT_image_dma_buf_import_modifiers { false };
+ };
+ const EGLExtensions& eglExtensions() const { return m_eglExtensions; }
#endif
#if ENABLE(VIDEO) && USE(GSTREAMER_GL)
@@ -145,6 +150,7 @@
bool m_eglDisplayInitialized { false };
int m_eglMajorVersion { 0 };
int m_eglMinorVersion { 0 };
+ EGLExtensions m_eglExtensions;
#endif
#if ENABLE(VIDEO) && USE(GSTREAMER_GL)
Modified: trunk/Source/WebCore/platform/graphics/gbm/GBMBufferSwapchain.cpp (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/gbm/GBMBufferSwapchain.cpp 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/gbm/GBMBufferSwapchain.cpp 2022-05-12 13:30:17 UTC (rev 294100)
@@ -158,8 +158,7 @@
object.fd[i] = UnixFileDescriptor { gbm_bo_get_fd(m_planes[i].bo), UnixFileDescriptor::Adopt };
object.offset[i] = 0;
object.stride[i] = m_planes[i].stride;
- // TODO: these should be the plane-specific modifiers. We don't use them yet.
- object.modifier[i] = 0;
+ object.modifier[i] = gbm_bo_get_modifier(m_planes[i].bo);
}
return object;
Modified: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp 2022-05-12 13:30:17 UTC (rev 294100)
@@ -100,8 +100,11 @@
auto result = contextSwapchain.images.ensure(contextSwapchain.drawBO->handle(),
[&] {
auto dmabufObject = contextSwapchain.drawBO->createDMABufObject(0);
+ bool importModifiers = static_cast<GraphicsContextGLGBM&>(*this).eglExtensions().EXT_image_dma_buf_import_modifiers;
- std::initializer_list<EGLint> attributes {
+ Vector<EGLint> attributes;
+ attributes.reserveInitialCapacity(12 + 4 + 1);
+ attributes.uncheckedAppend(Span<const EGLint>({
EGL_WIDTH, EGLint(dmabufObject.format.planeWidth(0, dmabufObject.width)),
EGL_HEIGHT, EGLint(dmabufObject.format.planeHeight(0, dmabufObject.height)),
EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLint>(dmabufObject.format.planes[0].fourcc),
@@ -108,9 +111,16 @@
EGL_DMA_BUF_PLANE0_FD_EXT, dmabufObject.fd[0].value(),
EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(dmabufObject.stride[0]),
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
- EGL_NONE,
- };
- return EGL_CreateImageKHR(contextSwapchain.platformDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, std::data(attributes));
+ }));
+ if (importModifiers) {
+ attributes.uncheckedAppend(Span<const EGLint>({
+ EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, static_cast<EGLint>(dmabufObject.modifier[0] >> 32),
+ EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, static_cast<EGLint>(dmabufObject.modifier[0] & 0xffffffff),
+ }));
+ }
+ attributes.uncheckedAppend(EGL_NONE);
+
+ return EGL_CreateImageKHR(contextSwapchain.platformDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, attributes.data());
});
GL_BindTexture(textureTarget, m_texture);
@@ -296,6 +306,10 @@
LOG(WebGL, "ANGLE makeContextCurrent failed.");
return false;
}
+
+ if (strstr(displayExtensions, "EGL_EXT_image_dma_buf_import_modifiers"))
+ m_eglExtensions.EXT_image_dma_buf_import_modifiers = true;
+
LOG(WebGL, "Got EGLContext");
return true;
}
Modified: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.h 2022-05-12 13:30:17 UTC (rev 294100)
@@ -85,10 +85,16 @@
Swapchain& swapchain() { return m_swapchain; }
+ struct EGLExtensions {
+ bool EXT_image_dma_buf_import_modifiers { false };
+ };
+ const EGLExtensions& eglExtensions() { return m_eglExtensions; }
+
protected:
GraphicsContextGLGBM(WebCore::GraphicsContextGLAttributes&&);
private:
+ EGLExtensions m_eglExtensions;
Swapchain m_swapchain;
#if USE(NICOSIA)
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp (294099 => 294100)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp 2022-05-12 13:12:22 UTC (rev 294099)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp 2022-05-12 13:30:17 UTC (rev 294100)
@@ -247,11 +247,14 @@
{
using EGLImageData = TextureMapperPlatformLayerProxyDMABuf::DMABufLayer::EGLImageData;
- EGLDisplay eglDisplay = PlatformDisplay::sharedDisplayForCompositing().eglDisplay();
+ auto& platformDisplay = PlatformDisplay::sharedDisplayForCompositing();
+ EGLDisplay eglDisplay = platformDisplay.eglDisplay();
EGLImageKHR image[DMABufFormat::c_maxPlanes];
for (unsigned i = 0; i < object.format.numPlanes; ++i) {
- std::initializer_list<EGLint> attributes {
+ Vector<EGLint> attributes;
+ attributes.reserveInitialCapacity(12 + 4 + 1);
+ attributes.uncheckedAppend(Span<const EGLint>({
EGL_WIDTH, EGLint(object.format.planeWidth(i, object.width)),
EGL_HEIGHT, EGLint(object.format.planeHeight(i, object.height)),
EGL_LINUX_DRM_FOURCC_EXT, EGLint(object.format.planes[i].fourcc),
@@ -258,9 +261,16 @@
EGL_DMA_BUF_PLANE0_FD_EXT, object.fd[i].value(),
EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGLint(object.offset[i]),
EGL_DMA_BUF_PLANE0_PITCH_EXT, EGLint(object.stride[i]),
- EGL_NONE,
- };
- image[i] = createImageKHR()(eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, std::data(attributes));
+ }));
+ if (platformDisplay.eglExtensions().EXT_image_dma_buf_import_modifiers) {
+ attributes.uncheckedAppend(Span<const EGLint>({
+ EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, static_cast<EGLint>(object.modifier[i] >> 32),
+ EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, static_cast<EGLint>(object.modifier[i] & 0xffffffff),
+ }));
+ }
+ attributes.uncheckedAppend(EGL_NONE);
+
+ image[i] = createImageKHR()(eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, attributes.data());
}
auto imageData = makeUnique<EGLImageData>();