Diff
Modified: trunk/Source/WebCore/ChangeLog (294150 => 294151)
--- trunk/Source/WebCore/ChangeLog 2022-05-13 08:36:08 UTC (rev 294150)
+++ trunk/Source/WebCore/ChangeLog 2022-05-13 09:07:17 UTC (rev 294151)
@@ -1,3 +1,28 @@
+2022-05-13 Zan Dobersek <[email protected]>
+
+ [Linux][GBM] Provide utility function for construction of eglCreateImage attributes data
+ https://bugs.webkit.org/show_bug.cgi?id=240373
+
+ Reviewed by Chris Lord.
+
+ Provide DMABufEGLUtilities::constructEGLCreateImageAttributes() helper
+ function that unifies the construction of the EGLImage creation
+ attributes. For a given DMABufObject and plane index, a Vector of EGLint
+ attributes for a single-plane EGLImage object is returned, optionally
+ including the modifier value if requested (when the EGL implementation,
+ through the necessary extensions, supports modifiers).
+
+ The new function replaces duplicated code in GraphicsContextGLGBM and
+ TextureMapperPlatformLayerProxyDMABuf.
+
+ * platform/TextureMapper.cmake:
+ * platform/graphics/gbm/DMABufEGLUtilities.h: Added.
+ (WebCore::DMABufEGLUtilities::constructEGLCreateImageAttributes):
+ * platform/graphics/gbm/GraphicsContextGLGBM.cpp:
+ (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+ * platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp:
+ (WebCore::TextureMapperPlatformLayerProxyDMABuf::DMABufLayer::createEGLImageData):
+
2022-05-13 Youenn Fablet <[email protected]>
Remove WorkerLoaderProxy::postTaskForModeToWorkerOrWorkletGlobalScope
Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (294150 => 294151)
--- trunk/Source/WebCore/platform/TextureMapper.cmake 2022-05-13 08:36:08 UTC (rev 294150)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake 2022-05-13 09:07:17 UTC (rev 294151)
@@ -153,6 +153,7 @@
if (USE_LIBGBM)
list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
+ platform/graphics/gbm/DMABufEGLUtilities.h
platform/graphics/gbm/DMABufFormat.h
platform/graphics/gbm/DMABufObject.h
platform/graphics/gbm/DMABufReleaseFlag.h
Added: trunk/Source/WebCore/platform/graphics/gbm/DMABufEGLUtilities.h (0 => 294151)
--- trunk/Source/WebCore/platform/graphics/gbm/DMABufEGLUtilities.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gbm/DMABufEGLUtilities.h 2022-05-13 09:07:17 UTC (rev 294151)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 Metrological Group B.V.
+ * Copyright (C) 2022 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "DMABufObject.h"
+#include <wtf/Span.h>
+#include <wtf/Vector.h>
+
+// This is a utilities header that provides helpers for integration of DMABuf operations with EGL.
+// No EGL headers are included here to keep the helpers usable across different EGL implementations,
+// so the expectation is that this header is included in the place-of-use implementation file after
+// the appropriate EGL headers have already been included.
+
+namespace WebCore {
+namespace DMABufEGLUtilities {
+
+enum class PlaneModifiersUsage : bool {
+ Use = true,
+ DoNotUse = false,
+};
+
+static inline Vector<EGLint> constructEGLCreateImageAttributes(const DMABufObject& object, unsigned planeIndex, PlaneModifiersUsage planeModifiersUsage)
+{
+ Vector<EGLint> attributes;
+ attributes.reserveInitialCapacity(12 + 4 + 1);
+
+ attributes.uncheckedAppend(Span<const EGLint>({
+ EGL_WIDTH, EGLint(object.format.planeWidth(planeIndex, object.width)),
+ EGL_HEIGHT, EGLint(object.format.planeHeight(planeIndex, object.height)),
+ EGL_LINUX_DRM_FOURCC_EXT, EGLint(object.format.planes[planeIndex].fourcc),
+ EGL_DMA_BUF_PLANE0_FD_EXT, object.fd[planeIndex].value(),
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGLint(object.offset[planeIndex]),
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, EGLint(object.stride[planeIndex]),
+ }));
+
+ if (planeModifiersUsage == PlaneModifiersUsage::Use) {
+ attributes.uncheckedAppend(Span<const EGLint>({
+ EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, EGLint(object.modifier[planeIndex] >> 32),
+ EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGLint(object.modifier[planeIndex] & 0xffffffff),
+ }));
+ }
+
+ attributes.uncheckedAppend(EGL_NONE);
+ return attributes;
+}
+
+} } // namespace WebCore::DMABufEGLUtilities
Modified: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp (294150 => 294151)
--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp 2022-05-13 08:36:08 UTC (rev 294150)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp 2022-05-13 09:07:17 UTC (rev 294151)
@@ -30,6 +30,7 @@
#if ENABLE(WEBGL) && USE(LIBGBM) && USE(ANGLE)
#include "ANGLEHeaders.h"
+#include "DMABufEGLUtilities.h"
#include "Logging.h"
#include "PixelBuffer.h"
@@ -100,26 +101,8 @@
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;
-
- 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),
- 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,
- }));
- 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);
-
+ auto attributes = DMABufEGLUtilities::constructEGLCreateImageAttributes(dmabufObject, 0,
+ DMABufEGLUtilities::PlaneModifiersUsage { static_cast<GraphicsContextGLGBM&>(*this).eglExtensions().EXT_image_dma_buf_import_modifiers });
return EGL_CreateImageKHR(contextSwapchain.platformDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, attributes.data());
});
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp (294150 => 294151)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp 2022-05-13 08:36:08 UTC (rev 294150)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp 2022-05-13 09:07:17 UTC (rev 294151)
@@ -44,6 +44,9 @@
#include <EGL/eglext.h>
#endif
+// This has to be included after the EGL headers.
+#include "DMABufEGLUtilities.h"
+
namespace WebCore {
static PFNEGLCREATEIMAGEKHRPROC createImageKHR()
@@ -252,24 +255,8 @@
EGLImageKHR image[DMABufFormat::c_maxPlanes];
for (unsigned i = 0; i < object.format.numPlanes; ++i) {
- 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),
- 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]),
- }));
- 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);
-
+ auto attributes = DMABufEGLUtilities::constructEGLCreateImageAttributes(object, i,
+ DMABufEGLUtilities::PlaneModifiersUsage { platformDisplay.eglExtensions().EXT_image_dma_buf_import_modifiers });
image[i] = createImageKHR()(eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, attributes.data());
}