Flutter Engine
flutter::FlutterWindowsView Class Reference

#include <flutter_windows_view.h>

Inheritance diagram for flutter::FlutterWindowsView:
flutter::WindowBindingHandlerDelegate flutter::TextInputPluginDelegate

Public Member Functions

 FlutterWindowsView (std::unique_ptr< WindowBindingHandler > window_binding)
 
virtual ~FlutterWindowsView ()
 
void SetEngine (std::unique_ptr< FlutterWindowsEngine > engine)
 
void CreateRenderSurface ()
 
void DestroyRenderSurface ()
 
WindowsRenderTargetGetRenderTarget () const
 
PlatformWindow GetPlatformWindow () const
 
FlutterWindowsEngineGetEngine ()
 
void ForceRedraw ()
 
bool ClearContext ()
 
bool MakeCurrent ()
 
bool MakeResourceCurrent ()
 
bool SwapBuffers ()
 
bool PresentSoftwareBitmap (const void *allocation, size_t row_bytes, size_t height)
 
void SendInitialBounds ()
 
uint32_t GetFrameBufferId (size_t width, size_t height)
 
void OnPreEngineRestart ()
 
void OnWindowSizeChanged (size_t width, size_t height) override
 
void OnPointerMove (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id) override
 
void OnPointerDown (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, FlutterPointerMouseButtons button) override
 
void OnPointerUp (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, FlutterPointerMouseButtons button) override
 
void OnPointerLeave (FlutterPointerDeviceKind device_kind, int32_t device_id=0) override
 
void OnText (const std::u16string &) override
 
bool OnKey (int key, int scancode, int action, char32_t character, bool extended, bool was_down) override
 
void OnComposeBegin () override
 
void OnComposeCommit () override
 
void OnComposeEnd () override
 
void OnComposeChange (const std::u16string &text, int cursor_pos) override
 
void OnScroll (double x, double y, double delta_x, double delta_y, int scroll_offset_multiplier, FlutterPointerDeviceKind device_kind, int32_t device_id) override
 
void OnPlatformBrightnessChanged () override
 
void OnCursorRectUpdated (const Rect &rect) override
 
void OnResetImeComposing () override
 

Protected Member Functions

virtual void RegisterKeyboardHandlers (flutter::BinaryMessenger *messenger, flutter::KeyboardKeyHandler::EventDispatcher dispatch_event, flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state)
 
void AddKeyboardHandler (std::unique_ptr< flutter::KeyboardHandlerBase > handler)
 

Detailed Description

Definition at line 40 of file flutter_windows_view.h.

Constructor & Destructor Documentation

◆ FlutterWindowsView()

flutter::FlutterWindowsView::FlutterWindowsView ( std::unique_ptr< WindowBindingHandler window_binding)

Definition at line 33 of file flutter_windows_view.cc.

34  {
35  // Take the binding handler, and give it a pointer back to self.
36  binding_handler_ = std::move(window_binding);
37  binding_handler_->SetView(this);
38 
39  render_target_ = std::make_unique<WindowsRenderTarget>(
40  binding_handler_->GetRenderTarget());
41 }

◆ ~FlutterWindowsView()

flutter::FlutterWindowsView::~FlutterWindowsView ( )
virtual

Definition at line 43 of file flutter_windows_view.cc.

References DestroyRenderSurface().

Member Function Documentation

◆ AddKeyboardHandler()

void flutter::FlutterWindowsView::AddKeyboardHandler ( std::unique_ptr< flutter::KeyboardHandlerBase handler)
protected

Definition at line 96 of file flutter_windows_view.cc.

Referenced by RegisterKeyboardHandlers().

97  {
98  keyboard_handlers_.push_back(std::move(handler));
99 }

◆ ClearContext()

bool flutter::FlutterWindowsView::ClearContext ( )

Definition at line 499 of file flutter_windows_view.cc.

499  {
500  return engine_->surface_manager()->ClearContext();
501 }

◆ CreateRenderSurface()

void flutter::FlutterWindowsView::CreateRenderSurface ( )

Definition at line 545 of file flutter_windows_view.cc.

References GetRenderTarget(), flutter::PhysicalWindowBounds::height, and flutter::PhysicalWindowBounds::width.

545  {
546  if (engine_ && engine_->surface_manager()) {
547  PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
548  engine_->surface_manager()->CreateSurface(GetRenderTarget(), bounds.width,
549  bounds.height);
550  }
551 }
WindowsRenderTarget * GetRenderTarget() const

◆ DestroyRenderSurface()

void flutter::FlutterWindowsView::DestroyRenderSurface ( )

Definition at line 553 of file flutter_windows_view.cc.

Referenced by ~FlutterWindowsView().

553  {
554  if (engine_ && engine_->surface_manager()) {
555  engine_->surface_manager()->DestroySurface();
556  }
557 }

◆ ForceRedraw()

void flutter::FlutterWindowsView::ForceRedraw ( )

Definition at line 120 of file flutter_windows_view.cc.

120  {
121  if (resize_status_ == ResizeState::kDone) {
122  // Request new frame
123  // TODO(knopp): Replace with more specific call once there is API for it
124  // https://github.com/flutter/flutter/issues/69716
125  SendWindowMetrics(resize_target_width_, resize_target_height_,
126  binding_handler_->GetDpiScale());
127  }
128 }

◆ GetEngine()

FlutterWindowsEngine * flutter::FlutterWindowsView::GetEngine ( )

Definition at line 567 of file flutter_windows_view.cc.

567  {
568  return engine_.get();
569 }

◆ GetFrameBufferId()

uint32_t flutter::FlutterWindowsView::GetFrameBufferId ( size_t  width,
size_t  height 
)

Definition at line 101 of file flutter_windows_view.cc.

References GetRenderTarget(), and flutter::kWindowFrameBufferID.

101  {
102  // Called on an engine-controlled (non-platform) thread.
103  std::unique_lock<std::mutex> lock(resize_mutex_);
104 
105  if (resize_status_ != ResizeState::kResizeStarted) {
106  return kWindowFrameBufferID;
107  }
108 
109  if (resize_target_width_ == width && resize_target_height_ == height) {
110  // Platform thread is blocked for the entire duration until the
111  // resize_status_ is set to kDone.
112  engine_->surface_manager()->ResizeSurface(GetRenderTarget(), width, height);
113  engine_->surface_manager()->MakeCurrent();
114  resize_status_ = ResizeState::kFrameGenerated;
115  }
116 
117  return kWindowFrameBufferID;
118 }
constexpr uint32_t kWindowFrameBufferID
int32_t width
int32_t height
WindowsRenderTarget * GetRenderTarget() const

◆ GetPlatformWindow()

PlatformWindow flutter::FlutterWindowsView::GetPlatformWindow ( ) const

Definition at line 563 of file flutter_windows_view.cc.

Referenced by FlutterDesktopViewGetHWND().

563  {
564  return binding_handler_->GetPlatformWindow();
565 }

◆ GetRenderTarget()

WindowsRenderTarget * flutter::FlutterWindowsView::GetRenderTarget ( ) const

◆ MakeCurrent()

bool flutter::FlutterWindowsView::MakeCurrent ( )

Definition at line 491 of file flutter_windows_view.cc.

491  {
492  return engine_->surface_manager()->MakeCurrent();
493 }

◆ MakeResourceCurrent()

bool flutter::FlutterWindowsView::MakeResourceCurrent ( )

Definition at line 495 of file flutter_windows_view.cc.

495  {
496  return engine_->surface_manager()->MakeResourceCurrent();
497 }

◆ OnComposeBegin()

void flutter::FlutterWindowsView::OnComposeBegin ( )
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 219 of file flutter_windows_view.cc.

219  {
220  SendComposeBegin();
221 }

◆ OnComposeChange()

void flutter::FlutterWindowsView::OnComposeChange ( const std::u16string &  text,
int  cursor_pos 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 231 of file flutter_windows_view.cc.

232  {
233  SendComposeChange(text, cursor_pos);
234 }
std::u16string text

◆ OnComposeCommit()

void flutter::FlutterWindowsView::OnComposeCommit ( )
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 223 of file flutter_windows_view.cc.

223  {
224  SendComposeCommit();
225 }

◆ OnComposeEnd()

void flutter::FlutterWindowsView::OnComposeEnd ( )
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 227 of file flutter_windows_view.cc.

227  {
228  SendComposeEnd();
229 }

◆ OnCursorRectUpdated()

void flutter::FlutterWindowsView::OnCursorRectUpdated ( const Rect rect)
overridevirtual

Implements flutter::TextInputPluginDelegate.

Definition at line 251 of file flutter_windows_view.cc.

251  {
252  binding_handler_->OnCursorRectUpdated(rect);
253 }

◆ OnKey()

bool flutter::FlutterWindowsView::OnKey ( int  key,
int  scancode,
int  action,
char32_t  character,
bool  extended,
bool  was_down 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 210 of file flutter_windows_view.cc.

215  {
216  return SendKey(key, scancode, action, character, extended, was_down);
217 }
char32_t character
SemanticsAction action

◆ OnPlatformBrightnessChanged()

void flutter::FlutterWindowsView::OnPlatformBrightnessChanged ( )
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 247 of file flutter_windows_view.cc.

247  {
248  SendPlatformBrightnessChanged();
249 }

◆ OnPointerDown()

void flutter::FlutterWindowsView::OnPointerDown ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id,
FlutterPointerMouseButtons  button 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 175 of file flutter_windows_view.cc.

References state.

180  {
181  if (flutter_button != 0) {
182  auto state = GetOrCreatePointerState(device_kind, device_id);
183  state->buttons |= flutter_button;
184  SendPointerDown(x, y, state);
185  }
186 }
AtkStateType state

◆ OnPointerLeave()

void flutter::FlutterWindowsView::OnPointerLeave ( FlutterPointerDeviceKind  device_kind,
int32_t  device_id = 0 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 201 of file flutter_windows_view.cc.

202  {
203  SendPointerLeave(GetOrCreatePointerState(device_kind, device_id));
204 }

◆ OnPointerMove()

void flutter::FlutterWindowsView::OnPointerMove ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 168 of file flutter_windows_view.cc.

171  {
172  SendPointerMove(x, y, GetOrCreatePointerState(device_kind, device_id));
173 }

◆ OnPointerUp()

void flutter::FlutterWindowsView::OnPointerUp ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id,
FlutterPointerMouseButtons  button 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 188 of file flutter_windows_view.cc.

References state.

193  {
194  if (flutter_button != 0) {
195  auto state = GetOrCreatePointerState(device_kind, device_id);
196  state->buttons &= ~flutter_button;
197  SendPointerUp(x, y, state);
198  }
199 }
AtkStateType state

◆ OnPreEngineRestart()

void flutter::FlutterWindowsView::OnPreEngineRestart ( )

Definition at line 130 of file flutter_windows_view.cc.

Referenced by flutter::FlutterWindowsEngine::RunWithEntrypoint().

130  {
131  keyboard_handlers_.clear();
132  InitializeKeyboard();
133 }

◆ OnResetImeComposing()

void flutter::FlutterWindowsView::OnResetImeComposing ( )
overridevirtual

Implements flutter::TextInputPluginDelegate.

Definition at line 255 of file flutter_windows_view.cc.

References event, height, RegisterKeyboardHandlers(), FlutterWindowMetricsEvent::struct_size, and width.

255  {
256  binding_handler_->OnResetImeComposing();
257 }

◆ OnScroll()

void flutter::FlutterWindowsView::OnScroll ( double  x,
double  y,
double  delta_x,
double  delta_y,
int  scroll_offset_multiplier,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 236 of file flutter_windows_view.cc.

242  {
243  SendScroll(x, y, delta_x, delta_y, scroll_offset_multiplier, device_kind,
244  device_id);
245 }

◆ OnText()

void flutter::FlutterWindowsView::OnText ( const std::u16string &  text)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 206 of file flutter_windows_view.cc.

206  {
207  SendText(text);
208 }
std::u16string text

◆ OnWindowSizeChanged()

void flutter::FlutterWindowsView::OnWindowSizeChanged ( size_t  width,
size_t  height 
)
overridevirtual

Implements flutter::WindowBindingHandlerDelegate.

Definition at line 135 of file flutter_windows_view.cc.

References height, flutter::SurfaceWillUpdate(), and width.

135  {
136  // Called on the platform thread.
137  std::unique_lock<std::mutex> lock(resize_mutex_);
138 
139  if (!engine_->surface_manager()) {
140  SendWindowMetrics(width, height, binding_handler_->GetDpiScale());
141  return;
142  }
143 
144  EGLint surface_width, surface_height;
145  engine_->surface_manager()->GetSurfaceDimensions(&surface_width,
146  &surface_height);
147 
148  bool surface_will_update =
149  SurfaceWillUpdate(surface_width, surface_height, width, height);
150  if (surface_will_update) {
151  resize_status_ = ResizeState::kResizeStarted;
152  resize_target_width_ = width;
153  resize_target_height_ = height;
154  }
155 
156  SendWindowMetrics(width, height, binding_handler_->GetDpiScale());
157 
158  if (surface_will_update) {
159  // Block the platform thread until:
160  // 1. GetFrameBufferId is called with the right frame size.
161  // 2. Any pending SwapBuffers calls have been invoked.
162  resize_cv_.wait(lock, [&resize_status = resize_status_] {
163  return resize_status == ResizeState::kDone;
164  });
165  }
166 }
static bool SurfaceWillUpdate(size_t cur_width, size_t cur_height, size_t target_width, size_t target_height)
int32_t width
int32_t height

◆ PresentSoftwareBitmap()

bool flutter::FlutterWindowsView::PresentSoftwareBitmap ( const void *  allocation,
size_t  row_bytes,
size_t  height 
)

Definition at line 538 of file flutter_windows_view.cc.

540  {
541  return binding_handler_->OnBitmapSurfaceUpdated(allocation, row_bytes,
542  height);
543 }
int32_t height

◆ RegisterKeyboardHandlers()

void flutter::FlutterWindowsView::RegisterKeyboardHandlers ( flutter::BinaryMessenger messenger,
flutter::KeyboardKeyHandler::EventDispatcher  dispatch_event,
flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler  get_key_state 
)
protectedvirtual

Definition at line 69 of file flutter_windows_view.cc.

References AddKeyboardHandler(), callback, event, and user_data.

Referenced by OnResetImeComposing().

72  {
73  // There must be only one handler that receives |SendInput|, i.e. only one
74  // handler that might redispatch events. (See the documentation of
75  // |KeyboardKeyHandler| to learn about redispatching.)
76  //
77  // Whether an event is a redispatched event is decided by calculating the hash
78  // of the event. In order to allow the same real event in the future, the
79  // handler is "toggled" when events pass through, therefore the redispatching
80  // algorithm does not allow more than 1 handler that takes |SendInput|.
81  auto key_handler =
82  std::make_unique<flutter::KeyboardKeyHandler>(dispatch_event);
83  key_handler->AddDelegate(std::make_unique<KeyboardKeyEmbedderHandler>(
85  void* user_data) {
86  return engine_->SendKeyEvent(event, callback, user_data);
87  },
88  get_key_state));
89  key_handler->AddDelegate(
90  std::make_unique<KeyboardKeyChannelHandler>(messenger));
91  AddKeyboardHandler(std::move(key_handler));
93  std::make_unique<flutter::TextInputPlugin>(messenger, this));
94 }
void * user_data
FlKeyEvent FlKeyResponderAsyncCallback callback
FlKeyEvent * event
void AddKeyboardHandler(std::unique_ptr< flutter::KeyboardHandlerBase > handler)
void(* FlutterKeyEventCallback)(bool, void *)
Definition: embedder.h:748

◆ SendInitialBounds()

void flutter::FlutterWindowsView::SendInitialBounds ( )

Definition at line 286 of file flutter_windows_view.cc.

References action, character, FlutterPointerEvent::device_kind, event, extended, flutter::PhysicalWindowBounds::height, kAdd, flutter::kDown, key, kFlutterPointerSignalKindScroll, kHover, kMove, kRemove, flutter::kUp, FlutterPointerEvent::phase, scancode, state, text, was_down, flutter::PhysicalWindowBounds::width, FlutterPointerEvent::x, and FlutterPointerEvent::y.

286  {
287  PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
288 
289  SendWindowMetrics(bounds.width, bounds.height,
290  binding_handler_->GetDpiScale());
291 }

◆ SetEngine()

void flutter::FlutterWindowsView::SetEngine ( std::unique_ptr< FlutterWindowsEngine engine)

Definition at line 47 of file flutter_windows_view.cc.

References flutter::PlatformHandler::Create().

48  {
49  engine_ = std::move(engine);
50 
51  engine_->SetView(this);
52 
53  internal_plugin_registrar_ =
54  std::make_unique<flutter::PluginRegistrar>(engine_->GetRegistrar());
55 
56  // Set up the system channel handlers.
57  auto internal_plugin_messenger = internal_plugin_registrar_->messenger();
58  InitializeKeyboard();
59  platform_handler_ = PlatformHandler::Create(internal_plugin_messenger, this);
60  cursor_handler_ = std::make_unique<flutter::CursorHandler>(
61  internal_plugin_messenger, binding_handler_.get());
62 
63  PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
64 
65  SendWindowMetrics(bounds.width, bounds.height,
66  binding_handler_->GetDpiScale());
67 }
static std::unique_ptr< PlatformHandler > Create(BinaryMessenger *messenger, FlutterWindowsView *view)

◆ SwapBuffers()

bool flutter::FlutterWindowsView::SwapBuffers ( )

Definition at line 503 of file flutter_windows_view.cc.

503  {
504  // Called on an engine-controlled (non-platform) thread.
505  std::unique_lock<std::mutex> lock(resize_mutex_);
506 
507  switch (resize_status_) {
508  // SwapBuffer requests during resize are ignored until the frame with the
509  // right dimensions has been generated. This is marked with
510  // kFrameGenerated resize status.
511  case ResizeState::kResizeStarted:
512  return false;
513  case ResizeState::kFrameGenerated: {
514  bool visible = binding_handler_->IsVisible();
515  bool swap_buffers_result;
516  // For visible windows swap the buffers while resize handler is waiting.
517  // For invisible windows unblock the handler first and then swap buffers.
518  // SwapBuffers waits for vsync and there's no point doing that for
519  // invisible windows.
520  if (visible) {
521  swap_buffers_result = engine_->surface_manager()->SwapBuffers();
522  }
523  resize_status_ = ResizeState::kDone;
524  lock.unlock();
525  resize_cv_.notify_all();
526  binding_handler_->OnWindowResized();
527  if (!visible) {
528  swap_buffers_result = engine_->surface_manager()->SwapBuffers();
529  }
530  return swap_buffers_result;
531  }
532  case ResizeState::kDone:
533  default:
534  return engine_->surface_manager()->SwapBuffers();
535  }
536 }

The documentation for this class was generated from the following files: