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

Commit 0d79389

Browse files
committed
fix cr comments
1 parent 6a09435 commit 0d79389

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

shell/platform/embedder/embedder.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,12 @@ typedef struct {
467467
/// Supported textures are YUVA and RGBA, in case of YUVA we expect 2 texture
468468
/// handles to be provided by the embedder, Y first and UV next. In case of
469469
/// RGBA only one should be passed.
470-
/// These are individually aliases for id<MTLTexture> which will be released
471-
/// once they have been composited: `external_texture_frame_callback`.
472-
FlutterMetalTextureHandle* textures;
470+
/// These are individually aliases for id<MTLTexture>. These textures are
471+
/// retained by the engine for the period of the composition. Once these
472+
/// textures have been unregistered via the
473+
/// `FlutterEngineUnregisterExternalTexture`, the embedder has to release
474+
/// these textures.
475+
const FlutterMetalTextureHandle* textures;
473476
} FlutterMetalExternalTexture;
474477

475478
/// Callback to provide an external texture for a given texture_id.

shell/platform/embedder/embedder_external_texture_metal.mm

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313

1414
namespace flutter {
1515

16+
static bool ValidNumTextures(int expected, int actual) {
17+
if (expected == actual) {
18+
return true;
19+
} else {
20+
FML_LOG(ERROR) << "Invalid number of textures, expected: " << expected << ", got: " << actual;
21+
return false;
22+
}
23+
}
24+
1625
EmbedderExternalTextureMetal::EmbedderExternalTextureMetal(int64_t texture_identifier,
1726
const ExternalTextureCallback& callback)
1827
: Texture(texture_identifier), external_texture_callback_(callback) {
@@ -47,30 +56,34 @@
4756
external_texture_callback_(texture_id, size.width(), size.height());
4857

4958
if (!texture) {
59+
FML_LOG(ERROR) << "External texture callback for ID " << texture_id
60+
<< " did not return a valid texture.";
5061
return nullptr;
5162
}
5263

5364
sk_sp<SkImage> image;
5465

5566
switch (texture->pixel_format) {
5667
case FlutterMetalExternalTexturePixelFormat::kRGBA: {
57-
FML_CHECK(texture->num_textures == 1);
58-
id<MTLTexture> rgbaTex = reinterpret_cast<id<MTLTexture>>(texture->textures[0]);
59-
image = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
60-
grContext:context
61-
width:size.width()
62-
height:size.height()];
68+
if (ValidNumTextures(1, texture->num_textures)) {
69+
id<MTLTexture> rgbaTex = reinterpret_cast<id<MTLTexture>>(texture->textures[0]);
70+
image = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
71+
grContext:context
72+
width:size.width()
73+
height:size.height()];
74+
}
6375
break;
6476
}
6577
case FlutterMetalExternalTexturePixelFormat::kYUVA: {
66-
FML_CHECK(texture->num_textures == 2);
67-
id<MTLTexture> yTex = reinterpret_cast<id<MTLTexture>>(texture->textures[0]);
68-
id<MTLTexture> uvTex = reinterpret_cast<id<MTLTexture>>(texture->textures[1]);
69-
image = [FlutterDarwinExternalTextureSkImageWrapper wrapYUVATexture:yTex
70-
UVTex:uvTex
71-
grContext:context
72-
width:size.width()
73-
height:size.height()];
78+
if (ValidNumTextures(2, texture->num_textures)) {
79+
id<MTLTexture> yTex = reinterpret_cast<id<MTLTexture>>(texture->textures[0]);
80+
id<MTLTexture> uvTex = reinterpret_cast<id<MTLTexture>>(texture->textures[1]);
81+
image = [FlutterDarwinExternalTextureSkImageWrapper wrapYUVATexture:yTex
82+
UVTex:uvTex
83+
grContext:context
84+
width:size.width()
85+
height:size.height()];
86+
}
7487
break;
7588
}
7689
}

0 commit comments

Comments
 (0)