Changeset 238767 in webkit
- Timestamp:
- Nov 30, 2018 5:11:12 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r238754 r238767 1 2018-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 1 19 2018-11-30 Don Olmstead <don.olmstead@sony.com> 2 20 -
trunk/Source/WebKit/UIProcess/ios/WKDrawingView.mm
r238708 r238767 40 40 RetainPtr<PKCanvasView> _pencilView; 41 41 42 #if !PLATFORM(IOS_FAMILY_SIMULATOR) 42 43 OSObjectPtr<dispatch_queue_t> _renderQueue; 43 44 RetainPtr<PKImageRenderer> _renderer; 45 #endif 44 46 45 47 WeakPtr<WebKit::WebPageProxy> _webPageProxy; … … 71 73 [_pencilView setFrame:self.bounds]; 72 74 75 #if !PLATFORM(IOS_FAMILY_SIMULATOR) 73 76 // The renderer is instantiated for a particular size output; if 74 77 // the size changes, we need to re-create the renderer. 75 78 _renderer = nil; 79 #endif 76 80 77 81 [self invalidateAttachment]; … … 79 83 } 80 84 81 - (NSData *)PNGRepresentation 85 static UIImage *emptyImage() 82 86 { 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 83 103 if (!self.bounds.size.width || !self.bounds.size.height || !self.window.screen.scale) 84 return nil;104 return emptyImage(); 85 105 86 106 if (!_renderQueue) … … 90 110 _renderer = adoptNS([WebKit::allocPKImageRendererInstance() initWithSize:self.bounds.size scale:self.window.screen.scale renderQueue:_renderQueue.get()]); 91 111 92 auto* drawing = [_pencilView drawing];112 __block RetainPtr<UIImage> resultImage; 93 113 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) { 105 115 resultImage = image; 106 116 }]; 107 #endif108 117 109 118 // FIXME: Ideally we would not synchronously wait for this rendering, … … 112 121 dispatch_sync(_renderQueue.get(), ^{ }); 113 122 123 return resultImage.get(); 124 #endif 125 } 126 127 - (NSData *)PNGRepresentation 128 { 129 RetainPtr<UIImage> image = [self renderedDrawing]; 114 130 RetainPtr<NSMutableData> PNGData = adoptNS([[NSMutableData alloc] init]); 115 131 RetainPtr<CGImageDestinationRef> imageDestination = adoptCF(CGImageDestinationCreateWithData((__bridge CFMutableDataRef)PNGData.get(), kUTTypePNG, 1, nil)); 116 NSString *base64Drawing = [[ drawingserialize] base64EncodedStringWithOptions:0];132 NSString *base64Drawing = [[[_pencilView drawing] serialize] base64EncodedStringWithOptions:0]; 117 133 NSDictionary *properties = nil; 118 134 if (base64Drawing) { … … 125 141 } 126 142 CGImageDestinationSetProperties(imageDestination.get(), (__bridge CFDictionaryRef)properties); 127 CGImageDestinationAddImage(imageDestination.get(), [ resultImage CGImage], (__bridge CFDictionaryRef)properties);143 CGImageDestinationAddImage(imageDestination.get(), [image CGImage], (__bridge CFDictionaryRef)properties); 128 144 CGImageDestinationFinalize(imageDestination.get()); 129 145
Note: See TracChangeset
for help on using the changeset viewer.