Skip to content

Commit 1f8ecb5

Browse files
committed
[WPE] Move the new API runtime check to a common place
https://bugs.webkit.org/show_bug.cgi?id=293678 Reviewed by Adrian Perez de Castro. We are using g_type_class_peek(WPE_TYPE_DISPLAY) to check whether the new api is being used in several places, we could add a common helper WKWPE::isUsingWPEPlatformAPI() and use it instead. Canonical link: https://commits.webkit.org/295498@main
1 parent f34b2de commit 1f8ecb5

11 files changed

Lines changed: 129 additions & 64 deletions

Source/WebKit/SourcesWPE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ UIProcess/soup/WebProcessPoolSoup.cpp
258258
UIProcess/wpe/AcceleratedBackingStoreDMABuf.cpp
259259
UIProcess/wpe/ScreenManagerWPE.cpp
260260
UIProcess/wpe/SystemSettingsManagerProxyWPE.cpp
261+
UIProcess/wpe/WPEUtilities.cpp
261262
UIProcess/wpe/WebPageProxyWPE.cpp
262263
UIProcess/wpe/WebPasteboardProxyWPE.cpp
263264
UIProcess/wpe/WebPreferencesWPE.cpp

Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@
6464
#include <gtk/gtk.h>
6565
#endif
6666

67-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
67+
#if PLATFORM(WPE)
68+
#include "WPEUtilities.h"
69+
#if ENABLE(WPE_PLATFORM)
6870
#include <wpe/wpe-platform.h>
6971
#endif
72+
#endif
7073

7174
#if USE(GBM)
7275
#include <WebCore/PlatformDisplayGBM.h>
@@ -449,12 +452,7 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request)
449452
#endif
450453

451454
#if PLATFORM(WPE)
452-
#if ENABLE(WPE_PLATFORM)
453-
bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
454-
#else
455-
bool usingWPEPlatformAPI = false;
456-
#endif
457-
455+
bool usingWPEPlatformAPI = WKWPE::isUsingWPEPlatformAPI();
458456
if (!usingWPEPlatformAPI) {
459457
addTableRow(versionObject, "WPE version"_s, makeString(WPE_MAJOR_VERSION, '.', WPE_MINOR_VERSION, '.', WPE_MICRO_VERSION, " (build) "_s, wpe_get_major_version(), '.', wpe_get_minor_version(), '.', wpe_get_micro_version(), " (runtime)"_s));
460458
addTableRow(versionObject, "WPE backend"_s, String::fromUTF8(wpe_loader_get_loaded_implementation_library_name()));

Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#endif
108108

109109
#if PLATFORM(WPE)
110+
#include "WPEUtilities.h"
110111
#include "WPEWebViewLegacy.h"
111112
#include "WPEWebViewPlatform.h"
112113
#include "WebKitOptionMenuPrivate.h"
@@ -904,7 +905,7 @@ static void webkitWebViewConstructed(GObject* object)
904905
if (priv->display) {
905906
g_critical("WebKitWebView backend can't be set when display is set too, passed backend is ignored.");
906907
priv->backend = nullptr;
907-
} else if (g_type_class_peek(WPE_TYPE_DISPLAY)) {
908+
} else if (WKWPE::isUsingWPEPlatformAPI()) {
908909
g_critical("WebKitWebView backend can't be set when WPE platform API is already in use, passed backend is ignored.");
909910
priv->backend = nullptr;
910911
priv->display = wpe_display_get_default();

Source/WebKit/UIProcess/API/wpe/WebKitWebViewWPE.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "WebKitWebView.h"
2222

2323
#include "PageClientImpl.h"
24+
#include "WPEUtilities.h"
2425
#include "WebInspectorUIProxy.h"
2526
#include "WebKitColorPrivate.h"
2627
#include "WebKitScriptDialogPrivate.h"
@@ -84,7 +85,7 @@ void webkitWebViewRestoreWindow(WebKitWebView*, CompletionHandler<void()>&& comp
8485
WebKitWebView* webkit_web_view_new(WebKitWebViewBackend* backend)
8586
{
8687
#if ENABLE(WPE_PLATFORM)
87-
g_return_val_if_fail(!backend || !g_type_class_peek(WPE_TYPE_DISPLAY), nullptr);
88+
g_return_val_if_fail(!backend || !WKWPE::isUsingWPEPlatformAPI(), nullptr);
8889
#else
8990
g_return_val_if_fail(backend, nullptr);
9091
#endif

Source/WebKit/UIProcess/Gamepad/libwpe/UIGamepadProviderLibWPE.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#if ENABLE(WPE_PLATFORM)
3737
#include "GamepadProviderWPE.h"
38+
#include "WPEUtilities.h"
3839
#include "WPEWebViewPlatform.h"
3940
#include <wpe/wpe-platform.h>
4041
#endif
@@ -43,20 +44,13 @@
4344
namespace WebKit {
4445
using namespace WebCore;
4546

46-
#if ENABLE(WPE_PLATFORM)
47-
static inline bool usingWPEPlatformAPI()
48-
{
49-
return !!g_type_class_peek(WPE_TYPE_DISPLAY);
50-
}
51-
#endif
52-
5347
void UIGamepadProvider::platformSetDefaultGamepadProvider()
5448
{
5549
if (GamepadProvider::singleton().isMockGamepadProvider())
5650
return;
5751

5852
#if ENABLE(WPE_PLATFORM)
59-
if (usingWPEPlatformAPI()) {
53+
if (WKWPE::isUsingWPEPlatformAPI()) {
6054
GamepadProvider::setSharedProvider(GamepadProviderWPE::singleton());
6155
return;
6256
}
@@ -71,7 +65,7 @@ WebPageProxy* UIGamepadProvider::platformWebPageProxyForGamepadInput()
7165
{
7266
#if PLATFORM(WPE)
7367
#if ENABLE(WPE_PLATFORM)
74-
if (usingWPEPlatformAPI())
68+
if (WKWPE::isUsingWPEPlatformAPI())
7569
return WKWPE::ViewPlatform::platformWebPageProxyForGamepadInput();
7670
#endif
7771
return WKWPE::ViewLegacy::platformWebPageProxyForGamepadInput();
@@ -83,15 +77,15 @@ WebPageProxy* UIGamepadProvider::platformWebPageProxyForGamepadInput()
8377
void UIGamepadProvider::platformStopMonitoringInput()
8478
{
8579
#if ENABLE(WPE_PLATFORM)
86-
if (usingWPEPlatformAPI())
80+
if (WKWPE::isUsingWPEPlatformAPI())
8781
GamepadProviderWPE::singleton().stopMonitoringInput();
8882
#endif
8983
}
9084

9185
void UIGamepadProvider::platformStartMonitoringInput()
9286
{
9387
#if ENABLE(WPE_PLATFORM)
94-
if (usingWPEPlatformAPI())
88+
if (WKWPE::isUsingWPEPlatformAPI())
9589
GamepadProviderWPE::singleton().startMonitoringInput();
9690
#endif
9791
}

Source/WebKit/UIProcess/glib/DRMDevice.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#endif
3939

4040
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
41+
#include "WPEUtilities.h"
4142
#include <wpe/wpe-platform.h>
4243
#endif
4344

@@ -170,7 +171,7 @@ const String& drmPrimaryDevice()
170171
static std::once_flag once;
171172
std::call_once(once, [] {
172173
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
173-
if (g_type_class_peek(WPE_TYPE_DISPLAY)) {
174+
if (WKWPE::isUsingWPEPlatformAPI()) {
174175
primaryDevice.construct(String::fromUTF8(wpe_display_get_drm_device(wpe_display_get_primary())));
175176
return;
176177
}
@@ -193,7 +194,7 @@ const String& drmRenderNodeDevice()
193194
static std::once_flag once;
194195
std::call_once(once, [] {
195196
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
196-
if (g_type_class_peek(WPE_TYPE_DISPLAY)) {
197+
if (WKWPE::isUsingWPEPlatformAPI()) {
197198
renderNodeDevice.construct(String::fromUTF8(wpe_display_get_drm_render_node(wpe_display_get_primary())));
198199
return;
199200
}

Source/WebKit/UIProcess/glib/DisplayVBlankMonitorDRM.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@
4040
#include <xf86drm.h>
4141
#include <xf86drmMode.h>
4242

43-
#if PLATFORM(GTK) || (PLATFORM(WPE) && ENABLE(WPE_PLATFORM))
43+
#if PLATFORM(GTK) || ENABLE(WPE_PLATFORM)
4444
#include "ScreenManager.h"
4545
#endif
4646

4747
#if PLATFORM(GTK)
4848
#include <gtk/gtk.h>
4949
#endif
5050

51-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
51+
#if ENABLE(WPE_PLATFORM)
52+
#include "WPEUtilities.h"
5253
#include <wpe/wpe-platform.h>
5354
#ifdef WPE_PLATFORM_DRM
5455
#include <wpe/drm/wpe-drm.h>
@@ -59,7 +60,7 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN // GTK/WPE port
5960

6061
namespace WebKit {
6162

62-
#if PLATFORM(GTK) || (PLATFORM(WPE) && ENABLE(WPE_PLATFORM))
63+
#if PLATFORM(GTK) || ENABLE(WPE_PLATFORM)
6364
static std::optional<std::pair<uint32_t, uint32_t>> findCrtc(int fd, PlatformScreen* screen)
6465
{
6566
drmModeRes* resources = drmModeGetResources(fd);
@@ -188,7 +189,7 @@ struct DrmNodeWithCrtc {
188189
UnixFileDescriptor drmNodeFd;
189190
std::pair<uint32_t, uint32_t> crtcInfo;
190191
};
191-
#if PLATFORM(GTK) || (PLATFORM(WPE) && ENABLE(WPE_PLATFORM))
192+
#if PLATFORM(GTK) || ENABLE(WPE_PLATFORM)
192193
static std::optional<DrmNodeWithCrtc> findDrmNodeWithCrtc(PlatformScreen* screen = nullptr)
193194
#else
194195
static std::optional<DrmNodeWithCrtc> findDrmNodeWithCrtc()
@@ -205,7 +206,7 @@ static std::optional<DrmNodeWithCrtc> findDrmNodeWithCrtc()
205206
if (!fd)
206207
continue;
207208
std::optional<std::pair<uint32_t, uint32_t>> crtcInfo;
208-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
209+
#if ENABLE(WPE_PLATFORM)
209210
if (screen)
210211
crtcInfo = findCrtc(fd.value(), screen);
211212
else
@@ -235,11 +236,11 @@ static int crtcBitmaskForIndex(uint32_t crtcIndex)
235236

236237
std::unique_ptr<DisplayVBlankMonitor> DisplayVBlankMonitorDRM::create(PlatformDisplayID displayID)
237238
{
238-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
239-
static bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
239+
#if ENABLE(WPE_PLATFORM)
240+
bool usingWPEPlatformAPI = WKWPE::isUsingWPEPlatformAPI();
240241
#endif
241242

242-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
243+
#if ENABLE(WPE_PLATFORM)
243244
PlatformScreen* screen = nullptr;
244245
if (usingWPEPlatformAPI) {
245246
screen = ScreenManager::singleton().screen(displayID);
@@ -259,7 +260,7 @@ std::unique_ptr<DisplayVBlankMonitor> DisplayVBlankMonitorDRM::create(PlatformDi
259260
#endif
260261

261262
std::optional<DrmNodeWithCrtc> drmNodeWithCrtcInfo;
262-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
263+
#if ENABLE(WPE_PLATFORM)
263264
#ifdef WPE_PLATFORM_DRM
264265
if (usingWPEPlatformAPI && WPE_IS_SCREEN_DRM(screen)) {
265266
String filename = String::fromUTF8(wpe_display_get_drm_device(wpe_display_get_primary()));

Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include <wpe/wpe.h>
5858
#endif
5959

60-
#if PLATFORM(GTK) || (PLATFORM(WPE) && ENABLE(WPE_PLATFORM))
60+
#if PLATFORM(GTK) || ENABLE(WPE_PLATFORM)
6161
#include "ScreenManager.h"
6262
#endif
6363

@@ -67,7 +67,8 @@
6767
#include <gtk/gtk.h>
6868
#endif
6969

70-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
70+
#if ENABLE(WPE_PLATFORM)
71+
#include "WPEUtilities.h"
7172
#include <wpe/wpe-platform.h>
7273
#endif
7374

@@ -79,7 +80,7 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
7980

8081
namespace WebKit {
8182

82-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
83+
#if ENABLE(WPE_PLATFORM)
8384
static OptionSet<AvailableInputDevices> toAvailableInputDevices(WPEAvailableInputDevices inputDevices)
8485
{
8586
OptionSet<AvailableInputDevices> availableInputDevices;
@@ -112,8 +113,7 @@ static OptionSet<AvailableInputDevices> toAvailableInputDevices(GdkSeatCapabilit
112113
static OptionSet<AvailableInputDevices> availableInputDevices()
113114
{
114115
#if ENABLE(WPE_PLATFORM)
115-
bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
116-
if (usingWPEPlatformAPI) {
116+
if (WKWPE::isUsingWPEPlatformAPI()) {
117117
const auto inputDevices = wpe_display_get_available_input_devices(wpe_display_get_primary());
118118
return toAvailableInputDevices(inputDevices);
119119
}
@@ -166,8 +166,7 @@ void WebProcessPool::platformInitialize(NeedsGlobalStaticInitialization)
166166
#endif
167167

168168
#if ENABLE(WPE_PLATFORM)
169-
bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
170-
if (usingWPEPlatformAPI) {
169+
if (WKWPE::isUsingWPEPlatformAPI()) {
171170
auto* display = wpe_display_get_primary();
172171
g_signal_connect(display, "notify::available-input-devices", G_CALLBACK(+[](WPEDisplay* display, GParamSpec*, WebProcessPool* pool) {
173172
auto availableInputDevices = toAvailableInputDevices(wpe_display_get_available_input_devices(display));
@@ -188,8 +187,8 @@ void WebProcessPool::platformInitialize(NeedsGlobalStaticInitialization)
188187

189188
void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process, WebProcessCreationParameters& parameters)
190189
{
191-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
192-
bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
190+
#if ENABLE(WPE_PLATFORM)
191+
bool usingWPEPlatformAPI = WKWPE::isUsingWPEPlatformAPI();
193192
#endif
194193

195194
#if USE(GBM)
@@ -198,7 +197,7 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
198197

199198
#if PLATFORM(GTK)
200199
parameters.rendererBufferTransportMode = AcceleratedBackingStoreDMABuf::rendererBufferTransportMode();
201-
#elif PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
200+
#elif ENABLE(WPE_PLATFORM)
202201
if (usingWPEPlatformAPI) {
203202
#if USE(GBM)
204203
if (!parameters.renderDeviceFile.isEmpty())
@@ -260,7 +259,7 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
260259
parameters.screenProperties = ScreenManager::singleton().collectScreenProperties();
261260
#endif
262261

263-
#if PLATFORM(WPE) && ENABLE(WPE_PLATFORM)
262+
#if ENABLE(WPE_PLATFORM)
264263
if (usingWPEPlatformAPI)
265264
parameters.screenProperties = ScreenManager::singleton().collectScreenProperties();
266265
#endif
@@ -269,8 +268,7 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
269268
void WebProcessPool::platformInvalidateContext()
270269
{
271270
#if ENABLE(WPE_PLATFORM)
272-
bool usingWPEPlatformAPI = !!g_type_class_peek(WPE_TYPE_DISPLAY);
273-
if (usingWPEPlatformAPI) {
271+
if (WKWPE::isUsingWPEPlatformAPI()) {
274272
auto* display = wpe_display_get_primary();
275273
g_signal_handlers_disconnect_by_data(display, this);
276274
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2025 Igalia S.L.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "config.h"
27+
#include "WPEUtilities.h"
28+
29+
#if ENABLE(WPE_PLATFORM)
30+
#include <wpe/wpe-platform.h>
31+
#endif
32+
33+
namespace WKWPE {
34+
35+
bool isUsingWPEPlatformAPI()
36+
{
37+
#if ENABLE(WPE_PLATFORM)
38+
return !!g_type_class_peek(WPE_TYPE_DISPLAY);
39+
#else
40+
return false;
41+
#endif
42+
}
43+
44+
} // namespace WKWPE
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2025 Igalia S.L.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
namespace WKWPE {
29+
30+
bool isUsingWPEPlatformAPI();
31+
32+
} // namespace WKWPE

0 commit comments

Comments
 (0)