Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Properties | List of all members
FlutterDarwinExternalTextureMetal Class Reference

#include <FlutterDarwinExternalTextureMetal.h>

Inheritance diagram for FlutterDarwinExternalTextureMetal:

Instance Methods

(nullable instancetype) - initWithTextureCache:textureID:texture:enableImpeller:
 
(void) - paintContext:bounds:freeze:sampling:
 
(void) - onGrContextCreated
 
(void) - onGrContextDestroyed
 
(void) - markNewFrameAvailable
 
(void) - onTextureUnregistered
 
(instancetype) - initWithTextureCache:textureID:texture:enableImpeller: [implementation]
 
(void) - dealloc [implementation]
 
(void) - onNeedsUpdatedTexture: [implementation]
 
(sk_sp< flutter::DlImage >) - wrapExternalPixelBuffer:context: [implementation]
 
(sk_sp< flutter::DlImage >) - wrapNV12ExternalPixelBuffer:context: [implementation]
 
(sk_sp< flutter::DlImage >) - wrapBGRAExternalPixelBuffer:context: [implementation]
 

Properties

int64_t textureID
 

Detailed Description

Definition at line 32 of file FlutterDarwinExternalTextureMetal.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

49 {
50 CVPixelBufferRelease(_lastPixelBuffer);
51 if (_textureCache) {
52 CVMetalTextureCacheFlush(_textureCache, // cache
53 0 // options (must be zero)
54 );
55 CFRelease(_textureCache);
56 }
57}
CVPixelBufferRef _lastPixelBuffer

◆ initWithTextureCache:textureID:texture:enableImpeller: [1/2]

- (instancetype) initWithTextureCache: (nonnull CVMetalTextureCacheRef)  textureCache
textureID: (int64_t)  textureID
texture: (NSObject<FlutterTexture>*)  texture
enableImpeller: (BOOL enableImpeller 
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

34 :(nonnull CVMetalTextureCacheRef)textureCache
35 textureID:(int64_t)textureID
37 enableImpeller:(BOOL)enableImpeller {
38 if (self = [super init]) {
39 _textureCache = textureCache;
40 CFRetain(_textureCache);
43 _enableImpeller = enableImpeller;
44 return self;
45 }
46 return nil;
47}
NSObject< FlutterTexture > * _externalTexture
int64_t _textureID
if(end==-1)
FlTexture * texture
init(device_serial, adb_binary)
Definition _adb_path.py:12
int BOOL

◆ initWithTextureCache:textureID:texture:enableImpeller: [2/2]

- (nullable instancetype) initWithTextureCache: (nonnull CVMetalTextureCacheRef)  textureCache
textureID: (int64_t)  textureID
texture: (nonnull NSObject< FlutterTexture > *)  texture
enableImpeller: (BOOL enableImpeller 

◆ markNewFrameAvailable

- (void) markNewFrameAvailable

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

114 {
116}

◆ onGrContextCreated

- (void) onGrContextCreated

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

97 {
98 // External images in this backend have no thread affinity and are not tied to the context in any
99 // way. Instead, they are tied to the Metal device which is associated with the cache already and
100 // is consistent throughout the shell run.
101}

◆ onGrContextDestroyed

- (void) onGrContextDestroyed

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

103 {
104 // The image must be reset because it is tied to the onscreen context. But the pixel buffer that
105 // created the image is still around. In case of context reacquisition, that last pixel
106 // buffer will be used to materialize the image in case the application fails to provide a new
107 // one.
109 CVMetalTextureCacheFlush(_textureCache, // cache
110 0 // options (must be zero)
111 );
112}
sk_sp< flutter::DlImage > _externalImage
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

◆ onNeedsUpdatedTexture:

- (void) onNeedsUpdatedTexture: (flutter::Texture::PaintContext&)  context
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

81 CVPixelBufferRef pixelBuffer = [_externalTexture copyPixelBuffer];
82 if (pixelBuffer) {
83 CVPixelBufferRelease(_lastPixelBuffer);
84 _lastPixelBuffer = pixelBuffer;
85 _pixelFormat = CVPixelBufferGetPixelFormatType(_lastPixelBuffer);
86 }
87
88 // If the application told us there was a texture frame available but did not provide one when
89 // asked for it, reuse the previous texture but make sure to ask again the next time around.
90 sk_sp<flutter::DlImage> image = [self wrapExternalPixelBuffer:_lastPixelBuffer context:context];
91 if (image) {
94 }
95}
sk_sp< SkImage > image
Definition examples.cpp:29

◆ onTextureUnregistered

- (void) onTextureUnregistered

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

118 {
119 if ([_externalTexture respondsToSelector:@selector(onTextureUnregistered:)]) {
120 [_externalTexture onTextureUnregistered:_externalTexture];
121 }
122}

◆ paintContext:bounds:freeze:sampling:

- (void) paintContext: (flutter::Texture::PaintContext&)  context
bounds: (const SkRect&)  bounds
freeze: (BOOL freeze
sampling: (const flutter::DlImageSampling sampling 

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

60 bounds:(const SkRect&)bounds
61 freeze:(BOOL)freeze
63 const bool needsUpdatedTexture = (!freeze && _textureFrameAvailable) || !_externalImage;
64
65 if (needsUpdatedTexture) {
66 [self onNeedsUpdatedTexture:context];
67 }
68
69 if (_externalImage) {
70 context.canvas->DrawImageRect(_externalImage, // image
71 SkRect::Make(_externalImage->bounds()), // source rect
72 bounds, // destination rect
73 sampling, // sampling
74 context.paint, // paint
76 );
77 }
78}
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)=0
SkIRect bounds() const
Definition dl_image.cc:31
Optional< SkRect > bounds
Definition SkRecords.h:189
SkSamplingOptions sampling
Definition SkRecords.h:337
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ wrapBGRAExternalPixelBuffer:context:

- (sk_sp< DlImage >) FlutterDarwinExternalTextureMetal: (CVPixelBufferRef)  pixelBuffer
context: (flutter::Texture::PaintContext&)  context 
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

241 :(CVPixelBufferRef)pixelBuffer
242 context:(flutter::Texture::PaintContext&)context {
243 SkISize textureSize =
244 SkISize::Make(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
245 CVMetalTextureRef metalTexture = nullptr;
246 CVReturn cvReturn =
247 CVMetalTextureCacheCreateTextureFromImage(/*allocator=*/kCFAllocatorDefault,
248 /*textureCache=*/_textureCache,
249 /*sourceImage=*/pixelBuffer,
250 /*textureAttributes=*/nullptr,
251 /*pixelFormat=*/MTLPixelFormatBGRA8Unorm,
252 /*width=*/textureSize.width(),
253 /*height=*/textureSize.height(),
254 /*planeIndex=*/0u,
255 /*texture=*/&metalTexture);
256
257 if (cvReturn != kCVReturnSuccess) {
258 FML_DLOG(ERROR) << "Could not create Metal texture from pixel buffer: CVReturn " << cvReturn;
259 return nullptr;
260 }
261
262 id<MTLTexture> rgbaTex = CVMetalTextureGetTexture(metalTexture);
263 CVBufferRelease(metalTexture);
264
265 if (_enableImpeller) {
269 desc.size = {textureSize.width(), textureSize.height()};
270 desc.mip_count = 1;
271 auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex);
274 }
275
277 grContext:context.gr_context
278 width:textureSize.width()
279 height:textureSize.height()];
280 if (!skImage) {
281 return nullptr;
282 }
283
284 // This image should not escape local use by this flutter::Texture implementation
285 return flutter::DlImage::Make(skImage);
286}
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
#define FML_DLOG(severity)
Definition logging.h:102
sk_sp< SkImage > wrapRGBATexture:grContext:width:height:(nonnull id< MTLTexture > rgbaTex,[grContext] nonnull GrDirectContext *grContext,[width] size_t width,[height] size_t height)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define ERROR(message)

◆ wrapExternalPixelBuffer:context:

- (sk_sp< DlImage >) FlutterDarwinExternalTextureMetal: (CVPixelBufferRef)  pixelBuffer
context: (flutter::Texture::PaintContext&)  context 
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

126 :(CVPixelBufferRef)pixelBuffer
127 context:(flutter::Texture::PaintContext&)context {
128 if (!pixelBuffer) {
129 return nullptr;
130 }
131
133 if (_pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange ||
134 _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
135 image = [self wrapNV12ExternalPixelBuffer:pixelBuffer context:context];
136 } else if (_pixelFormat == kCVPixelFormatType_32BGRA) {
137 image = [self wrapBGRAExternalPixelBuffer:pixelBuffer context:context];
138 } else {
139 FML_LOG(ERROR) << "Unsupported pixel format: " << _pixelFormat;
140 return nullptr;
141 }
142
143 if (!image) {
144 FML_DLOG(ERROR) << "Could not wrap Metal texture as a display list image.";
145 }
146
147 return image;
148}
#define FML_LOG(severity)
Definition logging.h:82

◆ wrapNV12ExternalPixelBuffer:context:

- (sk_sp< DlImage >) FlutterDarwinExternalTextureMetal: (CVPixelBufferRef)  pixelBuffer
context: (flutter::Texture::PaintContext&)  context 
implementation

Definition at line 31 of file FlutterDarwinExternalTextureMetal.mm.

150 :(CVPixelBufferRef)pixelBuffer
151 context:(flutter::Texture::PaintContext&)context {
152 SkISize textureSize =
153 SkISize::Make(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
154 CVMetalTextureRef yMetalTexture = nullptr;
155 {
156 CVReturn cvReturn =
157 CVMetalTextureCacheCreateTextureFromImage(/*allocator=*/kCFAllocatorDefault,
158 /*textureCache=*/_textureCache,
159 /*sourceImage=*/pixelBuffer,
160 /*textureAttributes=*/nullptr,
161 /*pixelFormat=*/MTLPixelFormatR8Unorm,
162 /*width=*/textureSize.width(),
163 /*height=*/textureSize.height(),
164 /*planeIndex=*/0u,
165 /*texture=*/&yMetalTexture);
166
167 if (cvReturn != kCVReturnSuccess) {
168 FML_DLOG(ERROR) << "Could not create Metal texture from pixel buffer: CVReturn " << cvReturn;
169 return nullptr;
170 }
171 }
172
173 CVMetalTextureRef uvMetalTexture = nullptr;
174 {
175 CVReturn cvReturn =
176 CVMetalTextureCacheCreateTextureFromImage(/*allocator=*/kCFAllocatorDefault,
177 /*textureCache=*/_textureCache,
178 /*sourceImage=*/pixelBuffer,
179 /*textureAttributes=*/nullptr,
180 /*pixelFormat=*/MTLPixelFormatRG8Unorm,
181 /*width=*/textureSize.width() / 2,
182 /*height=*/textureSize.height() / 2,
183 /*planeIndex=*/1u,
184 /*texture=*/&uvMetalTexture);
185
186 if (cvReturn != kCVReturnSuccess) {
187 FML_DLOG(ERROR) << "Could not create Metal texture from pixel buffer: CVReturn " << cvReturn;
188 return nullptr;
189 }
190 }
191
192 id<MTLTexture> yTex = CVMetalTextureGetTexture(yMetalTexture);
193 CVBufferRelease(yMetalTexture);
194
195 id<MTLTexture> uvTex = CVMetalTextureGetTexture(uvMetalTexture);
196 CVBufferRelease(uvMetalTexture);
197
198 if (_enableImpeller) {
202 yDesc.size = {textureSize.width(), textureSize.height()};
203 yDesc.mip_count = 1;
204 auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex);
205 yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
206
210 uvDesc.size = {textureSize.width() / 2, textureSize.height() / 2};
211 uvDesc.mip_count = 1;
212 auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex);
213 uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost);
214
215 impeller::YUVColorSpace yuvColorSpace =
216 _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
219
220 return impeller::DlImageImpeller::MakeFromYUVTextures(context.aiks_context, yTexture, uvTexture,
221 yuvColorSpace);
222 }
223
224 SkYUVColorSpace colorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
228 UVTex:uvTex
229 YUVColorSpace:colorSpace
230 grContext:context.gr_context
231 width:textureSize.width()
232 height:textureSize.height()];
233 if (!skImage) {
234 return nullptr;
235 }
236
237 // This image should not escape local use by this flutter::Texture implementation
238 return flutter::DlImage::Make(skImage);
239}
SkYUVColorSpace
Definition SkImageInfo.h:68
@ kRec601_Limited_SkYUVColorSpace
describes SDTV range
Definition SkImageInfo.h:70
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition SkImageInfo.h:69
static sk_sp< DlImageImpeller > MakeFromYUVTextures(AiksContext *aiks_context, std::shared_ptr< Texture > y_texture, std::shared_ptr< Texture > uv_texture, YUVColorSpace yuv_color_space)
sk_sp< SkImage > wrapYUVATexture:UVTex:YUVColorSpace:grContext:width:height:(nonnull id< MTLTexture > yTex,[UVTex] nonnull id< MTLTexture > uvTex,[YUVColorSpace] SkYUVColorSpace colorSpace,[grContext] nonnull GrDirectContext *grContext,[width] size_t width,[height] size_t height)
YUVColorSpace
Definition color.h:55
impeller::AiksContext * aiks_context
Definition texture.h:44
Type width
Definition size.h:22

Property Documentation

◆ textureID

- (int64_t) textureID
readnonatomicassign

Definition at line 52 of file FlutterDarwinExternalTextureMetal.h.


The documentation for this class was generated from the following files: