1414#include " flutter/fml/logging.h"
1515#include " flutter/lib/ui/window/pointer_data.h"
1616#include " flutter/lib/ui/window/window.h"
17+ #include " third_party/rapidjson/include/rapidjson/document.h"
18+ #include " third_party/rapidjson/include/rapidjson/stringbuffer.h"
19+ #include " third_party/rapidjson/include/rapidjson/writer.h"
20+
1721#include " logging.h"
18- #include " rapidjson/document.h"
19- #include " rapidjson/stringbuffer.h"
20- #include " rapidjson/writer.h"
2122#include " runtime/dart/utils/inlines.h"
2223#include " vsync_waiter.h"
2324
@@ -214,7 +215,8 @@ void PlatformView::OnScenicError(std::string error) {
214215void PlatformView::OnScenicEvent (
215216 std::vector<fuchsia::ui::scenic::Event> events) {
216217 TRACE_EVENT0 (" flutter" , " PlatformView::OnScenicEvent" );
217- bool should_update_metrics = false ;
218+
219+ bool metrics_changed = false ;
218220 for (const auto & event : events) {
219221 switch (event.Which ()) {
220222 case fuchsia::ui::scenic::Event::Tag::kGfx :
@@ -223,31 +225,52 @@ void PlatformView::OnScenicEvent(
223225 const fuchsia::ui::gfx::Metrics& metrics =
224226 event.gfx ().metrics ().metrics ;
225227 const float new_view_pixel_ratio = metrics.scale_x ;
228+ if (new_view_pixel_ratio <= 0 .f ) {
229+ FML_DLOG (ERROR)
230+ << " Got an invalid pixel ratio from Scenic; ignoring: "
231+ << new_view_pixel_ratio;
232+ break ;
233+ }
226234
227235 // Avoid metrics update when possible -- it is computationally
228236 // expensive.
229- if (view_pixel_ratio_ != new_view_pixel_ratio) {
230- view_pixel_ratio_ = new_view_pixel_ratio;
231- should_update_metrics = true ;
237+ if (view_pixel_ratio_.has_value () &&
238+ *view_pixel_ratio_ == new_view_pixel_ratio) {
239+ FML_DLOG (ERROR)
240+ << " Got an identical pixel ratio from Scenic; ignoring: "
241+ << new_view_pixel_ratio;
242+ break ;
232243 }
244+
245+ view_pixel_ratio_ = new_view_pixel_ratio;
246+ metrics_changed = true ;
233247 break ;
234248 }
235249 case fuchsia::ui::gfx::Event::Tag::kViewPropertiesChanged : {
236250 const fuchsia::ui::gfx::BoundingBox& bounding_box =
237251 event.gfx ().view_properties_changed ().properties .bounding_box ;
238- const float new_view_width =
239- std::max (bounding_box.max .x - bounding_box.min .x , 0 .0f );
240- const float new_view_height =
241- std::max (bounding_box.max .y - bounding_box.min .y , 0 .0f );
252+ const std::pair<float , float > new_view_size = {
253+ std::max (bounding_box.max .x - bounding_box.min .x , 0 .0f ),
254+ std::max (bounding_box.max .y - bounding_box.min .y , 0 .0f )};
255+ if (new_view_size.first <= 0 .f || new_view_size.second <= 0 .f ) {
256+ FML_DLOG (ERROR)
257+ << " Got an invalid view size from Scenic; ignoring: "
258+ << new_view_size.first << " " << new_view_size.second ;
259+ break ;
260+ }
242261
243262 // Avoid metrics update when possible -- it is computationally
244263 // expensive.
245- if (view_width_ != new_view_width ||
246- view_height_ != new_view_width) {
247- view_width_ = new_view_width;
248- view_height_ = new_view_height;
249- should_update_metrics = true ;
264+ if (view_logical_size_.has_value () &&
265+ *view_logical_size_ == new_view_size) {
266+ FML_DLOG (ERROR)
267+ << " Got an identical view size from Scenic; ignoring: "
268+ << new_view_size.first << " " << new_view_size.second ;
269+ break ;
250270 }
271+
272+ view_logical_size_ = new_view_size;
273+ metrics_changed = true ;
251274 break ;
252275 }
253276 case fuchsia::ui::gfx::Event::Tag::kViewConnected :
@@ -298,19 +321,22 @@ void PlatformView::OnScenicEvent(
298321 }
299322 }
300323
301- if (should_update_metrics) {
324+ if (view_pixel_ratio_.has_value () && view_logical_size_.has_value () &&
325+ metrics_changed) {
326+ const float pixel_ratio = *view_pixel_ratio_;
327+ const std::pair<float , float > logical_size = *view_logical_size_;
302328 SetViewportMetrics ({
303- view_pixel_ratio_, // device_pixel_ratio
304- view_width_ * view_pixel_ratio_ , // physical_width
305- view_height_ * view_pixel_ratio_ , // physical_height
306- 0 .0f , // physical_padding_top
307- 0 .0f , // physical_padding_right
308- 0 .0f , // physical_padding_bottom
309- 0 .0f , // physical_padding_left
310- 0 .0f , // physical_view_inset_top
311- 0 .0f , // physical_view_inset_right
312- 0 .0f , // physical_view_inset_bottom
313- 0 .0f , // physical_view_inset_left
329+ pixel_ratio, // device_pixel_ratio
330+ logical_size. first * pixel_ratio , // physical_width
331+ logical_size. second * pixel_ratio , // physical_height
332+ 0 .0f , // physical_padding_top
333+ 0 .0f , // physical_padding_right
334+ 0 .0f , // physical_padding_bottom
335+ 0 .0f , // physical_padding_left
336+ 0 .0f , // physical_view_inset_top
337+ 0 .0f , // physical_view_inset_right
338+ 0 .0f , // physical_view_inset_bottom
339+ 0 .0f , // physical_view_inset_left
314340 0 .0f , // p_physical_system_gesture_inset_top
315341 0 .0f , // p_physical_system_gesture_inset_right
316342 0 .0f , // p_physical_system_gesture_inset_bottom
@@ -421,15 +447,18 @@ bool PlatformView::OnHandlePointerEvent(
421447 PointerTraceHACK (pointer.radius_major , pointer.radius_minor );
422448 TRACE_FLOW_END (" input" , " dispatch_event_to_client" , trace_id);
423449
450+ const float pixel_ratio =
451+ view_pixel_ratio_.has_value () ? *view_pixel_ratio_ : 0 .f ;
452+
424453 flutter::PointerData pointer_data;
425454 pointer_data.Clear ();
426455 pointer_data.time_stamp = pointer.event_time / 1000 ;
427456 pointer_data.change = GetChangeFromPointerEventPhase (pointer.phase );
428457 pointer_data.kind = GetKindFromPointerType (pointer.type );
429458 pointer_data.device = pointer.pointer_id ;
430459 // Pointer events are in logical pixels, so scale to physical.
431- pointer_data.physical_x = pointer.x * view_pixel_ratio_ ;
432- pointer_data.physical_y = pointer.y * view_pixel_ratio_ ;
460+ pointer_data.physical_x = pointer.x * pixel_ratio ;
461+ pointer_data.physical_y = pointer.y * pixel_ratio ;
433462 // Buttons are single bit values starting with kMousePrimaryButton = 1.
434463 pointer_data.buttons = static_cast <uint64_t >(pointer.buttons );
435464
@@ -601,7 +630,10 @@ void PlatformView::DispatchSemanticsAction(int32_t node_id,
601630void PlatformView::UpdateSemantics (
602631 flutter::SemanticsNodeUpdates update,
603632 flutter::CustomAccessibilityActionUpdates actions) {
604- accessibility_bridge_->AddSemanticsNodeUpdate (update, view_pixel_ratio_);
633+ const float pixel_ratio =
634+ view_pixel_ratio_.has_value () ? *view_pixel_ratio_ : 0 .f ;
635+
636+ accessibility_bridge_->AddSemanticsNodeUpdate (update, pixel_ratio);
605637}
606638
607639// Channel handler for kAccessibilityChannel
0 commit comments