Skip to content

Commit

Permalink
[GTK][WPE][Skia] Add a setting to enable or disable 2D canvas acceler…
Browse files Browse the repository at this point in the history
…ation

https://bugs.webkit.org/show_bug.cgi?id=274306

Reviewed by Alejandro G. Castro.

Add a new setting enable-2d-canvas-acceleration because reusing the
existing deprecated one would confuse introspection and
documentation generation.

* Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp:
(WebKit::canvasAccelerationEnabled):
(WebKit::WebKitProtocolHandler::handleGPU):
* Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp:
(webKitSettingsSetProperty):
(webKitSettingsGetProperty):
(webkit_settings_class_init):
(webkit_settings_get_enable_2d_canvas_acceleration):
(webkit_settings_set_enable_2d_canvas_acceleration):
* Source/WebKit/UIProcess/API/glib/WebKitSettings.h.in:
* Source/WebKit/UIProcess/gtk/WebPreferencesGtk.cpp:
(WebKit::WebPreferences::platformInitializeStore):
* Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp:
(testWebKitSettings):

Canonical link: https://commits.webkit.org/278989@main
  • Loading branch information
carlosgcampos committed May 20, 2024
1 parent 7c2b66c commit 3cfaf38
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
13 changes: 13 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ static bool webGLEnabled(WebKitURISchemeRequest* request)
}
#endif

#if USE(SKIA)
static bool canvasAccelerationEnabled(WebKitURISchemeRequest* request)
{
auto* webView = webkit_uri_scheme_request_get_web_view(request);
ASSERT(webView);
return webkit_settings_get_enable_2d_canvas_acceleration(webkit_web_view_get_settings(webView));
}
#endif

static bool uiProcessContextIsEGL()
{
#if PLATFORM(GTK)
Expand Down Expand Up @@ -461,6 +470,10 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request)
addTableRow(hardwareAccelerationObject, "WebGL enabled"_s, webGLEnabled(request) ? "Yes"_s : "No"_s);
#endif

#if USE(SKIA)
addTableRow(hardwareAccelerationObject, "2D canvas"_s, canvasAccelerationEnabled(request) ? "Accelerated"_s : "Unaccelerated"_s);
#endif

std::unique_ptr<PlatformDisplay> renderDisplay;
if (policy != "never"_s) {
addTableRow(jsonObject, "API"_s, String::fromUTF8(openGLAPI()));
Expand Down
73 changes: 73 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ enum {
#if !ENABLE(2022_GLIB_API)
PROP_ENABLE_ACCELERATED_2D_CANVAS,
#endif
PROP_ENABLE_2D_CANVAS_ACCELERATION,
PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT,
PROP_ENABLE_MEDIA_STREAM,
PROP_ENABLE_MOCK_CAPTURE_DEVICES,
Expand Down Expand Up @@ -356,6 +357,9 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN
ALLOW_DEPRECATED_DECLARATIONS_END
break;
#endif
case PROP_ENABLE_2D_CANVAS_ACCELERATION:
webkit_settings_set_enable_2d_canvas_acceleration(settings, g_value_get_boolean(value));
break;
case PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT:
webkit_settings_set_enable_write_console_messages_to_stdout(settings, g_value_get_boolean(value));
break;
Expand Down Expand Up @@ -564,6 +568,9 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN
ALLOW_DEPRECATED_DECLARATIONS_END
break;
#endif
case PROP_ENABLE_2D_CANVAS_ACCELERATION:
g_value_set_boolean(value, webkit_settings_get_enable_2d_canvas_acceleration(settings));
break;
case PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT:
g_value_set_boolean(value, webkit_settings_get_enable_write_console_messages_to_stdout(settings));
break;
Expand Down Expand Up @@ -1302,6 +1309,24 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
static_cast<GParamFlags>(readWriteConstructParamFlags | G_PARAM_DEPRECATED));
#endif

/**
* WebKitSettings:enable-2d-canvas-acceleration:
*
* Enable or disable 2D canvas acceleration.
* If this setting is enabled, the 2D canvas will be accelerated even if Skia CPU
* is used for rendering. However, the canvas can be unaccelerated even when this setting
* is enabled, for other reasons like its size or when willReadFrequently property is used.
*
* Since: 2.46
*/
sObjProperties[PROP_ENABLE_2D_CANVAS_ACCELERATION] =
g_param_spec_boolean(
"enable-2d-canvas-acceleration",
_("Enable 2D canvas acceleration"),
_("Whether to enable 2D canvas acceleration"),
TRUE,
readWriteConstructParamFlags);

/**
* WebKitSettings:enable-write-console-messages-to-stdout:
*
Expand Down Expand Up @@ -3251,6 +3276,54 @@ void webkit_settings_set_enable_accelerated_2d_canvas(WebKitSettings* settings,
}
#endif

/**
* webkit_settings_get_enable_2d_canvas_acceleration:
* @settings: a #WebKitSettings
*
* Get the #WebKitSettings:enable-2d-canvas-acceleration property.
*
* Returns: %TRUE if 2D canvas acceleration is enabled or %FALSE otherwise.
*
* Since: 2.46
*/
gboolean webkit_settings_get_enable_2d_canvas_acceleration(WebKitSettings* settings)
{
g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);

#if USE(SKIA)
return settings->priv->preferences->canvasUsesAcceleratedDrawing();
#else
return FALSE;
#endif
}

/**
* webkit_settings_set_enable_2d_canvas_acceleration:
* @settings: a #WebKitSettings
* @enabled: Value to be set
*
* Set the #WebKitSettings:enable-2d-canvas-acceleration property.
*
* Since: 2.46
*/
void webkit_settings_set_enable_2d_canvas_acceleration(WebKitSettings* settings, gboolean enabled)
{
g_return_if_fail(WEBKIT_IS_SETTINGS(settings));

#if USE(SKIA)
WebKitSettingsPrivate* priv = settings->priv;
bool currentValue = priv->preferences->canvasUsesAcceleratedDrawing();
if (currentValue == enabled)
return;

priv->preferences->setCanvasUsesAcceleratedDrawing(enabled);
g_object_notify_by_pspec(G_OBJECT(settings), sObjProperties[PROP_ENABLE_2D_CANVAS_ACCELERATION]);
#else
if (enabled)
g_warning("2D canvas acceleration not supported, webkit_settings_set_enable_2d_canvas_acceleration does nothing");
#endif
}

/**
* webkit_settings_get_enable_write_console_messages_to_stdout:
* @settings: a #WebKitSettings
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitSettings.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ webkit_settings_set_enable_accelerated_2d_canvas (WebKitSettings *
gboolean enabled);
#endif

WEBKIT_API gboolean
webkit_settings_get_enable_2d_canvas_acceleration (WebKitSettings *settings);

WEBKIT_API void
webkit_settings_set_enable_2d_canvas_acceleration (WebKitSettings *settings,
gboolean enabled);

WEBKIT_API gboolean
webkit_settings_get_enable_write_console_messages_to_stdout (WebKitSettings *settings);

Expand Down
7 changes: 0 additions & 7 deletions Source/WebKit/UIProcess/gtk/WebPreferencesGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "WebPreferences.h"

#include "HardwareAccelerationManager.h"
#include <WebCore/NotImplemented.h>

namespace WebKit {

Expand All @@ -47,12 +46,6 @@ void WebPreferences::platformInitializeStore()
setAcceleratedCompositingEnabled(compositingState.acceleratedCompositingEnabled);
setForceCompositingMode(compositingState.forceCompositingMode);
setThreadedScrollingEnabled(compositingState.forceCompositingMode);
#if USE(SKIA)
// FIXME: Expose this as a setting when we switch to Skia.
static const char* disableAccelerated2DCanvas = getenv("WEBKIT_DISABLE_ACCELERATED_2D_CANVAS");
if (disableAccelerated2DCanvas && strcmp(disableAccelerated2DCanvas, "0"))
setCanvasUsesAcceleratedDrawing(false);
#endif
}

} // namespace WebKit
7 changes: 7 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN
ALLOW_DEPRECATED_DECLARATIONS_END
#endif

#if USE(SKIA)
// 2D canvas acceleration is enabled by default.
g_assert_true(webkit_settings_get_enable_2d_canvas_acceleration(settings));
webkit_settings_set_enable_2d_canvas_acceleration(settings, FALSE);
g_assert_false(webkit_settings_get_enable_2d_canvas_acceleration(settings));
#endif

// WebSecurity is enabled by default.
g_assert_false(webkit_settings_get_disable_web_security(settings));
webkit_settings_set_disable_web_security(settings, TRUE);
Expand Down

0 comments on commit 3cfaf38

Please sign in to comment.