Add API to force redraw of flutter view (#24186)

Currently when creating hidden window and showing it later the content does not get repainted automatically (unless something else triggers the repaint). This adds public `FlutterDesktopViewControllerForceRedraw()` to trigger repaint. The current implementation triggers this via a call to `SendWindowMetrics` but this should eventually be replaced by an embedder API call.

See: https://github.com/flutter/flutter/issues/75319
See: https://github.com/flutter/flutter/issues/69716
This commit is contained in:
Matej Knopp 2021-02-05 18:56:52 +01:00 committed by GitHub
parent 368bacf453
commit d1a763c17c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

View File

@ -64,6 +64,9 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView(
return reinterpret_cast<FlutterDesktopViewRef>(1);
}
void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller) {}
bool FlutterDesktopViewControllerHandleTopLevelWindowProc(
FlutterDesktopViewControllerRef controller,
HWND hwnd,

View File

@ -76,6 +76,11 @@ FlutterDesktopViewRef FlutterDesktopViewControllerGetView(
return HandleForView(controller->view.get());
}
void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller) {
controller->view->ForceRedraw();
}
FlutterDesktopEngineRef FlutterDesktopEngineCreate(
const FlutterDesktopEngineProperties& engine_properties) {
flutter::FlutterProjectBundle project(engine_properties);

View File

@ -95,6 +95,16 @@ uint32_t FlutterWindowsView::GetFrameBufferId(size_t width, size_t height) {
return kWindowFrameBufferID;
}
void FlutterWindowsView::ForceRedraw() {
if (resize_status_ == ResizeState::kDone) {
// Request new frame
// TODO(knopp): Replace with more specific call once there is API for it
// https://github.com/flutter/flutter/issues/69716
SendWindowMetrics(resize_target_width_, resize_target_height_,
binding_handler_->GetDpiScale());
}
}
void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
// Called on the platform thread.
std::unique_lock<std::mutex> lock(resize_mutex_);

View File

@ -64,6 +64,9 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
// Returns the engine backing this view.
FlutterWindowsEngine* GetEngine();
// Tells the engine to generate a new frame
void ForceRedraw();
// Callbacks for clearing context, settings context and swapping buffers,
// these are typically called on an engine-controlled (non-platform) thread.
bool ClearContext();

View File

@ -107,6 +107,10 @@ FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(
FLUTTER_EXPORT FlutterDesktopViewRef
FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller);
// Requests new frame from engine and repaints the view
FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller);
#ifndef WINUWP
// Allows the Flutter engine and any interested plugins an opportunity to
// handle the given message.