- Revision
- 289575
- Author
- [email protected]
- Date
- 2022-02-10 14:17:36 -0800 (Thu, 10 Feb 2022)
Log Message
[GTK][WPE] Improve device detection in the GbmDevice
https://bugs.webkit.org/show_bug.cgi?id=236436
Patch by Alejandro G. Castro <[email protected]> on 2022-02-10
Reviewed by Chris Lord.
.:
* Source/cmake/OptionsGTK.cmake: Search for drm and gbm libraries
when compiling WebGL ANGLE support.
* Source/cmake/OptionsWPE.cmake: Ditto.
Source/WebCore:
Use DRM library to detect the device location to create the gbm
device object.
No new tests, no change in behaviour.
* PlatformGTK.cmake: Add gbm and drm include directories and
libraries to the compilation.
* PlatformWPE.cmake: Ditto.
* platform/graphics/angle/GraphicsContextGLANGLE.h: Avoid storing
a pointer to the gdb device, to make sure it is just in one place,
* platform/graphics/gbm/GBMDevice.cpp:
(WebCore::GBMDevice::GBMDevice): Use the new getDeviceFd function
to open the device file. We just create the gbm device here.
(WebCore::GBMDevice::getDeviceFd): Added. Uses drm library to look
for the device file name and opens it.
* platform/graphics/gbm/GBMDevice.h: Ditto
* platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE): Remove
the direct pointer to the gdb device, just request it when required.
(WebCore::GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking): Ditto.
(WebCore::GraphicsContextGLANGLE::EGLImageBacking::reset): Ditto.
Modified Paths
Diff
Modified: trunk/ChangeLog (289574 => 289575)
--- trunk/ChangeLog 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/ChangeLog 2022-02-10 22:17:36 UTC (rev 289575)
@@ -1,3 +1,14 @@
+2022-02-10 Alejandro G. Castro <[email protected]>
+
+ [GTK][WPE] Improve device detection in the GbmDevice
+ https://bugs.webkit.org/show_bug.cgi?id=236436
+
+ Reviewed by Chris Lord.
+
+ * Source/cmake/OptionsGTK.cmake: Search for drm and gbm libraries
+ when compiling WebGL ANGLE support.
+ * Source/cmake/OptionsWPE.cmake: Ditto.
+
2022-02-10 Tim Nguyen <[email protected]>
Unreviewed, update my (Tim Nguyen) status to reviewer
Modified: trunk/Source/WebCore/ChangeLog (289574 => 289575)
--- trunk/Source/WebCore/ChangeLog 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/ChangeLog 2022-02-10 22:17:36 UTC (rev 289575)
@@ -1,3 +1,32 @@
+2022-02-10 Alejandro G. Castro <[email protected]>
+
+ [GTK][WPE] Improve device detection in the GbmDevice
+ https://bugs.webkit.org/show_bug.cgi?id=236436
+
+ Reviewed by Chris Lord.
+
+ Use DRM library to detect the device location to create the gbm
+ device object.
+
+ No new tests, no change in behaviour.
+
+ * PlatformGTK.cmake: Add gbm and drm include directories and
+ libraries to the compilation.
+ * PlatformWPE.cmake: Ditto.
+ * platform/graphics/angle/GraphicsContextGLANGLE.h: Avoid storing
+ a pointer to the gdb device, to make sure it is just in one place,
+ * platform/graphics/gbm/GBMDevice.cpp:
+ (WebCore::GBMDevice::GBMDevice): Use the new getDeviceFd function
+ to open the device file. We just create the gbm device here.
+ (WebCore::GBMDevice::getDeviceFd): Added. Uses drm library to look
+ for the device file name and opens it.
+ * platform/graphics/gbm/GBMDevice.h: Ditto
+ * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
+ (WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE): Remove
+ the direct pointer to the gdb device, just request it when required.
+ (WebCore::GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking): Ditto.
+ (WebCore::GraphicsContextGLANGLE::EGLImageBacking::reset): Ditto.
+
2022-02-10 Alan Bujtas <[email protected]>
[LFC][IFC] Adjust bidi (and mostly RTL) coords to support vertical writing mode
Modified: trunk/Source/WebCore/PlatformGTK.cmake (289574 => 289575)
--- trunk/Source/WebCore/PlatformGTK.cmake 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2022-02-10 22:17:36 UTC (rev 289575)
@@ -128,6 +128,17 @@
)
endif ()
+if (USE_ANGLE_WEBGL)
+ list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES
+ ${LIBDRM_INCLUDE_DIR}
+ ${GBM_INCLUDE_DIR}
+ )
+ list(APPEND WebCore_LIBRARIES
+ ${LIBDRM_LIBRARIES}
+ ${GBM_LIBRARIES}
+ )
+endif ()
+
if (ENABLE_WAYLAND_TARGET)
list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/wayland/PlatformDisplayWayland.h
Modified: trunk/Source/WebCore/PlatformWPE.cmake (289574 => 289575)
--- trunk/Source/WebCore/PlatformWPE.cmake 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/PlatformWPE.cmake 2022-02-10 22:17:36 UTC (rev 289575)
@@ -94,6 +94,17 @@
list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES ${OPENXR_INCLUDE_DIRS})
endif ()
+if (USE_ANGLE_WEBGL)
+ list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES
+ ${LIBDRM_INCLUDE_DIR}
+ ${GBM_INCLUDE_DIR}
+ )
+ list(APPEND WebCore_LIBRARIES
+ ${LIBDRM_LIBRARIES}
+ ${GBM_LIBRARIES}
+ )
+endif ()
+
if (USE_ATSPI)
set(WebCore_AtspiInterfaceFiles
${WEBCORE_DIR}/accessibility/atspi/xml/Accessible.xml
Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h (289574 => 289575)
--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h 2022-02-10 22:17:36 UTC (rev 289575)
@@ -459,7 +459,7 @@
class EGLImageBacking {
WTF_MAKE_FAST_ALLOCATED;
public:
- EGLImageBacking(gbm_device*, PlatformGraphicsContextGLDisplay);
+ EGLImageBacking(PlatformGraphicsContextGLDisplay);
~EGLImageBacking();
bool reset(int width, int height, bool hasAlpha);
@@ -472,7 +472,6 @@
private:
void releaseResources();
- gbm_device* m_device;
PlatformGraphicsContextGLDisplay m_display;
gbm_bo* m_BO { nullptr };
Modified: trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.cpp (289574 => 289575)
--- trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.cpp 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.cpp 2022-02-10 22:17:36 UTC (rev 289575)
@@ -33,6 +33,7 @@
#include <gbm.h>
#include <mutex>
#include <wtf/ThreadSpecific.h>
+#include <xf86drm.h>
namespace WebCore {
@@ -54,18 +55,9 @@
GBMDevice::GBMDevice()
{
- int fd;
- char deviceName[30];
- for (int i = 128; i < 192; ++i) {
- snprintf(deviceName, sizeof(deviceName), "/dev/dri/renderD%d", i);
- fd = open(deviceName, O_RDWR | O_CLOEXEC);
- if (fd >= 0) {
- m_device = gbm_create_device(fd);
- if (m_device)
- break;
- close(fd);
- }
- }
+ int fd = getDeviceFd();
+ if (fd >= 0)
+ m_device = gbm_create_device(fd);
}
GBMDevice::~GBMDevice()
@@ -76,6 +68,29 @@
}
}
+int GBMDevice::getDeviceFd()
+{
+ drmDevicePtr devices[64];
+ memset(devices, 0, sizeof(devices));
+
+ int numDevices = drmGetDevices2(0, devices, WTF_ARRAY_LENGTH(devices));
+ if (numDevices <=0)
+ return -1;
+
+ int fd = -1;
+ for (int i = 0; i < numDevices; ++i) {
+ drmDevice* device = devices[i];
+ if (!(device->available_nodes & (1 << DRM_NODE_PRIMARY)))
+ continue;
+
+ fd = open(device->nodes[DRM_NODE_PRIMARY], O_RDWR);
+ if (fd < 0)
+ continue;
+ }
+
+ return fd;
+}
+
} // namespace WebCore
#endif // USE(ANGLE) && USE(NICOSIA)
Modified: trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.h (289574 => 289575)
--- trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.h 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/platform/graphics/gbm/GBMDevice.h 2022-02-10 22:17:36 UTC (rev 289575)
@@ -44,6 +44,8 @@
struct gbm_device* device() const { return m_device; }
private:
+ int getDeviceFd();
+
struct gbm_device* m_device { nullptr };
};
Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp (289574 => 289575)
--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp 2022-02-10 22:17:36 UTC (rev 289575)
@@ -57,10 +57,10 @@
m_nicosiaLayer = makeUnique<Nicosia::GCGLANGLELayer>(*this);
const auto& gbmDevice = GBMDevice::get();
- if (auto* device = gbmDevice.device()) {
- m_textureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
- m_compositorTextureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
- m_intermediateTextureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
+ if (gbmDevice.device()) {
+ m_textureBacking = makeUnique<EGLImageBacking>(platformDisplay());
+ m_compositorTextureBacking = makeUnique<EGLImageBacking>(platformDisplay());
+ m_intermediateTextureBacking = makeUnique<EGLImageBacking>(platformDisplay());
}
#else
m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
@@ -124,9 +124,8 @@
}
#if USE(NICOSIA)
-GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking(gbm_device* device, PlatformGraphicsContextGLDisplay display)
- : m_device(device)
- , m_display(display)
+GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking(PlatformGraphicsContextGLDisplay display)
+ : m_display(display)
{
}
@@ -172,7 +171,8 @@
if (!width || !height)
return false;
- m_BO = gbm_bo_create(m_device, width, height, hasAlpha ? GBM_BO_FORMAT_ARGB8888 : GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_RENDERING);
+ const auto& gbmDevice = GBMDevice::get();
+ m_BO = gbm_bo_create(gbmDevice.device(), width, height, hasAlpha ? GBM_BO_FORMAT_ARGB8888 : GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_RENDERING);
if (m_BO) {
m_FD = gbm_bo_get_fd(m_BO);
if (m_FD >= 0) {
Modified: trunk/Source/cmake/OptionsGTK.cmake (289574 => 289575)
--- trunk/Source/cmake/OptionsGTK.cmake 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/cmake/OptionsGTK.cmake 2022-02-10 22:17:36 UTC (rev 289575)
@@ -383,6 +383,9 @@
if (USE_ANGLE_WEBGL)
SET_AND_EXPOSE_TO_BUILD(USE_ANGLE TRUE)
+
+ find_package(GBM REQUIRED)
+ find_package(LibDRM REQUIRED)
endif ()
if (ENABLE_SPELLCHECK)
Modified: trunk/Source/cmake/OptionsWPE.cmake (289574 => 289575)
--- trunk/Source/cmake/OptionsWPE.cmake 2022-02-10 22:09:14 UTC (rev 289574)
+++ trunk/Source/cmake/OptionsWPE.cmake 2022-02-10 22:17:36 UTC (rev 289575)
@@ -176,6 +176,9 @@
if (USE_ANGLE_WEBGL)
SET_AND_EXPOSE_TO_BUILD(USE_ANGLE TRUE)
+
+ find_package(GBM REQUIRED)
+ find_package(LibDRM REQUIRED)
endif ()
if (USE_JPEGXL)