Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,25 @@ void Shell::OnFrameRasterized(const FrameTiming& timing) {
},
fml::TimeDelta::FromMilliseconds(kBatchTimeInMilliseconds));
}

{
FML_LOG(ERROR) << "FireOnFrameRasteized";
std::scoped_lock lock(on_frame_rasterized_listener_mutex_);
for (auto pair : on_frame_rasterized_map_) {
auto value_pair = pair.second;
fml::closure callback = value_pair.second;
fml::AutoResetWaitableEvent latch;
fml::TaskRunner::RunNowOrPostTask(value_pair.first, [callback, &latch] {
callback();
FML_LOG(ERROR) << "Single1";
latch.Signal();
FML_LOG(ERROR) << "Single2";
});
FML_LOG(ERROR) << "Wait1";
latch.Wait();
FML_LOG(ERROR) << "Wait2";
}
}
}

fml::Milliseconds Shell::GetFrameBudget() {
Expand Down Expand Up @@ -1749,6 +1768,21 @@ void Shell::RegisterImageDecoder(ImageGeneratorFactory factory,
});
}

void Shell::RegisterOnFrameRasterizedCallback(
const std::string_view& key,
const fml::closure& callback,
const fml::RefPtr<fml::TaskRunner>& taskRunner) {
FML_LOG(ERROR) << "RegisterOnFrameRasterizedCallback";
std::scoped_lock lock(on_frame_rasterized_listener_mutex_);
on_frame_rasterized_map_[key] = {taskRunner, callback};
}

void Shell::UnregisterOnFrameRasterizedCallback(const std::string_view& key) {
FML_LOG(ERROR) << "UnregisterOnFrameRasterizedCallback";
std::scoped_lock lock(on_frame_rasterized_listener_mutex_);
on_frame_rasterized_map_.erase(key);
}

bool Shell::OnServiceProtocolGetSkSLs(
const ServiceProtocol::Handler::ServiceProtocolMap& params,
rapidjson::Document* response) {
Expand Down
18 changes: 18 additions & 0 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ class Shell final : public PlatformView::Delegate,
/// @see `CreateCompatibleGenerator`
void RegisterImageDecoder(ImageGeneratorFactory factory, int32_t priority);

/// TODO: Add comments.
void RegisterOnFrameRasterizedCallback(
const std::string_view& key,
const fml::closure& callback,
const fml::RefPtr<fml::TaskRunner>& taskRunner);

/// TODO: Add comments
void UnregisterOnFrameRasterizedCallback(const std::string_view& key);

// |Engine::Delegate|
const std::shared_ptr<PlatformMessageHandler>& GetPlatformMessageHandler()
const override;
Expand Down Expand Up @@ -474,6 +483,15 @@ class Shell final : public PlatformView::Delegate,
// Used to communicate the right frame bounds via service protocol.
double device_pixel_ratio_ = 0.0;

// Manage the listeners that get notified when |OnFrameRasterized|
std::mutex on_frame_rasterized_listener_mutex_;
std::unordered_map<std::string_view, // listener key
std::pair<fml::RefPtr<fml::TaskRunner>,
fml::closure> // task-runner/function
// pair
>
on_frame_rasterized_map_;

// How many frames have been timed since last report.
size_t UnreportedFramesCount() const;

Expand Down
29 changes: 12 additions & 17 deletions shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,9 @@ - (void)setupKeyboardSpringAnimationIfNeeded:(CAAnimation*)keyboardAnimation {
toValue:self.targetViewInsetBottom]);
}

/// TODO rename to `registerOnFrameRasterizedCallback`
- (void)setupKeyboardAnimationVsyncClient {
auto callback = [weakSelf =
[self getWeakPtr]](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {
auto onFrameRasterizedCallback = [weakSelf = [self getWeakPtr]] {
if (!weakSelf) {
return;
}
Expand All @@ -1600,7 +1600,8 @@ - (void)setupKeyboardAnimationVsyncClient {
}

if ([flutterViewController keyboardAnimationView].superview == nil) {
// Ensure the keyboardAnimationView is in view hierarchy when animation running.
// Ensure the keyboardAnimationView is in view hierarchy when
// animation running.
[flutterViewController.get().view addSubview:[flutterViewController keyboardAnimationView]];
}

Expand All @@ -1612,28 +1613,22 @@ - (void)setupKeyboardAnimationVsyncClient {
[flutterViewController updateViewportMetrics];
}
} else {
fml::TimeDelta timeElapsed = recorder.get()->GetVsyncTargetTime() -
flutterViewController.get().keyboardAnimationStartTime;

fml::TimeDelta timeElapsed =
fml::TimePoint::Now() - flutterViewController.get().keyboardAnimationStartTime;
flutterViewController.get()->_viewportMetrics.physical_view_inset_bottom =
[[flutterViewController keyboardSpringAnimation] curveFunction:timeElapsed.ToSecondsF()];
[flutterViewController updateViewportMetrics];
}
};
};
flutter::Shell& shell = [_engine.get() shell];
NSAssert(_keyboardAnimationVSyncClient == nil,
@"_keyboardAnimationVSyncClient must be nil when setup");
_keyboardAnimationVSyncClient =
[[VSyncClient alloc] initWithTaskRunner:shell.GetTaskRunners().GetPlatformTaskRunner()
callback:callback];
_keyboardAnimationVSyncClient.allowPauseAfterVsync = NO;
[_keyboardAnimationVSyncClient await];
shell.RegisterOnFrameRasterizedCallback("flutterVCKeyboard", onFrameRasterizedCallback,
shell.GetTaskRunners().GetPlatformTaskRunner());
}

/// TODO rename to `unregisterOnFrameRasterizedCallback`
- (void)invalidateKeyboardAnimationVSyncClient {
[_keyboardAnimationVSyncClient invalidate];
[_keyboardAnimationVSyncClient release];
_keyboardAnimationVSyncClient = nil;
flutter::Shell& shell = [_engine.get() shell];
shell.UnregisterOnFrameRasterizedCallback("flutterVCKeyboard");
}

- (void)removeKeyboardAnimationView {
Expand Down