|
13 | 13 |
|
14 | 14 | namespace flutter { |
15 | 15 |
|
| 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 | + |
16 | 25 | EmbedderExternalTextureMetal::EmbedderExternalTextureMetal(int64_t texture_identifier, |
17 | 26 | const ExternalTextureCallback& callback) |
18 | 27 | : Texture(texture_identifier), external_texture_callback_(callback) { |
|
47 | 56 | external_texture_callback_(texture_id, size.width(), size.height()); |
48 | 57 |
|
49 | 58 | if (!texture) { |
| 59 | + FML_LOG(ERROR) << "External texture callback for ID " << texture_id |
| 60 | + << " did not return a valid texture."; |
50 | 61 | return nullptr; |
51 | 62 | } |
52 | 63 |
|
53 | 64 | sk_sp<SkImage> image; |
54 | 65 |
|
55 | 66 | switch (texture->pixel_format) { |
56 | 67 | 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 | + } |
63 | 75 | break; |
64 | 76 | } |
65 | 77 | 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 | + } |
74 | 87 | break; |
75 | 88 | } |
76 | 89 | } |
|
0 commit comments