5#include "flutter/shell/platform/android/image_external_texture_vk.h"
9#include "flutter/impeller/core/formats.h"
10#include "flutter/impeller/core/texture_descriptor.h"
11#include "flutter/impeller/display_list/dl_image_impeller.h"
12#include "flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h"
13#include "flutter/impeller/renderer/backend/vulkan/command_buffer_vk.h"
14#include "flutter/impeller/renderer/backend/vulkan/command_encoder_vk.h"
15#include "flutter/impeller/renderer/backend/vulkan/texture_vk.h"
16#include "flutter/impeller/toolkit/android/hardware_buffer.h"
21 const std::shared_ptr<impeller::ContextVK>& impeller_context,
24 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
26 impeller_context_(impeller_context) {}
30void ImageExternalTextureVK::Attach(
PaintContext& context) {
37void ImageExternalTextureVK::Detach() {}
39void ImageExternalTextureVK::ProcessFrame(PaintContext& context,
42 if (
image.is_null()) {
50 std::optional<HardwareBufferKey>
key =
52 latest_hardware_buffer);
54 if (existing_image !=
nullptr || !hb_desc.has_value()) {
61 auto texture_source = std::make_shared<impeller::AHBTextureSourceVK>(
62 impeller_context_, latest_hardware_buffer, hb_desc.value());
63 if (!texture_source->IsValid()) {
69 std::make_shared<impeller::TextureVK>(impeller_context_, texture_source);
72 auto buffer = impeller_context_->CreateCommandBuffer();
78 barrier.
src_access = impeller::vk::AccessFlagBits::eColorAttachmentWrite |
79 impeller::vk::AccessFlagBits::eTransferWrite;
81 impeller::vk::PipelineStageFlagBits::eColorAttachmentOutput |
82 impeller::vk::PipelineStageFlagBits::eTransfer;
83 barrier.
dst_access = impeller::vk::AccessFlagBits::eShaderRead;
84 barrier.
dst_stage = impeller::vk::PipelineStageFlagBits::eFragmentShader;
86 barrier.
new_layout = impeller::vk::ImageLayout::eShaderReadOnlyOptimal;
88 if (!
texture->SetLayout(barrier)) {
91 if (!impeller_context_->GetCommandQueue()->Submit({buffer}).ok()) {
97 if (
key.has_value()) {
struct AHardwareBuffer AHardwareBuffer
~ImageExternalTextureVK() override
ImageExternalTextureVK(const std::shared_ptr< impeller::ContextVK > &impeller_context, int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &hardware_buffer_texture_entry, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
AHardwareBuffer * AHardwareBufferFor(const fml::jni::JavaRef< jobject > &hardware_buffer)
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef< jobject > &image)
void CloseHardwareBuffer(const fml::jni::JavaRef< jobject > &hardware_buffer)
sk_sp< flutter::DlImage > dl_image_
JavaLocalRef AcquireLatestImage()
HardwareBufferKey AddImage(const sk_sp< flutter::DlImage > &image, HardwareBufferKey key)
Add a new image to the cache with a key, returning the key of the LRU entry that was removed.
sk_sp< flutter::DlImage > FindImage(std::optional< HardwareBufferKey > key)
Retrieve the image associated with the given [key], or nullptr.
static CommandBufferVK & Cast(CommandBuffer &base)
const std::shared_ptr< CommandEncoderVK > & GetEncoder()
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
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...
Optional< SkRect > bounds
sk_sp< const SkImage > image
std::nullptr_t JavaLocalRef
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
Defines an operations and memory access barrier on a resource.
vk::CommandBuffer cmd_buffer
vk::AccessFlags src_access
vk::PipelineStageFlags dst_stage
vk::ImageLayout new_layout
vk::PipelineStageFlags src_stage
vk::AccessFlags dst_access