From 671cce2605ed50c9aba73ab5bd530cb7741c53cd Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Sun, 14 Jan 2018 16:52:17 -0500 Subject: Make ImageDecoder return animated Drawables Bug: 63909536 Bug: 63908092 Test: TODO If ImageDecoder.decodeDrawable is called with an animated image Source (currently GIF or WebP), return an object of a new (hidden) Drawable subclass. The new Drawable animates, and it implements Animatable (TODO: implement Animatable2) so users have some control over the animation. In addition to the normal features of Drawable, this new one supports many of the features of ImageDecoder, including scaling, cropping and PostProcess, which enables circle masks/rounded corners and other arbitrary after-effects. It does *not* support decoding directly to a Hardware Bitmap, since it cycles through frames and reuses the same bitmap memory. But it could be made to use shared memory (TODO?). TODO: Use a better number for the native allocation registry TODO: Use the RenderThread to drive the animation, and remove decoding on the UI thread. TODO: Add support for modifying the loop count Android.bp: - build new AnimatedImageDrawable.cpp AndroidRuntime.cpp: - register new native methods AnimatedImageDrawable.java AnimatedImageDrawable.cpp: - new Drawable that handles animated images Canvas.h, SkiaCanvas.h/.cpp - New virtual method and implementation for drawing SkAnimatedImages RecordingCanvas.h/.cpp - Stub implementation of drawing SkAnimatedImages ImageDecoder.h/cpp - Allow code sharing with AnimatedImageDrawable.cpp - postProcess - access the ImageDecoder struct Depends on https://skia-review.googlesource.com/c/skia/+/94660 in Skia. Change-Id: Ie2ec98d9c52deda4d439c6ef8e5dea2861bb93a3 --- libs/hwui/SkiaCanvas.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libs/hwui/SkiaCanvas.cpp') diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 2e08670a757a..dc274cf50a52 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -23,6 +23,7 @@ #include "hwui/MinikinUtils.h" #include "pipeline/skia/AnimatedDrawables.h" +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -723,6 +725,20 @@ void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, floa mCanvas->drawImageLattice(image.get(), lattice, dst, addFilter(paint, &tmpPaint, colorFilter)); } +void SkiaCanvas::drawAnimatedImage(SkAnimatedImage* image, float left, float top, + const SkPaint* paint) { + sk_sp pic(image->newPictureSnapshot()); + SkMatrix matrixStorage; + SkMatrix* matrix; + if (left == 0.0f && top == 0.0f) { + matrix = nullptr; + } else { + matrixStorage = SkMatrix::MakeTrans(left, top); + matrix = &matrixStorage; + } + mCanvas->drawPicture(pic.get(), matrix, paint); +} + void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) { vectorDrawable->drawStaging(this); } -- cgit v1.2.3-59-g8ed1b