Changeset 276473 in webkit


Ignore:
Timestamp:
Apr 22, 2021, 3:33:20 PM (4 years ago)
Author:
Simon Fraser
Message:

Add trace points for WKWebView snapshotting
https://bugs.webkit.org/show_bug.cgi?id=224943

Reviewed by Tim Horton.

Source/WebKit:

Add new trace points to make snapshotting-related issues easier to diagnose. In the UI
process we start/end a trace scope when requested to snapshot, and before calling the
client's completion handler.

Trace CARenderServer snapshots which happen in the UI process, and in the web process, trace
the start and end of the snapshot painting.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):

  • UIProcess/API/Cocoa/_WKThumbnailView.mm:

(-[_WKThumbnailView requestSnapshot]):

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::paintSnapshotAtSize):

Source/WTF:

New snapshot values.

  • wtf/SystemTracing.h:

Tools:

New snapshot descriptions.

  • Tracing/SystemTracePoints.plist:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r276448 r276473  
     12021-04-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add trace points for WKWebView snapshotting
     4        https://bugs.webkit.org/show_bug.cgi?id=224943
     5
     6        Reviewed by Tim Horton.
     7
     8        New snapshot values.
     9
     10        * wtf/SystemTracing.h:
     11
    1122021-04-22  Martin Robinson  <mrobinson@webkit.org>
    213
  • trunk/Source/WTF/wtf/SystemTracing.h

    r276360 r276473  
    120120    CreateInjectedBundleStart,
    121121    CreateInjectedBundleEnd,
     122    PaintSnapshotStart,
     123    PaintSnapshotEnd,
     124    RenderServerSnapshotStart,
     125    RenderServerSnapshotEnd,
     126    TakeSnapshotStart,
     127    TakeSnapshotEnd,
    122128
    123129    UIProcessRange = 14000,
  • trunk/Source/WebKit/ChangeLog

    r276472 r276473  
     12021-04-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add trace points for WKWebView snapshotting
     4        https://bugs.webkit.org/show_bug.cgi?id=224943
     5
     6        Reviewed by Tim Horton.
     7
     8        Add new trace points to make snapshotting-related issues easier to diagnose. In the UI
     9        process we start/end a trace scope when requested to snapshot, and before calling the
     10        client's completion handler.
     11
     12        Trace CARenderServer snapshots which happen in the UI process, and in the web process, trace
     13        the start and end of the snapshot painting.
     14
     15        * UIProcess/API/Cocoa/WKWebView.mm:
     16        (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
     17        * UIProcess/API/Cocoa/_WKThumbnailView.mm:
     18        (-[_WKThumbnailView requestSnapshot]):
     19        * UIProcess/API/ios/WKWebViewIOS.mm:
     20        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
     21        * WebProcess/WebPage/WebPage.cpp:
     22        (WebKit::WebPage::paintSnapshotAtSize):
     23
    1242021-04-22  Lauro Moura  <lmoura@igalia.com>
    225
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r276347 r276473  
    149149#import <wtf/Optional.h>
    150150#import <wtf/RetainPtr.h>
     151#import <wtf/SystemTracing.h>
    151152#import <wtf/UUID.h>
    152153#import <wtf/cocoa/VectorCocoa.h>
     
    11051106- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(CocoaImage *, NSError *))completionHandler
    11061107{
     1108    constexpr bool snapshotFailedTraceValue = false;
     1109    tracePoint(TakeSnapshotStart);
     1110
    11071111    CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
    11081112    CGFloat snapshotWidth;
     
    11291133    _page->takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle& imageHandle) {
    11301134        if (imageHandle.isNull()) {
     1135            tracePoint(TakeSnapshotEnd, snapshotFailedTraceValue);
    11311136            handler(nil, createNSError(WKErrorUnknown).get());
    11321137            return;
     
    11351140        RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
    11361141        auto image = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
     1142        tracePoint(TakeSnapshotEnd, true);
    11371143        handler(image.get(), nil);
    11381144    });
     
    11491155            else
    11501156                image = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
    1151            
     1157
     1158            tracePoint(TakeSnapshotEnd, !!snapshotImage);
    11521159            handler(image.get(), error.get());
    11531160        }];
     
    11611168    _page->callAfterNextPresentationUpdate([callSnapshotRect = WTFMove(callSnapshotRect), handler](WebKit::CallbackBase::Error error) {
    11621169        if (error != WebKit::CallbackBase::Error::None) {
     1170            tracePoint(TakeSnapshotEnd, snapshotFailedTraceValue);
    11631171            handler(nil, createNSError(WKErrorUnknown).get());
    11641172            return;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKThumbnailView.mm

    r272628 r276473  
    3737#import <pal/spi/cg/CoreGraphicsSPI.h>
    3838#import <wtf/NakedPtr.h>
     39#import <wtf/SystemTracing.h>
    3940
    4041// FIXME: Make it possible to leave a snapshot of the content presented in the WKView while the thumbnail is live.
     
    123124    }
    124125
     126    tracePoint(TakeSnapshotStart);
    125127    _waitingForSnapshot = YES;
    126128
     
    145147        auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
    146148        RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
     149        tracePoint(TakeSnapshotEnd, !!cgImage);
    147150        [thumbnailView _didTakeSnapshot:cgImage.get()];
    148151    });
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r276331 r276473  
    6161#import <pal/spi/ios/GraphicsServicesSPI.h>
    6262#import <wtf/BlockPtr.h>
     63#import <wtf/SystemTracing.h>
    6364#import <wtf/cocoa/VectorCocoa.h>
    6465
     
    30753076    NSString *displayName = self.window.screen.displayConfiguration.name;
    30763077    if (displayName && !self.window.hidden) {
     3078        TraceScope snapshotScope(RenderServerSnapshotStart, RenderServerSnapshotEnd);
    30773079        auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::sRGBColorSpaceRef());
    30783080        if (!surface) {
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r276351 r276473  
    260260#include <wtf/RunLoop.h>
    261261#include <wtf/SetForScope.h>
     262#include <wtf/SystemTracing.h>
    262263#include <wtf/text/TextStream.h>
    263264
     
    25392540void WebPage::paintSnapshotAtSize(const IntRect& rect, const IntSize& bitmapSize, SnapshotOptions options, Frame& frame, FrameView& frameView, GraphicsContext& graphicsContext)
    25402541{
     2542    TraceScope snapshotScope(PaintSnapshotStart, PaintSnapshotEnd, options);
     2543
    25412544    IntRect snapshotRect = rect;
    25422545    float horizontalScaleFactor = static_cast<float>(bitmapSize.width()) / rect.width();
  • trunk/Tools/ChangeLog

    r276457 r276473  
     12021-04-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add trace points for WKWebView snapshotting
     4        https://bugs.webkit.org/show_bug.cgi?id=224943
     5
     6        Reviewed by Tim Horton.
     7
     8        New snapshot descriptions.
     9
     10        * Tracing/SystemTracePoints.plist:
     11
    1122021-04-22  Tim Nguyen  <ntim@apple.com>
    213
  • trunk/Tools/Tracing/SystemTracePoints.plist

    r276360 r276473  
    513513             <dict>
    514514                 <key>Name</key>
     515                 <string>Paint snapshot</string>
     516                 <key>Type</key>
     517                 <string>Interval</string>
     518                 <key>Component</key>
     519                 <string>47</string>
     520                 <key>CodeBegin</key>
     521                 <string>12019</string>
     522                 <key>CodeEnd</key>
     523                 <string>12020</string>
     524                 <key>ArgNamesBegin</key>
     525                 <dict>
     526                     <key>Arg1</key>
     527                     <string>Options</string>
     528                 </dict>
     529             </dict>
     530             <dict>
     531                 <key>Name</key>
     532                 <string>Render server snapshot</string>
     533                 <key>Type</key>
     534                 <string>Interval</string>
     535                 <key>Component</key>
     536                 <string>47</string>
     537                 <key>CodeBegin</key>
     538                 <string>12021</string>
     539                 <key>CodeEnd</key>
     540                 <string>12022</string>
     541             </dict>
     542             <dict>
     543                 <key>Name</key>
     544                 <string>Take snapshot</string>
     545                 <key>Type</key>
     546                 <string>Interval</string>
     547                 <key>Component</key>
     548                 <string>47</string>
     549                 <key>CodeBegin</key>
     550                 <string>12023</string>
     551                 <key>CodeEnd</key>
     552                 <string>12024</string>
     553                 <key>ArgNamesEnd</key>
     554                 <dict>
     555                     <key>Arg1</key>
     556                     <string>Succeeded</string>
     557                 </dict>
     558             </dict>
     559             <dict>
     560                 <key>Name</key>
    515561                 <string>Commit RemoteLayerTree transaction</string>
    516562                 <key>Type</key>
Note: See TracChangeset for help on using the changeset viewer.