Add GLES support for the same pixel formats for copying texture -> buffer as when copying buffer -> texture (#183428)

`BlitCopyBufferToTextureCommandGLES` (and initializing/setting texture
contents in `TextureGLES`) supports a bunch of different pixel formats,
as defined in the `TexImage2DData` constructors in
`blit_command_gles.cc` and `texture_gles.cc`.

But `BlitCopyTextureToBufferCommandGLES` only has support specifically
for `kR8G8B8A8UNormInt` and `kB8G8R8A8UNormInt`.

This makes `BlitCopyTextureToBufferCommandGLES` support the same pixel
formats as `BlitCopyBufferToTextureCommandGLES` and `TextureGLES`.

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

## Changes:

### Share `ToPixelFormatGLES`

`blit_command_gles.cc` and `texture_gles.cc` have almost-duplicate logic
to convert `impeller::PixelFormat` to a `GLint internal_format`, a
`GLenum external_format`, and a `GLenum type`. Factor this out into a
shared `ToPixelFormatGLES` function in `formats_gles.h/cc`.

Where there were differences between the `blit_command_gles.cc` and
`texture_gles.cc`:
- `kR32G32B32A32Float`:
- `blit_command_gles.cc` has `internal_format = GL_RGBA`,
`external_format = GL_RGBA`
- `texture_gles.cc` has `internal_format = GL_RGBA32F`, `external_format
= GL_RGBA`
  - I used `internal_format = GL_RGBA32F`, `external_format = GL_RGBA`
- `kR16G16B16A16Float`:
- `blit_command_gles.cc` has `internal_format = GL_RGBA`,
`external_format = GL_RGBA`
- `texture_gles.cc` has `internal_format = GL_RGBA16F`, `external_format
= GL_RGBA`
  - I used `internal_format = GL_RGBA16F`, `external_format = GL_RGBA`
- `kR32Float`:
- `blit_command_gles.cc` has `internal_format = GL_RED`,
`external_format = GL_RED`
- `texture_gles.cc` has `internal_format = GL_R32F`, `external_format =
GL_RGBA`
  - I used `internal_format = GL_R32F`, `external_format = GL_RED`

All the other PixelFormat cases were the same between the two files and
copied over directly.

### Remove `TexImage2DData`

`blit_command_gles.cc` and `texture_gles.cc` each define a
`TexImage2DData` struct which just contains the pixel format data and
sometimes an optional data buffer. I removed both of these. Instead, we
just use the `ToPixelFormatGLES` return value directly, and use the
source data buffer directly.

### Improve pixel format support in
`BlitCopyTextureToBufferCommandGLES::Encode()`

In `BlitCopyTextureToBufferCommandGLES::Encode()`, use
`ToPixelFormatGLES()` to determine the format and type used for
`gl.ReadPixels()`. This expands the existing functionality that only
supported two specific pixel formats.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
6 files changed
tree: bc7c5879ae20d85af8d38462539fe7d93987c515
  1. .gemini/
  2. .github/
  3. .vscode/
  4. bin/
  5. buildtools/
  6. dev/
  7. docs/
  8. engine/
  9. examples/
  10. packages/
  11. third_party/
  12. .autoroller-preupload.sh
  13. .ci.yaml
  14. .gitattributes
  15. .gitignore
  16. analysis_options.yaml
  17. AUTHORS
  18. CHANGELOG.md
  19. CODE_OF_CONDUCT.md
  20. CODEOWNERS
  21. CONTRIBUTING.md
  22. dartdoc_options.yaml
  23. DEPS
  24. flutter_console.bat
  25. LICENSE
  26. PATENT_GRANT
  27. pubspec.lock
  28. pubspec.yaml
  29. README.md
  30. TESTOWNERS
README.md

Flutter CI Status Discord badge Twitter handle BlueSky badge codecov LFX Health Score CII Best Practices SLSA 1

Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.

Documentation

For release and other announcements, join the flutter-announce mailing list. Our documentation also tracks breaking changes across releases.

Terms of service

The Flutter tool may occasionally download resources from Google servers. By downloading or using the Flutter SDK, you agree to the Google Terms of Service: https://policies.google.com/terms

For example, when installed from GitHub (as opposed to from a prepackaged archive), the Flutter tool will download the Dart SDK from Google servers immediately when first run, as it is used to execute the flutter tool itself. This will also occur when Flutter is upgraded (e.g. by running the flutter upgrade command).

About Flutter

We think Flutter will help you create beautiful, fast apps, with a productive, extensible and open development model, whether you're targeting iOS or Android, web, Windows, macOS, Linux or embedding it as the UI toolkit for a platform of your choice.

Beautiful user experiences

We want to enable designers to deliver their full creative vision without being forced to water it down due to limitations of the underlying framework. Flutter‘s layered architecture gives you control over every pixel on the screen and its powerful compositing capabilities let you overlay and animate graphics, video, text, and controls without limitation. Flutter includes a full set of widgets that deliver pixel-perfect experiences whether you’re building for iOS (Cupertino) or other platforms (Material), along with support for customizing or creating entirely new visual components.

Fast results

Flutter is fast. It's powered by hardware-accelerated 2D graphics libraries like Skia (which underpins Chrome and Android) and Impeller. We architected Flutter to support glitch-free, jank-free graphics at the native speed of your device.

Flutter code is powered by the world-class Dart programming language, which enables compilation to 32-bit and 64-bit ARM machine code for iOS and Android, JavaScript and WebAssembly for the web, as well as Intel x64 and ARM for desktop devices.

Productive development

Flutter offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting your app or losing its state.

Hot reload animation

Extensible and open model

Flutter works with any development tool (or none at all), and also includes editor plug-ins for both Visual Studio Code and IntelliJ / Android Studio. Flutter provides tens of thousands of packages to speed your development, regardless of your target platform. And accessing other native code is easy, with support for both FFI (on Android, on iOS, on macOS, and on Windows) as well as platform-specific APIs.

Flutter is a fully open-source project, and we welcome contributions. Information on how to get started can be found in our contributor guide.