| Flutter Impeller |

surface_control.cc
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 #include "impeller/toolkit/android/surface_control.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/toolkit/android/proc_table.h"
9 #include "impeller/toolkit/android/surface_transaction.h"
10
11 namespace impeller::android {
12
13 SurfaceControl::SurfaceControl(ANativeWindow* window, const char* debug_name) {
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 }
24
25 SurfaceControl::~SurfaceControl() {
26 if (IsValid() && !RemoveFromParent()) {
27 VALIDATION_LOG << "Surface control could not be removed from its parent. "
28 "Expect a leak.";
29 }
30 }
31
32 bool SurfaceControl::IsValid() const {
33 return control_.is_valid();
34 }
35
36 ASurfaceControl* SurfaceControl::GetHandle() const {
37 return control_.get();
38 }
39
40 bool SurfaceControl::RemoveFromParent() const {
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 }
50
51 bool SurfaceControl::IsAvailableOnPlatform() {
52 return GetProcTable().IsValid() &&
53 GetProcTable().ASurfaceControl_createFromWindow.IsAvailable() &&
54 GetProcTable().ASurfaceTransaction_setEnableBackPressure.IsAvailable();
55 }
56
57 } // namespace impeller::android
impeller::android::SurfaceTransaction::SetParent
bool SetParent(const SurfaceControl &control, const SurfaceControl *new_parent=nullptr)
Set the new parent control of the given control. If the new parent is null, it is removed from the co...
Definition: surface_transaction.cc:92
impeller::android::SurfaceTransaction
A wrapper for ASurfaceTransaction. https://developer.android.com/ndk/reference/group/native-activity#...
Definition: surface_transaction.h:35
impeller::android::SurfaceControl::~SurfaceControl
~SurfaceControl()
Removes the surface control from the presentation hierarchy managed by the system compositor and rele...
Definition: surface_control.cc:25
impeller::android::SurfaceControl::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: surface_control.cc:51
surface_control.h
impeller::android::SurfaceControl::IsValid
bool IsValid() const
Definition: surface_control.cc:32
validation.h
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:40
impeller::android::SurfaceTransaction::Apply
bool Apply(OnCompleteCallback callback=nullptr)
Applies the updated encoded in the transaction and invokes the callback when the updated are complete...
Definition: surface_transaction.cc:26
proc_table.h
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
impeller::android::SurfaceControl::GetHandle
ASurfaceControl * GetHandle() const
Definition: surface_control.cc:36
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
surface_transaction.h
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:13