Title: [273462] trunk/Source
Revision
273462
Author
da...@apple.com
Date
2021-02-24 17:04:09 -0800 (Wed, 24 Feb 2021)

Log Message

[iOS] Reduce use of retain/release in WAKWindow and remove unneeded methods from that class
https://bugs.webkit.org/show_bug.cgi?id=222330

Reviewed by Chris Dumez.

Source/WebCore:

* platform/ios/LegacyTileCache.h: Use pragma once, remove unneeded includes,
tweak coding style a bit to match WebKit standard. Removed hasPendingDraw.
added WEBCORE_EXPORT to setTileBordersVisible and setTilePaintCountersVisible
so they can be used in WebKitLegacy.

* platform/ios/LegacyTileCache.mm:
(WebCore::LegacyTileCache::hasPendingDraw const): Deleted.

* platform/ios/wak/WAKWindow.h: Use pragma once, remove unneeded includes,
tweak coding style a bit to match WebKit standard. Removed hasPendingDraw,
setTileControllerShouldUseLowScaleTiles, setTileBordersVisible,
setTilePaintCountsVisible, setAcceleratedDrawingEnabled, freezeVisibleRect,
and unfreezeVisibleRect.

* platform/ios/wak/WAKWindow.mm: Removed "using namespace WebCore".
Removed unused _WAKKeyWindow global. Converted currentEvent and
gOrientationProvider globals to NeverDestroyed<RetainPtr<>>.
(orientationProvider): Added
(currentEvent): Added.
(-[WAKWindow isKeyWindow]): Remove dead code; this method already always
returns YES.
(-[WAKWindow makeKeyWindow]): Remove dead code. This method wrote to a
global that was never read anywhere.
(-[WAKWindow sendEventSynchronously:]): Use the currentEvent function
and take advantage of the fact that it's a RetainPtr so we don't need a
a local variable named currentEventProtector.
(-[WAKWindow hasPendingDraw]): Deleted. No callers depend on this.
(-[WAKWindow willRotate]): Set _frozenVisibleRect here directly instead
of calling anoether method to do that.
(-[WAKWindow didRotate]): Ditto.
(-[WAKWindow freezeVisibleRect]): Deleted. The method above was the only
caller for this method.
(-[WAKWindow unfreezeVisibleRect]): Ditto.
(+[WAKWindow setOrientationProvider:]): Use the orientationProvider function.
Note, this now retains the passed-in object. This is safe; the only caller
passes in a class, so there's no risk of a retain cycle.
(+[WAKWindow hasLandscapeOrientation]): Use the orientationProvider function.
(-[WAKWindow setTileBordersVisible:]): Deleted. The only caller for this
was in WebKitLegacy, and refactored to use the tile cache directly.
(-[WAKWindow setTilePaintCountsVisible:]): Ditto.
(-[WAKWindow setAcceleratedDrawingEnabled:]): Ditto.
(-[WAKWindow setTileControllerShouldUseLowScaleTiles:]): Deleted. No
callers depend on this.
(+[WAKWindow currentEvent]): Use the currentEvent function.

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _preferencesChanged:]): Call LegacyTileCache functions directly rather
than indirecting through WAKWindow methods.
(-[WebView viewDidMoveToWindow]): Ditto. Also tweaked conditionals a little for clarity.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273461 => 273462)


--- trunk/Source/WebCore/ChangeLog	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebCore/ChangeLog	2021-02-25 01:04:09 UTC (rev 273462)
@@ -1,3 +1,55 @@
+2021-02-23  Darin Adler  <da...@apple.com>
+
+        [iOS] Reduce use of retain/release in WAKWindow and remove unneeded methods from that class
+        https://bugs.webkit.org/show_bug.cgi?id=222330
+
+        Reviewed by Chris Dumez.
+
+        * platform/ios/LegacyTileCache.h: Use pragma once, remove unneeded includes,
+        tweak coding style a bit to match WebKit standard. Removed hasPendingDraw.
+        added WEBCORE_EXPORT to setTileBordersVisible and setTilePaintCountersVisible
+        so they can be used in WebKitLegacy.
+
+        * platform/ios/LegacyTileCache.mm:
+        (WebCore::LegacyTileCache::hasPendingDraw const): Deleted.
+
+        * platform/ios/wak/WAKWindow.h: Use pragma once, remove unneeded includes,
+        tweak coding style a bit to match WebKit standard. Removed hasPendingDraw,
+        setTileControllerShouldUseLowScaleTiles, setTileBordersVisible,
+        setTilePaintCountsVisible, setAcceleratedDrawingEnabled, freezeVisibleRect,
+        and unfreezeVisibleRect.
+
+        * platform/ios/wak/WAKWindow.mm: Removed "using namespace WebCore".
+        Removed unused _WAKKeyWindow global. Converted currentEvent and
+        gOrientationProvider globals to NeverDestroyed<RetainPtr<>>.
+        (orientationProvider): Added
+        (currentEvent): Added.
+        (-[WAKWindow isKeyWindow]): Remove dead code; this method already always
+        returns YES.
+        (-[WAKWindow makeKeyWindow]): Remove dead code. This method wrote to a
+        global that was never read anywhere.
+        (-[WAKWindow sendEventSynchronously:]): Use the currentEvent function
+        and take advantage of the fact that it's a RetainPtr so we don't need a
+        a local variable named currentEventProtector.
+        (-[WAKWindow hasPendingDraw]): Deleted. No callers depend on this.
+        (-[WAKWindow willRotate]): Set _frozenVisibleRect here directly instead
+        of calling anoether method to do that.
+        (-[WAKWindow didRotate]): Ditto.
+        (-[WAKWindow freezeVisibleRect]): Deleted. The method above was the only
+        caller for this method.
+        (-[WAKWindow unfreezeVisibleRect]): Ditto.
+        (+[WAKWindow setOrientationProvider:]): Use the orientationProvider function.
+        Note, this now retains the passed-in object. This is safe; the only caller
+        passes in a class, so there's no risk of a retain cycle.
+        (+[WAKWindow hasLandscapeOrientation]): Use the orientationProvider function.
+        (-[WAKWindow setTileBordersVisible:]): Deleted. The only caller for this
+        was in WebKitLegacy, and refactored to use the tile cache directly.
+        (-[WAKWindow setTilePaintCountsVisible:]): Ditto.
+        (-[WAKWindow setAcceleratedDrawingEnabled:]): Ditto.
+        (-[WAKWindow setTileControllerShouldUseLowScaleTiles:]): Deleted. No
+        callers depend on this.
+        (+[WAKWindow currentEvent]): Use the currentEvent function.
+
 2021-02-24  Jean-Yves Avenard  <j...@apple.com>
 
         [MSE] Media segment is incorrectly dropped when using negative timestampOffset or when source buffer appendWindow is set.

Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.h (273461 => 273462)


--- trunk/Source/WebCore/platform/ios/LegacyTileCache.h	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.h	2021-02-25 01:04:09 UTC (rev 273462)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,15 +23,12 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef LegacyTileCache_h
-#define LegacyTileCache_h
+#pragma once
 
 #if PLATFORM(IOS_FAMILY)
 
-#include "Color.h"
 #include "FloatRect.h"
 #include "IntRect.h"
-#include "IntSize.h"
 #include "Timer.h"
 #include <wtf/Lock.h>
 #include <wtf/Noncopyable.h>
@@ -40,26 +37,20 @@
 #include <wtf/Threading.h>
 #include <wtf/Vector.h>
 
-#ifdef __OBJC__
-@class CALayer;
-@class LegacyTileCacheTombstone;
-@class LegacyTileLayer;
-@class WAKWindow;
-#else
-class CALayer;
-class LegacyTileCacheTombstone;
-class LegacyTileLayer;
-class WAKWindow;
-#endif
+OBJC_CLASS CALayer;
+OBJC_CLASS LegacyTileCacheTombstone;
+OBJC_CLASS LegacyTileLayer;
+OBJC_CLASS WAKWindow;
 
 namespace WebCore {
 
+class Color;
 class LegacyTileGrid;
 
 class LegacyTileCache {
     WTF_MAKE_NONCOPYABLE(LegacyTileCache);
 public:
-    LegacyTileCache(WAKWindow*);
+    LegacyTileCache(WAKWindow *);
     ~LegacyTileCache();
 
     CGFloat screenScale() const;
@@ -80,10 +71,10 @@
     void setContentReplacementImage(RetainPtr<CGImageRef>);
     RetainPtr<CGImageRef> contentReplacementImage() const;
 
-    void setTileBordersVisible(bool);
+    WEBCORE_EXPORT void setTileBordersVisible(bool);
     bool tileBordersVisible() const { return m_tileBordersVisible; }
 
-    void setTilePaintCountersVisible(bool);
+    WEBCORE_EXPORT void setTilePaintCountersVisible(bool);
     bool tilePaintCountersVisible() const { return m_tilePaintCountersVisible; }
 
     void setAcceleratedDrawingEnabled(bool enabled) { m_acceleratedDrawingEnabled = enabled; }
@@ -112,17 +103,15 @@
     TilingMode tilingMode() const { return m_tilingMode; }
     void setTilingMode(TilingMode);
 
-    typedef enum {
+    enum TilingDirection {
         TilingDirectionUp,
         TilingDirectionDown,
         TilingDirectionLeft,
         TilingDirectionRight,
-    } TilingDirection;
+    };
     void setTilingDirection(TilingDirection);
     TilingDirection tilingDirection() const;
 
-    bool hasPendingDraw() const;
-
     void hostLayerSizeChanged();
 
     WEBCORE_EXPORT static void setLayerPoolCapacity(unsigned);
@@ -135,7 +124,7 @@
     void doLayoutTiles();
     
     enum class DrawingFlags { None, Snapshotting };
-    void drawLayer(LegacyTileLayer*, CGContextRef, DrawingFlags);
+    void drawLayer(LegacyTileLayer *, CGContextRef, DrawingFlags);
     void prepareToDraw();
     void finishedCreatingTiles(bool didCreateTiles, bool createMore);
     FloatRect visibleRectInLayer(CALayer *) const;
@@ -174,10 +163,10 @@
 
     void tileCreationTimerFired();
 
-    void drawReplacementImage(LegacyTileLayer*, CGContextRef, CGImageRef);
-    void drawWindowContent(LegacyTileLayer*, CGContextRef, CGRect dirtyRect, DrawingFlags);
+    void drawReplacementImage(LegacyTileLayer *, CGContextRef, CGImageRef);
+    void drawWindowContent(LegacyTileLayer *, CGContextRef, CGRect dirtyRect, DrawingFlags);
 
-    WAKWindow* m_window { nullptr };
+    WAKWindow *m_window { nullptr };
 
     RetainPtr<CGImageRef> m_contentReplacementImage;
 
@@ -222,5 +211,3 @@
 } // namespace WebCore
 
 #endif // PLATFORM(IOS_FAMILY)
-
-#endif // TileCache_h

Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.mm (273461 => 273462)


--- trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2021-02-25 01:04:09 UTC (rev 273462)
@@ -43,11 +43,11 @@
 #import <wtf/MemoryPressureHandler.h>
 #import <wtf/RAMSize.h>
 
+// FIXME: This should go into a WAKViewInternals.h header.
 @interface WAKView (WebViewExtras)
-- (void)_dispatchTileDidDraw:(CALayer*)tile;
+- (void)_dispatchTileDidDraw:(CALayer *)tile;
 - (void)_willStartScrollingOrZooming;
 - (void)_didFinishScrollingOrZooming;
-- (void)_dispatchTileDidDraw;
 - (void)_scheduleRenderingUpdateForPendingTileCacheRepaint;
 @end
 
@@ -55,13 +55,10 @@
     BOOL dead;
 }
 @property(getter=isDead) BOOL dead;
-
 @end
 
 @implementation LegacyTileCacheTombstone
-
 @synthesize dead;
-
 @end
 
 namespace WebCore {
@@ -775,11 +772,6 @@
         m_tileCreationTimer.startOneShot(0_s);
 }
 
-bool LegacyTileCache::hasPendingDraw() const
-{
-    return !m_savedDisplayRects.isEmpty();
-}
-
 void LegacyTileCache::prepareToDraw()
 {
     // This will trigger document relayout if needed.

Modified: trunk/Source/WebCore/platform/ios/wak/WAKWindow.h (273461 => 273462)


--- trunk/Source/WebCore/platform/ios/wak/WAKWindow.h	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebCore/platform/ios/wak/WAKWindow.h	2021-02-25 01:04:09 UTC (rev 273462)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,13 +23,11 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WAKWindow_h
-#define WAKWindow_h
+#pragma once
 
 #if TARGET_OS_IPHONE
 
 #import "WAKAppKitStubs.h"
-#import "WAKResponder.h"
 #import "WAKView.h"
 #import "WKContentObservation.h"
 #import <CoreGraphics/CoreGraphics.h>
@@ -68,7 +66,7 @@
 
 WEBCORE_EXPORT @interface WAKWindow : WAKResponder
 {
-    CALayer* _hostLayer;
+    CALayer *_hostLayer;
     LegacyTileCache* _tileCache;
     CGRect _frozenVisibleRect;
     CALayer *_rootLayer;
@@ -101,21 +99,21 @@
 
 - (CALayer*)hostLayer;
 
-- (void)setContentView:(WAKView *)aView;
+- (void)setContentView:(WAKView *)view;
 - (WAKView *)contentView;
 - (void)close;
 - (WAKView *)firstResponder;
 
-- (NSPoint)convertBaseToScreen:(NSPoint)aPoint;
-- (NSPoint)convertScreenToBase:(NSPoint)aPoint;
-- (NSRect)convertRectToScreen:(NSRect)aRect;
-- (NSRect)convertRectFromScreen:(NSRect)aRect;
+- (NSPoint)convertBaseToScreen:(NSPoint)point;
+- (NSPoint)convertScreenToBase:(NSPoint)point;
+- (NSRect)convertRectToScreen:(NSRect)rect;
+- (NSRect)convertRectFromScreen:(NSRect)rect;
 - (BOOL)isKeyWindow;
 - (void)makeKeyWindow;
 - (BOOL)isVisible;
 - (void)setVisible:(BOOL)visible;
 - (NSSelectionDirection)keyViewSelectionDirection;
-- (BOOL)makeFirstResponder:(NSResponder *)aResponder;
+- (BOOL)makeFirstResponder:(NSResponder *)responder;
 - (WAKView *)_newFirstResponderAfterResigning NS_RETURNS_NOT_RETAINED;
 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
 - (CGRect)frame;
@@ -128,9 +126,9 @@
 - (CGFloat)screenScale;
 - (void)setRootLayer:(CALayer *)layer;
 - (CALayer *)rootLayer;
-- (void)sendEvent:(WebEvent *)anEvent;
-- (void)sendEventSynchronously:(WebEvent *)anEvent;
-- (void)sendMouseMoveEvent:(WebEvent *)anEvent contentChange:(WKContentChange *)aContentChange;
+- (void)sendEvent:(WebEvent *)event;
+- (void)sendEventSynchronously:(WebEvent *)event;
+- (void)sendMouseMoveEvent:(WebEvent *)event contentChange:(WKContentChange *)change;
 
 - (void)setIsInSnapshottingPaint:(BOOL)isInSnapshottingPaint;
 - (BOOL)isInSnapshottingPaint;
@@ -161,7 +159,6 @@
 - (WAKWindowTilingMode)tilingMode;
 - (void)setTilingDirection:(WAKTilingDirection)tilingDirection;
 - (WAKTilingDirection)tilingDirection;
-- (BOOL)hasPendingDraw;
 - (void)displayRect:(NSRect)rect;
 - (void)setZoomedOutTileScale:(float)scale;
 - (float)zoomedOutTileScale;
@@ -169,18 +166,10 @@
 - (float)currentTileScale;
 - (void)setKeepsZoomedOutTiles:(BOOL)keepsZoomedOutTiles;
 - (BOOL)keepsZoomedOutTiles;
-- (LegacyTileCache *)tileCache;
+- (LegacyTileCache*)tileCache;
 
-- (void)setTileControllerShouldUseLowScaleTiles:(BOOL)lowScaleTiles;
-
 - (void)dumpTiles;
 
-- (void)setTileBordersVisible:(BOOL)visible;
-- (void)setTilePaintCountsVisible:(BOOL)visible;
-- (void)setAcceleratedDrawingEnabled:(BOOL)enabled;
-
-- (void)freezeVisibleRect;
-- (void)unfreezeVisibleRect;
 - (void)willRotate;
 - (void)didRotate;
 
@@ -192,8 +181,7 @@
 + (WebEvent *)currentEvent;
 
 - (NSString *)recursiveDescription;
+
 @end
 
 #endif // TARGET_OS_IPHONE
-
-#endif // WAKWindow_h

Modified: trunk/Source/WebCore/platform/ios/wak/WAKWindow.mm (273461 => 273462)


--- trunk/Source/WebCore/platform/ios/wak/WAKWindow.mm	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebCore/platform/ios/wak/WAKWindow.mm	2021-02-25 01:04:09 UTC (rev 273462)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,20 +37,28 @@
 #import "WKViewPrivate.h"
 #import <QuartzCore/QuartzCore.h>
 #import <wtf/Lock.h>
+#import <wtf/NeverDestroyed.h>
+#import <wtf/RetainPtr.h>
 
 WEBCORE_EXPORT NSString * const WAKWindowScreenScaleDidChangeNotification = @"WAKWindowScreenScaleDidChangeNotification";
 WEBCORE_EXPORT NSString * const WAKWindowVisibilityDidChangeNotification = @"WAKWindowVisibilityDidChangeNotification";
 
-using namespace WebCore;
-
 @protocol OrientationProvider
 - (BOOL)hasLandscapeOrientation;
 @end
 
-static WAKWindow *_WAKKeyWindow = nil;        // weak
-static WebEvent *currentEvent = nil;
-static id<OrientationProvider> gOrientationProvider;
+static RetainPtr<id<OrientationProvider>>& orientationProvider()
+{
+    static NeverDestroyed<RetainPtr<id<OrientationProvider>>> provider;
+    return provider;
+}
 
+static RetainPtr<WebEvent>& currentEvent()
+{
+    static NeverDestroyed<RetainPtr<WebEvent>> event;
+    return event;
+}
+
 @implementation WAKWindow {
     Lock _exposedScrollViewRectLock;
     CGRect _exposedScrollViewRect;
@@ -67,8 +75,8 @@
     _hostLayer = [layer retain];
 
     _frame = [_hostLayer frame];
-    _screenScale = screenScaleFactor();
-    
+    _screenScale = WebCore::screenScaleFactor();
+
     _tileCache = new LegacyTileCache(self);
 
     _frozenVisibleRect = CGRectNull;
@@ -78,7 +86,7 @@
     return self;
 }
 
-// This is used for WebViews that are not backed by the tile cache. Their content must be painted manually.
+// This is used for WebViews that are not backed by a tile cache. Their content must be painted manually.
 - (id)initWithFrame:(CGRect)frame
 {
     self = [super init];
@@ -86,7 +94,7 @@
         return nil;
 
     _frame = frame;
-    _screenScale = screenScaleFactor();
+    _screenScale = WebCore::screenScaleFactor();
 
     _exposedScrollViewRect = CGRectNull;
 
@@ -101,14 +109,14 @@
     [super dealloc];
 }
 
-- (void)setContentView:(WAKView *)aView
+- (void)setContentView:(WAKView *)view
 {
-    [aView retain];
+    [view retain];
     [_contentView release];
 
-    if (aView)
-        _WKViewSetWindow([aView _viewRef], self);
-    _contentView = aView;
+    if (view)
+        _WKViewSetWindow([view _viewRef], self);
+    _contentView = view;
 }
 
 - (WAKView *)contentView
@@ -176,15 +184,11 @@
 
 - (BOOL)isKeyWindow
 {
-    return YES || self == _WAKKeyWindow; 
+    return YES;
 }
 
 - (void)makeKeyWindow
 {
-    if ([self isKeyWindow])
-        return;
-    
-    _WAKKeyWindow = self;
 }
 
 - (BOOL)isVisible
@@ -221,12 +225,12 @@
     return NO;
 }
 
-- (BOOL)makeFirstResponder:(NSResponder *)aResponder
+- (BOOL)makeFirstResponder:(NSResponder *)responder
 {
-    if (![aResponder isKindOfClass:[WAKView class]])
+    if (![responder isKindOfClass:[WAKView class]])
         return NO;
 
-    WAKView *view = static_cast<WAKView*>(aResponder);
+    WAKView *view = static_cast<WAKView*>(responder);
     BOOL result = YES;
     if (view != _responderView) {
         // We need to handle the case of the view not accepting to be a first responder,
@@ -324,27 +328,25 @@
     return _rootLayer;
 }
 
-- (void)sendEvent:(WebEvent *)anEvent
+- (void)sendEvent:(WebEvent *)event
 {
-    ASSERT(anEvent);
+    ASSERT(event);
     WebThreadRun(^{
-        [self sendEventSynchronously:anEvent];
+        [self sendEventSynchronously:event];
     });
 }
 
-- (void)sendEventSynchronously:(WebEvent *)anEvent
+- (void)sendEventSynchronously:(WebEvent *)event
 {
-    ASSERT(anEvent);
+    ASSERT(event);
     ASSERT(WebThreadIsLockedOrDisabled());
-    WebEvent *lastEvent = currentEvent;
-    auto currentEventProtector = retainPtr(anEvent);
-    currentEvent = anEvent;
+    auto lastEvent = std::exchange(currentEvent(), event);
 
-    switch (anEvent.type) {
+    switch (event.type) {
     case WebEventMouseMoved:
     case WebEventScrollWheel:
-        if (WAKView *hitView = [_contentView hitTest:(anEvent.locationInWindow)])
-            [hitView handleEvent:anEvent];
+        if (WAKView *hitView = [_contentView hitTest:event.locationInWindow])
+            [hitView handleEvent:event];
         break;
 
     case WebEventMouseUp:
@@ -351,7 +353,7 @@
     case WebEventKeyDown:
     case WebEventKeyUp:
     case WebEventTouchChange:
-        [_responderView handleEvent:anEvent];
+        [_responderView handleEvent:event];
         break;
 
     case WebEventMouseDown:
@@ -358,20 +360,20 @@
     case WebEventTouchBegin:
     case WebEventTouchEnd:
     case WebEventTouchCancel:
-        if (WAKView *hitView = [_contentView hitTest:(anEvent.locationInWindow)]) {
+        if (WAKView *hitView = [_contentView hitTest:event.locationInWindow]) {
             [self makeFirstResponder:hitView];
-            [hitView handleEvent:anEvent];
+            [hitView handleEvent:event];
         }
         break;
     }
 
-    currentEvent = lastEvent;
+    currentEvent() = WTFMove(lastEvent);
 }
 
-- (void)sendMouseMoveEvent:(WebEvent *)anEvent contentChange:(WKContentChange *)aContentChange
+- (void)sendMouseMoveEvent:(WebEvent *)event contentChange:(WKContentChange *)aContentChange
 {
     WebThreadRun(^{
-        [self sendEvent:anEvent];
+        [self sendEvent:event];
 
         if (aContentChange) {
             // We always make the decision asynchronously. See EventHandler::mouseMoved.
@@ -416,7 +418,7 @@
 {
     if (!_tileCache)
         return;
-    _tileCache->layoutTilesNowForRect(enclosingIntRect(rect));
+    _tileCache->layoutTilesNowForRect(WebCore::enclosingIntRect(rect));
 }
 
 - (void)setNeedsDisplay
@@ -430,7 +432,7 @@
 {
     if (!_tileCache)
         return;
-    _tileCache->setNeedsDisplayInRect(enclosingIntRect(rect));
+    _tileCache->setNeedsDisplayInRect(WebCore::enclosingIntRect(rect));
 }
 
 - (BOOL)tilesOpaque
@@ -600,13 +602,6 @@
     return _tileCache;
 }
 
-- (BOOL)hasPendingDraw
-{
-    if (!_tileCache)
-        return NO;
-     return _tileCache->hasPendingDraw();
-}
-
 - (void)setContentReplacementImage:(CGImageRef)contentReplacementImage
 {
     if (!_tileCache)
@@ -628,21 +623,11 @@
 
 - (void)willRotate
 {
-    [self freezeVisibleRect];
+    _frozenVisibleRect = [self visibleRect];
 }
 
 - (void)didRotate
 {
-    [self unfreezeVisibleRect];
-}
-
-- (void)freezeVisibleRect
-{
-    _frozenVisibleRect = [self visibleRect];
-}
-
-- (void)unfreezeVisibleRect
-{
     _frozenVisibleRect = CGRectNull;
 }
 
@@ -649,13 +634,13 @@
 + (void)setOrientationProvider:(id)provider
 {
     // This is really the UIWebDocumentView class that calls into UIApplication to get the orientation.
-    gOrientationProvider = provider;
+    orientationProvider() = provider;
 }
 
 + (BOOL)hasLandscapeOrientation
 {
     // this should be perfectly thread safe
-    return [gOrientationProvider hasLandscapeOrientation];
+    return [orientationProvider() hasLandscapeOrientation];
 }
 
 - (CALayer*)hostLayer
@@ -663,30 +648,6 @@
     return _hostLayer;
 }
 
-- (void)setTileBordersVisible:(BOOL)visible
-{
-    if (!_tileCache)
-        return;
-
-    _tileCache->setTileBordersVisible(visible);
-}
-
-- (void)setTilePaintCountsVisible:(BOOL)visible
-{
-    if (!_tileCache)
-        return;
-
-    _tileCache->setTilePaintCountersVisible(visible);
-}
-
-- (void)setAcceleratedDrawingEnabled:(BOOL)enabled
-{
-    if (!_tileCache)
-        return;
-
-    _tileCache->setAcceleratedDrawingEnabled(enabled);
-}
-
 - (void)dumpTiles
 {
     CGRect savedFrozenVisibleRect = _frozenVisibleRect;
@@ -701,14 +662,6 @@
     _tileCache->dumpTiles();
 }
 
-- (void)setTileControllerShouldUseLowScaleTiles:(BOOL)lowScaleTiles 
-{ 
-    if (!_tileCache) 
-        return; 
-
-    _tileCache->setTileControllerShouldUseLowScaleTiles(lowScaleTiles); 
-} 
-
 - (NSString *)description
 {
     NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: WAK: %p; ", [self class], self];
@@ -726,7 +679,7 @@
 
 + (WebEvent *)currentEvent
 {
-    return currentEvent;
+    return currentEvent().get();
 }
 
 - (NSString *)recursiveDescription

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (273461 => 273462)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-02-25 01:04:09 UTC (rev 273462)
@@ -1,3 +1,15 @@
+2021-02-23  Darin Adler  <da...@apple.com>
+
+        [iOS] Reduce use of retain/release in WAKWindow and remove unneeded methods from that class
+        https://bugs.webkit.org/show_bug.cgi?id=222330
+
+        Reviewed by Chris Dumez.
+
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]): Call LegacyTileCache functions directly rather
+        than indirecting through WAKWindow methods.
+        (-[WebView viewDidMoveToWindow]): Ditto. Also tweaked conditionals a little for clarity.
+
 2021-02-22  Chris Dumez  <cdu...@apple.com>
 
         Use adoptNS() as soon as we [[ObjcClass alloc] init] to avoid leaks

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (273461 => 273462)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2021-02-25 00:57:53 UTC (rev 273461)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2021-02-25 01:04:09 UTC (rev 273462)
@@ -2966,9 +2966,11 @@
         [self _setZoomMultiplier:_private->zoomMultiplier isTextOnly:zoomsTextOnly];
 
 #if PLATFORM(IOS_FAMILY)
-    [[self window] setTileBordersVisible:[preferences showDebugBorders]];
-    [[self window] setTilePaintCountsVisible:[preferences showRepaintCounter]];
-    [[self window] setAcceleratedDrawingEnabled:[preferences acceleratedDrawingEnabled]];
+    if (auto tileCache = self.window.tileCache) {
+        tileCache->setTileBordersVisible(preferences.showDebugBorders);
+        tileCache->setTilePaintCountersVisible(preferences.showRepaintCounter);
+        tileCache->setAcceleratedDrawingEnabled(preferences.acceleratedDrawingEnabled);
+    }
     [WAKView _setInterpolationQuality:[preferences _interpolationQuality]];
 #endif
 }
@@ -5642,11 +5644,12 @@
         _private->page->setIsInWindow(true);
 
 #if PLATFORM(IOS_FAMILY)
-        WebPreferences *preferences = [self preferences];
-        NSWindow *window = [self window];
-        [window setTileBordersVisible:[preferences showDebugBorders]];
-        [window setTilePaintCountsVisible:[preferences showRepaintCounter]];
-        [window setAcceleratedDrawingEnabled:[preferences acceleratedDrawingEnabled]];
+        auto preferences = self.preferences;
+        if (auto tileCache = self.window.tileCache) {
+            tileCache->setTileBordersVisible(preferences.showDebugBorders);
+            tileCache->setTilePaintCountersVisible(preferences.showRepaintCounter);
+            tileCache->setAcceleratedDrawingEnabled(preferences.acceleratedDrawingEnabled);
+        }
 #endif
     }
 #if PLATFORM(IOS_FAMILY)
@@ -5654,11 +5657,9 @@
         [_private->fullscreenController requestHideAndExitFullscreen];
 #endif
 
-#if !PLATFORM(IOS_FAMILY)
+#if PLATFORM(MAC)
     _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
-#endif
 
-#if PLATFORM(MAC)
     if (_private->immediateActionController) {
         NSImmediateActionGestureRecognizer *recognizer = [_private->immediateActionController immediateActionRecognizer];
         if ([self window]) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to