Changeset 167168 in webkit


Ignore:
Timestamp:
Apr 11, 2014 4:20:27 PM (10 years ago)
Author:
commit-queue@webkit.org
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-04-11
Reviewed by Martin Robinson.

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:

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

  • UIProcess/cairo/BackingStoreCairo.cpp:

(WebKit::createBackingStoreForGTK): Pass the scale factor to the WebCore backing store.
(WebKit::BackingStore::incorporateUpdate): Ditto.

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167167 r167168  
     12014-04-11  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 Martin Robinson.
     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-04-11  Jon Honeycutt  <jhoneycutt@apple.com>
    222
  • trunk/Source/WebCore/platform/cairo/WidgetBackingStore.h

    r162451 r167168  
    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

    r151398 r167168  
    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

    r166138 r167168  
    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

    r165676 r167168  
    3737#include "PlatformPathCairo.h"
    3838#include "RefPtrCairo.h"
     39#include <wtf/Assertions.h>
    3940#include <wtf/Vector.h>
    4041
     
    260261}
    261262
     263void cairoSurfaceSetDeviceScale(cairo_surface_t* surface, double xScale, double yScale)
     264{
     265    // This function was added pretty much simultaneous to when 1.13 was branched.
     266#if HAVE(CAIRO_SURFACE_SET_DEVICE_SCALE)
     267    cairo_surface_set_device_scale(surface, xScale, yScale);
     268#else
     269    UNUSED_PARAM(surface);
     270    ASSERT_UNUSED(xScale, 1 == xScale);
     271    ASSERT_UNUSED(yScale, 1 == yScale);
     272#endif
     273}
    262274} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/cairo/CairoUtilities.h

    r165676 r167168  
    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;
     
    5760
    5861IntSize cairoSurfaceSize(cairo_surface_t*);
     62void cairoSurfaceSetDeviceScale(cairo_surface_t*, double xScale, double yScale);
    5963
    6064} // namespace WebCore
  • trunk/Source/WebCore/platform/gtk/WidgetBackingStoreGtkX11.cpp

    r167078 r167168  
    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

    r166138 r167168  
    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

    r167164 r167168  
     12014-04-11  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 Martin Robinson.
     7
     8        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     9        (scaleFactorChanged): Added this callback to pass scale changes to the page proxy.
     10        (webkitWebViewBaseCreateWebPage): Attach the callback to the notify signal.
     11        * UIProcess/cairo/BackingStoreCairo.cpp:
     12        (WebKit::createBackingStoreForGTK): Pass the scale factor to the WebCore backing store.
     13        (WebKit::BackingStore::incorporateUpdate): Ditto.
     14
    1152014-04-10  Jer Noble  <jer.noble@apple.com>
    216
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r167084 r167168  
    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;
     
    962967}
    963968
     969#if HAVE(GTK_SCALE_FACTOR)
     970static void scaleFactorChanged(GObject* object, GParamSpec*)
     971{
     972    WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
     973    ASSERT(priv->pageProxy);
     974    priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(object)));
     975}
     976#endif // HAVE(GTK_SCALE_FACTOR)
     977
    964978void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup, WebPageProxy* relatedPage)
    965979{
     
    975989    if (priv->redirectedWindow)
    976990        priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId());
     991#endif
     992
     993#if HAVE(GTK_SCALE_FACTOR)
     994    // We attach this here, because changes in scale factor are passed directly to the page proxy.
     995    priv->pageProxy->setIntrinsicDeviceScaleFactor(gtk_widget_get_scale_factor(GTK_WIDGET(webkitWebViewBase)));
     996    g_signal_connect(object, "notify::scale-factor", G_CALLBACK(scaleFactorChanged), NULL);
    977997#endif
    978998
  • trunk/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp

    r155032 r167168  
    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.