⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278657 in webkit


Ignore:
Timestamp:
Jun 9, 2021, 5:36:07 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK4] Add support for navigation gestures
https://bugs.webkit.org/show_bug.cgi?id=212327

Patch by Alexander Mikhaylenko <Alexander Mikhaylenko> on 2021-06-09
Reviewed by Michael Catanzaro.

Source/WebCore:

Support GskRenderNode for GRefPtr.

  • platform/gtk/GRefPtrGtk.cpp:

(WTF::refGPtr):
(WTF::derefGPtr):

  • platform/gtk/GRefPtrGtk.h:

Source/WebKit:

Make ViewSnapshotStore store GdkTexture instead of Cairo surfaces
for GTK4. Split ViewSnapshotStoreGtk.cpp into GTK3 and GTK4 versions
since they don't have much in common.

When taking a view snapshot, render the web view into a texture.

When starting a navigation gesture, create a render node from
either the texture, or a fallback color, then render that instead
of using Cairo.

Implement the same dimming+shadow as in GTK3. This time don't bother
with CSS, the approach we used in GTK3 doesn't work anymore, and since
elements like scrollbars aren't themeable anyway it's not very important
to preserve that.

  • SourcesGTK.txt:
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseTakeViewSnapshot):

  • UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp:

(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):

  • UIProcess/ViewGestureController.h:
  • UIProcess/ViewSnapshotStore.cpp:

(WebKit::ViewSnapshotStore::didAddImageToSnapshot):
(WebKit::ViewSnapshotStore::willRemoveImageFromSnapshot):

  • UIProcess/ViewSnapshotStore.h:

(WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
(WebKit::ViewSnapshot::texture const):
(WebKit::ViewSnapshot::imageSizeInBytes const): Renamed to estimatedImageSizeInBytes().

  • UIProcess/gtk/ViewGestureControllerGtk.cpp:

(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::snapshot):
(WebKit::ViewGestureController::removeSwipeSnapshot):

  • UIProcess/gtk/ViewSnapshotStoreGtk3.cpp: Copied from Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk.cpp.

(WebKit::ViewSnapshot::create):
(WebKit::ViewSnapshot::ViewSnapshot):
(WebKit::ViewSnapshot::hasImage const):
(WebKit::ViewSnapshot::clearImage):
(WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
(WebKit::ViewSnapshot::size const):

  • UIProcess/gtk/ViewSnapshotStoreGtk4.cpp: Renamed from Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk.cpp.

(WebKit::ViewSnapshot::create):
(WebKit::ViewSnapshot::ViewSnapshot):
(WebKit::ViewSnapshot::hasImage const):
(WebKit::ViewSnapshot::clearImage):
(WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
(WebKit::ViewSnapshot::size const):

Location:
trunk/Source
Files:
11 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278655 r278657  
     12021-06-09  Alexander Mikhaylenko  <alexm@gnome.org>
     2
     3        [GTK4] Add support for navigation gestures
     4        https://bugs.webkit.org/show_bug.cgi?id=212327
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Support GskRenderNode for GRefPtr.
     9
     10        * platform/gtk/GRefPtrGtk.cpp:
     11        (WTF::refGPtr):
     12        (WTF::derefGPtr):
     13        * platform/gtk/GRefPtrGtk.h:
     14
    1152021-06-09  Alicia Boya García  <aboya@igalia.com>
    216
  • trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp

    r260752 r278657  
    7777#endif
    7878
     79#if USE(GTK4)
     80template <> GskRenderNode* refGPtr(GskRenderNode* ptr)
     81{
     82    if (ptr)
     83        gsk_render_node_ref(ptr);
     84    return ptr;
    7985}
     86
     87template <> void derefGPtr(GskRenderNode* ptr)
     88{
     89    if (ptr)
     90        gsk_render_node_unref(ptr);
     91}
     92#endif
     93
     94}
  • trunk/Source/WebCore/platform/gtk/GRefPtrGtk.h

    r260752 r278657  
    2525typedef struct _GtkWidgetPath GtkWidgetPath;
    2626typedef struct _SecretValue SecretValue;
     27typedef struct _GskRenderNode GskRenderNode;
    2728
    2829namespace WTF {
     
    4344#endif
    4445
     46#if USE(GTK4)
     47template <> GskRenderNode* refGPtr(GskRenderNode* ptr);
     48template <> void derefGPtr(GskRenderNode* ptr);
     49#endif
     50
    4551}
    4652
  • trunk/Source/WebKit/ChangeLog

    r278651 r278657  
     12021-06-09  Alexander Mikhaylenko  <alexm@gnome.org>
     2
     3        [GTK4] Add support for navigation gestures
     4        https://bugs.webkit.org/show_bug.cgi?id=212327
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Make ViewSnapshotStore store GdkTexture instead of Cairo surfaces
     9        for GTK4. Split ViewSnapshotStoreGtk.cpp into GTK3 and GTK4 versions
     10        since they don't have much in common.
     11
     12        When taking a view snapshot, render the web view into a texture.
     13
     14        When starting a navigation gesture, create a render node from
     15        either the texture, or a fallback color, then render that instead
     16        of using Cairo.
     17
     18        Implement the same dimming+shadow as in GTK3. This time don't bother
     19        with CSS, the approach we used in GTK3 doesn't work anymore, and since
     20        elements like scrollbars aren't themeable anyway it's not very important
     21        to preserve that.
     22
     23        * SourcesGTK.txt:
     24        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     25        (webkitWebViewBaseTakeViewSnapshot):
     26        * UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp:
     27        (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
     28        * UIProcess/ViewGestureController.h:
     29        * UIProcess/ViewSnapshotStore.cpp:
     30        (WebKit::ViewSnapshotStore::didAddImageToSnapshot):
     31        (WebKit::ViewSnapshotStore::willRemoveImageFromSnapshot):
     32        * UIProcess/ViewSnapshotStore.h:
     33        (WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
     34        (WebKit::ViewSnapshot::texture const):
     35        (WebKit::ViewSnapshot::imageSizeInBytes const): Renamed to estimatedImageSizeInBytes().
     36        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
     37        (WebKit::ViewGestureController::beginSwipeGesture):
     38        (WebKit::ViewGestureController::snapshot):
     39        (WebKit::ViewGestureController::removeSwipeSnapshot):
     40        * UIProcess/gtk/ViewSnapshotStoreGtk3.cpp: Copied from Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk.cpp.
     41        (WebKit::ViewSnapshot::create):
     42        (WebKit::ViewSnapshot::ViewSnapshot):
     43        (WebKit::ViewSnapshot::hasImage const):
     44        (WebKit::ViewSnapshot::clearImage):
     45        (WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
     46        (WebKit::ViewSnapshot::size const):
     47        * UIProcess/gtk/ViewSnapshotStoreGtk4.cpp: Renamed from Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk.cpp.
     48        (WebKit::ViewSnapshot::create):
     49        (WebKit::ViewSnapshot::ViewSnapshot):
     50        (WebKit::ViewSnapshot::hasImage const):
     51        (WebKit::ViewSnapshot::clearImage):
     52        (WebKit::ViewSnapshot::estimatedImageSizeInBytes const):
     53        (WebKit::ViewSnapshot::size const):
     54
    1552021-06-09  Chris Dumez  <cdumez@apple.com>
    256
  • trunk/Source/WebKit/SourcesGTK.txt

    r277172 r278657  
    260260UIProcess/gtk/PointerLockManagerX11.cpp @no-unify
    261261UIProcess/gtk/TextCheckerGtk.cpp @no-unify
    262 UIProcess/gtk/ViewSnapshotStoreGtk.cpp
     262UIProcess/gtk/ViewSnapshotStoreGtk3.cpp @no-unify
     263UIProcess/gtk/ViewSnapshotStoreGtk4.cpp @no-unify
    263264UIProcess/gtk/ViewGestureControllerGtk.cpp
    264265UIProcess/gtk/WaylandCompositor.cpp @no-unify
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r278301 r278657  
    25292529    size.scale(deviceScale);
    25302530
     2531#if !USE(GTK4)
    25312532    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_RGB24, size.width(), size.height()));
    25322533    cairo_surface_set_device_scale(surface.get(), deviceScale, deviceScale);
     
    25382539        cairo_clip(cr.get());
    25392540    }
    2540 #if !USE(GTK4)
    25412541    webkitWebViewBaseDraw(GTK_WIDGET(webkitWebViewBase), cr.get());
    2542 #endif
    25432542
    25442543    return ViewSnapshot::create(WTFMove(surface));
     2544#else
     2545    WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
     2546    auto* renderer = gtk_native_get_renderer(GTK_NATIVE(priv->toplevelOnScreenWindow));
     2547
     2548    GRefPtr<GtkSnapshot> snapshot = adoptGRef(gtk_snapshot_new());
     2549
     2550    if (clipRect) {
     2551        graphene_point_t point = { -static_cast<float>(clipRect->x()), -static_cast<float>(clipRect->y()) };
     2552        graphene_rect_t rect = {
     2553            { static_cast<float>(clipRect->x()), static_cast<float>(clipRect->y()) },
     2554            { static_cast<float>(clipRect->width()), static_cast<float>(clipRect->height()) }
     2555        };
     2556
     2557        gtk_snapshot_translate(snapshot.get(), &point);
     2558        gtk_snapshot_push_clip(snapshot.get(), &rect);
     2559    }
     2560
     2561    gtk_snapshot_scale(snapshot.get(), deviceScale, deviceScale);
     2562    webkitWebViewBaseSnapshot(GTK_WIDGET(webkitWebViewBase), snapshot.get());
     2563
     2564    if (clipRect)
     2565        gtk_snapshot_pop(snapshot.get());
     2566
     2567    GRefPtr<GskRenderNode> renderNode = adoptGRef(gtk_snapshot_to_node(snapshot.get()));
     2568
     2569    graphene_rect_t viewport = { 0, 0, static_cast<float>(size.width()), static_cast<float>(size.height()) };
     2570    GdkTexture* texture = gsk_renderer_render_texture(renderer, renderNode.get(), &viewport);
     2571
     2572    return ViewSnapshot::create(WTFMove(texture));
     2573#endif
    25452574}
    25462575
  • trunk/Source/WebKit/UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp

    r278253 r278657  
    6565std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ViewSnapshot& snapshot)
    6666{
    67 #if PLATFORM(GTK)
     67#if PLATFORM(GTK) && !USE(GTK4)
    6868    return base64EncodedPNGData(snapshot.surface());
    6969#else
  • trunk/Source/WebKit/UIProcess/ViewGestureController.h

    r277172 r278657  
    4141
    4242#if PLATFORM(GTK)
    43 #include <WebCore/CairoUtilities.h>
    4443#include <gtk/gtk.h>
    4544#include <wtf/glib/GRefPtr.h>
     45
     46#if USE(GTK4)
     47#include <WebCore/GRefPtrGtk.h>
     48#else
     49#include <WebCore/CairoUtilities.h>
     50#endif
    4651#endif
    4752
     
    437442    SwipeProgressTracker m_swipeProgressTracker;
    438443
     444#if USE(GTK4)
     445    GRefPtr<GskRenderNode> m_currentSwipeSnapshotPattern;
     446#else
    439447    RefPtr<cairo_pattern_t> m_currentSwipeSnapshotPattern;
    440448    RefPtr<cairo_pattern_t> m_swipeDimmingPattern;
     
    442450    RefPtr<cairo_pattern_t> m_swipeBorderPattern;
    443451    RefPtr<cairo_pattern_t> m_swipeOutlinePattern;
     452
    444453    int m_swipeShadowSize;
    445454    int m_swipeBorderSize;
    446455    int m_swipeOutlineSize;
    447456    GRefPtr<GtkCssProvider> m_cssProvider;
     457#endif
    448458
    449459    bool m_isSimulatedSwipe { false };
  • trunk/Source/WebKit/UIProcess/ViewSnapshotStore.cpp

    r278185 r278657  
    5959    bool isNewEntry = m_snapshotsWithImages.add(&snapshot).isNewEntry;
    6060    ASSERT_UNUSED(isNewEntry, isNewEntry);
    61     m_snapshotCacheSize += snapshot.imageSizeInBytes();
     61    m_snapshotCacheSize += snapshot.estimatedImageSizeInBytes();
    6262}
    6363
     
    6666    bool removed = m_snapshotsWithImages.remove(&snapshot);
    6767    ASSERT_UNUSED(removed, removed);
    68     m_snapshotCacheSize -= snapshot.imageSizeInBytes();
     68    m_snapshotCacheSize -= snapshot.estimatedImageSizeInBytes();
    6969}
    7070
  • trunk/Source/WebKit/UIProcess/ViewSnapshotStore.h

    r269824 r278657  
    3737
    3838#if PLATFORM(GTK)
     39#if USE(GTK4)
     40#include <gtk/gtk.h>
     41#else
    3942#include <WebCore/RefPtrCairo.h>
     43#endif
    4044#endif
    4145
     
    5155#endif
    5256#if PLATFORM(GTK)
     57#if USE(GTK4)
     58    static Ref<ViewSnapshot> create(GRefPtr<GdkTexture>&&);
     59#else
    5360    static Ref<ViewSnapshot> create(RefPtr<cairo_surface_t>&&);
     61#endif
    5462#endif
    5563
     
    7987    WebCore::IOSurface* surface() const { return m_surface.get(); }
    8088
    81     size_t imageSizeInBytes() const { return m_surface ? m_surface->totalBytes() : 0; }
     89    size_t estimatedImageSizeInBytes() const { return m_surface ? m_surface->totalBytes() : 0; }
    8290    WebCore::IntSize size() const { return m_surface ? m_surface->size() : WebCore::IntSize(); }
    8391
     
    8896
    8997#if PLATFORM(GTK)
     98#if USE(GTK4)
     99    GdkTexture* texture() const { return m_texture.get(); }
     100#else
    90101    cairo_surface_t* surface() const { return m_surface.get(); }
     102#endif
    91103
    92     size_t imageSizeInBytes() const;
     104    size_t estimatedImageSizeInBytes() const;
    93105    WebCore::IntSize size() const;
    94106#endif
     
    102114
    103115#if PLATFORM(GTK)
     116#if USE(GTK4)
     117    explicit ViewSnapshot(GRefPtr<GdkTexture>&&);
     118
     119    GRefPtr<GdkTexture> m_texture;
     120#else
    104121    explicit ViewSnapshot(RefPtr<cairo_surface_t>&&);
    105122
    106123    RefPtr<cairo_surface_t> m_surface;
     124#endif
    107125#endif
    108126
  • trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp

    r277172 r278657  
    4949static const double swipeCancelVelocityThreshold = 0.4;
    5050
     51#if USE(GTK4)
     52static const float swipeOverlayShadowOpacity = 0.06;
     53static const float swipeOverlayBorderOpacity = 0.05;
     54static const float swipeOverlayOutlineOpacity = 0.05;
     55static const float swipeOverlayDimmingOpacity = 0.12;
     56static const float swipeOverlayShadowWidth = 57;
     57static const GskColorStop swipeOverlayShadowStops[] = {
     58    { 0,     { 0, 0, 0, 0.08  } },
     59    { 0.125, { 0, 0, 0, 0.053 } },
     60    { 0.428, { 0, 0, 0, 0.026 } },
     61    { 0.714, { 0, 0, 0, 0.01  } },
     62    { 1,     { 0, 0, 0, 0     } }
     63};
     64#endif
     65
    5166static bool isEventStop(PlatformGtkScrollData* event)
    5267{
     
    310325    return width;
    311326}
     327
    312328#endif
    313329
     
    319335
    320336    willBeginGesture(ViewGestureType::Swipe);
     337
     338    FloatSize viewSize(m_webPageProxy.viewSize());
     339
     340#if USE(GTK4)
     341    graphene_rect_t bounds = { 0, 0, viewSize.width(), viewSize.height() };
     342#endif
    321343
    322344    if (auto* snapshot = targetItem->snapshot()) {
    323345        m_currentSwipeSnapshot = snapshot;
    324346
    325         FloatSize viewSize(m_webPageProxy.viewSize());
    326347        if (snapshot->hasImage() && shouldUseSnapshotForSize(*snapshot, viewSize, 0))
     348#if USE(GTK4)
     349            m_currentSwipeSnapshotPattern = gsk_texture_node_new(snapshot->texture(), &bounds);
     350#else
    327351            m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_for_surface(snapshot->surface()));
     352#endif
    328353
    329354        Color color = snapshot->backgroundColor();
     
    332357            if (!m_currentSwipeSnapshotPattern) {
    333358                auto [red, green, blue, alpha] = color.toSRGBALossy<float>();
     359#if USE(GTK4)
     360                GdkRGBA rgba = { red, green, blue, alpha };
     361                m_currentSwipeSnapshotPattern = adoptGRef(gsk_color_node_new(&rgba, &bounds));
     362#else
    334363                m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_rgba(red, green, blue, alpha));
     364#endif
    335365            }
    336366        }
    337367    }
    338368
    339 #if !USE(GTK4)
    340369    if (!m_currentSwipeSnapshotPattern) {
    341370        GdkRGBA color;
    342371        auto* context = gtk_widget_get_style_context(m_webPageProxy.viewWidget());
    343372        if (gtk_style_context_lookup_color(context, "theme_base_color", &color))
     373#if USE(GTK4)
     374            m_currentSwipeSnapshotPattern = adoptGRef(gsk_color_node_new(&color, &bounds));
     375#else
    344376            m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_rgba(color.red, color.green, color.blue, color.alpha));
    345     }
    346 
    347     if (!m_currentSwipeSnapshotPattern)
     377#endif
     378    }
     379
     380    if (!m_currentSwipeSnapshotPattern) {
     381#if USE(GTK4)
     382        GdkRGBA color = { 1, 1, 1, 1 };
     383        m_currentSwipeSnapshotPattern = adoptGRef(gsk_color_node_new(&color, &bounds));
     384#else
    348385        m_currentSwipeSnapshotPattern = adoptRef(cairo_pattern_create_rgb(1, 1, 1));
    349 
     386#endif
     387    }
     388
     389#if !USE(GTK4)
    350390    auto size = m_webPageProxy.drawingArea()->size();
    351391
     
    405445    double scale = m_webPageProxy.deviceScaleFactor();
    406446
    407     double swipingLayerOffset = (swipingLeft ? 0 : width) + floor(width * progress * scale) / scale;
    408 
    409     double dimmingProgress = swipingLeft ? 1 - progress : -progress;
     447    float swipingLayerOffset = (swipingLeft ? 0 : width) + floor(width * progress * scale) / scale;
     448
     449    float dimmingProgress = swipingLeft ? 1 - progress : -progress;
    410450    if (isRTL) {
    411451        dimmingProgress = 1 - dimmingProgress;
     
    413453    }
    414454
     455    float remainingSwipeDistance = dimmingProgress * width;
     456
     457    float shadowOpacity = 1;
     458    if (remainingSwipeDistance < swipeOverlayShadowWidth)
     459        shadowOpacity = remainingSwipeDistance / swipeOverlayShadowWidth;
     460
    415461    gtk_snapshot_save(snapshot);
    416462
    417     graphene_point_t translation = { static_cast<float>(swipingLayerOffset), 0 };
     463    graphene_rect_t clip = { 0, 0, static_cast<float>(size.width()), static_cast<float>(size.height()) };
     464    gtk_snapshot_push_clip(snapshot, &clip);
     465
     466    graphene_point_t translation = { swipingLayerOffset, 0 };
    418467    if (!swipingBack) {
    419468        gtk_snapshot_append_node(snapshot, pageRenderNode);
     
    421470    }
    422471
    423     graphene_rect_t rect = { 0, 0, (float)width, (float)height };
    424     auto* cr = gtk_snapshot_append_cairo(snapshot, &rect);
    425     cairo_set_source(cr, m_currentSwipeSnapshotPattern.get());
    426     cairo_rectangle(cr, 0, 0, width, height);
    427     cairo_fill(cr);
     472    gtk_snapshot_append_node(snapshot, m_currentSwipeSnapshotPattern.get());
    428473
    429474    if (swipingBack) {
     
    432477    }
    433478
     479    if (!progress) {
     480        gtk_snapshot_pop(snapshot);
     481        gtk_snapshot_restore(snapshot);
     482        return;
     483    }
     484
     485    if (isRTL) {
     486        translation = { static_cast<float>(width), 0 };
     487        gtk_snapshot_translate(snapshot, &translation);
     488    } else
     489        gtk_snapshot_scale(snapshot, -1, 1);
     490
     491    GdkRGBA dimming = { 0, 0, 0, swipeOverlayDimmingOpacity * dimmingProgress };
     492    GdkRGBA border = { 0, 0, 0, swipeOverlayBorderOpacity };
     493    GdkRGBA outline = { 1, 1, 1, swipeOverlayOutlineOpacity };
     494
     495    graphene_rect_t dimmingRect = { 0, 0,  static_cast<float>(width), static_cast<float>(height) };
     496    graphene_rect_t borderRect = { 0, 0, 1, static_cast<float>(height) };
     497    graphene_rect_t outlineRect = { -1, 0, 1, static_cast<float>(height) };
     498    graphene_rect_t shadowRect = { 0, 0, swipeOverlayShadowWidth, static_cast<float>(height) };
     499    graphene_point_t shadowStart = { 0, 0 };
     500    graphene_point_t shadowEnd = { swipeOverlayShadowWidth, 0 };
     501
     502    gtk_snapshot_append_color(snapshot, &dimming, &dimmingRect);
     503    gtk_snapshot_append_color(snapshot, &border, &borderRect);
     504    gtk_snapshot_append_color(snapshot, &outline, &outlineRect);
     505    gtk_snapshot_push_opacity(snapshot, shadowOpacity);
     506    gtk_snapshot_append_linear_gradient(snapshot, &shadowRect, &shadowStart, &shadowEnd,
     507        swipeOverlayShadowStops, G_N_ELEMENTS(swipeOverlayShadowStops));
     508    gtk_snapshot_pop(snapshot);
     509
     510    gtk_snapshot_pop(snapshot);
    434511    gtk_snapshot_restore(snapshot);
    435512}
     
    537614
    538615    m_currentSwipeSnapshotPattern = nullptr;
     616#if !USE(GTK4)
    539617    m_swipeDimmingPattern = nullptr;
    540618    m_swipeShadowPattern = nullptr;
    541619    m_swipeBorderPattern = nullptr;
    542620    m_swipeOutlinePattern = nullptr;
     621#endif
    543622
    544623    m_currentSwipeSnapshot = nullptr;
  • trunk/Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk3.cpp

    r278656 r278657  
    2626#include "config.h"
    2727#include "ViewSnapshotStore.h"
     28
     29#if !USE(GTK4)
    2830
    2931#include <WebCore/CairoUtilities.h>
     
    5961}
    6062
    61 size_t ViewSnapshot::imageSizeInBytes() const
     63size_t ViewSnapshot::estimatedImageSizeInBytes() const
    6264{
    6365    if (!m_surface)
     
    8486
    8587} // namespace WebKit
     88
     89#endif
  • trunk/Source/WebKit/UIProcess/gtk/ViewSnapshotStoreGtk4.cpp

    r278656 r278657  
    1212 *
    1313 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
    14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,dd
    1515 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1616 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     
    2727#include "ViewSnapshotStore.h"
    2828
    29 #include <WebCore/CairoUtilities.h>
     29#if USE(GTK4)
    3030
    3131namespace WebKit {
    3232using namespace WebCore;
    3333
    34 Ref<ViewSnapshot> ViewSnapshot::create(RefPtr<cairo_surface_t>&& surface)
     34Ref<ViewSnapshot> ViewSnapshot::create(GRefPtr<GdkTexture>&& texture)
    3535{
    36     return adoptRef(*new ViewSnapshot(WTFMove(surface)));
     36    return adoptRef(*new ViewSnapshot(WTFMove(texture)));
    3737}
    3838
    39 ViewSnapshot::ViewSnapshot(RefPtr<cairo_surface_t>&& surface)
    40     : m_surface(WTFMove(surface))
     39ViewSnapshot::ViewSnapshot(GRefPtr<GdkTexture>&& texture)
     40    : m_texture(WTFMove(texture))
    4141{
    4242    if (hasImage())
     
    4646bool ViewSnapshot::hasImage() const
    4747{
    48     return !!m_surface;
     48    return m_texture;
    4949}
    5050
     
    5656    ViewSnapshotStore::singleton().willRemoveImageFromSnapshot(*this);
    5757
    58     m_surface = nullptr;
     58    m_texture = nullptr;
    5959}
    6060
    61 size_t ViewSnapshot::imageSizeInBytes() const
     61size_t ViewSnapshot::estimatedImageSizeInBytes() const
    6262{
    63     if (!m_surface)
     63    if (!m_texture)
    6464        return 0;
    6565
    66     cairo_surface_t* surface = m_surface.get();
    67     int stride = cairo_image_surface_get_stride(surface);
    68     int height = cairo_image_surface_get_width(surface);
     66    int width = gdk_texture_get_width(m_texture.get());
     67    int height = gdk_texture_get_height(m_texture.get());
    6968
    70     return stride * height;
     69    // Unfortunately we don't have a way to get size of a texture in
     70    // bytes, so we'll have to make something up. Let's assume that
     71    // pixel == 4 bytes.
     72    return width * height * 4;
    7173}
    7274
    7375WebCore::IntSize ViewSnapshot::size() const
    7476{
    75     if (!m_surface)
     77    if (!m_texture)
    7678        return { };
    7779
    78     cairo_surface_t* surface = m_surface.get();
    79     int width = cairo_image_surface_get_width(surface);
    80     int height = cairo_image_surface_get_height(surface);
     80    int width = gdk_texture_get_width(m_texture.get());
     81    int height = gdk_texture_get_height(m_texture.get());
    8182
    8283    return { width, height };
     
    8485
    8586} // namespace WebKit
     87
     88#endif
Note: See TracChangeset for help on using the changeset viewer.