|
4 | 4 |
|
5 | 5 | #import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h" |
6 | 6 | #include "flutter/display_list/image/dl_image.h" |
| 7 | +#include "impeller/aiks/aiks_context.h" |
7 | 8 | #include "impeller/base/validation.h" |
8 | 9 | #include "impeller/display_list/dl_image_impeller.h" |
9 | 10 | #include "impeller/renderer/backend/metal/texture_mtl.h" |
@@ -196,29 +197,14 @@ - (void)onTextureUnregistered { |
196 | 197 | CVBufferRelease(uvMetalTexture); |
197 | 198 |
|
198 | 199 | if (_enableImpeller) { |
199 | | - impeller::TextureDescriptor yDesc; |
200 | | - yDesc.storage_mode = impeller::StorageMode::kHostVisible; |
201 | | - yDesc.format = impeller::PixelFormat::kR8UNormInt; |
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 | | - |
207 | | - impeller::TextureDescriptor uvDesc; |
208 | | - uvDesc.storage_mode = impeller::StorageMode::kHostVisible; |
209 | | - uvDesc.format = impeller::PixelFormat::kR8G8UNormInt; |
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 | 200 | impeller::YUVColorSpace yuvColorSpace = |
216 | 201 | _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange |
217 | 202 | ? impeller::YUVColorSpace::kBT601LimitedRange |
218 | 203 | : impeller::YUVColorSpace::kBT601FullRange; |
219 | | - |
220 | | - return impeller::DlImageImpeller::MakeFromYUVTextures(context.aiks_context, yTexture, uvTexture, |
221 | | - yuvColorSpace); |
| 204 | + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapYUVATexture:yTex |
| 205 | + UVTex:uvTex |
| 206 | + YUVColorSpace:yuvColorSpace |
| 207 | + aiksContext:context.aiks_context]; |
222 | 208 | } |
223 | 209 |
|
224 | 210 | SkYUVColorSpace colorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange |
@@ -263,14 +249,8 @@ - (void)onTextureUnregistered { |
263 | 249 | CVBufferRelease(metalTexture); |
264 | 250 |
|
265 | 251 | if (_enableImpeller) { |
266 | | - impeller::TextureDescriptor desc; |
267 | | - desc.storage_mode = impeller::StorageMode::kHostVisible; |
268 | | - desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt; |
269 | | - desc.size = {textureSize.width(), textureSize.height()}; |
270 | | - desc.mip_count = 1; |
271 | | - auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex); |
272 | | - texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); |
273 | | - return impeller::DlImageImpeller::Make(texture); |
| 252 | + return [FlutterDarwinExternalTextureImpellerImageWrapper wrapRGBATexture:rgbaTex |
| 253 | + aiksContext:context.aiks_context]; |
274 | 254 | } |
275 | 255 |
|
276 | 256 | auto skImage = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex |
@@ -342,3 +322,43 @@ GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, skiaBackendTextures, |
342 | 322 | #endif // SLIMPELLER |
343 | 323 | } |
344 | 324 | @end |
| 325 | + |
| 326 | +@implementation FlutterDarwinExternalTextureImpellerImageWrapper |
| 327 | + |
| 328 | ++ (sk_sp<flutter::DlImage>)wrapYUVATexture:(id<MTLTexture>)yTex |
| 329 | + UVTex:(id<MTLTexture>)uvTex |
| 330 | + YUVColorSpace:(impeller::YUVColorSpace)colorSpace |
| 331 | + aiksContext:(nonnull impeller::AiksContext*)aiks_context { |
| 332 | + impeller::TextureDescriptor yDesc; |
| 333 | + yDesc.storage_mode = impeller::StorageMode::kDevicePrivate; |
| 334 | + yDesc.format = impeller::PixelFormat::kR8UNormInt; |
| 335 | + yDesc.size = impeller::ISize(yTex.width, yTex.height); |
| 336 | + yDesc.mip_count = 1; |
| 337 | + auto yTexture = impeller::TextureMTL::Wrapper(yDesc, yTex); |
| 338 | + yTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); |
| 339 | + |
| 340 | + impeller::TextureDescriptor uvDesc; |
| 341 | + uvDesc.storage_mode = impeller::StorageMode::kDevicePrivate; |
| 342 | + uvDesc.format = impeller::PixelFormat::kR8G8UNormInt; |
| 343 | + uvDesc.size = impeller::ISize(uvTex.width, uvTex.height); |
| 344 | + uvDesc.mip_count = 1; |
| 345 | + auto uvTexture = impeller::TextureMTL::Wrapper(uvDesc, uvTex); |
| 346 | + uvTexture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); |
| 347 | + ; |
| 348 | + |
| 349 | + return impeller::DlImageImpeller::MakeFromYUVTextures(aiks_context, yTexture, uvTexture, |
| 350 | + colorSpace); |
| 351 | +} |
| 352 | + |
| 353 | ++ (sk_sp<flutter::DlImage>)wrapRGBATexture:(id<MTLTexture>)rgbaTex |
| 354 | + aiksContext:(nonnull impeller::AiksContext*)aiks_context { |
| 355 | + impeller::TextureDescriptor desc; |
| 356 | + desc.storage_mode = impeller::StorageMode::kDevicePrivate; |
| 357 | + desc.format = impeller::PixelFormat::kB8G8R8A8UNormInt; |
| 358 | + desc.size = impeller::ISize(rgbaTex.width, rgbaTex.height); |
| 359 | + desc.mip_count = 1; |
| 360 | + auto texture = impeller::TextureMTL::Wrapper(desc, rgbaTex); |
| 361 | + texture->SetCoordinateSystem(impeller::TextureCoordinateSystem::kUploadFromHost); |
| 362 | + return impeller::DlImageImpeller::Make(texture); |
| 363 | +} |
| 364 | +@end |
0 commit comments