Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
hardware_buffer.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
8
9namespace impeller::android {
10
11static AHardwareBuffer_Format ToAHardwareBufferFormat(
13 switch (format) {
15 return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
16 }
18}
19
20static AHardwareBuffer_Desc ToAHardwareBufferDesc(
21 const HardwareBufferDescriptor& desc) {
22 AHardwareBuffer_Desc ahb_desc = {};
23 ahb_desc.width = desc.size.width;
24 ahb_desc.height = desc.size.height;
25 ahb_desc.format = ToAHardwareBufferFormat(desc.format);
26 ahb_desc.layers = 1u;
28 ahb_desc.usage |= AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
29 }
31 ahb_desc.usage |= AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY;
32 }
34 ahb_desc.usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
35 }
36 return ahb_desc;
37}
38
40 const auto desc = ToAHardwareBufferDesc(*this);
41 return GetProcTable().AHardwareBuffer_isSupported(&desc) != 0u;
42}
43
45 : descriptor_(descriptor),
46 android_descriptor_(ToAHardwareBufferDesc(descriptor_)) {
47 if (!descriptor_.IsAllocatable()) {
48 VALIDATION_LOG << "The hardware buffer descriptor is not allocatable.";
49 return;
50 }
51 const auto& proc_table = GetProcTable();
52
53 AHardwareBuffer* buffer = nullptr;
54 if (auto result =
55 proc_table.AHardwareBuffer_allocate(&android_descriptor_, &buffer);
56 result != 0 || buffer == nullptr) {
57 VALIDATION_LOG << "Could not allocate hardware buffer. Error: " << result;
58 return;
59 }
60 buffer_.reset(buffer);
61 is_valid_ = true;
62}
63
65
67 return is_valid_;
68}
69
71 return buffer_.get();
72}
73
85
87 return descriptor_;
88}
89
90const AHardwareBuffer_Desc& HardwareBuffer::GetAndroidDescriptor() const {
91 return android_descriptor_;
92}
93
95 return GetProcTable().IsValid() && GetProcTable().AHardwareBuffer_isSupported;
96}
97
98std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID() const {
100}
101
102std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID(
104 if (!GetProcTable().AHardwareBuffer_getId) {
105 return std::nullopt;
106 }
107 uint64_t out_id = 0u;
108 if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
109 return std::nullopt;
110 }
111 return out_id;
112}
113
114std::optional<AHardwareBuffer_Desc> HardwareBuffer::Describe(
116 if (!buffer || !GetProcTable().AHardwareBuffer_describe) {
117 return std::nullopt;
118 }
119 AHardwareBuffer_Desc desc = {};
120 GetProcTable().AHardwareBuffer_describe(buffer, &desc);
121 return desc;
122}
123
124} // namespace impeller::android
struct AHardwareBuffer AHardwareBuffer
void reset(const T &value=Traits::InvalidValue())
const T & get() const
HardwareBuffer(HardwareBufferDescriptor descriptor)
const HardwareBufferDescriptor & GetDescriptor() const
AHardwareBuffer * GetHandle() const
const AHardwareBuffer_Desc & GetAndroidDescriptor() const
static std::optional< AHardwareBuffer_Desc > Describe(AHardwareBuffer *buffer)
std::optional< uint64_t > GetSystemUniqueID() const
Get the system wide unique ID of the hardware buffer if possible. This is only available on Android A...
static const uint8_t buffer[]
GAsyncResult * result
uint32_t uint32_t * format
#define FML_UNREACHABLE()
Definition logging.h:109
const ProcTable & GetProcTable()
Definition proc_table.cc:12
static AHardwareBuffer_Desc ToAHardwareBufferDesc(const HardwareBufferDescriptor &desc)
static AHardwareBuffer_Format ToAHardwareBufferFormat(HardwareBufferFormat format)
constexpr TSize Max(const TSize &o) const
Definition size.h:81
A descriptor use to specify hardware buffer allocations.
static HardwareBufferDescriptor MakeForSwapchainImage(const ISize &size)
Create a descriptor of the given size that is suitable for use as a swapchain image.
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
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:73