diff --git a/lib/ui/painting/image_generator_apng.h b/lib/ui/painting/image_generator_apng.h index 14b357ad4a35c..1bf1c26e298d0 100644 --- a/lib/ui/painting/image_generator_apng.h +++ b/lib/ui/painting/image_generator_apng.h @@ -128,7 +128,7 @@ class APNGImageGenerator : public ImageGenerator { // X offset of this image when composited. Only applicable to frames. unsigned int x_offset; - // X offset of this image when composited. Only applicable to frames. + // Y offset of this image when composited. Only applicable to frames. unsigned int y_offset; }; diff --git a/lib/ui/painting/multi_frame_codec.cc b/lib/ui/painting/multi_frame_codec.cc index c66da59bf288c..ca0654d3299c4 100644 --- a/lib/ui/painting/multi_frame_codec.cc +++ b/lib/ui/painting/multi_frame_codec.cc @@ -54,39 +54,6 @@ static void InvokeNextFrameCallback( tonic::ToDart(decode_error)}); } -// Copied the source bitmap to the destination. If this cannot occur due to -// running out of memory or the image info not being compatible, returns false. -static bool CopyToBitmap(SkBitmap* dst, - SkColorType dstColorType, - const SkBitmap& src) { - SkPixmap srcPM; - if (!src.peekPixels(&srcPM)) { - return false; - } - - SkBitmap tmpDst; - SkImageInfo dstInfo = srcPM.info().makeColorType(dstColorType); - if (!tmpDst.setInfo(dstInfo)) { - return false; - } - - if (!tmpDst.tryAllocPixels()) { - return false; - } - - SkPixmap dstPM; - if (!tmpDst.peekPixels(&dstPM)) { - return false; - } - - if (!srcPM.readPixels(dstPM)) { - return false; - } - - dst->swap(tmpDst); - return true; -} - std::pair, std::string> MultiFrameCodec::State::GetNextFrameImage( fml::WeakPtr resourceContext, @@ -113,13 +80,12 @@ MultiFrameCodec::State::GetNextFrameImage( const int requiredFrameIndex = frameInfo.required_frame.value_or(SkCodec::kNoFrame); - std::optional prior_frame_index = std::nullopt; if (requiredFrameIndex != SkCodec::kNoFrame) { // We are here when the frame said |disposal_method| is // `DisposalMethod::kKeep` or `DisposalMethod::kRestorePrevious` and // |requiredFrameIndex| is set to ex-frame or ex-ex-frame. - if (lastRequiredFrame_ == nullptr) { + if (!lastRequiredFrame_.has_value()) { FML_DLOG(INFO) << "Frame " << nextFrameIndex_ << " depends on frame " << requiredFrameIndex @@ -127,11 +93,7 @@ MultiFrameCodec::State::GetNextFrameImage( } else { // Copy the previous frame's output buffer into the current frame as the // starting point. - if (lastRequiredFrame_->getPixels() && - CopyToBitmap(&bitmap, lastRequiredFrame_->colorType(), - *lastRequiredFrame_)) { - prior_frame_index = requiredFrameIndex; - } + bitmap.writePixels(lastRequiredFrame_->pixmap()); } } @@ -151,7 +113,7 @@ MultiFrameCodec::State::GetNextFrameImage( const bool restore_previous_frame = frameInfo.disposal_method == SkCodecAnimation::DisposalMethod::kRestorePrevious; - const bool previous_frame_available = !!lastRequiredFrame_; + const bool previous_frame_available = lastRequiredFrame_.has_value(); // Store the current frame in `lastRequiredFrame_` if the frame's disposal // method indicates we should do so. @@ -167,7 +129,7 @@ MultiFrameCodec::State::GetNextFrameImage( (previous_frame_available && !restore_previous_frame)) { // Replace the stored frame. The `lastRequiredFrame_` will get used as the // starting backdrop for the next frame. - lastRequiredFrame_ = std::make_unique(bitmap); + lastRequiredFrame_ = bitmap; lastRequiredFrameIndex_ = nextFrameIndex_; } diff --git a/lib/ui/painting/multi_frame_codec.h b/lib/ui/painting/multi_frame_codec.h index a5f6acf07e809..107d23bca9f64 100644 --- a/lib/ui/painting/multi_frame_codec.h +++ b/lib/ui/painting/multi_frame_codec.h @@ -53,7 +53,7 @@ class MultiFrameCodec : public Codec { // thread. int nextFrameIndex_; // The last decoded frame that's required to decode any subsequent frames. - std::unique_ptr lastRequiredFrame_; + std::optional lastRequiredFrame_; // The index of the last decoded required frame. int lastRequiredFrameIndex_ = -1;