Ricky van den berg 0b894805c9
[Impeller] Fix VkImageView leak in WrappedTextureSourceVK (#181966)
## Description

Fixes https://github.com/flutter/flutter/issues/181967

`WrappedTextureSourceVK` in the embedder delegate path creates a
`VkImageView` every frame via `createImageView()` but never destroys it.
The handle is stored as a raw non-owning `vk::ImageView` and the
destructor is empty, leaking one `VkImageView` per frame (~60/sec on a
typical app).

This switches to `vk::UniqueImageView` for RAII ownership so the image
view is destroyed when the `WrappedTextureSourceVK` is released.

## Why this is safe

The resource lifetime is correct because Impeller's `TrackedObjectsVK`
holds a `shared_ptr` to the `TextureSourceVK` until the GPU fence
signals completion:

1. `RenderPassVK` calls `Track(attachment.texture)` on all render target
textures
2. `CommandBufferVK::Track()` stores `shared_ptr<TextureSourceVK>` in
`TrackedObjectsVK`
3. `TrackedObjectsVK` is cleared only in the fence completion callback,
after the GPU finishes

The `VkImageView` cannot be destroyed while the GPU is still using it.

## Scope

This only affects the **embedder delegate code path** (when `delegate_
!= nullptr` in `GPUSurfaceVulkanImpeller::AcquireFrame`). Android passes
`nullptr` as the delegate and uses `AcquireNextSurface()` instead, so
this change has **no effect on Android, iOS, or standard swapchain
rendering**.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added a test for the change if applicable. *(See note below)*

**Note on testing:** This is a resource leak fix in a Vulkan code path
that requires a running Vulkan device and embedder delegate. I was
unable to find existing test infrastructure for the embedder delegate
path in `GPUSurfaceVulkanImpeller`. Happy to add a test if reviewers can
point me to the right test harness.

Found while working on Impeller Vulkan support for Linux/Wayland with a
custom embedder.

[Contributor Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
2026-02-11 17:40:32 +00:00
..
2025-10-09 19:44:25 +00:00

Flutter Engine

Setting up the Engine development environment

See here