Flutter Engine
window.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/lib/ui/window/window.h"
6 
11 
12 namespace flutter {
13 
14 Window::Window(int64_t window_id, ViewportMetrics metrics)
15  : window_id_(window_id), viewport_metrics_(metrics) {
16  library_.Set(tonic::DartState::Current(),
17  Dart_LookupLibrary(tonic::ToDart("dart:ui")));
18 }
19 
21 
23  std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
24  if (!dart_state) {
25  return;
26  }
27  tonic::DartState::Scope scope(dart_state);
28 
29  const std::vector<uint8_t>& buffer = packet.data();
30  Dart_Handle data_handle =
31  tonic::DartByteData::Create(buffer.data(), buffer.size());
32  if (Dart_IsError(data_handle)) {
33  return;
34  }
36  library_.value(), "_dispatchPointerDataPacket", {data_handle}));
37 }
38 
40  uint64_t response_id) {
41  std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
42  if (!dart_state)
43  return;
44  tonic::DartState::Scope scope(dart_state);
45 
46  const std::vector<uint8_t>& buffer = packet.data();
47  Dart_Handle data_handle =
48  tonic::DartByteData::Create(buffer.data(), buffer.size());
49  if (Dart_IsError(data_handle)) {
50  return;
51  }
53  tonic::DartInvokeField(library_.value(), "_dispatchKeyData",
54  {data_handle, tonic::ToDart(response_id)}));
55 }
56 
58  viewport_metrics_ = metrics;
59 
60  std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
61  if (!dart_state) {
62  return;
63  }
64  tonic::DartState::Scope scope(dart_state);
66  library_.value(), "_updateWindowMetrics",
67  {tonic::ToDart(window_id_), tonic::ToDart(metrics.device_pixel_ratio),
83 }
84 
85 } // namespace flutter
Dart_PersistentHandle value() const
void Set(DartState *dart_state, Dart_Handle value)
static DartState * Current()
Definition: dart_state.cc:56
Dart_Handle DartInvokeField(Dart_Handle target, const char *name, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:12
const std::vector< uint8_t > & data() const
const std::weak_ptr< DartState > & dart_state() const
Window(int64_t window_id, ViewportMetrics metrics)
Definition: window.cc:14
static const uint8_t buffer[]
void DispatchKeyDataPacket(const KeyDataPacket &packet, uint64_t response_id)
Definition: window.cc:39
void DispatchPointerDataPacket(const PointerDataPacket &packet)
Definition: window.cc:22
static Dart_Handle Create(const void *data, size_t length)
Dart_Handle ToDart(const T &object)
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15
const std::vector< uint8_t > & data() const
void UpdateWindowMetrics(const ViewportMetrics &metrics)
Definition: window.cc:57