Changeset 211363 in webkit


Ignore:
Timestamp:
Jan 30, 2017 5:50:37 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add API to handle the accelerated compositing policy
https://bugs.webkit.org/show_bug.cgi?id=167509

Reviewed by Michael Catanzaro.

Source/WebKit2:

Now that we have brought back the on demand mode, we should allow applications to choose the policy, without
having to deal with environment variables. Settings also allows to set different policy depending on the web
view, so for example evolution could disable AC for the composer, but leave the on demand mode for the email
viewer. This patch adds a single new setting hardware-acceleration-policy to handle both
acceleratedCompositingEnabled and forceCompositingMode preferences using an enum with values
WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS and
WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER.

  • UIProcess/API/gtk/WebKitSettings.cpp:

(webKitSettingsSetProperty): Add setter for hardware-acceleration-policy property.
(webKitSettingsGetProperty): Add getter for hardware-acceleration-policy property.
(webkit_settings_class_init): Add hardware-acceleration-policy property.
(webkit_settings_get_hardware_acceleration_policy): Return policy according to the preferences.
(webkit_settings_set_hardware_acceleration_policy): set preferences according to the given policy.

  • UIProcess/API/gtk/WebKitSettings.h:
  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
  • WebProcess/WebPage/DrawingAreaImpl.cpp:

(WebKit::DrawingAreaImpl::updatePreferences):

Tools:

Handle new setting in MiniBrowser. The settings dialog doesn't support enum settings so it needs to be handled
as a special case. Also add test cases to the get/set API.

  • MiniBrowser/gtk/BrowserSettingsDialog.c:

(hardwareAccelerationPolicyToString):
(stringToHardwareAccelerationPolicy):
(cellRendererChanged):
(browserSettingsDialogConstructed):

  • TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:

(testWebKitSettings):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r211357 r211363  
     12017-01-30  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add API to handle the accelerated compositing policy
     4        https://bugs.webkit.org/show_bug.cgi?id=167509
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Now that we have brought back the on demand mode, we should allow applications to choose the policy, without
     9        having to deal with environment variables. Settings also allows to set different policy depending on the web
     10        view, so for example evolution could disable AC for the composer, but leave the on demand mode for the email
     11        viewer. This patch adds a single new setting hardware-acceleration-policy to handle both
     12        acceleratedCompositingEnabled and forceCompositingMode preferences using an enum with values
     13        WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS and
     14        WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER.
     15
     16        * UIProcess/API/gtk/WebKitSettings.cpp:
     17        (webKitSettingsSetProperty): Add setter for hardware-acceleration-policy property.
     18        (webKitSettingsGetProperty): Add getter for hardware-acceleration-policy property.
     19        (webkit_settings_class_init): Add hardware-acceleration-policy property.
     20        (webkit_settings_get_hardware_acceleration_policy): Return policy according to the preferences.
     21        (webkit_settings_set_hardware_acceleration_policy): set preferences according to the given policy.
     22        * UIProcess/API/gtk/WebKitSettings.h:
     23        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
     24        * WebProcess/WebPage/DrawingAreaImpl.cpp:
     25        (WebKit::DrawingAreaImpl::updatePreferences):
     26
    1272017-01-29  Carlos Garcia Campos  <cgarcia@igalia.com>
    228
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp

    r211138 r211363  
    3333
    3434#include "ExperimentalFeatures.h"
     35#include "WebKitEnumTypes.h"
    3536#include "WebKitPrivate.h"
    3637#include "WebKitSettingsPrivate.h"
     
    146147    PROP_ENABLE_MEDIASOURCE,
    147148    PROP_ALLOW_FILE_ACCESS_FROM_FILE_URLS,
    148     PROP_ALLOW_UNIVERSAL_ACCESS_FROM_FILE_URLS
     149    PROP_ALLOW_UNIVERSAL_ACCESS_FROM_FILE_URLS,
     150    PROP_HARDWARE_ACCELERATION_POLICY,
    149151};
    150152
     
    324326        webkit_settings_set_allow_universal_access_from_file_urls(settings, g_value_get_boolean(value));
    325327        break;
     328    case PROP_HARDWARE_ACCELERATION_POLICY:
     329        webkit_settings_set_hardware_acceleration_policy(settings, static_cast<WebKitHardwareAccelerationPolicy>(g_value_get_enum(value)));
     330        break;
    326331    default:
    327332        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    486491    case PROP_ALLOW_UNIVERSAL_ACCESS_FROM_FILE_URLS:
    487492        g_value_set_boolean(value, webkit_settings_get_allow_universal_access_from_file_urls(settings));
     493        break;
     494    case PROP_HARDWARE_ACCELERATION_POLICY:
     495        g_value_set_enum(value, webkit_settings_get_hardware_acceleration_policy(settings));
    488496        break;
    489497    default:
     
    12801288            FALSE,
    12811289            readWriteConstructParamFlags));
     1290
     1291    /**
     1292     * WebKitSettings:hardware-acceleration-policy:
     1293     *
     1294     * The #WebKitHardwareAccelerationPolicy to decide how to enable and disable
     1295     * hardware acceleration. The default value %WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND
     1296     * enables the hardware acceleration when the web contents request it, disabling it again
     1297     * when no longer needed. It's possible to enfore hardware acceleration to be always enabled
     1298     * by using %WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS. And it's also posible to disable it
     1299     * completely using %WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER. Note that disabling hardware
     1300     * acceleration might cause some websites to not render correctly or consume more CPU.
     1301     *
     1302     * Since: 2.16
     1303     */
     1304    g_object_class_install_property(gObjectClass,
     1305        PROP_HARDWARE_ACCELERATION_POLICY,
     1306        g_param_spec_enum("hardware-acceleration-policy",
     1307            _("Hardware Acceleration Policy"),
     1308            _("The policy to decide how to enable and disable hardware acceleration"),
     1309            WEBKIT_TYPE_HARDWARE_ACCELERATION_POLICY,
     1310            WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND,
     1311            readWriteConstructParamFlags));
    12821312}
    12831313
     
    31433173    g_object_notify(G_OBJECT(settings), "allow-universal-access-from-file-urls");
    31443174}
     3175
     3176/**
     3177 * webkit_settings_get_hardware_acceleration_policy:
     3178 * @settings: a #WebKitSettings
     3179 *
     3180 * Get the #WebKitSettings:hardware-acceleration-policy property.
     3181 *
     3182 * Return: a #WebKitHardwareAccelerationPolicy
     3183 *
     3184 * Since: 2.16
     3185 */
     3186WebKitHardwareAccelerationPolicy webkit_settings_get_hardware_acceleration_policy(WebKitSettings* settings)
     3187{
     3188    g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     3189
     3190    WebKitSettingsPrivate* priv = settings->priv;
     3191    if (!priv->preferences->acceleratedCompositingEnabled())
     3192        return WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER;
     3193
     3194    if (priv->preferences->forceCompositingMode())
     3195        return WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS;
     3196
     3197    return WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND;
     3198}
     3199
     3200/**
     3201 * webkit_settings_set_hardware_acceleration_policy:
     3202 * @settings: a #WebKitSettings
     3203 * @policy: a #WebKitHardwareAccelerationPolicy
     3204 *
     3205 * Set the #WebKitSettings:hardware-acceleration-policy property.
     3206 *
     3207 * Since: 2.16
     3208 */
     3209void webkit_settings_set_hardware_acceleration_policy(WebKitSettings* settings, WebKitHardwareAccelerationPolicy policy)
     3210{
     3211    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
     3212
     3213    WebKitSettingsPrivate* priv = settings->priv;
     3214    bool changed = false;
     3215    switch (policy) {
     3216    case WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS:
     3217        if (!priv->preferences->acceleratedCompositingEnabled()) {
     3218            priv->preferences->setAcceleratedCompositingEnabled(true);
     3219            changed = true;
     3220        }
     3221        if (!priv->preferences->forceCompositingMode()) {
     3222            priv->preferences->setForceCompositingMode(true);
     3223            changed = true;
     3224        }
     3225        break;
     3226    case WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER:
     3227        if (priv->preferences->acceleratedCompositingEnabled()) {
     3228            priv->preferences->setAcceleratedCompositingEnabled(false);
     3229            changed = true;
     3230        }
     3231
     3232        if (priv->preferences->forceCompositingMode()) {
     3233            priv->preferences->setForceCompositingMode(false);
     3234            changed = true;
     3235        }
     3236        break;
     3237
     3238    case WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND:
     3239        if (!priv->preferences->acceleratedCompositingEnabled()) {
     3240            priv->preferences->setAcceleratedCompositingEnabled(true);
     3241            changed = true;
     3242        }
     3243
     3244        if (priv->preferences->forceCompositingMode()) {
     3245            priv->preferences->setForceCompositingMode(false);
     3246            changed = true;
     3247        }
     3248
     3249        break;
     3250    }
     3251
     3252    if (changed)
     3253        g_object_notify(G_OBJECT(settings), "hardware-acceleration-policy");
     3254}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h

    r211138 r211363  
    4848#define WEBKIT_SETTINGS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_SETTINGS, WebKitSettingsClass))
    4949
     50/**
     51 * WebKitHardwareAccelerationPolicy:
     52 * @WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND: Hardware acceleration is enabled/disabled as request by web contents.
     53 * @WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS: Hardware acceleration is always enabled, even for websites not requesting it.
     54 * @WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER: Hardware acceleration is always disabled, even for websites requesting it.
     55 *
     56 * Enum values used for determining the hardware acceleration policy.
     57 *
     58 * Since: 2.16
     59 */
     60typedef enum {
     61    WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND,
     62    WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS,
     63    WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER
     64} WebKitHardwareAccelerationPolicy;
     65
    5066typedef struct _WebKitSettings WebKitSettings;
    5167typedef struct _WebKitSettingsClass WebKitSettingsClass;
     
    429445                                                                gboolean        allowed);
    430446
     447WEBKIT_API WebKitHardwareAccelerationPolicy
     448webkit_settings_get_hardware_acceleration_policy               (WebKitSettings *settings);
     449
     450WEBKIT_API void
     451webkit_settings_set_hardware_acceleration_policy               (WebKitSettings *settings,
     452                                                                WebKitHardwareAccelerationPolicy policy);
     453
    431454G_END_DECLS
    432455
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r211138 r211363  
    359359<FILE>WebKitSettings</FILE>
    360360WebKitSettings
     361WebKitHardwareAccelerationPolicy
    361362webkit_settings_new
    362363webkit_settings_new_with_settings
     
    462463webkit_settings_get_allow_universal_access_from_file_urls
    463464webkit_settings_set_allow_universal_access_from_file_urls
     465webkit_settings_get_hardware_acceleration_policy
     466webkit_settings_set_hardware_acceleration_policy
    464467
    465468<SUBSECTION Standard>
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp

    r211346 r211363  
    178178    // Fixed position elements need to be composited and create stacking contexts
    179179    // in order to be scrolled by the ScrollingCoordinator.
    180     settings.setAcceleratedCompositingForFixedPositionEnabled(true);
    181     settings.setFixedPositionCreatesStackingContext(true);
     180    settings.setAcceleratedCompositingForFixedPositionEnabled(settings.acceleratedCompositingEnabled());
     181    settings.setFixedPositionCreatesStackingContext(settings.acceleratedCompositingEnabled());
    182182#endif
    183183
  • trunk/Tools/ChangeLog

    r211355 r211363  
     12017-01-30  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add API to handle the accelerated compositing policy
     4        https://bugs.webkit.org/show_bug.cgi?id=167509
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Handle new setting in MiniBrowser. The settings dialog doesn't support enum settings so it needs to be handled
     9        as a special case. Also add test cases to the get/set API.
     10
     11        * MiniBrowser/gtk/BrowserSettingsDialog.c:
     12        (hardwareAccelerationPolicyToString):
     13        (stringToHardwareAccelerationPolicy):
     14        (cellRendererChanged):
     15        (browserSettingsDialogConstructed):
     16        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
     17        (testWebKitSettings):
     18
    1192017-01-29  Andy Estes  <aestes@apple.com>
    220
  • trunk/Tools/MiniBrowser/gtk/BrowserSettingsDialog.c

    r104018 r211363  
    5656G_DEFINE_TYPE(BrowserSettingsDialog, browser_settings_dialog, GTK_TYPE_DIALOG)
    5757
     58static const char *hardwareAccelerationPolicyToString(WebKitHardwareAccelerationPolicy policy)
     59{
     60    switch (policy) {
     61    case WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS:
     62        return "always";
     63    case WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER:
     64        return "never";
     65    case WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND:
     66        return "ondemand";
     67    }
     68
     69    g_assert_not_reached();
     70    return "ondemand";
     71}
     72
     73static int stringToHardwareAccelerationPolicy(const char *policy)
     74{
     75    if (!g_ascii_strcasecmp(policy, "always"))
     76        return WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS;
     77    if (!g_ascii_strcasecmp(policy, "never"))
     78        return WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER;
     79    if (!g_ascii_strcasecmp(policy, "ondemand"))
     80        return WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND;
     81
     82    g_warning("Invalid value %s for hardware-acceleration-policy setting valid values are always, never and ondemand", policy);
     83    return -1;
     84}
     85
    5886static void cellRendererChanged(GtkCellRenderer *renderer, const char *path, const GValue *value, BrowserSettingsDialog *dialog)
    5987{
     
    6391    gtk_tree_model_get_iter(model, &iter, treePath);
    6492
     93    gboolean updateTreeStore = TRUE;
    6594    char *name;
    6695    gtk_tree_model_get(model, &iter, SETTINGS_LIST_COLUMN_NAME, &name, -1);
    67     g_object_set_property(G_OBJECT(dialog->settings), name, value);
     96    if (!g_strcmp0(name, "hardware-acceleration-policy")) {
     97        int policy = stringToHardwareAccelerationPolicy(g_value_get_string(value));
     98        if (policy != -1)
     99            webkit_settings_set_hardware_acceleration_policy(dialog->settings, policy);
     100        else
     101            updateTreeStore = FALSE;
     102    } else
     103        g_object_set_property(G_OBJECT(dialog->settings), name, value);
    68104    g_free(name);
    69105
    70     gtk_list_store_set(GTK_LIST_STORE(model), &iter, SETTINGS_LIST_COLUMN_VALUE, value, -1);
     106    if (updateTreeStore)
     107        gtk_list_store_set(GTK_LIST_STORE(model), &iter, SETTINGS_LIST_COLUMN_VALUE, value, -1);
    71108    gtk_tree_path_free(treePath);
    72109}
     
    135172        const char *name = g_param_spec_get_name(property);
    136173        const char *nick = g_param_spec_get_nick(property);
     174        char *blurb = g_markup_escape_text(g_param_spec_get_blurb(property), -1);
    137175
    138176        GValue value = { 0, { { 0 } } };
    139         g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(property));
    140         g_object_get_property(G_OBJECT(settings), name, &value);
     177        if (!g_strcmp0(name, "hardware-acceleration-policy")) {
     178            g_value_init(&value, G_TYPE_STRING);
     179            g_value_set_string(&value, hardwareAccelerationPolicyToString(webkit_settings_get_hardware_acceleration_policy(settings)));
     180            char *extendedBlutb = g_strdup_printf("%s (always, never or ondemand)", blurb);
     181            g_free(blurb);
     182            blurb = extendedBlutb;
     183        } else {
     184            g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(property));
     185            g_object_get_property(G_OBJECT(settings), name, &value);
     186        }
    141187
    142188        GtkAdjustment *adjustment = NULL;
     
    147193        }
    148194
    149         char *blurb = g_markup_escape_text(g_param_spec_get_blurb(property), -1);
    150195        GtkTreeIter iter;
    151196        gtk_list_store_append(model, &iter);
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp

    r211138 r211363  
    286286    g_assert(webkit_settings_get_allow_universal_access_from_file_urls(settings));
    287287
     288    // Ondemand is the default hardware acceleration policy.
     289    g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     290    webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER);
     291    g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER);
     292    webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
     293    g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
     294    webkit_settings_set_hardware_acceleration_policy(settings, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     295    g_assert_cmpuint(webkit_settings_get_hardware_acceleration_policy(settings), ==, WEBKIT_HARDWARE_ACCELERATION_POLICY_ON_DEMAND);
     296
    288297    g_object_unref(G_OBJECT(settings));
    289298}
Note: See TracChangeset for help on using the changeset viewer.