5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
7#include "flutter/fml/platform/darwin/cf_utils.h"
25 _darwinMetalContext = context;
42 OSType pixel_format = CVPixelBufferGetPixelFormatType(pixelBuffer);
43 if (pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange ||
44 pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
45 return [
self populateTextureFromYUVAPixelBuffer:pixelBuffer textureOut:textureOut];
46 }
else if (pixel_format == kCVPixelFormatType_32BGRA) {
47 return [
self populateTextureFromRGBAPixelBuffer:pixelBuffer textureOut:textureOut];
49 NSLog(
@"Unsupported pixel format: %d", pixel_format);
54- (
BOOL)populateTextureFromYUVAPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer
56 CVMetalTextureRef yCVMetalTexture =
nullptr;
57 CVMetalTextureRef uvCVMetalTextureRef =
nullptr;
59 SkISize::Make(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
61 CVReturn yCVReturn = CVMetalTextureCacheCreateTextureFromImage(
63 _darwinMetalContext.textureCache,
66 MTLPixelFormatR8Unorm,
67 CVPixelBufferGetWidthOfPlane(pixelBuffer, 0u),
68 CVPixelBufferGetHeightOfPlane(pixelBuffer, 0u),
72 if (yCVReturn != kCVReturnSuccess) {
73 NSLog(
@"Could not create Metal texture from pixel buffer: CVReturn %d", yCVReturn);
77 CVReturn uvCVReturn = CVMetalTextureCacheCreateTextureFromImage(
79 _darwinMetalContext.textureCache,
82 MTLPixelFormatRG8Unorm,
83 CVPixelBufferGetWidthOfPlane(pixelBuffer, 1u),
84 CVPixelBufferGetHeightOfPlane(pixelBuffer, 1u),
86 &uvCVMetalTextureRef);
88 if (uvCVReturn != kCVReturnSuccess) {
89 CVBufferRelease(yCVMetalTexture);
90 NSLog(
@"Could not create Metal texture from pixel buffer: CVReturn %d", uvCVReturn);
96 CVBufferRelease(yCVMetalTexture);
97 CVBufferRelease(uvCVMetalTextureRef);
104 OSType pixel_format = CVPixelBufferGetPixelFormatType(pixelBuffer);
105 textureOut->
yuv_color_space = pixel_format == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
112- (
BOOL)populateTextureFromRGBAPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer
115 SkISize::Make(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
117 CVMetalTextureRef cvMetalTexture =
nullptr;
119 CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
120 _darwinMetalContext.textureCache,
123 MTLPixelFormatBGRA8Unorm,
129 if (cvReturn != kCVReturnSuccess) {
130 NSLog(
@"Could not create Metal texture from pixel buffer: CVReturn %d", cvReturn);
135 CVBufferRelease(cvMetalTexture);
std::vector< FlutterMetalTextureHandle > _textures
id< FlutterTexture > _texture
const void * FlutterMetalTextureHandle
Alias for id<MTLTexture>.
FlutterMetalTextureHandle * textures
size_t num_textures
Represents the size of the textures array.
FlutterMetalExternalTexturePixelFormat pixel_format
The pixel format type of the external.
FlutterMetalExternalTextureYUVColorSpace yuv_color_space
The YUV color space of the YUV external texture.
size_t height
Height of the texture.
size_t width
Height of the texture.
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const