• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SESSION_CONNECTION_H_
6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_SESSION_CONNECTION_H_
7 
8 #include <fuchsia/ui/gfx/cpp/fidl.h>
9 #include <fuchsia/ui/scenic/cpp/fidl.h>
10 #include <fuchsia/ui/views/cpp/fidl.h>
11 #include <lib/fidl/cpp/interface_handle.h>
12 #include <lib/fidl/cpp/optional.h>
13 #include <lib/fit/function.h>
14 #include <lib/ui/scenic/cpp/resources.h>
15 #include <lib/ui/scenic/cpp/session.h>
16 
17 #include "flutter/flow/compositor_context.h"
18 #include "flutter/flow/scene_update_context.h"
19 #include "flutter/fml/closure.h"
20 #include "flutter/fml/macros.h"
21 #include "flutter/fml/trace_event.h"
22 #include "vulkan_surface_producer.h"
23 
24 namespace flutter_runner {
25 
26 // The component residing on the GPU thread that is responsible for
27 // maintaining the Scenic session connection and presenting node updates.
28 class SessionConnection final {
29  public:
30   SessionConnection(std::string debug_label,
31                     fuchsia::ui::views::ViewToken view_token,
32                     fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
33                     fml::closure session_error_callback,
34                     zx_handle_t vsync_event_handle);
35 
36   ~SessionConnection();
37 
has_metrics()38   bool has_metrics() const { return scene_update_context_.has_metrics(); }
39 
metrics()40   const fuchsia::ui::gfx::MetricsPtr& metrics() const {
41     return scene_update_context_.metrics();
42   }
43 
set_metrics(const fuchsia::ui::gfx::Metrics & metrics)44   void set_metrics(const fuchsia::ui::gfx::Metrics& metrics) {
45     fuchsia::ui::gfx::Metrics metrics_copy;
46     metrics.Clone(&metrics_copy);
47     scene_update_context_.set_metrics(
48         fidl::MakeOptional(std::move(metrics_copy)));
49   }
50 
scene_update_context()51   flutter::SceneUpdateContext& scene_update_context() {
52     return scene_update_context_;
53   }
54 
root_node()55   scenic::ContainerNode& root_node() { return root_node_; }
root_view()56   scenic::View* root_view() { return &root_view_; }
57 
58   void Present(flutter::CompositorContext::ScopedFrame& frame);
59 
60   void OnSessionSizeChangeHint(float width_change_factor,
61                                float height_change_factor);
62 
63  private:
64   const std::string debug_label_;
65   scenic::Session session_wrapper_;
66 
67   scenic::View root_view_;
68   scenic::EntityNode root_node_;
69 
70   std::unique_ptr<VulkanSurfaceProducer> surface_producer_;
71   flutter::SceneUpdateContext scene_update_context_;
72 
73   zx_handle_t vsync_event_handle_;
74 
75   // A flow event trace id for following |Session::Present| calls into
76   // Scenic.  This will be incremented each |Session::Present| call.  By
77   // convention, the Scenic side will also contain its own trace id that
78   // begins at 0, and is incremented each |Session::Present| call.
79   uint64_t next_present_trace_id_ = 0;
80   uint64_t next_present_session_trace_id_ = 0;
81   uint64_t processed_present_session_trace_id_ = 0;
82 
83   bool presentation_callback_pending_ = false;
84   bool present_session_pending_ = false;
85 
86   void EnqueueClearOps();
87 
88   void PresentSession();
89 
90   static void ToggleSignal(zx_handle_t handle, bool raise);
91 
92   FML_DISALLOW_COPY_AND_ASSIGN(SessionConnection);
93 };
94 
95 }  // namespace flutter_runner
96 
97 #endif  // FLUTTER_SHELL_PLATFORM_FUCHSIA_SESSION_CONNECTION_H_
98