Flutter Engine
The Flutter Engine
surface_transaction.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 "flutter/impeller/toolkit/android/surface_transaction.h"
6
7#include "flutter/impeller/toolkit/android/hardware_buffer.h"
8#include "flutter/impeller/toolkit/android/surface_control.h"
10
11namespace impeller::android {
12
14 : transaction_(GetProcTable().ASurfaceTransaction_create()) {}
15
17
19 return transaction_.is_valid();
20}
21
24};
25
27 if (!IsValid()) {
28 return false;
29 }
30
31 if (!callback) {
32 callback = [](auto) {};
33 }
34
35 const auto& proc_table = GetProcTable();
36
37 auto data = std::make_unique<TransactionInFlightData>();
38 data->callback = callback;
39 proc_table.ASurfaceTransaction_setOnComplete(
40 transaction_.get(), //
41 data.release(), //
42 [](void* context, ASurfaceTransactionStats* stats) -> void {
43 auto data = reinterpret_cast<TransactionInFlightData*>(context);
44 data->callback(stats);
45 delete data;
46 });
47 proc_table.ASurfaceTransaction_apply(transaction_.get());
48
49 // Transactions may not be applied over and over.
50 transaction_.reset();
51 return true;
52}
53
56 fml::UniqueFD acquire_fence) {
57 if (control == nullptr || buffer == nullptr) {
58 VALIDATION_LOG << "Invalid control or buffer.";
59 return false;
60 }
61
62 const auto& proc_table = GetProcTable();
63
64 proc_table.ASurfaceTransaction_setEnableBackPressure(
65 transaction_.get(), control->GetHandle(), true);
66
67 proc_table.ASurfaceTransaction_setBuffer(
68 transaction_.get(), //
69 control->GetHandle(), //
70 buffer->GetHandle(), //
71 acquire_fence.is_valid() ? acquire_fence.release() : -1 //
72 );
73 return true;
74}
75
77 const Color& color) {
78 if (!IsValid() || !control.IsValid()) {
79 return false;
80 }
81 GetProcTable().ASurfaceTransaction_setColor(transaction_.get(), //
82 control.GetHandle(), //
83 color.red, //
84 color.green, //
85 color.blue, //
86 color.alpha, //
87 ADATASPACE_SRGB_LINEAR //
88 );
89 return true;
90}
91
93 const SurfaceControl* new_parent) {
94 if (!IsValid() || !control.IsValid()) {
95 return false;
96 }
97 if (new_parent && !new_parent->IsValid()) {
98 return false;
99 }
100 GetProcTable().ASurfaceTransaction_reparent(
101 transaction_.get(), //
102 control.GetHandle(), //
103 new_parent == nullptr ? nullptr : new_parent->GetHandle() //
104 );
105 return true;
106}
107
109 return GetProcTable().IsValid() &&
110 GetProcTable().ASurfaceTransaction_create.IsAvailable();
111}
112
113} // namespace impeller::android
void reset(const T &value=Traits::InvalidValue())
Definition: unique_object.h:62
bool is_valid() const
Definition: unique_object.h:89
const T & get() const
Definition: unique_object.h:87
A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.
A wrapper for ASurfaceControl. https://developer.android.com/ndk/reference/group/native-activity#asur...
ASurfaceControl * GetHandle() const
bool SetContents(const SurfaceControl *control, const HardwareBuffer *buffer, fml::UniqueFD acquire_fence={})
Encodes that the updated contents of a surface control are specified by the given hardware buffer....
std::function< void(ASurfaceTransactionStats *)> OnCompleteCallback
bool Apply(OnCompleteCallback callback=nullptr)
Applies the updated encoded in the transaction and invokes the callback when the updated are complete...
bool SetBackgroundColor(const SurfaceControl &control, const Color &color)
Encodes the updated background color of the surface control. The update will not be committed till th...
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...
DlColor color
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
const ProcTable & GetProcTable()
Definition: proc_table.cc:12
dictionary stats
Definition: malisc.py:20
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
SurfaceTransaction::OnCompleteCallback callback
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define VALIDATION_LOG
Definition: validation.h:73