[macOS/iOS] FlutterTextureRegistry accepts only a few CVPixelBuffer formats. It should be documented. #147242
Labels
d: api docs
Issues with https://api.flutter.dev/
engine
flutter/engine repository. See also e: labels.
platform-ios
iOS applications specifically
platform-mac
Building on or for macOS specifically
team-engine
Owned by Engine team
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
FlutterTextureRegistry
.kCVPixelFormatType_420YpCbCr8PlanarFullRange
.Expected results
The CVPixelBuffer should be rendered on Flutter's Texture widget.
Actual results
Glitches and incorrect colors.
Code sample
Unfortunately, the minimal working example is quite large. I will only attempt to upload a minimal example if it is necessary.
Analysis
According to the Flutter engine source code, the root cause of this issue is quite clear.
https://github.com/flutter/engine/blob/79f49954cce802a841be46a9a466ff4e50b8fa47/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm#80
In short, the Flutter engine checks if
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
andkCVPixelFormatType_420YpCbCr8BiPlanarFullRange
(a.k.a NV12) are used, and then proceeds to thewrapNV12ExternalPixelBuffer method
. Otherwise, it moves on to thewrapRGBAExternalPixelBuffer
method, which assumes that the pixel format iskCVPixelFormatType_32BGRA
, I guess. However, these source code lines ignore other pixel formats likekCVPixelFormatType_420YpCbCr8PlanarFullRange
(a.k.a I420) and treat them as RGBA. That is why the colors are incorrect, and the images repeat four times.Suggestion
I understand that the preferred formats in Apple's ecosystem are
kCVPixelFormatType_32BGRA
,kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
, andkCVPixelFormatType_420YpCbCr8BiPlanarFullRange
. Other formats are not well-supported even in Apple's own APIs. However, when it comes to APIs, it's better to log an error message stating that the pixel format is not supported, rather than rendering incorrect images. Additionally, it would be helpful to document this limitation in Flutter's official documentation.Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: