If the application says there is a new texture but does not provide one, reuse the last texture. (flutter/engine#17437)

This matches the behavior of the OpenGL backend.
This commit is contained in:
Chinmay Garde
2020-03-31 22:01:32 -07:00
committed by GitHub
parent f434b2e6a8
commit 1eec7d5d8e
2 changed files with 10 additions and 8 deletions

View File

@@ -48,7 +48,7 @@ class IOSExternalTextureMetal final : public Texture {
// |Texture|
void OnTextureUnregistered() override;
sk_sp<SkImage> WrapExternalPixelBuffer(GrContext* context);
sk_sp<SkImage> WrapExternalPixelBuffer(GrContext* context) const;
FML_DISALLOW_COPY_AND_ASSIGN(IOSExternalTextureMetal);
};

View File

@@ -27,13 +27,15 @@ void IOSExternalTextureMetal::Paint(SkCanvas& canvas,
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 @@ void IOSExternalTextureMetal::Paint(SkCanvas& canvas,
}
}
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;