Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
flatland_connection.h
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#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_CONNECTION_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_CONNECTION_H_
7
8#include <fuchsia/ui/composition/cpp/fidl.h>
9
10#include "flutter/fml/closure.h"
11#include "flutter/fml/macros.h"
12#include "flutter/fml/time/time_delta.h"
13#include "flutter/fml/time/time_point.h"
14
15#include "vsync_waiter.h"
16
17#include <cstdint>
18#include <mutex>
19#include <queue>
20#include <string>
21
22namespace flutter_runner {
23
25 std::function<void(fuchsia::scenic::scheduling::FramePresentedInfo)>;
26
27// 10ms interval to target vsync is only used until Scenic sends presentation
28// feedback.
31
32// The component residing on the raster thread that is responsible for
33// maintaining the Flatland instance connection and presenting updates.
34class FlatlandConnection final {
35 public:
36 FlatlandConnection(std::string debug_label,
37 fuchsia::ui::composition::FlatlandHandle flatland,
38 fml::closure error_callback,
39 on_frame_presented_event on_frame_presented_callback);
40
42
43 void Present();
44
45 // Used to implement VsyncWaiter functionality.
46 // Note that these two methods are called from the UI thread while the
47 // rest of the methods on this class are called from the raster thread.
50
51 fuchsia::ui::composition::Flatland* flatland() { return flatland_.get(); }
52
53 fuchsia::ui::composition::TransformId NextTransformId() {
54 return {++next_transform_id_};
55 }
56
57 fuchsia::ui::composition::ContentId NextContentId() {
58 return {++next_content_id_};
59 }
60
61 void EnqueueAcquireFence(zx::event fence);
62 void EnqueueReleaseFence(zx::event fence);
63
64 private:
65 void OnError(fuchsia::ui::composition::FlatlandError error);
66
67 void OnNextFrameBegin(
68 fuchsia::ui::composition::OnNextFrameBeginValues values);
69 void OnFramePresented(fuchsia::scenic::scheduling::FramePresentedInfo info);
70 void DoPresent();
71
72 fml::TimePoint GetNextPresentationTime(const fml::TimePoint& now);
73 bool MaybeRunInitialVsyncCallback(const fml::TimePoint& now,
75 void RunVsyncCallback(const fml::TimePoint& now,
77
78 fuchsia::ui::composition::FlatlandPtr flatland_;
79
80 fml::closure error_callback_;
81
82 uint64_t next_transform_id_ = 0;
83 uint64_t next_content_id_ = 0;
84
85 on_frame_presented_event on_frame_presented_callback_;
86 bool present_waiting_for_credit_ = false;
87
88 // A flow event trace id for following |Flatland::Present| calls into Scenic.
89 uint64_t next_present_trace_id_ = 0;
90
91 // This struct contains state that is accessed from both from the UI thread
92 // (in AwaitVsync) and the raster thread (in OnNextFrameBegin and Present).
93 // You should always lock mutex_ before touching anything in this struct
94 struct {
95 std::mutex mutex_;
96 std::queue<fml::TimePoint> next_presentation_times_;
101 uint32_t present_credits_ = 1;
103 } threadsafe_state_;
104
105 std::vector<zx::event> acquire_fences_;
106 std::vector<zx::event> current_present_release_fences_;
107 std::vector<zx::event> previous_present_release_fences_;
108 std::string debug_label_;
109
111};
112
113} // namespace flutter_runner
114
115#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_CONNECTION_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
fuchsia::ui::composition::ContentId NextContentId()
fuchsia::ui::composition::Flatland * flatland()
std::queue< fml::TimePoint > next_presentation_times_
void AwaitVsyncForSecondaryCallback(FireCallbackCallback callback)
void AwaitVsync(FireCallbackCallback callback)
fuchsia::ui::composition::TransformId NextTransformId()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition time_delta.h:46
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const uint8_t uint32_t uint32_t GError ** error
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event
std::function< void(fml::TimePoint, fml::TimePoint)> FireCallbackCallback
static constexpr fml::TimeDelta kInitialFlatlandVsyncOffset
std::function< void()> closure
Definition closure.h:14