aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/android
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2018-05-23 16:15:09 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-23 20:49:42 +0000
commit4aafb3a8d12015067fae1301c2f5951f398eb25b (patch)
tree99f3f8476851cc141d35cd5ec944866207e1315c /include/android
parent1530f390087e48bd88981eeee69086ef9a52c243 (diff)
Alternate between two SkBitmaps in SkAnimatedImage
Bug: 78866720 The client in Android calls newPictureSnapshot, which results in copying the mutable SkBitmap into a newly allocated one in each frame. Avoid this by calling SkMakeImageFromRasterBitmap with kNever_SkCopyPixelsMode. Make SkAnimatedImage copy on write, by copying before decoding if the bitmap's pixel ref is not unique. Android's AnimatedImageDrawable's current architecture only decodes one frame in advance, so it will never need to perform the copy on write. This will save one bitmap allocation per GIF frame. Add a test to verify that copy on write works as expected. Change-Id: I87eb6e84089096cd2d618b91fb627fc58677e66a Reviewed-on: https://skia-review.googlesource.com/129841 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com> Auto-Submit: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'include/android')
-rw-r--r--include/android/SkAnimatedImage.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/include/android/SkAnimatedImage.h b/include/android/SkAnimatedImage.h
index 51f0e5b84b..983a57bd5c 100644
--- a/include/android/SkAnimatedImage.h
+++ b/include/android/SkAnimatedImage.h
@@ -107,7 +107,20 @@ private:
int fIndex;
SkCodecAnimation::DisposalMethod fDisposalMethod;
+ // init() may have to create a new SkPixelRef, if the
+ // current one is already in use by another owner (e.g.
+ // an SkPicture). This determines whether to copy the
+ // existing one to the new one.
+ enum class OnInit {
+ // Restore the image from the old SkPixelRef to the
+ // new one.
+ kRestoreIfNecessary,
+ // No need to restore.
+ kNoRestore,
+ };
+
Frame();
+ bool init(const SkImageInfo& info, OnInit);
bool copyTo(Frame*) const;
};
@@ -122,7 +135,8 @@ private:
bool fFinished;
int fCurrentFrameDuration;
- Frame fActiveFrame;
+ Frame fDisplayFrame;
+ Frame fDecodingFrame;
Frame fRestoreFrame;
int fRepetitionCount;
int fRepetitionsCompleted;