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/lib/ui/window/window.h" |
6 | |
7 | #include "third_party/tonic/converter/dart_converter.h" |
8 | #include "third_party/tonic/dart_args.h" |
9 | #include "third_party/tonic/logging/dart_invoke.h" |
10 | #include "third_party/tonic/typed_data/dart_byte_data.h" |
11 | |
12 | namespace flutter { |
13 | |
14 | Window::Window(ViewportMetrics metrics) : viewport_metrics_(metrics) { |
15 | library_.Set(tonic::DartState::Current(), |
16 | Dart_LookupLibrary(tonic::ToDart("dart:ui" ))); |
17 | } |
18 | |
19 | Window::~Window() {} |
20 | |
21 | void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) { |
22 | std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock(); |
23 | if (!dart_state) { |
24 | return; |
25 | } |
26 | tonic::DartState::Scope scope(dart_state); |
27 | |
28 | const std::vector<uint8_t>& buffer = packet.data(); |
29 | Dart_Handle data_handle = |
30 | tonic::DartByteData::Create(buffer.data(), buffer.size()); |
31 | if (Dart_IsError(data_handle)) { |
32 | return; |
33 | } |
34 | tonic::LogIfError(tonic::DartInvokeField( |
35 | library_.value(), "_dispatchPointerDataPacket" , {data_handle})); |
36 | } |
37 | |
38 | void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { |
39 | viewport_metrics_ = metrics; |
40 | |
41 | std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock(); |
42 | if (!dart_state) { |
43 | return; |
44 | } |
45 | tonic::DartState::Scope scope(dart_state); |
46 | tonic::LogIfError(tonic::DartInvokeField( |
47 | library_.value(), "_updateWindowMetrics" , |
48 | { |
49 | tonic::ToDart(metrics.device_pixel_ratio), |
50 | tonic::ToDart(metrics.physical_width), |
51 | tonic::ToDart(metrics.physical_height), |
52 | tonic::ToDart(metrics.physical_padding_top), |
53 | tonic::ToDart(metrics.physical_padding_right), |
54 | tonic::ToDart(metrics.physical_padding_bottom), |
55 | tonic::ToDart(metrics.physical_padding_left), |
56 | tonic::ToDart(metrics.physical_view_inset_top), |
57 | tonic::ToDart(metrics.physical_view_inset_right), |
58 | tonic::ToDart(metrics.physical_view_inset_bottom), |
59 | tonic::ToDart(metrics.physical_view_inset_left), |
60 | tonic::ToDart(metrics.physical_system_gesture_inset_top), |
61 | tonic::ToDart(metrics.physical_system_gesture_inset_right), |
62 | tonic::ToDart(metrics.physical_system_gesture_inset_bottom), |
63 | tonic::ToDart(metrics.physical_system_gesture_inset_left), |
64 | })); |
65 | } |
66 | |
67 | } // namespace flutter |
68 | |