| Flutter Impeller |

ahb_texture_pool_vk.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/renderer/backend/vulkan/swapchain/ahb/ahb_texture_pool_vk.h"
6
7 #include "flutter/fml/trace_event.h"
8
9 namespace impeller {
10
11 AHBTexturePoolVK::AHBTexturePoolVK(std::weak_ptr<Context> context,
12 android::HardwareBufferDescriptor desc)
13 : context_(std::move(context)), desc_(desc) {
14 if (!desc_.IsAllocatable()) {
15 VALIDATION_LOG << "Swapchain image is not allocatable.";
16 return;
17 }
18 is_valid_ = true;
19 }
20
21 AHBTexturePoolVK::~AHBTexturePoolVK() = default;
22
23 AHBTexturePoolVK::PoolEntry AHBTexturePoolVK::Pop() {
24 {
25 Lock lock(pool_mutex_);
26 if (!pool_.empty()) {
27 // Buffers are pushed to the back of the queue. To give the ready fences
28 // the most time to signal, pick a buffer from the front of the queue.
29 auto entry = pool_.front();
30 pool_.pop_front();
31 return entry;
32 }
33 }
34 return PoolEntry{CreateTexture()};
35 }
36
37 void AHBTexturePoolVK::Push(std::shared_ptr<AHBTextureSourceVK> texture,
38 fml::UniqueFD render_ready_fence) {
39 if (!texture) {
40 return;
41 }
42 Lock lock(pool_mutex_);
43 pool_.push_back(PoolEntry{std::move(texture), std::move(render_ready_fence)});
44 }
45
46 std::shared_ptr<AHBTextureSourceVK> AHBTexturePoolVK::CreateTexture() const {
47 TRACE_EVENT0("impeller", "CreateSwapchainTexture");
48 auto context = context_.lock();
49 if (!context) {
50 VALIDATION_LOG << "Context died before image could be created.";
51 return nullptr;
52 }
53
54 auto ahb = std::make_unique<android::HardwareBuffer>(desc_);
55 if (!ahb->IsValid()) {
56 VALIDATION_LOG << "Could not create hardware buffer of size: "
57 << desc_.size;
58 return nullptr;
59 }
60
61 auto ahb_texture_source =
62 std::make_shared<AHBTextureSourceVK>(context, std::move(ahb), true);
63 if (!ahb_texture_source->IsValid()) {
64 VALIDATION_LOG << "Could not create hardware buffer texture source for "
65 "swapchain image of size: "
66 << desc_.size;
67 return nullptr;
68 }
69
70 return ahb_texture_source;
71 }
72
73 bool AHBTexturePoolVK::IsValid() const {
74 return is_valid_;
75 }
76
77 } // namespace impeller
ahb_texture_pool_vk.h
impeller::AHBTexturePoolVK::Pop
PoolEntry Pop()
Pops an texture source from the pool. If the pool is empty, a new texture source is created and retur...
Definition: ahb_texture_pool_vk.cc:23
impeller::AHBTexturePoolVK::IsValid
bool IsValid() const
If the pool can create and pool hardware buffer backed texture sources. The only reason valid texture...
Definition: ahb_texture_pool_vk.cc:73
impeller::AHBTexturePoolVK::AHBTexturePoolVK
AHBTexturePoolVK(std::weak_ptr< Context > context, android::HardwareBufferDescriptor desc)
Create a new (empty) texture pool.
Definition: ahb_texture_pool_vk.cc:11
impeller::AHBTexturePoolVK::~AHBTexturePoolVK
~AHBTexturePoolVK()
impeller::AHBTexturePoolVK::Push
void Push(std::shared_ptr< AHBTextureSourceVK > texture, fml::UniqueFD render_ready_fence)
Push a popped texture back into the pool. This also performs a GC.
Definition: ahb_texture_pool_vk.cc:37
impeller::Lock
Definition: thread.h:72
desc_
std::optional< PipelineDescriptor > desc_
Definition: content_context.cc:77
impeller
Definition: allocation.cc:12
std
Definition: comparable.h:95
impeller::AHBTexturePoolVK::PoolEntry
Definition: ahb_texture_pool_vk.h:31
impeller::android::HardwareBufferDescriptor
A descriptor use to specify hardware buffer allocations.
Definition: hardware_buffer.h:47
impeller::android::HardwareBufferDescriptor::size
ISize size
Definition: hardware_buffer.h:49
impeller::android::HardwareBufferDescriptor::IsAllocatable
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
Definition: hardware_buffer.cc:52
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91