Changeset 260667 in webkit


Ignore:
Timestamp:
Apr 24, 2020 2:02:48 PM (4 years ago)
Author:
ddkilzer@apple.com
Message:

Use CocoaImage platform abstraction for NSImage/UIImage
<https://webkit.org/b/210974>

Reviewed by Darin Adler.

  • Platform/cocoa/CocoaImage.h: Add.
  • Define CocoaImage here for cross-platform use. Don't use OBJC_CLASS() here because this is an Objective-C header.
  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):

  • Combine separate platform-specific methods into one method.
  • UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
  • Combine separate platform-specific instance variables into one instance variable.

(-[_WKActivatedElementInfo image]):

  • Combine separate methods into one platform-specific method.
  • UIProcess/QuickLookThumbnailLoader.h:
  • Move cross-platform definition to CocoaImge.h.
  • UIProcess/QuickLookThumbnailLoader.mm:
  • Drive-by fix of soft-linking header include order.
  • WebKit.xcodeproj/project.pbxproj:
  • Add CocoaImage.h to the project.
  • WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:

(-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]):
(-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:width:]):

  • Combine separate platform-specific methods into one method.
Location:
trunk/Source/WebKit
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260666 r260667  
     12020-04-24  David Kilzer  <ddkilzer@apple.com>
     2
     3        Use CocoaImage platform abstraction for NSImage/UIImage
     4        <https://webkit.org/b/210974>
     5
     6        Reviewed by Darin Adler.
     7
     8        * Platform/cocoa/CocoaImage.h: Add.
     9        - Define CocoaImage here for cross-platform use.  Don't use
     10          OBJC_CLASS() here because this is an Objective-C header.
     11        * UIProcess/API/Cocoa/WKWebView.mm:
     12        (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
     13        - Combine separate platform-specific methods into one method.
     14        * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
     15        - Combine separate platform-specific instance variables into
     16          one instance variable.
     17        (-[_WKActivatedElementInfo image]):
     18        - Combine separate methods into one platform-specific method.
     19        * UIProcess/QuickLookThumbnailLoader.h:
     20        - Move cross-platform definition to CocoaImge.h.
     21        * UIProcess/QuickLookThumbnailLoader.mm:
     22        - Drive-by fix of soft-linking header include order.
     23        * WebKit.xcodeproj/project.pbxproj:
     24        - Add CocoaImage.h to the project.
     25        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:
     26        (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]):
     27        (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:width:]):
     28        - Combine separate platform-specific methods into one method.
     29
    1302020-04-24  David Kilzer  <ddkilzer@apple.com>
    231
  • trunk/Source/WebKit/Platform/cocoa/CocoaImage.h

    r260666 r260667  
    2424*/
    2525
    26 #if HAVE(QUICKLOOK_THUMBNAILING)
    27 
    2826#if USE(APPKIT)
    2927@class NSImage;
     
    3331using CocoaImage = UIImage;
    3432#endif
    35 
    36 @interface WKQLThumbnailQueueManager : NSObject
    37 
    38 @property (nonatomic, readonly, retain) NSOperationQueue *queue;
    39 
    40 - (instancetype)init;
    41 + (WKQLThumbnailQueueManager *)sharedInstance;
    42 
    43 @end
    44 
    45 @interface WKQLThumbnailLoadOperation : NSOperation
    46 
    47 @property (atomic, readonly, getter=isAsynchronous) BOOL asynchronous;
    48 @property (atomic, readonly, getter=isExecuting) BOOL executing;
    49 @property (atomic, readonly, getter=isFinished) BOOL finished;
    50 
    51 @property (nonatomic, readonly, copy) NSString *identifier;
    52 @property (nonatomic, readonly, retain) CocoaImage *thumbnail;
    53 
    54 - (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;
    55 - (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;
    56 
    57 @end
    58 
    59 #endif // HAVE(QUICKLOOK_THUMBNAILING)
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r260485 r260667  
    3232#import "APISerializedScriptValue.h"
    3333#import "AttributedString.h"
     34#import "CocoaImage.h"
    3435#import "CompletionHandlerCallChecker.h"
    3536#import "ContentAsStringIncludesChildFrames.h"
     
    980981}
    981982
    982 #if PLATFORM(MAC)
    983 - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(NSImage *, NSError *))completionHandler
     983- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(CocoaImage *, NSError *))completionHandler
    984984{
    985985    CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
     
    991991
    992992    auto handler = makeBlockPtr(completionHandler);
     993
     994#if USE(APPKIT)
    993995    CGFloat imageScale = snapshotWidth / rectInViewCoordinates.size.width;
    994996    CGFloat imageHeight = imageScale * rectInViewCoordinates.size.height;
     
    10121014        auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
    10131015        RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
    1014         RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
    1015         handler(nsImage.get(), nil);
     1016        auto image = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
     1017        handler(image.get(), nil);
    10161018    });
    1017 }
    1018 
    1019 #elif PLATFORM(IOS_FAMILY)
    1020 - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(UIImage *, NSError *))completionHandler
    1021 {
    1022     CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
    1023     CGFloat snapshotWidth;
    1024     if (snapshotConfiguration)
    1025         snapshotWidth = snapshotConfiguration.snapshotWidth.doubleValue ?: rectInViewCoordinates.size.width;
    1026     else
    1027         snapshotWidth = self.bounds.size.width;
    1028 
    1029     auto handler = makeBlockPtr(completionHandler);
     1019#else
    10301020    CGFloat deviceScale = _page->deviceScaleFactor();
    10311021    RetainPtr<WKWebView> strongSelf = self;
     
    10331023        [strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
    10341024            RetainPtr<NSError> error;
    1035             RetainPtr<UIImage> uiImage;
     1025            RetainPtr<UIImage> image;
    10361026           
    10371027            if (!snapshotImage)
    10381028                error = createNSError(WKErrorUnknown);
    10391029            else
    1040                 uiImage = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
     1030                image = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
    10411031           
    1042             handler(uiImage.get(), error.get());
     1032            handler(image.get(), error.get());
    10431033        }];
    10441034    };
     
    10561046        callSnapshotRect();
    10571047    });
    1058 }
    1059 #endif
     1048#endif
     1049}
    10601050
    10611051- (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm

    r252309 r260667  
    2727#import "_WKActivatedElementInfoInternal.h"
    2828
     29#import "CocoaImage.h"
    2930#import "ShareableBitmap.h"
    3031#import <wtf/RetainPtr.h>
    3132
    32 #if PLATFORM(IOS_FAMILY)
     33#if USE(APPKIT)
     34#import <AppKit/NSImage.h>
     35#else
    3336#import <UIKit/UIImage.h>
    34 #endif
    35 
    36 #if PLATFORM(MAC)
    37 #import <AppKit/NSImage.h>
    3837#endif
    3938
     
    4544    RetainPtr<NSString> _ID;
    4645    RefPtr<WebKit::ShareableBitmap> _image;
     46    RetainPtr<CocoaImage> _cocoaImage;
    4747#if PLATFORM(IOS_FAMILY)
    48     RetainPtr<UIImage> _uiImage;
    4948    RetainPtr<NSDictionary> _userInfo;
    50 #endif
    51 #if PLATFORM(MAC)
    52     RetainPtr<NSImage> _nsImage;
    5349#endif
    5450    BOOL _animatedImage;
     
    151147    return _userInfo.get();
    152148}
     149#endif
    153150
    154 - (UIImage *)image
     151- (CocoaImage *)image
    155152{
    156     if (_uiImage)
    157         return [[_uiImage copy] autorelease];
     153    if (_cocoaImage)
     154        return [[_cocoaImage copy] autorelease];
    158155
    159156    if (!_image)
    160157        return nil;
    161158
    162     _uiImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]);
     159#if USE(APPKIT)
     160    _cocoaImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);
     161#else
     162    _cocoaImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]);
     163#endif
    163164    _image = nullptr;
    164165
    165     return [[_uiImage copy] autorelease];
     166    return [[_cocoaImage copy] autorelease];
    166167}
    167 #endif
    168 
    169 #if PLATFORM(MAC)
    170 - (NSImage *)image
    171 {
    172     if (_nsImage)
    173         return [[_nsImage copy] autorelease];
    174 
    175     if (!_image)
    176         return nil;
    177 
    178     _nsImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);
    179     _image = nullptr;
    180 
    181     return [[_nsImage copy] autorelease];
    182 }
    183 #endif
    184168
    185169@end
  • trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h

    r260611 r260667  
    2626#if HAVE(QUICKLOOK_THUMBNAILING)
    2727
    28 #if USE(APPKIT)
    29 @class NSImage;
    30 using CocoaImage = NSImage;
    31 #else
    32 @class UIImage;
    33 using CocoaImage = UIImage;
    34 #endif
     28#import "CocoaImage.h"
    3529
    3630@interface WKQLThumbnailQueueManager : NSObject
  • trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm

    r260611 r260667  
    2929#if HAVE(QUICKLOOK_THUMBNAILING)
    3030
     31#import <wtf/FileSystem.h>
     32
    3133#import "QuickLookThumbnailingSoftLink.h"
    32 
    33 #import <wtf/FileSystem.h>
    3434
    3535@implementation WKQLThumbnailQueueManager
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r260653 r260667  
    933933                41FAF5F81E3C1021001AE678 /* LibWebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */; };
    934934                4459984222833E8700E61373 /* SyntheticEditingCommandType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4459984122833E6000E61373 /* SyntheticEditingCommandType.h */; };
     935                4482734724528F6000A95493 /* CocoaImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4482734624528F6000A95493 /* CocoaImage.h */; };
    935936                449D90DA21FDC30B00F677C0 /* LocalAuthenticationSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */; };
    936937                44E936FD2447C2D8009FA3E3 /* LegacyCustomProtocolID.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E936FC2447C256009FA3E3 /* LegacyCustomProtocolID.h */; };
     
    35253526                4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedMemoryCocoa.cpp; sourceTree = "<group>"; };
    35263527                4459984122833E6000E61373 /* SyntheticEditingCommandType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SyntheticEditingCommandType.h; sourceTree = "<group>"; };
     3528                4482734624528F6000A95493 /* CocoaImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoaImage.h; sourceTree = "<group>"; };
    35273529                449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalAuthenticationSoftLink.mm; sourceTree = "<group>"; };
    35283530                44A481C621F2D27B00F2F919 /* ClientCertificateAuthenticationXPCConstants.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClientCertificateAuthenticationXPCConstants.cpp; sourceTree = "<group>"; };
     
    76917693                        isa = PBXGroup;
    76927694                        children = (
     7695                                4482734624528F6000A95493 /* CocoaImage.h */,
    76937696                                BCE0937614FB128B001138D9 /* LayerHostingContext.h */,
    76947697                                BCE0937514FB128B001138D9 /* LayerHostingContext.mm */,
     
    1073810741                                1AA2E51D12E4C05E00BC4966 /* CGUtilities.h in Headers */,
    1073910742                                57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */,
     10743                                4482734724528F6000A95493 /* CocoaImage.h in Headers */,
    1074010744                                CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */,
    1074110745                                37BEC4E119491486008B4286 /* CompletionHandlerCallChecker.h in Headers */,
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm

    r248373 r260667  
    2727#import "WKWebProcessPlugInNodeHandleInternal.h"
    2828
     29#import "CocoaImage.h"
    2930#import "WKSharedAPICast.h"
    3031#import "WKWebProcessPlugInFrameInternal.h"
     
    5556}
    5657
    57 #if PLATFORM(IOS_FAMILY)
    58 - (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options
     58- (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options
    5959{
    6060    return [self renderedImageWithOptions:options width:nil];
    6161}
    6262
    63 - (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
     63- (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
    6464{
    6565    Optional<float> optionalWidth;
     
    7171        return nil;
    7272
     73#if USE(APPKIT)
     74    return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease];
     75#else
    7376    return [[[UIImage alloc] initWithCGImage:image->bitmap().makeCGImage().get()] autorelease];
    74 }
    7577#endif
    76 
    77 #if PLATFORM(MAC)
    78 - (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options
    79 {
    80     return [self renderedImageWithOptions:options width:nil];
    81 }
    82 
    83 - (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
    84 {
    85     Optional<float> optionalWidth;
    86     if (width)
    87         optionalWidth = width.floatValue;
    88 
    89     RefPtr<WebKit::WebImage> image = _nodeHandle->renderedImage(WebKit::toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow, optionalWidth);
    90     if (!image)
    91         return nil;
    92 
    93     return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease];
    94 }
    95 #endif
     78}
    9679
    9780- (CGRect)elementBounds
Note: See TracChangeset for help on using the changeset viewer.