Changeset 260816 in webkit


Ignore:
Timestamp:
Apr 28, 2020 4:28:36 AM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK4][Wayland] Add support for rendering web view contents
https://bugs.webkit.org/show_bug.cgi?id=211021

Reviewed by Adrian Perez de Castro.

Source/WebKit:

Implement GtkWidgetClass::snapshot and GtkWidgetClass::measure instead of GtkWidgetClass::draw and
GtkWidgetClass::get_preferred_width|height. Add AcceleratedBackingStore::snapshot() pure virtual to be used with
GTK4 instead of AcceleratedBackingStore::paint(), and implement it for Wayland.

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseSnapshot): Call AcceleratedBackingStore::snapshot().
(webkitWebViewBaseMeasure): Return the natural width/height for the WebView.
(webkit_web_view_base_class_init): Add implementations for snapshot and measure vfuncs.

  • UIProcess/gtk/AcceleratedBackingStore.h:
  • UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:

(WebKit::AcceleratedBackingStoreWayland::tryEnsureGLContext): Always try to realize the context here, since that
can fail too.
(WebKit::AcceleratedBackingStoreWayland::tryEnsureTexture): Helper to share the code to prepare the texture.
(WebKit::AcceleratedBackingStoreWayland::downloadTexture): Helper to share the code to download the texture.
(WebKit::AcceleratedBackingStoreWayland::snapshot): Use gtk_snapshot_append_texture().
(WebKit::AcceleratedBackingStoreWayland::paint): Use new helpers.

  • UIProcess/gtk/AcceleratedBackingStoreWayland.h:
  • UIProcess/gtk/AcceleratedBackingStoreX11.cpp:

(WebKit::AcceleratedBackingStoreX11::snapshot):

  • UIProcess/gtk/AcceleratedBackingStoreX11.h:
  • UIProcess/gtk/HardwareAccelerationManager.cpp:

(WebKit::HardwareAccelerationManager::HardwareAccelerationManager): Force accelerated compositing mode for GTK4.

Tools:

Set vertical expand of web view to TRUE.

  • MiniBrowser/gtk/BrowserTab.c:

(browserTabConstructed):

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260807 r260816  
     12020-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK4][Wayland] Add support for rendering web view contents
     4        https://bugs.webkit.org/show_bug.cgi?id=211021
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Implement GtkWidgetClass::snapshot and GtkWidgetClass::measure instead of GtkWidgetClass::draw and
     9        GtkWidgetClass::get_preferred_width|height. Add AcceleratedBackingStore::snapshot() pure virtual to be used with
     10        GTK4 instead of AcceleratedBackingStore::paint(), and implement it for Wayland.
     11
     12        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     13        (webkitWebViewBaseSnapshot): Call AcceleratedBackingStore::snapshot().
     14        (webkitWebViewBaseMeasure): Return the natural width/height for the WebView.
     15        (webkit_web_view_base_class_init): Add implementations for snapshot and measure vfuncs.
     16        * UIProcess/gtk/AcceleratedBackingStore.h:
     17        * UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:
     18        (WebKit::AcceleratedBackingStoreWayland::tryEnsureGLContext): Always try to realize the context here, since that
     19        can fail too.
     20        (WebKit::AcceleratedBackingStoreWayland::tryEnsureTexture): Helper to share the code to prepare the texture.
     21        (WebKit::AcceleratedBackingStoreWayland::downloadTexture): Helper to share the code to download the texture.
     22        (WebKit::AcceleratedBackingStoreWayland::snapshot): Use gtk_snapshot_append_texture().
     23        (WebKit::AcceleratedBackingStoreWayland::paint): Use new helpers.
     24        * UIProcess/gtk/AcceleratedBackingStoreWayland.h:
     25        * UIProcess/gtk/AcceleratedBackingStoreX11.cpp:
     26        (WebKit::AcceleratedBackingStoreX11::snapshot):
     27        * UIProcess/gtk/AcceleratedBackingStoreX11.h:
     28        * UIProcess/gtk/HardwareAccelerationManager.cpp:
     29        (WebKit::HardwareAccelerationManager::HardwareAccelerationManager): Force accelerated compositing mode for GTK4.
     30
    1312020-04-27  Devin Rousso  <drousso@apple.com>
    232
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r260752 r260816  
    615615}
    616616
    617 #if !USE(GTK4)
     617#if USE(GTK4)
     618void webkitWebViewBaseSnapshot(GtkWidget* widget, GtkSnapshot* snapshot)
     619{
     620    int scaleFactor = gtk_widget_get_scale_factor(widget);
     621    int width = gtk_widget_get_width(widget) * scaleFactor;
     622    int height = gtk_widget_get_height(widget) * scaleFactor;
     623    if (!width || !height)
     624        return;
     625
     626    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     627    auto* drawingArea = static_cast<DrawingAreaProxyCoordinatedGraphics*>(webViewBase->priv->pageProxy->drawingArea());
     628    if (!drawingArea)
     629        return;
     630
     631    ASSERT(drawingArea->isInAcceleratedCompositingMode());
     632    webViewBase->priv->acceleratedBackingStore->snapshot(snapshot);
     633}
     634#else
    618635static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr)
    619636{
     
    721738}
    722739
    723 #if !USE(GTK4)
     740#if USE(GTK4)
     741static void webkitWebViewBaseMeasure(GtkWidget* widget, GtkOrientation orientation, int, int* minimumSize, int* naturalSize, int*, int*)
     742{
     743    WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
     744    switch (orientation) {
     745    case GTK_ORIENTATION_HORIZONTAL:
     746        *naturalSize = priv->contentsSize.width();
     747        break;
     748    case GTK_ORIENTATION_VERTICAL:
     749        *naturalSize = priv->contentsSize.height();
     750        break;
     751    }
     752
     753    *minimumSize = 0;
     754}
     755#else
    724756static void webkitWebViewBaseGetPreferredWidth(GtkWidget* widget, gint* minimumSize, gint* naturalSize)
    725757{
     
    14771509    widgetClass->realize = webkitWebViewBaseRealize;
    14781510    widgetClass->unrealize = webkitWebViewBaseUnrealize;
    1479 #if !USE(GTK4)
     1511#if USE(GTK4)
     1512    widgetClass->snapshot = webkitWebViewBaseSnapshot;
     1513#else
    14801514    widgetClass->draw = webkitWebViewBaseDraw;
    14811515#endif
    14821516    widgetClass->size_allocate = webkitWebViewBaseSizeAllocate;
    1483 #if !USE(GTK4)
     1517#if USE(GTK4)
     1518    widgetClass->measure = webkitWebViewBaseMeasure;
     1519#else
    14841520    widgetClass->get_preferred_width = webkitWebViewBaseGetPreferredWidth;
    14851521    widgetClass->get_preferred_height = webkitWebViewBaseGetPreferredHeight;
  • trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStore.h

    r249947 r260816  
    3030typedef struct _cairo cairo_t;
    3131
     32#if USE(GTK4)
     33typedef struct _GdkSnapshot GdkSnapshot;
     34typedef GdkSnapshot GtkSnapshot;
     35#endif
     36
    3237namespace WebCore {
    3338class IntRect;
     
    4752
    4853    virtual void update(const LayerTreeContext&) { }
     54#if USE(GTK4)
     55    virtual void snapshot(GtkSnapshot*) = 0;
     56#else
    4957    virtual bool paint(cairo_t*, const WebCore::IntRect&) = 0;
     58#endif
    5059    virtual void realize() { };
    5160    virtual void unrealize() { };
  • trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp

    r260752 r260816  
    215215
    216216    m_glContextInitialized = true;
    217 
    218 #if !USE(GTK4)
    219217    GUniqueOutPtr<GError> error;
     218#if USE(GTK4)
     219    m_gdkGLContext = adoptGRef(gdk_surface_create_gl_context(gtk_native_get_surface(gtk_widget_get_native(m_webPage.viewWidget())), &error.outPtr()));
     220#else
    220221    m_gdkGLContext = adoptGRef(gdk_window_create_gl_context(gtk_widget_get_window(m_webPage.viewWidget()), &error.outPtr()));
     222#endif
    221223    if (m_gdkGLContext) {
    222224#if USE(OPENGL_ES)
    223225        gdk_gl_context_set_use_es(m_gdkGLContext.get(), TRUE);
    224226#endif
    225         return;
     227        gdk_gl_context_realize(m_gdkGLContext.get(), &error.outPtr());
     228        if (!error)
     229            return;
    226230    }
    227231
    228232    g_warning("GDK is not able to create a GL context, falling back to glReadPixels (slow!): %s", error->message);
    229 #endif
    230233
    231234    m_glContext = GLContext::createOffscreenContext();
     
    279282#endif
    280283
    281 bool AcceleratedBackingStoreWayland::paint(cairo_t* cr, const IntRect& clipRect)
    282 {
    283     GLuint texture;
    284     IntSize textureSize;
    285 
     284bool AcceleratedBackingStoreWayland::tryEnsureTexture(unsigned& texture, IntSize& textureSize)
     285{
    286286#if USE(WPE_RENDERER)
    287287    if (!makeContextCurrent())
    288         return true;
     288        return false;
    289289
    290290    if (m_pendingImage) {
     
    298298
    299299    if (!m_committedImage)
    300         return true;
     300        return false;
    301301
    302302    if (!m_viewTexture) {
     
    318318#endif
    319319
    320     cairo_save(cr);
    321 
    322 #if !USE(GTK4)
    323     if (m_gdkGLContext) {
    324         gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height());
    325         cairo_restore(cr);
    326         return true;
    327     }
    328 #endif
    329 
     320    return true;
     321}
     322
     323void AcceleratedBackingStoreWayland::downloadTexture(unsigned texture, const IntSize& textureSize)
     324{
    330325    ASSERT(m_glContext);
    331326
     
    367362    glDeleteFramebuffers(1, &fb);
    368363
    369     // The surface can be modified by the web process at any time, so we mark it
    370     // as dirty to ensure we always render the updated contents as soon as possible.
    371364    cairo_surface_mark_dirty(m_surface.get());
     365}
     366
     367#if USE(GTK4)
     368void AcceleratedBackingStoreWayland::snapshot(GtkSnapshot* gtkSnapshot)
     369{
     370    GLuint texture;
     371    IntSize textureSize;
     372    if (!tryEnsureTexture(texture, textureSize))
     373        return;
     374
     375    FloatSize viewSize(gtk_widget_get_width(m_webPage.viewWidget()), gtk_widget_get_height(m_webPage.viewWidget()));
     376    if (m_gdkGLContext) {
     377        GRefPtr<GdkTexture> gdkTexture = adoptGRef(gdk_gl_texture_new(m_gdkGLContext.get(), texture, textureSize.width(), textureSize.height(), nullptr, nullptr));
     378        graphene_rect_t rect = GRAPHENE_RECT_INIT(0, 0, viewSize.width(), viewSize.height());
     379        gtk_snapshot_append_texture(gtkSnapshot, gdkTexture.get(), &rect);
     380        return;
     381    }
     382
     383    downloadTexture(texture, textureSize);
     384
     385    graphene_rect_t rect = GRAPHENE_RECT_INIT(0, 0, viewSize.width(), viewSize.height());
     386    RefPtr<cairo_t> cr = adoptRef(gtk_snapshot_append_cairo(gtkSnapshot, &rect));
     387
     388    // The compositor renders the texture flipped for gdk, fix that here.
     389    cairo_matrix_t transform;
     390    cairo_matrix_init(&transform, 1, 0, 0, -1, 0, textureSize.height() / m_webPage.deviceScaleFactor());
     391    cairo_transform(cr.get(), &transform);
     392
     393    cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0);
     394    cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
     395    cairo_paint(cr.get());
     396}
     397#else
     398bool AcceleratedBackingStoreWayland::paint(cairo_t* cr, const IntRect& clipRect)
     399{
     400    GLuint texture;
     401    IntSize textureSize;
     402    if (!tryEnsureTexture(texture, textureSize))
     403        return true;
     404
     405    cairo_save(cr);
     406
     407    if (m_gdkGLContext) {
     408        gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(m_webPage.viewWidget()), texture, GL_TEXTURE, m_webPage.deviceScaleFactor(), 0, 0, textureSize.width(), textureSize.height());
     409        cairo_restore(cr);
     410        return true;
     411    }
     412
     413    downloadTexture(texture, textureSize);
    372414
    373415    // The compositor renders the texture flipped for gdk_cairo_draw_from_gl, fix that here.
     
    385427    return true;
    386428}
     429#endif
    387430
    388431} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.h

    r249947 r260816  
    4444namespace WebCore {
    4545class GLContext;
     46class IntSize;
    4647}
    4748
     
    6465    void displayBuffer(struct wpe_fdo_egl_exported_image*);
    6566#endif
     67    bool tryEnsureTexture(unsigned&, WebCore::IntSize&);
     68    void downloadTexture(unsigned, const WebCore::IntSize&);
    6669
     70#if USE(GTK4)
     71    void snapshot(GtkSnapshot*) override;
     72#else
    6773    bool paint(cairo_t*, const WebCore::IntRect&) override;
     74#endif
    6875    void realize() override;
    6976    void unrealize() override;
  • trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.cpp

    r260752 r260816  
    196196}
    197197
     198#if USE(GTK4)
     199void AcceleratedBackingStoreX11::snapshot(GtkSnapshot*)
     200{
     201    // FIXME: Implement this.
     202}
     203#else
    198204bool AcceleratedBackingStoreX11::paint(cairo_t* cr, const IntRect& clipRect)
    199205{
     
    217223    return true;
    218224}
     225#endif
    219226
    220227} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreX11.h

    r247563 r260816  
    4848
    4949    void update(const LayerTreeContext&) override;
     50#if USE(GTK4)
     51    void snapshot(GtkSnapshot*) override;
     52#else
    5053    bool paint(cairo_t*, const WebCore::IntRect&) override;
     54#endif
    5155
    5256    RefPtr<cairo_surface_t> m_surface;
  • trunk/Source/WebKit/UIProcess/gtk/HardwareAccelerationManager.cpp

    r260760 r260816  
    4747#endif
    4848
     49#if USE(GTK4)
     50    RELEASE_ASSERT(AcceleratedBackingStore::checkRequirements());
     51    m_forceHardwareAcceleration = true;
     52#endif
     53
    4954    const char* disableCompositing = getenv("WEBKIT_DISABLE_COMPOSITING_MODE");
    5055    if (disableCompositing && strcmp(disableCompositing, "0")) {
  • trunk/Tools/ChangeLog

    r260811 r260816  
     12020-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK4][Wayland] Add support for rendering web view contents
     4        https://bugs.webkit.org/show_bug.cgi?id=211021
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Set vertical expand of web view to TRUE.
     9
     10        * MiniBrowser/gtk/BrowserTab.c:
     11        (browserTabConstructed):
     12
    1132020-04-27  Philippe Normand  <pnormand@igalia.com>
    214
  • trunk/Tools/MiniBrowser/gtk/BrowserTab.c

    r260752 r260816  
    428428    gtk_widget_show(GTK_WIDGET(tab->webView));
    429429#else
     430    gtk_widget_set_vexpand(GTK_WIDGET(tab->webView), TRUE);
    430431    gtk_container_add(GTK_CONTAINER(tab), GTK_WIDGET(tab->webView));
    431432#endif
Note: See TracChangeset for help on using the changeset viewer.