Changeset 169445 in webkit


Ignore:
Timestamp:
May 29, 2014 8:10:54 AM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add HighDPI support for non-accelerated compositing contents
https://bugs.webkit.org/show_bug.cgi?id=131562

Patch by Owen Taylor <otaylor@redhat.com> on 2014-05-29
Reviewed by Anders Carlsson.

Source/WebCore:
No new tests. This will be tested once we have the proper dependencies in the WebKit testing
JHBuild.

  • platform/cairo/WidgetBackingStore.h:

(WebCore::WidgetBackingStore::WidgetBackingStore): Accept a device scale argument.

  • platform/cairo/WidgetBackingStoreCairo.cpp: Use the device scale argument to make the surface the proper size and set the surface device scale.
  • platform/cairo/WidgetBackingStoreCairo.h: Accept a device scale argument.
  • platform/graphics/cairo/CairoUtilities.cpp: Add a new helper to set the device scale if Cairo built against is new enough.
  • platform/graphics/cairo/CairoUtilities.h:
  • platform/gtk/GtkVersioning.h: Add the HAVE_GTK_SCALE_FACTOR macro.
  • platform/gtk/WidgetBackingStoreGtkX11.cpp: Use the device scale argument to make the surface the proper size and set the surface device scale.
  • platform/gtk/WidgetBackingStoreGtkX11.h: Accept a device scale argument.

Source/WebKit2:

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(deviceScaleFactorChanged): Added this callback to pass scale changes to the page proxy.
(webkitWebViewBaseCreateWebPage): Attach the callback to the notify signal.

  • UIProcess/WebPageProxy.cpp:
  • UIProcess/cairo/BackingStoreCairo.cpp:

(WebKit::WebPageProxy::setCustomDeviceScaleFactor): Do not set a
custom device scale factor for cairo when it's not supported.
(WebKit::createBackingStoreForGTK): Pass the scale factor to the WebCore backing store.
(WebKit::BackingStore::incorporateUpdate): Ditto.

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r169440 r169445  
     12014-05-29  Owen Taylor  <otaylor@redhat.com>
     2
     3        [GTK] Add HighDPI support for non-accelerated compositing contents
     4        https://bugs.webkit.org/show_bug.cgi?id=131562
     5
     6        Reviewed by Anders Carlsson.
     7
     8        No new tests. This will be tested once we have the proper dependencies in the WebKit testing
     9        JHBuild.
     10
     11        * platform/cairo/WidgetBackingStore.h:
     12        (WebCore::WidgetBackingStore::WidgetBackingStore): Accept a device scale argument.
     13        * platform/cairo/WidgetBackingStoreCairo.cpp: Use the device scale argument to make the surface the proper size and set the surface device scale.
     14        * platform/cairo/WidgetBackingStoreCairo.h: Accept a device scale argument.
     15        * platform/graphics/cairo/CairoUtilities.cpp: Add a new helper to set the device scale if Cairo built against is new enough.
     16        * platform/graphics/cairo/CairoUtilities.h:
     17        * platform/gtk/GtkVersioning.h: Add the HAVE_GTK_SCALE_FACTOR macro.
     18        * platform/gtk/WidgetBackingStoreGtkX11.cpp: Use the device scale argument to make the surface the proper size and set the surface device scale.
     19        * platform/gtk/WidgetBackingStoreGtkX11.h: Accept a device scale argument.
     20
    1212014-05-28  Brent Fulgham  <bfulgham@apple.com>
    222
  • trunk/Source/WebCore/platform/cairo/WidgetBackingStore.h

    r167195 r169445  
    5050    virtual void scroll(const IntRect& scrollRect, const IntSize& scrollOffset) = 0;
    5151    const IntSize& size() { return m_size; }
    52     WidgetBackingStore(const IntSize& size) : m_size(size) { }
     52
     53    WidgetBackingStore(const IntSize& size, float deviceScaleFactor)
     54        : m_size(size)
     55        , m_deviceScaleFactor(deviceScaleFactor)
     56    { }
     57
    5358    virtual ~WidgetBackingStore() { }
    5459
    55 private:
     60protected:
    5661    IntSize m_size;
     62    float m_deviceScaleFactor;
    5763};
    5864
  • trunk/Source/WebCore/platform/cairo/WidgetBackingStoreCairo.cpp

    r167195 r169445  
    2727namespace WebCore {
    2828
    29 static PassRefPtr<cairo_surface_t> createSurfaceForBackingStore(PlatformWidget widget, const IntSize& size)
     29static PassRefPtr<cairo_surface_t> createSurfaceForBackingStore(PlatformWidget widget, IntSize size, float deviceScaleFactor)
    3030{
     31    size.scale(deviceScaleFactor);
     32
    3133#if PLATFORM(GTK)
    3234    return adoptRef(gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR_ALPHA, size.width(), size.height()));
     
    3739}
    3840
    39 PassOwnPtr<WidgetBackingStore> WidgetBackingStoreCairo::create(PlatformWidget widget, const IntSize& size)
     41PassOwnPtr<WidgetBackingStore> WidgetBackingStoreCairo::create(PlatformWidget widget, const IntSize& size, float deviceScaleFactor)
    4042{
    41     return adoptPtr(new WidgetBackingStoreCairo(widget, size));
     43    return adoptPtr(new WidgetBackingStoreCairo(widget, size, deviceScaleFactor));
    4244}
    4345
     
    4547// scrolling performance since we do not have to keep reallocating a memory region during
    4648// quick scrolling requests.
    47 WidgetBackingStoreCairo::WidgetBackingStoreCairo(PlatformWidget widget, const IntSize& size)
    48     : WidgetBackingStore(size)
    49     , m_surface(createSurfaceForBackingStore(widget, size))
    50     , m_scrollSurface(createSurfaceForBackingStore(widget, size))
    51 
     49WidgetBackingStoreCairo::WidgetBackingStoreCairo(PlatformWidget widget, const IntSize& size, float deviceScaleFactor)
     50    : WidgetBackingStore(size, deviceScaleFactor)
     51    , m_surface(createSurfaceForBackingStore(widget, size, deviceScaleFactor))
     52    , m_scrollSurface(createSurfaceForBackingStore(widget, size, deviceScaleFactor))
    5253{
     54    cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
    5355}
    5456
  • trunk/Source/WebCore/platform/cairo/WidgetBackingStoreCairo.h

    r167195 r169445  
    2828
    2929public:
    30     static PassOwnPtr<WidgetBackingStore> create(PlatformWidget, const IntSize&);
    31     WidgetBackingStoreCairo(PlatformWidget, const IntSize&);
     30    static PassOwnPtr<WidgetBackingStore> create(PlatformWidget, const IntSize&, float deviceScaleFactor);
     31    WidgetBackingStoreCairo(PlatformWidget, const IntSize&, float deviceScaleFactor);
    3232    ~WidgetBackingStoreCairo();
    3333    cairo_surface_t* cairoSurface();
  • trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.cpp

    r167342 r169445  
    3737#include "PlatformPathCairo.h"
    3838#include "RefPtrCairo.h"
     39#include <wtf/Assertions.h>
    3940#include <wtf/Vector.h>
    4041
     
    283284}
    284285
     286void cairoSurfaceSetDeviceScale(cairo_surface_t* surface, double xScale, double yScale)
     287{
     288    // This function was added pretty much simultaneous to when 1.13 was branched.
     289#if HAVE(CAIRO_SURFACE_SET_DEVICE_SCALE)
     290    cairo_surface_set_device_scale(surface, xScale, yScale);
     291#else
     292    UNUSED_PARAM(surface);
     293    ASSERT_UNUSED(xScale, 1 == xScale);
     294    ASSERT_UNUSED(yScale, 1 == yScale);
     295#endif
     296}
    285297} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.h

    r167342 r169445  
    3232#include <cairo.h>
    3333
     34// This function was added pretty much simultaneous to when 1.13 was branched.
     35#define HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE CAIRO_VERSION_MAJOR > 1 || (CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR >= 13)
     36
    3437namespace WebCore {
    3538class AffineTransform;
     
    5861IntSize cairoSurfaceSize(cairo_surface_t*);
    5962void flipImageSurfaceVertically(cairo_surface_t*);
     63void cairoSurfaceSetDeviceScale(cairo_surface_t*, double xScale, double yScale);
    6064
    6165} // namespace WebCore
  • trunk/Source/WebCore/platform/gtk/WidgetBackingStoreGtkX11.cpp

    r167195 r169445  
    2020#include "WidgetBackingStoreGtkX11.h"
    2121
     22#include "CairoUtilities.h"
    2223#include "GtkVersioning.h"
    2324#include "RefPtrCairo.h"
     
    2829namespace WebCore {
    2930
    30 PassOwnPtr<WidgetBackingStore> WidgetBackingStoreGtkX11::create(GtkWidget* widget, const IntSize& size)
     31PassOwnPtr<WidgetBackingStore> WidgetBackingStoreGtkX11::create(GtkWidget* widget, const IntSize& size, float deviceScaleFactor)
    3132{
    32     return adoptPtr(new WidgetBackingStoreGtkX11(widget, size));
     33    return adoptPtr(new WidgetBackingStoreGtkX11(widget, size, deviceScaleFactor));
    3334}
    3435
    35 WidgetBackingStoreGtkX11::WidgetBackingStoreGtkX11(GtkWidget* widget, const IntSize& size)
    36     : WidgetBackingStore(size)
     36WidgetBackingStoreGtkX11::WidgetBackingStoreGtkX11(GtkWidget* widget, const IntSize& size, float deviceScaleFactor)
     37    : WidgetBackingStore(size, deviceScaleFactor)
    3738{
     39    IntSize scaledSize = size;
     40    scaledSize.scale(deviceScaleFactor);
     41
    3842    GdkVisual* visual = gtk_widget_get_visual(widget);
    3943    GdkScreen* screen = gdk_visual_get_screen(visual);
    4044    m_display = GDK_SCREEN_XDISPLAY(screen);
    4145    m_pixmap = XCreatePixmap(m_display, GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
    42         size.width(), size.height(), gdk_visual_get_depth(visual));
     46        scaledSize.width(), scaledSize.height(), gdk_visual_get_depth(visual));
    4347    m_gc = XCreateGC(m_display, m_pixmap, 0, 0);
    4448
    4549    m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap,
    46         GDK_VISUAL_XVISUAL(visual), size.width(), size.height()));
     50        GDK_VISUAL_XVISUAL(visual), scaledSize.width(), scaledSize.height()));
     51
     52    cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
    4753}
    4854
     
    6874        return;
    6975
     76    targetRect.scale(m_deviceScaleFactor);
     77
     78    IntSize scaledScrollOffset = scrollOffset;
     79    scaledScrollOffset.scale(m_deviceScaleFactor);
     80
    7081    cairo_surface_flush(m_surface.get());
    7182    XCopyArea(m_display, m_pixmap, m_pixmap, m_gc,
    72         targetRect.x() - scrollOffset.width(), targetRect.y() - scrollOffset.height(),
     83        targetRect.x() - scaledScrollOffset.width(), targetRect.y() - scaledScrollOffset.height(),
    7384        targetRect.width(), targetRect.height(),
    7485        targetRect.x(), targetRect.y());
  • trunk/Source/WebCore/platform/gtk/WidgetBackingStoreGtkX11.h

    r167195 r169445  
    3030
    3131public:
    32     static PassOwnPtr<WidgetBackingStore> create(GtkWidget*, const IntSize&);
    33     WidgetBackingStoreGtkX11(GtkWidget*, const IntSize&);
     32    static PassOwnPtr<WidgetBackingStore> create(GtkWidget*, const IntSize&, float deviceScaleFactor);
     33    WidgetBackingStoreGtkX11(GtkWidget*, const IntSize&, float deviceScaleFactor);
    3434    ~WidgetBackingStoreGtkX11();
    3535    cairo_surface_t* cairoSurface();
  • trunk/Source/WebKit2/ChangeLog

    r169444 r169445  
     12014-05-29  Owen Taylor  <otaylor@redhat.com>
     2
     3        [GTK] Add HighDPI support for non-accelerated compositing contents
     4        https://bugs.webkit.org/show_bug.cgi?id=131562
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     9        (deviceScaleFactorChanged): Added this callback to pass scale changes to the page proxy.
     10        (webkitWebViewBaseCreateWebPage): Attach the callback to the notify signal.
     11        * UIProcess/WebPageProxy.cpp:
     12        * UIProcess/cairo/BackingStoreCairo.cpp:
     13        (WebKit::WebPageProxy::setCustomDeviceScaleFactor): Do not set a
     14        custom device scale factor for cairo when it's not supported.
     15        (WebKit::createBackingStoreForGTK): Pass the scale factor to the WebCore backing store.
     16        (WebKit::BackingStore::incorporateUpdate): Ditto.
     17
    1182014-05-28  Carlos Garcia Campos  <cgarcia@igalia.com>
    219
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r169439 r169445  
    4747#include "WebPreferences.h"
    4848#include "WebViewBaseInputMethodFilter.h"
     49#include <WebCore/CairoUtilities.h>
    4950#include <WebCore/ClipboardUtilitiesGtk.h>
    5051#include <WebCore/DataObjectGtk.h>
     
    7879#include <WebCore/RedirectedXCompositeWindow.h>
    7980#endif
     81
     82// gtk_widget_get_scale_factor() appeared in GTK 3.10, but we also need
     83// to make sure we have cairo new enough to support cairo_surface_set_device_scale
     84#define HAVE_GTK_SCALE_FACTOR HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE && GTK_CHECK_VERSION(3, 10, 0)
    8085
    8186using namespace WebKit;
     
    966971}
    967972
     973#if HAVE(GTK_SCALE_FACTOR)
     974static void deviceScaleFactorChanged(WebKitWebViewBase* webkitWebViewBase)
     975{
     976    webkitWebViewBase->priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase)));
     977}
     978#endif // HAVE(GTK_SCALE_FACTOR)
     979
    968980void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage)
    969981{
     
    979991    if (priv->redirectedWindow)
    980992        priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId());
     993#endif
     994
     995#if HAVE(GTK_SCALE_FACTOR)
     996    // We attach this here, because changes in scale factor are passed directly to the page proxy.
     997    priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase)));
     998    g_signal_connect(webkitWebViewBase, "notify::scale-factor", G_CALLBACK(deviceScaleFactorChanged), nullptr);
    981999#endif
    9821000
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r169439 r169445  
    140140#endif
    141141
     142#if USE(CAIRO)
     143#include <WebCore/CairoUtilities.h>
     144#endif
     145
    142146// This controls what strategy we use for mouse wheel coalescing.
    143147#define MERGE_WHEEL_EVENTS 1
     
    18451849    if (!isValid())
    18461850        return;
     1851
     1852    // FIXME: Remove this once we bump cairo requirements to support HiDPI.
     1853    // https://bugs.webkit.org/show_bug.cgi?id=133378
     1854#if USE(CAIRO) && !HAVE(CAIRO_SURFACE_SET_DEVICE_SCALE)
     1855    return;
     1856#endif
    18471857
    18481858    if (m_customDeviceScaleFactor == customScaleFactor)
  • trunk/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp

    r167195 r169445  
    4949
    5050#if PLATFORM(GTK)
    51 static OwnPtr<WidgetBackingStore> createBackingStoreForGTK(GtkWidget* widget, const IntSize& size)
     51static OwnPtr<WidgetBackingStore> createBackingStoreForGTK(GtkWidget* widget, const IntSize& size, float deviceScaleFactor)
    5252{
    5353#if PLATFORM(X11) && defined(GDK_WINDOWING_X11)
    5454    GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    5555    if (GDK_IS_X11_DISPLAY(display))
    56         return WebCore::WidgetBackingStoreGtkX11::create(widget, size);
     56        return WebCore::WidgetBackingStoreGtkX11::create(widget, size, deviceScaleFactor);
    5757#endif
    58     return WebCore::WidgetBackingStoreCairo::create(widget, size);
     58    return WebCore::WidgetBackingStoreCairo::create(widget, size, deviceScaleFactor);
    5959}
    6060#endif
     
    7474    if (!m_backingStore)
    7575#if PLATFORM(EFL)
    76         m_backingStore = WidgetBackingStoreCairo::create(EwkView::toEvasObject(toAPI(m_webPageProxy)), size());
     76        m_backingStore = WidgetBackingStoreCairo::create(EwkView::toEvasObject(toAPI(m_webPageProxy)), size(), deviceScaleFactor());
    7777#else
    78         m_backingStore = createBackingStoreForGTK(m_webPageProxy->viewWidget(), size());
     78        m_backingStore = createBackingStoreForGTK(m_webPageProxy->viewWidget(), size(), deviceScaleFactor());
    7979#endif
    8080
     
    8989        IntRect srcRect = updateRect;
    9090        srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
    91         bitmap->paint(graphicsContext, updateRect.location(), srcRect);
     91        bitmap->paint(graphicsContext, deviceScaleFactor(), updateRect.location(), srcRect);
    9292    }
    9393}
Note: See TracChangeset for help on using the changeset viewer.