Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 34878d9

Browse files
author
Jonah Williams
authored
[Impeller] finish wiring up external textures for macOS embedder. (#55347)
Fixes flutter/flutter#135898 Note that the macOS embedder is still using the apple texture cache object from the SkiaMetalContext. it can't initialize an equivalent ImpellerMetalContext without creating a second copy of the content context and all that jazz, so I'm leaving that as is for now.
1 parent 2a13c3a commit 34878d9

7 files changed

Lines changed: 370 additions & 31 deletions

shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import <Metal/Metal.h>
1010

1111
#include "flutter/common/graphics/texture.h"
12+
#include "flutter/display_list/image/dl_image.h"
13+
#include "flutter/impeller/aiks/aiks_context.h"
1214
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
1315
#include "third_party/skia/include/core/SkCanvas.h"
1416
#include "third_party/skia/include/core/SkImage.h"
@@ -29,6 +31,18 @@
2931

3032
@end
3133

34+
@interface FlutterDarwinExternalTextureImpellerImageWrapper : NSObject
35+
36+
+ (sk_sp<flutter::DlImage>)wrapYUVATexture:(nonnull id<MTLTexture>)yTex
37+
UVTex:(nonnull id<MTLTexture>)uvTex
38+
YUVColorSpace:(impeller::YUVColorSpace)colorSpace
39+
aiksContext:(nonnull impeller::AiksContext*)aiksContext;
40+
41+
+ (sk_sp<flutter::DlImage>)wrapRGBATexture:(nonnull id<MTLTexture>)rgbaTex
42+
aiksContext:(nonnull impeller::AiksContext*)aiks_context;
43+
44+
@end
45+
3246
@interface FlutterDarwinExternalTextureMetal : NSObject
3347

3448
- (nullable instancetype)initWithTextureCache:(nonnull CVMetalTextureCacheRef)textureCache

shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
66
#include "flutter/display_list/image/dl_image.h"
7+
#include "impeller/aiks/aiks_context.h"
78
#include "impeller/base/validation.h"
89
#include "impeller/display_list/dl_image_impeller.h"
910
#include "impeller/renderer/backend/metal/texture_mtl.h"
@@ -196,29 +197,14 @@ - (void)onTextureUnregistered {
196197
CVBufferRelease(uvMetalTexture);
197198

198199
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-
215200
impeller::YUVColorSpace yuvColorSpace =
216201
_pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
217202
? impeller::YUVColorSpace::kBT601LimitedRange
218203
: 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];
222208
}
223209

224210
SkYUVColorSpace colorSpace = _pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
@@ -263,14 +249,8 @@ - (void)onTextureUnregistered {
263249
CVBufferRelease(metalTexture);
264250

265251
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];
274254
}
275255

276256
auto skImage = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
@@ -342,3 +322,43 @@ GrYUVABackendTextures yuvaBackendTextures(yuvaInfo, skiaBackendTextures,
342322
#endif // SLIMPELLER
343323
}
344324
@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

Comments
 (0)