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 
6 
9 
10 namespace impeller::android {
11 
12 SurfaceControl::SurfaceControl(ANativeWindow* window, const char* debug_name) {
13  if (window == nullptr) {
14  VALIDATION_LOG << "Parent window of surface was null.";
15  return;
16  }
17  if (debug_name == nullptr) {
18  debug_name = "Impeller Layer";
19  }
20  control_.reset(
21  GetProcTable().ASurfaceControl_createFromWindow(window, debug_name));
22 }
23 
25  if (IsValid() && !RemoveFromParent()) {
26  VALIDATION_LOG << "Surface control could not be removed from its parent. "
27  "Expect a leak.";
28  }
29 }
30 
32  return control_.is_valid();
33 }
34 
35 ASurfaceControl* SurfaceControl::GetHandle() const {
36  return control_.get();
37 }
38 
40  if (!IsValid()) {
41  return false;
42  }
43  SurfaceTransaction transaction;
44  if (!transaction.SetParent(*this, nullptr)) {
45  return false;
46  }
47  return transaction.Apply();
48 }
49 
51  auto api_level = android_get_device_api_level();
52 
53  // Technically SurfaceControl is supported on API 29 but I've observed
54  // enough reported bugs that I'm bumping the constraint to 30. If
55  // we had more time to test all of these older devices maybe we could
56  // figure out what the problem is.
57  // https://github.com/flutter/flutter/issues/155877
58  return api_level >= 29 && GetProcTable().IsValid() &&
59  GetProcTable().ASurfaceControl_createFromWindow.IsAvailable();
60 }
61 
62 } // namespace impeller::android
~SurfaceControl()
Removes the surface control from the presentation hierarchy managed by the system compositor and rele...
SurfaceControl(ANativeWindow *window, const char *debug_name=nullptr)
Creates a new surface control and adds it as a child of the given window.
bool RemoveFromParent() const
Remove the surface control from the hierarchy of nodes presented by the system compositor.
ASurfaceControl * GetHandle() const
A wrapper for ASurfaceTransaction. https://developer.android.com/ndk/reference/group/native-activity#...
bool Apply(OnCompleteCallback callback=nullptr)
Applies the updated encoded in the transaction and invokes the callback when the updated are complete...
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...
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
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
#define VALIDATION_LOG
Definition: validation.h:91