Flutter Impeller
surface_control.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_IMPELLER_TOOLKIT_ANDROID_SURFACE_CONTROL_H_
6 #define FLUTTER_IMPELLER_TOOLKIT_ANDROID_SURFACE_CONTROL_H_
7 
8 #include "flutter/fml/unique_object.h"
10 
11 namespace impeller::android {
12 
13 //------------------------------------------------------------------------------
14 /// @brief A wrapper for ASurfaceControl.
15 /// https://developer.android.com/ndk/reference/group/native-activity#asurfacecontrol
16 ///
17 /// Instances of this class represent a node in the hierarchy of
18 /// surfaces sent to the system compositor for final composition.
19 ///
20 /// This wrapper is only available on Android API 29 and above.
21 ///
23  public:
24  //----------------------------------------------------------------------------
25  /// @return `true` if any surface controls can be created on this
26  /// platform.
27  ///
28  static bool IsAvailableOnPlatform();
29 
30  //----------------------------------------------------------------------------
31  /// @brief Creates a new surface control and adds it as a child of the
32  /// given window.
33  ///
34  /// @param window The window
35  /// @param[in] debug_name A debug name. See it using
36  /// `adb shell dumpsys SurfaceFlinger` along with
37  /// other control properties. If no debug name is
38  /// specified, the value "Impeller Layer" is used.
39  ///
40  explicit SurfaceControl(ANativeWindow* window,
41  const char* debug_name = nullptr);
42 
43  //----------------------------------------------------------------------------
44  /// @brief Removes the surface control from the presentation hierarchy
45  /// managed by the system compositor and release the client side
46  /// reference to the control. At this point, it may be collected
47  /// when the compositor is also done using it.
48  ///
50 
51  SurfaceControl(const SurfaceControl&) = delete;
52 
53  SurfaceControl& operator=(const SurfaceControl&) = delete;
54 
55  bool IsValid() const;
56 
57  ASurfaceControl* GetHandle() const;
58 
59  //----------------------------------------------------------------------------
60  /// @brief Remove the surface control from the hierarchy of nodes
61  /// presented by the system compositor.
62  ///
63  /// @return `true` If the control will be removed from the hierarchy of
64  /// nodes presented by the system compositor.
65  ///
66  bool RemoveFromParent() const;
67 
68  private:
69  struct UniqueASurfaceControlTraits {
70  static ASurfaceControl* InvalidValue() { return nullptr; }
71 
72  static bool IsValid(ASurfaceControl* value) {
73  return value != InvalidValue();
74  }
75 
76  static void Free(ASurfaceControl* value) {
77  GetProcTable().ASurfaceControl_release(value);
78  }
79  };
80 
81  fml::UniqueObject<ASurfaceControl*, UniqueASurfaceControlTraits> control_;
82 };
83 
84 } // namespace impeller::android
85 
86 #endif // FLUTTER_IMPELLER_TOOLKIT_ANDROID_SURFACE_CONTROL_H_
impeller::android::SurfaceControl::~SurfaceControl
~SurfaceControl()
Removes the surface control from the presentation hierarchy managed by the system compositor and rele...
Definition: surface_control.cc:24
impeller::android::SurfaceControl::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: surface_control.cc:50
impeller::android::SurfaceControl
A wrapper for ASurfaceControl. https://developer.android.com/ndk/reference/group/native-activity#asur...
Definition: surface_control.h:22
impeller::android::SurfaceControl::IsValid
bool IsValid() const
Definition: surface_control.cc:31
impeller::android::SurfaceControl::operator=
SurfaceControl & operator=(const SurfaceControl &)=delete
impeller::android
Definition: choreographer.cc:9
impeller::android::SurfaceControl::RemoveFromParent
bool RemoveFromParent() const
Remove the surface control from the hierarchy of nodes presented by the system compositor.
Definition: surface_control.cc:39
proc_table.h
impeller::android::SurfaceControl::GetHandle
ASurfaceControl * GetHandle() const
Definition: surface_control.cc:35
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
impeller::android::SurfaceControl::SurfaceControl
SurfaceControl(ANativeWindow *window, const char *debug_name=nullptr)
Creates a new surface control and adds it as a child of the given window.
Definition: surface_control.cc:12