| Flutter Windows Embedder |

flutter_windows_view.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/windows/flutter_windows_view.h"
6
7 #include <chrono>
8
9 #include "flutter/fml/platform/win/wstring_conversion.h"
10 #include "flutter/shell/platform/common/accessibility_bridge.h"
11 #include "flutter/shell/platform/windows/keyboard_key_channel_handler.h"
12 #include "flutter/shell/platform/windows/text_input_plugin.h"
13 #include "flutter/third_party/accessibility/ax/platform/ax_platform_node_win.h"
14
15 namespace flutter {
16
17 namespace {
18 // The maximum duration to block the platform thread for while waiting
19 // for a window resize operation to complete.
20 constexpr std::chrono::milliseconds kWindowResizeTimeout{100};
21
22 /// Returns true if the surface will be updated as part of the resize process.
23 ///
24 /// This is called on window resize to determine if the platform thread needs
25 /// to be blocked until the frame with the right size has been rendered. It
26 /// should be kept in-sync with how the engine deals with a new surface request
27 /// as seen in `CreateOrUpdateSurface` in `GPUSurfaceGL`.
28 bool SurfaceWillUpdate(size_t cur_width,
29 size_t cur_height,
30 size_t target_width,
31 size_t target_height) {
32 // TODO (https://github.com/flutter/flutter/issues/65061) : Avoid special
33 // handling for zero dimensions.
34 bool non_zero_target_dims = target_height > 0 && target_width > 0;
35 bool not_same_size =
36 (cur_height != target_height) || (cur_width != target_width);
37 return non_zero_target_dims && not_same_size;
38 }
39 } // namespace
40
41 FlutterWindowsView::FlutterWindowsView(
42 std::unique_ptr<WindowBindingHandler> window_binding) {
43 // Take the binding handler, and give it a pointer back to self.
44 binding_handler_ = std::move(window_binding);
45 binding_handler_->SetView(this);
46
47 render_target_ = std::make_unique<WindowsRenderTarget>(
48 binding_handler_->GetRenderTarget());
49 }
50
51 FlutterWindowsView::~FlutterWindowsView() {
52 // The engine renders into the view's surface. The engine must be
53 // shutdown before the view's resources can be destroyed.
54 if (engine_) {
55 engine_->Stop();
56 }
57
58 DestroyRenderSurface();
59 }
60
61 void FlutterWindowsView::SetEngine(
62 std::unique_ptr<FlutterWindowsEngine> engine) {
63 engine_ = std::move(engine);
64
65 engine_->SetView(this);
66
67 PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
68
69 SendWindowMetrics(bounds.width, bounds.height,
70 binding_handler_->GetDpiScale());
71 }
72
73 uint32_t FlutterWindowsView::GetFrameBufferId(size_t width, size_t height) {
74 // Called on an engine-controlled (non-platform) thread.
75 std::unique_lock<std::mutex> lock(resize_mutex_);
76
77 if (resize_status_ != ResizeState::kResizeStarted) {
78 return kWindowFrameBufferID;
79 }
80
81 if (resize_target_width_ == width && resize_target_height_ == height) {
82 // Platform thread is blocked for the entire duration until the
83 // resize_status_ is set to kDone.
84 engine_->surface_manager()->ResizeSurface(GetRenderTarget(), width, height,
85 binding_handler_->NeedsVSync());
86 resize_status_ = ResizeState::kFrameGenerated;
87 }
88
89 return kWindowFrameBufferID;
90 }
91
92 void FlutterWindowsView::UpdateFlutterCursor(const std::string& cursor_name) {
93 binding_handler_->UpdateFlutterCursor(cursor_name);
94 }
95
96 void FlutterWindowsView::SetFlutterCursor(HCURSOR cursor) {
97 binding_handler_->SetFlutterCursor(cursor);
98 }
99
100 void FlutterWindowsView::ForceRedraw() {
101 if (resize_status_ == ResizeState::kDone) {
102 // Request new frame.
103 engine_->ScheduleFrame();
104 }
105 }
106
107 void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
108 // Called on the platform thread.
109 std::unique_lock<std::mutex> lock(resize_mutex_);
110
111 if (!engine_->surface_manager()) {
112 SendWindowMetrics(width, height, binding_handler_->GetDpiScale());
113 return;
114 }
115
116 EGLint surface_width, surface_height;
117 engine_->surface_manager()->GetSurfaceDimensions(&surface_width,
118 &surface_height);
119
120 bool surface_will_update =
121 SurfaceWillUpdate(surface_width, surface_height, width, height);
122 if (surface_will_update) {
123 resize_status_ = ResizeState::kResizeStarted;
124 resize_target_width_ = width;
125 resize_target_height_ = height;
126 }
127
128 SendWindowMetrics(width, height, binding_handler_->GetDpiScale());
129
130 if (surface_will_update) {
131 // Block the platform thread until:
132 // 1. GetFrameBufferId is called with the right frame size.
133 // 2. Any pending SwapBuffers calls have been invoked.
134 resize_cv_.wait_for(lock, kWindowResizeTimeout,
135 [&resize_status = resize_status_] {
136 return resize_status == ResizeState::kDone;
137 });
138 }
139 }
140
141 void FlutterWindowsView::OnWindowRepaint() {
142 ForceRedraw();
143 }
144
145 void FlutterWindowsView::OnPointerMove(double x,
146 double y,
147 FlutterPointerDeviceKind device_kind,
148 int32_t device_id,
149 int modifiers_state) {
150 engine_->keyboard_key_handler()->SyncModifiersIfNeeded(modifiers_state);
151 SendPointerMove(x, y, GetOrCreatePointerState(device_kind, device_id));
152 }
153
154 void FlutterWindowsView::OnPointerDown(
155 double x,
156 double y,
157 FlutterPointerDeviceKind device_kind,
158 int32_t device_id,
159 FlutterPointerMouseButtons flutter_button) {
160 if (flutter_button != 0) {
161 auto state = GetOrCreatePointerState(device_kind, device_id);
162 state->buttons |= flutter_button;
163 SendPointerDown(x, y, state);
164 }
165 }
166
167 void FlutterWindowsView::OnPointerUp(
168 double x,
169 double y,
170 FlutterPointerDeviceKind device_kind,
171 int32_t device_id,
172 FlutterPointerMouseButtons flutter_button) {
173 if (flutter_button != 0) {
174 auto state = GetOrCreatePointerState(device_kind, device_id);
175 state->buttons &= ~flutter_button;
176 SendPointerUp(x, y, state);
177 }
178 }
179
180 void FlutterWindowsView::OnPointerLeave(double x,
181 double y,
182 FlutterPointerDeviceKind device_kind,
183 int32_t device_id) {
184 SendPointerLeave(x, y, GetOrCreatePointerState(device_kind, device_id));
185 }
186
187 void FlutterWindowsView::OnPointerPanZoomStart(int32_t device_id) {
188 PointerLocation point = binding_handler_->GetPrimaryPointerLocation();
189 SendPointerPanZoomStart(device_id, point.x, point.y);
190 }
191
192 void FlutterWindowsView::OnPointerPanZoomUpdate(int32_t device_id,
193 double pan_x,
194 double pan_y,
195 double scale,
196 double rotation) {
197 SendPointerPanZoomUpdate(device_id, pan_x, pan_y, scale, rotation);
198 }
199
200 void FlutterWindowsView::OnPointerPanZoomEnd(int32_t device_id) {
201 SendPointerPanZoomEnd(device_id);
202 }
203
204 void FlutterWindowsView::OnText(const std::u16string& text) {
205 SendText(text);
206 }
207
208 void FlutterWindowsView::OnKey(int key,
209 int scancode,
210 int action,
211 char32_t character,
212 bool extended,
213 bool was_down,
214 KeyEventCallback callback) {
215 SendKey(key, scancode, action, character, extended, was_down, callback);
216 }
217
218 void FlutterWindowsView::OnComposeBegin() {
219 SendComposeBegin();
220 }
221
222 void FlutterWindowsView::OnComposeCommit() {
223 SendComposeCommit();
224 }
225
226 void FlutterWindowsView::OnComposeEnd() {
227 SendComposeEnd();
228 }
229
230 void FlutterWindowsView::OnComposeChange(const std::u16string& text,
231 int cursor_pos) {
232 SendComposeChange(text, cursor_pos);
233 }
234
235 void FlutterWindowsView::OnScroll(double x,
236 double y,
237 double delta_x,
238 double delta_y,
239 int scroll_offset_multiplier,
240 FlutterPointerDeviceKind device_kind,
241 int32_t device_id) {
242 SendScroll(x, y, delta_x, delta_y, scroll_offset_multiplier, device_kind,
243 device_id);
244 }
245
246 void FlutterWindowsView::OnScrollInertiaCancel(int32_t device_id) {
247 PointerLocation point = binding_handler_->GetPrimaryPointerLocation();
248 SendScrollInertiaCancel(device_id, point.x, point.y);
249 }
250
251 void FlutterWindowsView::OnUpdateSemanticsEnabled(bool enabled) {
252 engine_->UpdateSemanticsEnabled(enabled);
253 }
254
255 gfx::NativeViewAccessible FlutterWindowsView::GetNativeViewAccessible() {
256 if (!accessibility_bridge_) {
257 return nullptr;
258 }
259
260 return accessibility_bridge_->GetChildOfAXFragmentRoot();
261 }
262
263 void FlutterWindowsView::OnCursorRectUpdated(const Rect& rect) {
264 binding_handler_->OnCursorRectUpdated(rect);
265 }
266
267 void FlutterWindowsView::OnResetImeComposing() {
268 binding_handler_->OnResetImeComposing();
269 }
270
271 // Sends new size information to FlutterEngine.
272 void FlutterWindowsView::SendWindowMetrics(size_t width,
273 size_t height,
274 double dpiScale) const {
275 FlutterWindowMetricsEvent event = {};
276 event.struct_size = sizeof(event);
277 event.width = width;
278 event.height = height;
279 event.pixel_ratio = dpiScale;
280 engine_->SendWindowMetricsEvent(event);
281 }
282
283 void FlutterWindowsView::SendInitialBounds() {
284 PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
285
286 SendWindowMetrics(bounds.width, bounds.height,
287 binding_handler_->GetDpiScale());
288 }
289
290 FlutterWindowsView::PointerState* FlutterWindowsView::GetOrCreatePointerState(
291 FlutterPointerDeviceKind device_kind,
292 int32_t device_id) {
293 // Create a virtual pointer ID that is unique across all device types
294 // to prevent pointers from clashing in the engine's converter
295 // (lib/ui/window/pointer_data_packet_converter.cc)
296 int32_t pointer_id = (static_cast<int32_t>(device_kind) << 28) | device_id;
297
298 auto [it, added] = pointer_states_.try_emplace(pointer_id, nullptr);
299 if (added) {
300 auto state = std::make_unique<PointerState>();
301 state->device_kind = device_kind;
302 state->pointer_id = pointer_id;
303 it->second = std::move(state);
304 }
305
306 return it->second.get();
307 }
308
309 // Set's |event_data|'s phase to either kMove or kHover depending on the current
310 // primary mouse button state.
311 void FlutterWindowsView::SetEventPhaseFromCursorButtonState(
312 FlutterPointerEvent* event_data,
313 const PointerState* state) const {
314 // For details about this logic, see FlutterPointerPhase in the embedder.h
315 // file.
316 if (state->buttons == 0) {
317 event_data->phase = state->flutter_state_is_down
318 ? FlutterPointerPhase::kUp
319 : FlutterPointerPhase::kHover;
320 } else {
321 event_data->phase = state->flutter_state_is_down
322 ? FlutterPointerPhase::kMove
323 : FlutterPointerPhase::kDown;
324 }
325 }
326
327 void FlutterWindowsView::SendPointerMove(double x,
328 double y,
329 PointerState* state) {
330 FlutterPointerEvent event = {};
331 event.x = x;
332 event.y = y;
333
334 SetEventPhaseFromCursorButtonState(&event, state);
335 SendPointerEventWithData(event, state);
336 }
337
338 void FlutterWindowsView::SendPointerDown(double x,
339 double y,
340 PointerState* state) {
341 FlutterPointerEvent event = {};
342 event.x = x;
343 event.y = y;
344
345 SetEventPhaseFromCursorButtonState(&event, state);
346 SendPointerEventWithData(event, state);
347
348 state->flutter_state_is_down = true;
349 }
350
351 void FlutterWindowsView::SendPointerUp(double x,
352 double y,
353 PointerState* state) {
354 FlutterPointerEvent event = {};
355 event.x = x;
356 event.y = y;
357
358 SetEventPhaseFromCursorButtonState(&event, state);
359 SendPointerEventWithData(event, state);
360 if (event.phase == FlutterPointerPhase::kUp) {
361 state->flutter_state_is_down = false;
362 }
363 }
364
365 void FlutterWindowsView::SendPointerLeave(double x,
366 double y,
367 PointerState* state) {
368 FlutterPointerEvent event = {};
369 event.x = x;
370 event.y = y;
371 event.phase = FlutterPointerPhase::kRemove;
372 SendPointerEventWithData(event, state);
373 }
374
375 void FlutterWindowsView::SendPointerPanZoomStart(int32_t device_id,
376 double x,
377 double y) {
378 auto state =
379 GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);
380 state->pan_zoom_start_x = x;
381 state->pan_zoom_start_y = y;
382 FlutterPointerEvent event = {};
383 event.x = x;
384 event.y = y;
385 event.phase = FlutterPointerPhase::kPanZoomStart;
386 SendPointerEventWithData(event, state);
387 }
388
389 void FlutterWindowsView::SendPointerPanZoomUpdate(int32_t device_id,
390 double pan_x,
391 double pan_y,
392 double scale,
393 double rotation) {
394 auto state =
395 GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);
396 FlutterPointerEvent event = {};
397 event.x = state->pan_zoom_start_x;
398 event.y = state->pan_zoom_start_y;
399 event.pan_x = pan_x;
400 event.pan_y = pan_y;
401 event.scale = scale;
402 event.rotation = rotation;
403 event.phase = FlutterPointerPhase::kPanZoomUpdate;
404 SendPointerEventWithData(event, state);
405 }
406
407 void FlutterWindowsView::SendPointerPanZoomEnd(int32_t device_id) {
408 auto state =
409 GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);
410 FlutterPointerEvent event = {};
411 event.x = state->pan_zoom_start_x;
412 event.y = state->pan_zoom_start_y;
413 event.phase = FlutterPointerPhase::kPanZoomEnd;
414 SendPointerEventWithData(event, state);
415 }
416
417 void FlutterWindowsView::SendText(const std::u16string& text) {
418 engine_->text_input_plugin()->TextHook(text);
419 }
420
421 void FlutterWindowsView::SendKey(int key,
422 int scancode,
423 int action,
424 char32_t character,
425 bool extended,
426 bool was_down,
427 KeyEventCallback callback) {
428 engine_->keyboard_key_handler()->KeyboardHook(
429 key, scancode, action, character, extended, was_down,
430 [=, callback = std::move(callback)](bool handled) {
431 if (!handled) {
432 engine_->text_input_plugin()->KeyboardHook(
433 key, scancode, action, character, extended, was_down);
434 }
435 callback(handled);
436 });
437 }
438
439 void FlutterWindowsView::SendComposeBegin() {
440 engine_->text_input_plugin()->ComposeBeginHook();
441 }
442
443 void FlutterWindowsView::SendComposeCommit() {
444 engine_->text_input_plugin()->ComposeCommitHook();
445 }
446
447 void FlutterWindowsView::SendComposeEnd() {
448 engine_->text_input_plugin()->ComposeEndHook();
449 }
450
451 void FlutterWindowsView::SendComposeChange(const std::u16string& text,
452 int cursor_pos) {
453 engine_->text_input_plugin()->ComposeChangeHook(text, cursor_pos);
454 }
455
456 void FlutterWindowsView::SendScroll(double x,
457 double y,
458 double delta_x,
459 double delta_y,
460 int scroll_offset_multiplier,
461 FlutterPointerDeviceKind device_kind,
462 int32_t device_id) {
463 auto state = GetOrCreatePointerState(device_kind, device_id);
464
465 FlutterPointerEvent event = {};
466 event.x = x;
467 event.y = y;
468 event.signal_kind = FlutterPointerSignalKind::kFlutterPointerSignalKindScroll;
469 event.scroll_delta_x = delta_x * scroll_offset_multiplier;
470 event.scroll_delta_y = delta_y * scroll_offset_multiplier;
471 SetEventPhaseFromCursorButtonState(&event, state);
472 SendPointerEventWithData(event, state);
473 }
474
475 void FlutterWindowsView::SendScrollInertiaCancel(int32_t device_id,
476 double x,
477 double y) {
478 auto state =
479 GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);
480
481 FlutterPointerEvent event = {};
482 event.x = x;
483 event.y = y;
484 event.signal_kind =
485 FlutterPointerSignalKind::kFlutterPointerSignalKindScrollInertiaCancel;
486 SetEventPhaseFromCursorButtonState(&event, state);
487 SendPointerEventWithData(event, state);
488 }
489
490 void FlutterWindowsView::SendPointerEventWithData(
491 const FlutterPointerEvent& event_data,
492 PointerState* state) {
493 // If sending anything other than an add, and the pointer isn't already added,
494 // synthesize an add to satisfy Flutter's expectations about events.
495 if (!state->flutter_state_is_added &&
496 event_data.phase != FlutterPointerPhase::kAdd) {
497 FlutterPointerEvent event = {};
498 event.phase = FlutterPointerPhase::kAdd;
499 event.x = event_data.x;
500 event.y = event_data.y;
501 event.buttons = 0;
502 SendPointerEventWithData(event, state);
503 }
504
505 // Don't double-add (e.g., if events are delivered out of order, so an add has
506 // already been synthesized).
507 if (state->flutter_state_is_added &&
508 event_data.phase == FlutterPointerPhase::kAdd) {
509 return;
510 }
511
512 FlutterPointerEvent event = event_data;
513 event.device_kind = state->device_kind;
514 event.device = state->pointer_id;
515 event.buttons = state->buttons;
516
517 // Set metadata that's always the same regardless of the event.
518 event.struct_size = sizeof(event);
519 event.timestamp =
520 std::chrono::duration_cast<std::chrono::microseconds>(
521 std::chrono::high_resolution_clock::now().time_since_epoch())
522 .count();
523
524 engine_->SendPointerEvent(event);
525
526 if (event_data.phase == FlutterPointerPhase::kAdd) {
527 state->flutter_state_is_added = true;
528 } else if (event_data.phase == FlutterPointerPhase::kRemove) {
529 auto it = pointer_states_.find(state->pointer_id);
530 if (it != pointer_states_.end()) {
531 pointer_states_.erase(it);
532 }
533 }
534 }
535
536 bool FlutterWindowsView::MakeCurrent() {
537 return engine_->surface_manager()->MakeCurrent();
538 }
539
540 bool FlutterWindowsView::MakeResourceCurrent() {
541 return engine_->surface_manager()->MakeResourceCurrent();
542 }
543
544 bool FlutterWindowsView::ClearContext() {
545 return engine_->surface_manager()->ClearContext();
546 }
547
548 bool FlutterWindowsView::SwapBuffers() {
549 // Called on an engine-controlled (non-platform) thread.
550 std::unique_lock<std::mutex> lock(resize_mutex_);
551
552 switch (resize_status_) {
553 // SwapBuffer requests during resize are ignored until the frame with the
554 // right dimensions has been generated. This is marked with
555 // kFrameGenerated resize status.
556 case ResizeState::kResizeStarted:
557 return false;
558 case ResizeState::kFrameGenerated: {
559 bool visible = binding_handler_->IsVisible();
560 bool swap_buffers_result;
561 // For visible windows swap the buffers while resize handler is waiting.
562 // For invisible windows unblock the handler first and then swap buffers.
563 // SwapBuffers waits for vsync and there's no point doing that for
564 // invisible windows.
565 if (visible) {
566 swap_buffers_result = engine_->surface_manager()->SwapBuffers();
567 }
568 resize_status_ = ResizeState::kDone;
569 lock.unlock();
570 resize_cv_.notify_all();
571 binding_handler_->OnWindowResized();
572 if (!visible) {
573 swap_buffers_result = engine_->surface_manager()->SwapBuffers();
574 }
575 return swap_buffers_result;
576 }
577 case ResizeState::kDone:
578 default:
579 return engine_->surface_manager()->SwapBuffers();
580 }
581 }
582
583 bool FlutterWindowsView::PresentSoftwareBitmap(const void* allocation,
584 size_t row_bytes,
585 size_t height) {
586 return binding_handler_->OnBitmapSurfaceUpdated(allocation, row_bytes,
587 height);
588 }
589
590 void FlutterWindowsView::CreateRenderSurface() {
591 if (engine_ && engine_->surface_manager()) {
592 PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
593 bool enable_vsync = binding_handler_->NeedsVSync();
594 engine_->surface_manager()->CreateSurface(GetRenderTarget(), bounds.width,
595 bounds.height, enable_vsync);
596
597 // The EGL context cannot be current on multiple threads.
598 // Creating the render surface runs on the platform thread and
599 // makes the EGL context current. Thus, the EGL context must be
600 // released so that the raster thread can use it for rendering.
601 engine_->surface_manager()->ClearCurrent();
602
603 resize_target_width_ = bounds.width;
604 resize_target_height_ = bounds.height;
605 }
606 }
607
608 void FlutterWindowsView::DestroyRenderSurface() {
609 if (engine_ && engine_->surface_manager()) {
610 engine_->surface_manager()->DestroySurface();
611 }
612 }
613
614 void FlutterWindowsView::SendInitialAccessibilityFeatures() {
615 binding_handler_->SendInitialAccessibilityFeatures();
616 }
617
618 void FlutterWindowsView::UpdateHighContrastEnabled(bool enabled) {
619 engine_->UpdateHighContrastEnabled(enabled);
620 }
621
622 WindowsRenderTarget* FlutterWindowsView::GetRenderTarget() const {
623 return render_target_.get();
624 }
625
626 PlatformWindow FlutterWindowsView::GetPlatformWindow() const {
627 return binding_handler_->GetPlatformWindow();
628 }
629
630 FlutterWindowsEngine* FlutterWindowsView::GetEngine() {
631 return engine_.get();
632 }
633
634 void FlutterWindowsView::AnnounceAlert(const std::wstring& text) {
635 auto alert_delegate = binding_handler_->GetAlertDelegate();
636 if (!alert_delegate) {
637 return;
638 }
639 alert_delegate->SetText(fml::WideStringToUtf16(text));
640 ui::AXPlatformNodeWin* alert_node = binding_handler_->GetAlert();
641 NotifyWinEventWrapper(alert_node, ax::mojom::Event::kAlert);
642 }
643
644 void FlutterWindowsView::NotifyWinEventWrapper(ui::AXPlatformNodeWin* node,
645 ax::mojom::Event event) {
646 if (node) {
647 node->NotifyAccessibilityEvent(event);
648 }
649 }
650
651 ui::AXFragmentRootDelegateWin* FlutterWindowsView::GetAxFragmentRootDelegate() {
652 return accessibility_bridge_.get();
653 }
654
655 ui::AXPlatformNodeWin* FlutterWindowsView::AlertNode() const {
656 return binding_handler_->GetAlert();
657 }
658
659 std::shared_ptr<AccessibilityBridgeWindows>
660 FlutterWindowsView::CreateAccessibilityBridge() {
661 return std::make_shared<AccessibilityBridgeWindows>(this);
662 }
663
664 void FlutterWindowsView::UpdateSemanticsEnabled(bool enabled) {
665 if (semantics_enabled_ != enabled) {
666 semantics_enabled_ = enabled;
667
668 if (!semantics_enabled_ && accessibility_bridge_) {
669 accessibility_bridge_.reset();
670 } else if (semantics_enabled_ && !accessibility_bridge_) {
671 accessibility_bridge_ = CreateAccessibilityBridge();
672 }
673 }
674 }
675
676 void FlutterWindowsView::OnDwmCompositionChanged() {
677 AngleSurfaceManager* surface_manager = engine_->surface_manager();
678 if (!surface_manager) {
679 return;
680 }
681
682 // Update the surface with the new composition state.
683 // Switch to the raster thread as the render EGL context can only be
684 // current on a single thread a time.
685 auto needs_vsync = binding_handler_->NeedsVSync();
686 engine_->PostRasterThreadTask([surface_manager, needs_vsync]() {
687 if (!surface_manager->MakeCurrent()) {
688 FML_LOG(ERROR)
689 << "Unable to make surface current to update the swap interval";
690 return;
691 }
692
693 surface_manager->SetVSyncEnabled(needs_vsync);
694 });
695 }
696
697 void FlutterWindowsView::OnWindowStateEvent(HWND hwnd, WindowStateEvent event) {
698 if (engine_) {
699 engine_->OnWindowStateEvent(hwnd, event);
700 }
701 }
702
703 } // namespace flutter
flutter::FlutterWindowsView::OnPointerMove
void OnPointerMove(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, int modifiers_state) override
Definition: flutter_windows_view.cc:145
flutter::FlutterWindowsView::OnPointerUp
void OnPointerUp(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, FlutterPointerMouseButtons button) override
Definition: flutter_windows_view.cc:167
flutter::WindowStateEvent
WindowStateEvent
An event representing a change in window state that may update the.
Definition: windows_lifecycle_manager.h:24
flutter::FlutterWindowsView::OnWindowStateEvent
void OnWindowStateEvent(HWND hwnd, WindowStateEvent event) override
Definition: flutter_windows_view.cc:697
flutter::FlutterWindowsView::FlutterWindowsView
FlutterWindowsView(std::unique_ptr< WindowBindingHandler > window_binding)
Definition: flutter_windows_view.cc:41
flutter::FlutterWindowsView::CreateRenderSurface
void CreateRenderSurface()
Definition: flutter_windows_view.cc:590
flutter::FlutterWindowsView::OnWindowSizeChanged
void OnWindowSizeChanged(size_t width, size_t height) override
Definition: flutter_windows_view.cc:107
flutter::FlutterWindowsView::OnUpdateSemanticsEnabled
virtual void OnUpdateSemanticsEnabled(bool enabled) override
Definition: flutter_windows_view.cc:251
flutter::FlutterWindowsView::OnComposeCommit
void OnComposeCommit() override
Definition: flutter_windows_view.cc:222
scancode
int scancode
Definition: keyboard_key_handler_unittests.cc:115
flutter::FlutterWindowsView::GetRenderTarget
WindowsRenderTarget * GetRenderTarget() const
Definition: flutter_windows_view.cc:622
flutter::FlutterWindowsView::~FlutterWindowsView
virtual ~FlutterWindowsView()
Definition: flutter_windows_view.cc:51
flutter::FlutterWindowsView::ClearContext
bool ClearContext()
Definition: flutter_windows_view.cc:544
was_down
bool was_down
Definition: keyboard_key_handler_unittests.cc:119
text_input_plugin.h
extended
bool extended
Definition: keyboard_key_handler_unittests.cc:118
flutter::FlutterWindowsView::OnPointerDown
void OnPointerDown(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, FlutterPointerMouseButtons button) override
Definition: flutter_windows_view.cc:154
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:78
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
flutter::FlutterWindowsView::OnComposeChange
void OnComposeChange(const std::u16string &text, int cursor_pos) override
Definition: flutter_windows_view.cc:230
flutter::FlutterWindowsView::OnScrollInertiaCancel
void OnScrollInertiaCancel(int32_t device_id) override
Definition: flutter_windows_view.cc:246
flutter::FlutterWindowsView::ForceRedraw
void ForceRedraw()
Definition: flutter_windows_view.cc:100
flutter::FlutterWindowsView::DestroyRenderSurface
void DestroyRenderSurface()
Definition: flutter_windows_view.cc:608
flutter::WindowsRenderTarget
std::variant< HWND > WindowsRenderTarget
Definition: window_binding_handler.h:44
flutter::FlutterWindowsView::OnPointerPanZoomStart
virtual void OnPointerPanZoomStart(int32_t device_id) override
Definition: flutter_windows_view.cc:187
flutter::Rect
Definition: geometry.h:56
flutter::FlutterWindowsView::MakeResourceCurrent
bool MakeResourceCurrent()
Definition: flutter_windows_view.cc:540
flutter::PhysicalWindowBounds::width
size_t width
Definition: window_binding_handler.h:28
flutter::PhysicalWindowBounds
Definition: window_binding_handler.h:27
flutter::PointerLocation
Definition: window_binding_handler.h:34
flutter::FlutterWindowsView::OnCursorRectUpdated
void OnCursorRectUpdated(const Rect &rect) override
Definition: flutter_windows_view.cc:263
flutter::FlutterWindowsView::AnnounceAlert
void AnnounceAlert(const std::wstring &text)
Definition: flutter_windows_view.cc:634
flutter::kWindowFrameBufferID
constexpr uint32_t kWindowFrameBufferID
Definition: flutter_windows_view.h:31
flutter::FlutterWindowsView::OnPointerPanZoomUpdate
virtual void OnPointerPanZoomUpdate(int32_t device_id, double pan_x, double pan_y, double scale, double rotation) override
Definition: flutter_windows_view.cc:192
flutter::FlutterWindowsView::OnWindowRepaint
void OnWindowRepaint() override
Definition: flutter_windows_view.cc:141
flutter::WindowBindingHandlerDelegate::KeyEventCallback
std::function< void(bool)> KeyEventCallback
Definition: window_binding_handler_delegate.h:20
flutter::FlutterWindowsView::OnComposeEnd
void OnComposeEnd() override
Definition: flutter_windows_view.cc:226
flutter::AngleSurfaceManager
Definition: angle_surface_manager.h:28
flutter::PlatformWindow
HWND PlatformWindow
Definition: window_binding_handler.h:40
flutter::PointerLocation::y
size_t y
Definition: window_binding_handler.h:36
flutter_windows_view.h
text
std::u16string text
Definition: keyboard_unittests.cc:332
flutter::FlutterWindowsView::SetEngine
void SetEngine(std::unique_ptr< FlutterWindowsEngine > engine)
Definition: flutter_windows_view.cc:61
flutter::FlutterWindowsView::SwapBuffers
bool SwapBuffers()
Definition: flutter_windows_view.cc:548
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::FlutterWindowsView::UpdateFlutterCursor
void UpdateFlutterCursor(const std::string &cursor_name)
Definition: flutter_windows_view.cc:92
flutter::FlutterWindowsView::SetFlutterCursor
void SetFlutterCursor(HCURSOR cursor)
Definition: flutter_windows_view.cc:96
flutter::AngleSurfaceManager::MakeCurrent
bool MakeCurrent()
Definition: angle_surface_manager.cc:312
flutter::FlutterWindowsView::OnPointerLeave
void OnPointerLeave(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id=0) override
Definition: flutter_windows_view.cc:180
flutter::FlutterWindowsView::OnText
void OnText(const std::u16string &) override
Definition: flutter_windows_view.cc:204
flutter::FlutterWindowsView::PresentSoftwareBitmap
bool PresentSoftwareBitmap(const void *allocation, size_t row_bytes, size_t height)
Definition: flutter_windows_view.cc:583
flutter::FlutterWindowsView::AlertNode
ui::AXPlatformNodeWin * AlertNode() const
Definition: flutter_windows_view.cc:655
flutter::FlutterWindowsView::MakeCurrent
bool MakeCurrent()
Definition: flutter_windows_view.cc:536
flutter::FlutterWindowsView::OnPointerPanZoomEnd
virtual void OnPointerPanZoomEnd(int32_t device_id) override
Definition: flutter_windows_view.cc:200
flutter::FlutterWindowsView::OnDwmCompositionChanged
void OnDwmCompositionChanged()
Definition: flutter_windows_view.cc:676
flutter::FlutterWindowsView::NotifyWinEventWrapper
virtual void NotifyWinEventWrapper(ui::AXPlatformNodeWin *node, ax::mojom::Event event)
Definition: flutter_windows_view.cc:644
flutter::PhysicalWindowBounds::height
size_t height
Definition: window_binding_handler.h:29
flutter::FlutterWindowsView::UpdateSemanticsEnabled
virtual void UpdateSemanticsEnabled(bool enabled)
Definition: flutter_windows_view.cc:664
flutter::AngleSurfaceManager::SetVSyncEnabled
virtual void SetVSyncEnabled(bool enabled)
Definition: angle_surface_manager.cc:344
flutter::FlutterWindowsView::OnComposeBegin
void OnComposeBegin() override
Definition: flutter_windows_view.cc:218
flutter::FlutterWindowsView::UpdateHighContrastEnabled
void UpdateHighContrastEnabled(bool enabled) override
Definition: flutter_windows_view.cc:618
flutter::FlutterWindowsView::SendInitialBounds
void SendInitialBounds()
Definition: flutter_windows_view.cc:283
flutter::FlutterWindowsView::CreateAccessibilityBridge
virtual std::shared_ptr< AccessibilityBridgeWindows > CreateAccessibilityBridge()
Definition: flutter_windows_view.cc:660
action
int action
Definition: keyboard_key_handler_unittests.cc:116
flutter::FlutterWindowsView::OnScroll
void OnScroll(double x, double y, double delta_x, double delta_y, int scroll_offset_multiplier, FlutterPointerDeviceKind device_kind, int32_t device_id) override
Definition: flutter_windows_view.cc:235
flutter::FlutterWindowsView::OnResetImeComposing
void OnResetImeComposing() override
Definition: flutter_windows_view.cc:267
flutter::PointerLocation::x
size_t x
Definition: window_binding_handler.h:35
flutter::FlutterWindowsView::GetAxFragmentRootDelegate
virtual ui::AXFragmentRootDelegateWin * GetAxFragmentRootDelegate() override
Definition: flutter_windows_view.cc:651
flutter::FlutterWindowsView::GetPlatformWindow
virtual PlatformWindow GetPlatformWindow() const
Definition: flutter_windows_view.cc:626
key
int key
Definition: keyboard_key_handler_unittests.cc:114
accessibility_bridge.h
keyboard_key_channel_handler.h
flutter::FlutterWindowsView::OnKey
void OnKey(int key, int scancode, int action, char32_t character, bool extended, bool was_down, KeyEventCallback callback) override
Definition: flutter_windows_view.cc:208
flutter::FlutterWindowsView::GetNativeViewAccessible
virtual gfx::NativeViewAccessible GetNativeViewAccessible() override
Definition: flutter_windows_view.cc:255
flutter::FlutterWindowsView::GetEngine
FlutterWindowsEngine * GetEngine()
Definition: flutter_windows_view.cc:630
flutter::FlutterWindowsView::GetFrameBufferId
uint32_t GetFrameBufferId(size_t width, size_t height)
Definition: flutter_windows_view.cc:73
flutter::FlutterWindowsView::SendInitialAccessibilityFeatures
void SendInitialAccessibilityFeatures()
Definition: flutter_windows_view.cc:614
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:46