Flutter Impeller
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
"
9
#include "
impeller/base/validation.h
"
10
11
namespace
impeller::android
{
12
13
SurfaceTransaction::SurfaceTransaction
()
14
: transaction_(
GetProcTable
().ASurfaceTransaction_create()) {}
15
16
SurfaceTransaction::~SurfaceTransaction
() =
default
;
17
18
bool
SurfaceTransaction::IsValid
()
const
{
19
return
transaction_.is_valid();
20
}
21
22
struct
TransactionInFlightData
{
23
SurfaceTransaction::OnCompleteCallback
callback
;
24
};
25
26
bool
SurfaceTransaction::Apply
(
OnCompleteCallback
callback) {
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
54
bool
SurfaceTransaction::SetContents
(
const
SurfaceControl
* control,
55
const
HardwareBuffer
* buffer,
56
fml::UniqueFD acquire_fence) {
57
if
(control ==
nullptr
|| buffer ==
nullptr
) {
58
VALIDATION_LOG
<<
"Invalid control or buffer."
;
59
return
false
;
60
}
61
GetProcTable
().ASurfaceTransaction_setBuffer(
62
transaction_.get(),
//
63
control->
GetHandle
(),
//
64
buffer->
GetHandle
(),
//
65
acquire_fence.is_valid() ? acquire_fence.release() : -1
//
66
);
67
return
true
;
68
}
69
70
bool
SurfaceTransaction::SetBackgroundColor
(
const
SurfaceControl
& control,
71
const
Color
&
color
) {
72
if
(!
IsValid
() || !control.
IsValid
()) {
73
return
false
;
74
}
75
GetProcTable
().ASurfaceTransaction_setColor(transaction_.get(),
//
76
control.
GetHandle
(),
//
77
color
.red,
//
78
color
.green,
//
79
color
.blue,
//
80
color
.alpha,
//
81
ADATASPACE_SRGB_LINEAR
//
82
);
83
return
true
;
84
}
85
86
bool
SurfaceTransaction::SetParent
(
const
SurfaceControl
& control,
87
const
SurfaceControl
* new_parent) {
88
if
(!
IsValid
() || !control.
IsValid
()) {
89
return
false
;
90
}
91
if
(new_parent && !new_parent->
IsValid
()) {
92
return
false
;
93
}
94
GetProcTable
().ASurfaceTransaction_reparent(
95
transaction_.get(),
//
96
control.
GetHandle
(),
//
97
new_parent ==
nullptr
?
nullptr
: new_parent->
GetHandle
()
//
98
);
99
return
true
;
100
}
101
102
bool
SurfaceTransaction::IsAvailableOnPlatform
() {
103
return
GetProcTable
().
IsValid
() &&
104
GetProcTable
().ASurfaceTransaction_create.IsAvailable();
105
}
106
107
}
// namespace impeller::android
hardware_buffer.h
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:86
impeller::android::TransactionInFlightData::callback
SurfaceTransaction::OnCompleteCallback callback
Definition:
surface_transaction.cc:23
impeller::android::SurfaceTransaction::~SurfaceTransaction
~SurfaceTransaction()
impeller::android::SurfaceTransaction::OnCompleteCallback
std::function< void(ASurfaceTransactionStats *)> OnCompleteCallback
Definition:
surface_transaction.h:87
surface_control.h
impeller::Color
Definition:
color.h:123
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
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::SurfaceTransaction::SetBackgroundColor
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...
Definition:
surface_transaction.cc:70
validation.h
impeller::android
Definition:
choreographer.cc:9
impeller::android::HardwareBuffer
A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.
Definition:
hardware_buffer.h:95
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
impeller::android::TransactionInFlightData
Definition:
surface_transaction.cc:22
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::SurfaceTransaction::IsValid
bool IsValid() const
Definition:
surface_transaction.cc:18
impeller::android::HardwareBuffer::GetHandle
AHardwareBuffer * GetHandle() const
Definition:
hardware_buffer.cc:83
impeller::android::SurfaceControl::GetHandle
ASurfaceControl * GetHandle() const
Definition:
surface_control.cc:35
VALIDATION_LOG
#define VALIDATION_LOG
Definition:
validation.h:91
surface_transaction.h
impeller::android::GetProcTable
const ProcTable & GetProcTable()
Definition:
proc_table.cc:12
color
DlColor color
Definition:
dl_golden_blur_unittests.cc:24
impeller::android::SurfaceTransaction::SurfaceTransaction
SurfaceTransaction()
Definition:
surface_transaction.cc:13
impeller::android::SurfaceTransaction::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition:
surface_transaction.cc:102
impeller::android::SurfaceTransaction::SetContents
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....
Definition:
surface_transaction.cc:54
impeller
toolkit
android
surface_transaction.cc
Generated by
1.8.17