• 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_FLOW_VIEW_HOLDER_H_
6 #define FLUTTER_FLOW_VIEW_HOLDER_H_
7 
8 #include <fuchsia/ui/gfx/cpp/fidl.h>
9 #include <fuchsia/ui/views/cpp/fidl.h>
10 #include <lib/ui/scenic/cpp/id.h>
11 #include <lib/ui/scenic/cpp/resources.h>
12 #include <third_party/skia/include/core/SkMatrix.h>
13 #include <third_party/skia/include/core/SkPoint.h>
14 #include <third_party/skia/include/core/SkSize.h>
15 #include <zircon/types.h>
16 
17 #include <memory>
18 
19 #include "flutter/flow/scene_update_context.h"
20 #include "flutter/fml/macros.h"
21 #include "flutter/fml/memory/ref_counted.h"
22 #include "flutter/fml/task_runner.h"
23 
24 namespace flutter {
25 
26 // Represents a Scenic |ViewHolder| resource that imports a |View| from another
27 // session.
28 //
29 // This object is created and destroyed on the |Rasterizer|'s thread.
30 class ViewHolder {
31  public:
32   using BindCallback = std::function<void(scenic::ResourceId)>;
33 
34   static void Create(zx_koid_t id,
35                      fml::RefPtr<fml::TaskRunner> ui_task_runner,
36                      fuchsia::ui::views::ViewHolderToken view_holder_token,
37                      BindCallback on_bind_callback);
38   static void Destroy(zx_koid_t id);
39   static ViewHolder* FromId(zx_koid_t id);
40 
41   ViewHolder(fml::RefPtr<fml::TaskRunner> ui_task_runner,
42              fuchsia::ui::views::ViewHolderToken view_holder_token,
43              BindCallback on_bind_callback);
44   ~ViewHolder() = default;
45 
46   // Sets the properties/opacity of the child view by issuing a Scenic command.
47   void SetProperties(double width,
48                      double height,
49                      double insetTop,
50                      double insetRight,
51                      double insetBottom,
52                      double insetLeft,
53                      bool focusable);
54   void SetOpacity(double opacity);
55 
56   // Creates or updates the contained ViewHolder resource using the specified
57   // |SceneUpdateContext|.
58   void UpdateScene(SceneUpdateContext& context,
59                    const SkPoint& offset,
60                    const SkSize& size,
61                    bool hit_testable);
62 
63  private:
64   fml::RefPtr<fml::TaskRunner> ui_task_runner_;
65 
66   std::unique_ptr<scenic::OpacityNodeHACK> opacity_node_;
67   std::unique_ptr<scenic::EntityNode> entity_node_;
68   std::unique_ptr<scenic::ViewHolder> view_holder_;
69 
70   fuchsia::ui::views::ViewHolderToken pending_view_holder_token_;
71   BindCallback pending_bind_callback_;
72 
73   fuchsia::ui::gfx::ViewProperties pending_properties_;
74   double pending_opacity_;
75   bool has_pending_properties_ = false;
76   bool has_pending_opacity_ = false;
77 
78   FML_DISALLOW_COPY_AND_ASSIGN(ViewHolder);
79 };
80 
81 }  // namespace flutter
82 
83 #endif  // FLUTTER_FLOW_VIEW_HOLDER_H_
84