Skip to content

Commit

Permalink
[iOS] run keyboard scrolling animations at a higher frame rate when p…
Browse files Browse the repository at this point in the history
…ossible

https://bugs.webkit.org/show_bug.cgi?id=268850
rdar://122323815

Reviewed by Simon Fraser.

In 273122@main we opted into higher frame rate animations when performed by Core Animation on
qualifying hardware. We now do the same with scrolling animations resulting from interacting
with the keyboard (such as pressing the space bar) by setting similar properties on the
`CADisplayLink` created by `WKKeyboardScrollingAnimator`. Because we now have two different
places where we opt into a higher frame rate, we distinguish between the two cases by using
a different `CAHighFrameRateReason` value.

* Source/WebCore/PAL/pal/spi/cocoa/QuartzCoreSPI.h:
* Source/WebKit/Platform/cocoa/CAFrameRateRangeUtilities.h: Added.
(WebKit::highFrameRateRange):
* Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm:
(-[WKKeyboardScrollingAnimator startDisplayLinkIfNeeded]):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
(WebKit::createAnimation):
(highFrameRateRange): Deleted.

Canonical link: https://commits.webkit.org/274234@main
  • Loading branch information
graouts committed Feb 7, 2024
1 parent 4ad01b4 commit 0eec24a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Source/WebCore/PAL/pal/spi/cocoa/QuartzCoreSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ typedef uint32_t CAHighFrameRateReason;
@interface CAAnimation ()
@property CAHighFrameRateReason highFrameRateReason;
@end

@interface CADisplayLink ()
@property CAHighFrameRateReason highFrameRateReason;
@end
#endif // HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)

#endif // __OBJC__
Expand Down
47 changes: 47 additions & 0 deletions Source/WebKit/Platform/cocoa/CAFrameRateRangeUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)

#import <pal/spi/cocoa/QuartzCoreSPI.h>

namespace WebKit {

#define WEBKIT_HIGH_FRAME_RATE_REASON_COMPONENT 44

static CAFrameRateRange highFrameRateRange()
{
static CAFrameRateRange highFrameRateRange = CAFrameRateRangeMake(80, 120, 120);
return highFrameRateRange;
}

static CAHighFrameRateReason webAnimationHighFrameRateReason = CAHighFrameRateReasonMake(WEBKIT_HIGH_FRAME_RATE_REASON_COMPONENT, 1);
static CAHighFrameRateReason keyboardScrollingAnimationHighFrameRateReason = CAHighFrameRateReasonMake(WEBKIT_HIGH_FRAME_RATE_REASON_COMPONENT, 2);

}

#endif // HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)
12 changes: 12 additions & 0 deletions Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if PLATFORM(IOS_FAMILY)

#import "AccessibilitySupportSPI.h"
#import "CAFrameRateRangeUtilities.h"
#import "UIKitSPI.h"
#import "UIKitUtilities.h"
#import "WKVelocityTrackingScrollView.h"
Expand All @@ -43,6 +44,10 @@
#import <wtf/RetainPtr.h>
#import <wtf/WeakObjCPtr.h>

#if HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)
#import <pal/spi/cocoa/QuartzCoreSPI.h>
#endif

@protocol WKKeyboardScrollableInternal <NSObject>
@required
- (BOOL)isKeyboardScrollable;
Expand Down Expand Up @@ -434,6 +439,13 @@ - (void)startDisplayLinkIfNeeded
return;

_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkFired:)];

#if HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)
// Opt into a higher frame-rate for displays that support higher refresh rates.
[_displayLink setPreferredFrameRateRange:WebKit::highFrameRateRange()];
[_displayLink setHighFrameRateReason:WebKit::keyboardScrollingAnimationHighFrameRateReason];
#endif // HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)

[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}

Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@
6D9A666E2A27FAE300BD68A0 /* WebTouchEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4001002527D73C00E91DA7 /* WebTouchEvent.h */; };
6EE849C81368D9390038D481 /* WKInspectorPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
711725A9228D564300018514 /* WebsiteLegacyOverflowScrollingTouchPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 711725A8228D563A00018514 /* WebsiteLegacyOverflowScrollingTouchPolicy.h */; };
7121A3CF2B73728B00C8F7A4 /* CAFrameRateRangeUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7121A3CE2B73727B00C8F7A4 /* CAFrameRateRangeUtilities.h */; };
7134A3DA2603B92500624BD3 /* WKModelInteractionGestureRecognizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7134A3D92603B80E00624BD3 /* WKModelInteractionGestureRecognizer.h */; };
7137BA8025F1542000914EE3 /* ModelElementController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7137BA7F25F1540C00914EE3 /* ModelElementController.h */; };
71A676A622C62325007D6295 /* WKTouchActionGestureRecognizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 71A676A422C62318007D6295 /* WKTouchActionGestureRecognizer.h */; };
Expand Down Expand Up @@ -6149,6 +6150,7 @@
6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = com.apple.WebProcess.sb.in; path = WebProcess/com.apple.WebProcess.sb.in; sourceTree = "<group>"; };
6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKInspectorPrivateMac.h; path = mac/WKInspectorPrivateMac.h; sourceTree = "<group>"; };
711725A8228D563A00018514 /* WebsiteLegacyOverflowScrollingTouchPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteLegacyOverflowScrollingTouchPolicy.h; sourceTree = "<group>"; };
7121A3CE2B73727B00C8F7A4 /* CAFrameRateRangeUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CAFrameRateRangeUtilities.h; sourceTree = "<group>"; };
7134A3D82603B80E00624BD3 /* WKModelInteractionGestureRecognizer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKModelInteractionGestureRecognizer.mm; path = ios/WKModelInteractionGestureRecognizer.mm; sourceTree = "<group>"; };
7134A3D92603B80E00624BD3 /* WKModelInteractionGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKModelInteractionGestureRecognizer.h; path = ios/WKModelInteractionGestureRecognizer.h; sourceTree = "<group>"; };
71371D1E2B1F89C00092C32D /* RemoteAcceleratedEffectStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteAcceleratedEffectStack.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11608,6 +11610,7 @@
07E4BDC62A3A7089000D5509 /* _WKWebViewTextInputNotifications.mm */,
A1D615662B06BBAB002D0E19 /* AssertionCapability.h */,
A1D615632B06BBAB002D0E19 /* AssertionCapability.mm */,
7121A3CE2B73727B00C8F7A4 /* CAFrameRateRangeUtilities.h */,
1C62747B288B4C3E00CED3A2 /* CocoaHelpers.h */,
1C62747C288B4C3E00CED3A2 /* CocoaHelpers.mm */,
4482734624528F6000A95493 /* CocoaImage.h */,
Expand Down Expand Up @@ -15641,6 +15644,7 @@
935BF8042936BF1A00B41326 /* CacheStorageRecord.h in Headers */,
935BF8072936C9FD00B41326 /* CacheStorageRegistry.h in Headers */,
935BF7FF2936BF1A00B41326 /* CacheStorageStore.h in Headers */,
7121A3CF2B73728B00C8F7A4 /* CAFrameRateRangeUtilities.h in Headers */,
57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */,
1C62747D288B4C3E00CED3A2 /* CocoaHelpers.h in Headers */,
4482734724528F6000A95493 /* CocoaImage.h in Headers */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "PlatformCAAnimationRemote.h"

#import "ArgumentCoders.h"
#import "CAFrameRateRangeUtilities.h"
#import "RemoteLayerTreeHost.h"
#import "WKAnimationDelegate.h"
#import "WebCoreArgumentCoders.h"
Expand All @@ -46,16 +47,6 @@ static MonotonicTime mediaTimeToCurrentTime(CFTimeInterval t)
return WTF::MonotonicTime::now() + Seconds(t - CACurrentMediaTime());
}

#if HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)
static CAFrameRateRange highFrameRateRange()
{
static CAFrameRateRange highFrameRateRange = CAFrameRateRangeMake(80, 120, 120);
return highFrameRateRange;
}

static CAHighFrameRateReason highFrameRateReason = CAHighFrameRateReasonMake(44, 0);
#endif // HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)

static NSString * const WKExplicitBeginTimeFlag = @"WKPlatformCAAnimationExplicitBeginTimeFlag";

@interface WKAnimationDelegate () <CAAnimationDelegate>
Expand Down Expand Up @@ -614,8 +605,8 @@ - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished

#if HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)
// Opt into a higher frame-rate for displays that support higher refresh rates.
[caAnimation setPreferredFrameRateRange:highFrameRateRange()];
[caAnimation setHighFrameRateReason:highFrameRateReason];
[caAnimation setPreferredFrameRateRange:WebKit::highFrameRateRange()];
[caAnimation setHighFrameRateReason:WebKit::webAnimationHighFrameRateReason];
#endif // HAVE(CORE_ANIMATION_FRAME_RATE_RANGE)

return caAnimation;
Expand Down

0 comments on commit 0eec24a

Please sign in to comment.