Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit efd628a

Browse files
LeonScrogginsSkia Commit-Bot
authored andcommitted
Revert "SkAnimatedImage: Use fSampleSize"
This reverts commit 4fdf9f9. Reason for revert: Google3 and ASAN failures caused by the prior change, which this depends on. Original change's description: > SkAnimatedImage: Use fSampleSize > > Bug: b/163595585 > > This will allow using less memory when decoding an animated GIF by > sampling at decode time. This is tested by the animated_image GMs. > > Change-Id: I748b2180827623e4ca1fc0fd4d6dd02733b3b5f2 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333226 > Commit-Queue: Leon Scroggins <[email protected]> > Reviewed-by: Derek Sollenberger <[email protected]> [email protected],[email protected] Change-Id: I0d30ada4eba2302ce0c5f85b1174d0618ae0f589 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: b/163595585 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334839 Commit-Queue: Leon Scroggins <[email protected]> Reviewed-by: Leon Scroggins <[email protected]>
1 parent 586df95 commit efd628a

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

include/android/SkAnimatedImage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class SK_API SkAnimatedImage : public SkDrawable {
143143
const sk_sp<SkPicture> fPostProcess;
144144
const int fFrameCount;
145145
SkMatrix fMatrix;
146-
int fSampleSize;
147146

148147
bool fFinished;
149148
int fCurrentFrameDuration;
@@ -153,8 +152,9 @@ class SK_API SkAnimatedImage : public SkDrawable {
153152
int fRepetitionCount;
154153
int fRepetitionsCompleted;
155154

156-
SkAnimatedImage(std::unique_ptr<SkAndroidCodec>, const SkImageInfo& requestedInfo,
157-
SkIRect cropRect, sk_sp<SkPicture> postProcess);
155+
SkAnimatedImage(std::unique_ptr<SkAndroidCodec>, SkISize scaledSize,
156+
SkImageInfo decodeInfo, SkIRect cropRect, sk_sp<SkPicture> postProcess);
157+
SkAnimatedImage(std::unique_ptr<SkAndroidCodec>);
158158

159159
int computeNextFrame(int current, bool* animationEnded);
160160
double finish();

src/android/SkAnimatedImage.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ sk_sp<SkAnimatedImage> SkAnimatedImage::Make(std::unique_ptr<SkAndroidCodec> cod
2929
return nullptr;
3030
}
3131

32-
auto image = sk_sp<SkAnimatedImage>(new SkAnimatedImage(std::move(codec), requestedInfo,
33-
cropRect, std::move(postProcess)));
32+
auto scaledSize = requestedInfo.dimensions();
33+
auto decodeInfo = requestedInfo;
34+
if (codec->getEncodedFormat() != SkEncodedImageFormat::kWEBP
35+
|| scaledSize.width() >= decodeInfo.width()
36+
|| scaledSize.height() >= decodeInfo.height()) {
37+
// Only libwebp can decode to arbitrary smaller sizes.
38+
auto dims = codec->getInfo().dimensions();
39+
decodeInfo = decodeInfo.makeDimensions(dims);
40+
}
41+
42+
auto image = sk_sp<SkAnimatedImage>(new SkAnimatedImage(std::move(codec), scaledSize,
43+
decodeInfo, cropRect, std::move(postProcess)));
3444
if (!image->fDisplayFrame.fBitmap.getPixels()) {
3545
// tryAllocPixels failed.
3646
return nullptr;
@@ -44,28 +54,32 @@ sk_sp<SkAnimatedImage> SkAnimatedImage::Make(std::unique_ptr<SkAndroidCodec> cod
4454
return nullptr;
4555
}
4656

47-
const auto& decodeInfo = codec->getInfo();
48-
const auto cropRect = SkIRect::MakeSize(decodeInfo.dimensions());
49-
auto image = Make(std::move(codec), decodeInfo, cropRect, nullptr);
57+
const auto decodeInfo = codec->getInfo();
58+
const auto scaledSize = decodeInfo.dimensions();
59+
const auto cropRect = SkIRect::MakeSize(scaledSize);
60+
auto image = sk_sp<SkAnimatedImage>(new SkAnimatedImage(std::move(codec), scaledSize,
61+
decodeInfo, cropRect, nullptr));
62+
63+
if (!image->fDisplayFrame.fBitmap.getPixels()) {
64+
// tryAllocPixels failed.
65+
return nullptr;
66+
}
5067

51-
SkASSERT(!image || image->simple());
68+
SkASSERT(image->simple());
5269
return image;
5370
}
5471

55-
SkAnimatedImage::SkAnimatedImage(std::unique_ptr<SkAndroidCodec> codec,
56-
const SkImageInfo& requestedInfo, SkIRect cropRect, sk_sp<SkPicture> postProcess)
72+
SkAnimatedImage::SkAnimatedImage(std::unique_ptr<SkAndroidCodec> codec, SkISize scaledSize,
73+
SkImageInfo decodeInfo, SkIRect cropRect, sk_sp<SkPicture> postProcess)
5774
: fCodec(std::move(codec))
58-
, fDecodeInfo(requestedInfo)
75+
, fDecodeInfo(decodeInfo)
5976
, fCropRect(cropRect)
6077
, fPostProcess(std::move(postProcess))
6178
, fFrameCount(fCodec->codec()->getFrameCount())
62-
, fSampleSize(1)
6379
, fFinished(false)
6480
, fRepetitionCount(fCodec->codec()->getRepetitionCount())
6581
, fRepetitionsCompleted(0)
6682
{
67-
auto scaledSize = requestedInfo.dimensions();
68-
6983
// For simplicity in decoding and compositing frames, decode directly to a size and
7084
// orientation that fCodec can do directly, and then use fMatrix to handle crop (along with a
7185
// clip), orientation, and scaling outside of fCodec. The matrices are computed individually
@@ -86,11 +100,6 @@ SkAnimatedImage::SkAnimatedImage(std::unique_ptr<SkAndroidCodec> codec,
86100
scaledSize = { scaledSize.height(), scaledSize.width() };
87101
}
88102
}
89-
90-
auto decodeSize = scaledSize;
91-
fSampleSize = fCodec->computeSampleSize(&decodeSize);
92-
fDecodeInfo = fDecodeInfo.makeDimensions(decodeSize);
93-
94103
if (!fDecodingFrame.fBitmap.tryAllocPixels(fDecodeInfo)) {
95104
return;
96105
}
@@ -246,8 +255,7 @@ int SkAnimatedImage::decodeNextFrame() {
246255
// for frame |i+1|.
247256
// We could be even smarter about which frames to save by looking at the
248257
// entire dependency chain.
249-
SkAndroidCodec::AndroidOptions options;
250-
options.fSampleSize = fSampleSize;
258+
SkCodec::Options options;
251259
options.fFrameIndex = frameToDecode;
252260
if (frameInfo.fRequiredFrame == SkCodec::kNoFrame) {
253261
if (is_restore_previous(frameInfo.fDisposalMethod)) {
@@ -302,8 +310,8 @@ int SkAnimatedImage::decodeNextFrame() {
302310
return this->finish();
303311
}
304312

305-
auto result = fCodec->getAndroidPixels(dst->info(), dst->getPixels(), dst->rowBytes(),
306-
&options);
313+
auto result = fCodec->codec()->getPixels(dst->info(), dst->getPixels(), dst->rowBytes(),
314+
&options);
307315
if (result != SkCodec::kSuccess) {
308316
SkCodecPrintf("error %i, frame %i of %i\n", result, frameToDecode, fFrameCount);
309317
return this->finish();

0 commit comments

Comments
 (0)