Changeset 238767 in webkit


Ignore:
Timestamp:
Nov 30, 2018 5:11:12 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Editable images should always return some data, even if the canvas doesn't have a size yet
https://bugs.webkit.org/show_bug.cgi?id=192265
<rdar://problem/46385911>

Reviewed by Wenson Hsieh.

  • UIProcess/ios/WKDrawingView.mm:

(-[WKDrawingView layoutSubviews]):
(emptyImage):
(-[WKDrawingView renderedDrawing]):
(-[WKDrawingView PNGRepresentation]):
Some clients strongly depend on there being some data in an image, even if
it's not of a usable size yet. We'll invalidate the attachment when the
canvas size changes, so it will eventually settle at a usable size (after
the first layer tree commit that includes the editable image).

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r238754 r238767  
     12018-11-30  Tim Horton  <timothy_horton@apple.com>
     2
     3        Editable images should always return some data, even if the canvas doesn't have a size yet
     4        https://bugs.webkit.org/show_bug.cgi?id=192265
     5        <rdar://problem/46385911>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * UIProcess/ios/WKDrawingView.mm:
     10        (-[WKDrawingView layoutSubviews]):
     11        (emptyImage):
     12        (-[WKDrawingView renderedDrawing]):
     13        (-[WKDrawingView PNGRepresentation]):
     14        Some clients strongly depend on there being some data in an image, even if
     15        it's not of a usable size yet. We'll invalidate the attachment when the
     16        canvas size changes, so it will eventually settle at a usable size (after
     17        the first layer tree commit that includes the editable image).
     18
    1192018-11-30  Don Olmstead  <don.olmstead@sony.com>
    220
  • trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm

    r238708 r238767  
    4040    RetainPtr<PKCanvasView> _pencilView;
    4141
     42#if !PLATFORM(IOS_FAMILY_SIMULATOR)
    4243    OSObjectPtr<dispatch_queue_t> _renderQueue;
    4344    RetainPtr<PKImageRenderer> _renderer;
     45#endif
    4446
    4547    WeakPtr<WebKit::WebPageProxy> _webPageProxy;
     
    7173        [_pencilView setFrame:self.bounds];
    7274
     75#if !PLATFORM(IOS_FAMILY_SIMULATOR)
    7376        // The renderer is instantiated for a particular size output; if
    7477        // the size changes, we need to re-create the renderer.
    7578        _renderer = nil;
     79#endif
    7680
    7781        [self invalidateAttachment];
     
    7983}
    8084
    81 - (NSData *)PNGRepresentation
     85static UIImage *emptyImage()
    8286{
     87    UIGraphicsBeginImageContext(CGSizeMake(1, 1));
     88    CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, 1, 1));
     89    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
     90    UIGraphicsEndImageContext();
     91
     92    return resultImage;
     93}
     94
     95- (UIImage *)renderedDrawing
     96{
     97#if PLATFORM(IOS_FAMILY_SIMULATOR)
     98    // PKImageRenderer currently doesn't work in the simulator. In order to
     99    // allow strokes to persist regardless (mostly for testing), we'll
     100    // synthesize an empty 1x1 image.
     101    return emptyImage();
     102#else
    83103    if (!self.bounds.size.width || !self.bounds.size.height || !self.window.screen.scale)
    84         return nil;
     104        return emptyImage();
    85105
    86106    if (!_renderQueue)
     
    90110        _renderer = adoptNS([WebKit::allocPKImageRendererInstance() initWithSize:self.bounds.size scale:self.window.screen.scale renderQueue:_renderQueue.get()]);
    91111
    92     auto* drawing = [_pencilView drawing];
     112    __block RetainPtr<UIImage> resultImage;
    93113
    94     __block RetainPtr<UIImage> resultImage;
    95 #if PLATFORM(IOS_FAMILY_SIMULATOR)
    96     // PKImageRenderer currently doesn't work in the simulator. In order to
    97     // allow strokes to persist regardless (mostly for testing), we'll
    98     // synthesize an empty 1x1 image.
    99     UIGraphicsBeginImageContext(CGSizeMake(1, 1));
    100     CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, 1, 1));
    101     resultImage = UIGraphicsGetImageFromCurrentImageContext();
    102     UIGraphicsEndImageContext();
    103 #else
    104     [_renderer renderDrawing:drawing completion:^(UIImage *image) {
     114    [_renderer renderDrawing:[_pencilView drawing] completion:^(UIImage *image) {
    105115        resultImage = image;
    106116    }];
    107 #endif
    108117
    109118    // FIXME: Ideally we would not synchronously wait for this rendering,
     
    112121    dispatch_sync(_renderQueue.get(), ^{ });
    113122
     123    return resultImage.get();
     124#endif
     125}
     126
     127- (NSData *)PNGRepresentation
     128{
     129    RetainPtr<UIImage> image = [self renderedDrawing];
    114130    RetainPtr<NSMutableData> PNGData = adoptNS([[NSMutableData alloc] init]);
    115131    RetainPtr<CGImageDestinationRef> imageDestination = adoptCF(CGImageDestinationCreateWithData((__bridge CFMutableDataRef)PNGData.get(), kUTTypePNG, 1, nil));
    116     NSString *base64Drawing = [[drawing serialize] base64EncodedStringWithOptions:0];
     132    NSString *base64Drawing = [[[_pencilView drawing] serialize] base64EncodedStringWithOptions:0];
    117133    NSDictionary *properties = nil;
    118134    if (base64Drawing) {
     
    125141    }
    126142    CGImageDestinationSetProperties(imageDestination.get(), (__bridge CFDictionaryRef)properties);
    127     CGImageDestinationAddImage(imageDestination.get(), [resultImage CGImage], (__bridge CFDictionaryRef)properties);
     143    CGImageDestinationAddImage(imageDestination.get(), [image CGImage], (__bridge CFDictionaryRef)properties);
    128144    CGImageDestinationFinalize(imageDestination.get());
    129145
Note: See TracChangeset for help on using the changeset viewer.