Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ui/painting/image_generator_apng.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
46 changes: 4 additions & 42 deletions lib/ui/painting/multi_frame_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<sk_sp<DlImage>, std::string>
MultiFrameCodec::State::GetNextFrameImage(
fml::WeakPtr<GrDirectContext> resourceContext,
Expand All @@ -113,25 +80,20 @@ MultiFrameCodec::State::GetNextFrameImage(

const int requiredFrameIndex =
frameInfo.required_frame.value_or(SkCodec::kNoFrame);
std::optional<unsigned int> 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
<< " and no required frames are cached. Using blank slate instead.";
} 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());
}
}

Expand All @@ -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.
Expand All @@ -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<SkBitmap>(bitmap);
lastRequiredFrame_ = bitmap;
lastRequiredFrameIndex_ = nextFrameIndex_;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/multi_frame_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkBitmap> lastRequiredFrame_;
std::optional<SkBitmap> lastRequiredFrame_;

// The index of the last decoded required frame.
int lastRequiredFrameIndex_ = -1;
Expand Down