10#define GL_GLEXT_PROTOTYPES
11#include <GLES2/gl2ext.h>
26 std::shared_ptr<impeller::ContextVK> context,
29 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
31 context_(
std::move(context)),
32 trampoline_(
std::make_shared<glvk::Trampoline>()) {
33 is_valid_ = trampoline_->IsValid();
46 vk::ImageLayout layout,
53 if (!command_buffer) {
55 <<
"Could not create command buffer for texture layout update.";
58 command_buffer->SetLabel(
"GLVKTextureLayoutUpdateCB");
59 const CommandBufferVK& encoder = CommandBufferVK::Cast(*command_buffer);
65 barrier.
src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput |
66 impeller::vk::PipelineStageFlagBits::eFragmentShader;
67 barrier.
src_access = vk::AccessFlagBits::eColorAttachmentWrite |
68 vk::AccessFlagBits::eShaderRead;
69 barrier.
dst_stage = impeller::vk::PipelineStageFlagBits::eFragmentShader;
70 barrier.
dst_access = vk::AccessFlagBits::eShaderRead;
72 if (!
texture->SetLayout(barrier).ok()) {
79 vk::SubmitInfo submit_info;
80 submit_info.setCommandBuffers(command_buffer_vk);
84 vk::UniqueFence fence;
88 context.
GetDevice().createFenceUnique(vk::FenceCreateFlags{});
89 if (fence_pair.result != impeller::vk::Result::eSuccess) {
93 fence = std::move(fence_pair.value);
97 impeller::vk::Result::eSuccess) {
102 using namespace std::chrono_literals;
108 std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count()
109 ) != impeller::vk::Result::eSuccess) {
118void SurfaceTextureExternalTextureVKImpeller::ProcessFrame(
119 PaintContext& context,
120 const SkRect& bounds) {
121 if (!is_valid_ || !context.aiks_context) {
125 DlMatrix matrix = context.canvas->GetMatrix();
128 const auto& surface_context =
129 SurfaceContextVK::Cast(*context.aiks_context->GetContext());
130 const auto& context_vk = ContextVK::Cast(*surface_context.GetParent());
132 auto dst_texture = GetCachedTextureSource(
133 surface_context.GetParent(),
136 if (!dst_texture || !dst_texture->IsValid()) {
141 auto current_context = trampoline_->MakeCurrentContext();
143 GLuint src_gl_texture = {};
144 glGenTextures(1u, &src_gl_texture);
149 vk::ImageLayout::eColorAttachmentOptimal,
154 reinterpret_cast<SkScalar*
>(&uv_transformation));
157 src_texture.
texture = src_gl_texture;
158 src_texture.
target = GL_TEXTURE_EXTERNAL_OES;
161 if (!trampoline_->BlitTextureOpenGLToVulkan(src_texture, *dst_texture)) {
166 vk::ImageLayout::eShaderReadOnlyOptimal,
169 glDeleteTextures(1u, &src_gl_texture);
172 std::make_shared<TextureVK>(surface_context.GetParent(), dst_texture));
176void SurfaceTextureExternalTextureVKImpeller::Detach() {
180 auto context = trampoline_->MakeCurrentContext();
182 cached_texture_source_.reset();
185std::shared_ptr<impeller::AHBTextureSourceVK>
186SurfaceTextureExternalTextureVKImpeller::GetCachedTextureSource(
187 const std::shared_ptr<Context>& context,
189 if (cached_texture_source_ &&
190 cached_texture_source_->GetTextureDescriptor().size ==
size) {
191 return cached_texture_source_;
193 cached_texture_source_ =
nullptr;
196 ahb_descriptor.
format = android::HardwareBufferFormat::kR8G8B8A8UNormInt;
198 ahb_descriptor.
usage =
199 android::HardwareBufferUsageFlags::kFrameBufferAttachment |
200 android::HardwareBufferUsageFlags::kSampledImage;
207 auto ahb = std::make_unique<android::HardwareBuffer>(ahb_descriptor);
208 if (!ahb->IsValid()) {
213 auto texture_source =
214 std::make_shared<AHBTextureSourceVK>(context, std::move(ahb),
false);
216 if (!texture_source->IsValid()) {
220 cached_texture_source_ = std::move(texture_source);
221 return cached_texture_source_;
225void SurfaceTextureExternalTextureVKImpeller::DrawFrame(
226 PaintContext& context,
227 const SkRect& bounds,
Instances of external textures peered to android.graphics.SurfaceTexture.
sk_sp< flutter::DlImage > dl_image_
void Attach(int gl_tex_id)
Attaches the given OpenGL texture handle to the surface texture via a bind operation.
const SkM44 & GetCurrentUVTransformation() const
Get the transformation that should be applied to the UV texture coordinates when sampling from this t...
virtual void Detach()
Provides an opportunity for the subclasses to sever the connection between the OpenGL texture resourc...
void Update()
Update the surface texture contents and transformation matrix.
SurfaceTextureExternalTextureVKImpeller(std::shared_ptr< impeller::ContextVK > context, int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &surface_texture, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
~SurfaceTextureExternalTextureVKImpeller() override
bool EndCommandBuffer() const
End recording of the current command buffer.
vk::CommandBuffer GetCommandBuffer() const
Retrieve the native command buffer from this object.
const vk::Device & GetDevice() const
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
const std::shared_ptr< QueueVK > & GetGraphicsQueue() const
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Abstract base class that represents a vkImage and an vkImageView.
impeller::Matrix DlMatrix
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
static bool SetTextureLayout(const ContextVK &context, const TextureSourceVK *texture, vk::ImageLayout layout, LayoutUpdateMode mode)
const DlRect & ToDlRect(const SkRect &rect)
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
A 4x4 matrix using column-major storage.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
constexpr TSize Max(const TSize &o) const
static constexpr TSize MakeWH(Type width, Type height)
A descriptor use to specify hardware buffer allocations.
HardwareBufferUsage usage
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
HardwareBufferFormat format
Describes an OpenGL texture along with information on how to sample from it.
#define TRACE_EVENT0(category_group, name)