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  viewport_metrics_ = metrics;
41 
42  std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
43  if (!dart_state) {
44  return;
45  }
46  tonic::DartState::Scope scope(dart_state);
48  library_.value(), "_updateWindowMetrics",
49  {
50  tonic::ToDart(window_id_),
66  }));
67 }
68 
69 } // namespace flutter
Dart_PersistentHandle value() const
void Set(DartState *dart_state, Dart_Handle value)
static DartState * Current()
Definition: dart_state.cc:55
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
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
void UpdateWindowMetrics(const ViewportMetrics &metrics)
Definition: window.cc:39