If the application says there is a new texture but does not provide one, reuse the last texture. (#17437)
This matches the behavior of the OpenGL backend.
diff --git a/shell/platform/darwin/ios/ios_external_texture_metal.h b/shell/platform/darwin/ios/ios_external_texture_metal.h
index 82e4d69..efedc9f 100644
--- a/shell/platform/darwin/ios/ios_external_texture_metal.h
+++ b/shell/platform/darwin/ios/ios_external_texture_metal.h
@@ -48,7 +48,7 @@
// |Texture|
void OnTextureUnregistered() override;
- sk_sp<SkImage> WrapExternalPixelBuffer(GrContext* context);
+ sk_sp<SkImage> WrapExternalPixelBuffer(GrContext* context) const;
FML_DISALLOW_COPY_AND_ASSIGN(IOSExternalTextureMetal);
};
diff --git a/shell/platform/darwin/ios/ios_external_texture_metal.mm b/shell/platform/darwin/ios/ios_external_texture_metal.mm
index 7ab55c9..e987132 100644
--- a/shell/platform/darwin/ios/ios_external_texture_metal.mm
+++ b/shell/platform/darwin/ios/ios_external_texture_metal.mm
@@ -27,13 +27,15 @@
const SkRect& bounds,
bool freeze,
GrContext* context) {
- if (!freeze && texture_frame_available_) {
- external_image_ = nullptr;
- }
+ const bool needs_updated_texture = (!freeze && texture_frame_available_) || !external_image_;
- if (!external_image_) {
- external_image_ = WrapExternalPixelBuffer(context);
- texture_frame_available_ = false;
+ if (needs_updated_texture) {
+ // If the application told us there was a texture frame available but did not provide one when
+ // asked for it, reuse the previous texture but make sure to ask again the next time around.
+ if (auto wrapped_texture = WrapExternalPixelBuffer(context)) {
+ external_image_ = wrapped_texture;
+ texture_frame_available_ = false;
+ }
}
if (external_image_) {
@@ -46,7 +48,7 @@
}
}
-sk_sp<SkImage> IOSExternalTextureMetal::WrapExternalPixelBuffer(GrContext* context) {
+sk_sp<SkImage> IOSExternalTextureMetal::WrapExternalPixelBuffer(GrContext* context) const {
auto pixel_buffer = fml::CFRef<CVPixelBufferRef>([external_texture_ copyPixelBuffer]);
if (!pixel_buffer) {
return nullptr;