| Flutter Impeller |

Classes | Public Member Functions | Static Public Member Functions | List of all members
impeller::android::SurfaceControl Class Reference

A wrapper for ASurfaceControl. https://developer.android.com/ndk/reference/group/native-activity#asurfacecontrol. More...

`#include <surface_control.h>`

## Public Member Functions
| SurfaceControl (ANativeWindow *window, const char *debug_name=nullptr)
| Creates a new surface control and adds it as a child of the given window. More...
| ~SurfaceControl ()
| Removes the surface control from the presentation hierarchy managed by the system compositor and release the client side reference to the control. At this point, it may be collected when the compositor is also done using it. More...
| SurfaceControl (const SurfaceControl &)=delete
SurfaceControl & | operator= (const SurfaceControl &)=delete
bool | IsValid () const
ASurfaceControl * | GetHandle () const
bool | RemoveFromParent () const
| Remove the surface control from the hierarchy of nodes presented by the system compositor. More...

## Static Public Member Functions
static bool | IsAvailableOnPlatform ()

## Detailed Description

A wrapper for ASurfaceControl. https://developer.android.com/ndk/reference/group/native-activity#asurfacecontrol.

Instances of this class represent a node in the hierarchy of surfaces sent to the system compositor for final composition.

This wrapper is only available on Android API 29 and above.

Definition at line 22 of file surface_control.h.

## Constructor & Destructor Documentation

## ◆ SurfaceControl() [1/2]

impeller::android::SurfaceControl::SurfaceControl | ( | ANativeWindow * | window,
|  | const char * | debug_name = `nullptr`
| ) |  |
| explicit

Creates a new surface control and adds it as a child of the given window.

Parameters

  | window | The window
  [in] | debug_name | A debug name. See it using `adb shell dumpsys SurfaceFlinger` along with other control properties. If no debug name is specified, the value "Impeller Layer" is used.

Definition at line 13 of file surface_control.cc.

13 {
14 if (window == nullptr) {
15 VALIDATION_LOG << "Parent window of surface was null.";
16 return;
17 }
18 if (debug_name == nullptr) {
19 debug_name = "Impeller Layer";
20 }
21 control_.reset(
22 GetProcTable().ASurfaceControl_createFromWindow(window, debug_name));
23 }

References impeller::android::GetProcTable(), and VALIDATION_LOG.

## ◆ ~SurfaceControl()

impeller::android::SurfaceControl::~SurfaceControl | ( |  | ) |

Removes the surface control from the presentation hierarchy managed by the system compositor and release the client side reference to the control. At this point, it may be collected when the compositor is also done using it.

Definition at line 25 of file surface_control.cc.

25 {
26 if (IsValid() && !RemoveFromParent()) {
27 VALIDATION_LOG << "Surface control could not be removed from its parent. "
28 "Expect a leak.";
29 }
30 }

References IsValid(), RemoveFromParent(), and VALIDATION_LOG.

## ◆ SurfaceControl() [2/2]

impeller::android::SurfaceControl::SurfaceControl | ( | const SurfaceControl & |  | ) |
| delete

## Member Function Documentation

## ◆ GetHandle()

ASurfaceControl * impeller::android::SurfaceControl::GetHandle | ( |  | ) | const

Definition at line 36 of file surface_control.cc.

36 {
37 return control_.get();
38 }

Referenced by impeller::android::CreatePreviousReleaseFence(), impeller::android::SurfaceTransaction::SetBackgroundColor(), impeller::android::SurfaceTransaction::SetContents(), and impeller::android::SurfaceTransaction::SetParent().

## ◆ IsAvailableOnPlatform()

bool impeller::android::SurfaceControl::IsAvailableOnPlatform | ( |  | ) |
| static

Returns
  `true` if any surface controls can be created on this platform.

Definition at line 51 of file surface_control.cc.

51 {
52 return GetProcTable().IsValid() &&
53 GetProcTable().ASurfaceControl_createFromWindow.IsAvailable() &&
54 GetProcTable().ASurfaceTransaction_setEnableBackPressure.IsAvailable();
55 }

References impeller::android::GetProcTable(), and impeller::android::ProcTable::IsValid().

Referenced by impeller::AHBSwapchainVK::IsAvailableOnPlatform(), and impeller::android::testing::TEST().

## ◆ IsValid()

bool impeller::android::SurfaceControl::IsValid | ( |  | ) | const

Definition at line 32 of file surface_control.cc.

32 {
33 return control_.is_valid();
34 }

Referenced by RemoveFromParent(), impeller::android::SurfaceTransaction::SetBackgroundColor(), impeller::android::SurfaceTransaction::SetParent(), and ~SurfaceControl().

## ◆ operator=()

SurfaceControl& impeller::android::SurfaceControl::operator= | ( | const SurfaceControl & |  | ) |
| delete

## ◆ RemoveFromParent()

bool impeller::android::SurfaceControl::RemoveFromParent | ( |  | ) | const

Remove the surface control from the hierarchy of nodes presented by the system compositor.

This is called implicitly when the surface control is collected.

Returns
  `true` If the control will be removed from the hierarchy of nodes presented by the system compositor.

Definition at line 40 of file surface_control.cc.

40 {
41 if (!IsValid()) {
42 return false;
43 }
44 SurfaceTransaction transaction;
45 if (!transaction.SetParent(*this, nullptr)) {
46 return false;
47 }
48 return transaction.Apply();
49 }

References impeller::android::SurfaceTransaction::Apply(), IsValid(), and impeller::android::SurfaceTransaction::SetParent().

Referenced by ~SurfaceControl().

The documentation for this class was generated from the following files:

- impeller/toolkit/android/surface_control.h
- impeller/toolkit/android/surface_control.cc

impeller::android::SurfaceControl::IsValid
bool IsValid() const
Definition: surface_control.cc:32
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:40
impeller::android::ProcTable::IsValid
bool IsValid() const
If a valid proc table could be setup. This may fail in case of setup on non-Android platforms.
Definition: proc_table.cc:65
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition: proc_table.cc:12