mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-12-01 01:53:27 +01:00
79 lines
2.5 KiB
Diff
79 lines
2.5 KiB
Diff
diff --git a/apple/worklets/apple/AnimationFrameQueue.mm b/apple/worklets/apple/AnimationFrameQueue.mm
|
|
index c064030..415e5f7 100644
|
|
--- a/apple/worklets/apple/AnimationFrameQueue.mm
|
|
+++ b/apple/worklets/apple/AnimationFrameQueue.mm
|
|
@@ -18,6 +18,9 @@
|
|
#import <React/RCTUtils.h>
|
|
|
|
constexpr auto TIME_SAMPLES_AMOUNT = 4;
|
|
+// Scroll-driven mappers request one frame per scroll event. Pausing the display link after each
|
|
+// of those frames toggles it every vsync, which halves ProMotion scroll deceleration to 30 Hz.
|
|
+constexpr auto IDLE_FRAMES_BEFORE_PAUSE = 4;
|
|
|
|
namespace FrameRateRange {
|
|
const auto BEST = CAFrameRateRangeMake(60, 120, 120);
|
|
@@ -34,6 +37,7 @@ const auto POOR = CAFrameRateRangeMake(10, 24, 24);
|
|
std::chrono::duration<double, std::milli> timeDeltas_[TIME_SAMPLES_AMOUNT];
|
|
int timeDeltaIndex_;
|
|
CAFrameRateRange currentFrameRate_;
|
|
+ int idleFrames_;
|
|
}
|
|
|
|
typedef void (^AnimationFrameCallback)(WorkletsDisplayLink *displayLink);
|
|
@@ -70,11 +74,10 @@ typedef void (^AnimationFrameCallback)(WorkletsDisplayLink *displayLink);
|
|
|
|
- (void)requestAnimationFrame:(std::function<void(double)>)callback
|
|
{
|
|
- {
|
|
- std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
- frameCallbacks_.push_back(callback);
|
|
- }
|
|
- [self scheduleQueueExecution];
|
|
+ std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
+ frameCallbacks_.push_back(callback);
|
|
+ idleFrames_ = 0;
|
|
+ [displayLink_ setPaused:FALSE];
|
|
}
|
|
|
|
- (void)invalidate
|
|
@@ -85,17 +88,21 @@ typedef void (^AnimationFrameCallback)(WorkletsDisplayLink *displayLink);
|
|
|
|
#pragma mark-- private
|
|
|
|
-- (void)scheduleQueueExecution
|
|
-{
|
|
- [displayLink_ setPaused:FALSE];
|
|
-}
|
|
-
|
|
- (void)executeQueue:(WorkletsDisplayLink *)displayLink
|
|
{
|
|
RCTAssertMainQueue();
|
|
|
|
- auto frameCallbacks = [self pullCallbacks];
|
|
- [displayLink_ setPaused:TRUE];
|
|
+ std::vector<std::function<void(double)>> frameCallbacks;
|
|
+ {
|
|
+ std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
+ frameCallbacks.swap(frameCallbacks_);
|
|
+ if (frameCallbacks.empty()) {
|
|
+ if (++idleFrames_ >= IDLE_FRAMES_BEFORE_PAUSE) {
|
|
+ [displayLink_ setPaused:TRUE];
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
|
|
#if TARGET_OS_OSX
|
|
auto targetTimestamp = displayLink.timestamp + displayLink.duration;
|
|
@@ -143,11 +150,4 @@ typedef void (^AnimationFrameCallback)(WorkletsDisplayLink *displayLink);
|
|
}
|
|
}
|
|
|
|
-- (std::vector<std::function<void(double)>>)pullCallbacks
|
|
-{
|
|
- RCTAssertMainQueue();
|
|
- std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
- return std::move(frameCallbacks_);
|
|
-}
|
|
-
|
|
@end
|