Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 659fd202 authored by Jorge Betancourt's avatar Jorge Betancourt
Browse files

Revert "add support for rendering lottie animations through a LottieDrawable"

This reverts commit 2e58b5c4.

Reason for revert: prep for mainline

Bug: 257304231
Change-Id: I51515a6eed577ad098020588f12cafc8fff0541e
parent 2e58b5c4
Loading
Loading
Loading
Loading
+0 −151
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics.drawable;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PixelFormat;

import dalvik.annotation.optimization.FastNative;

import libcore.util.NativeAllocationRegistry;

import java.io.IOException;

/**
 * {@link Drawable} for drawing Lottie files.
 *
 * <p>The framework handles decoding subsequent frames in another thread and
 * updating when necessary. The drawable will only animate while it is being
 * displayed.</p>
 *
 * @hide
 */
@SuppressLint("NotCloseable")
public class LottieDrawable extends Drawable implements Animatable {
    private long mNativePtr;

    /**
     * Create an animation from the provided JSON string
     * @hide
     */
    private LottieDrawable(@NonNull String animationJson) throws IOException {
        mNativePtr = nCreate(animationJson);
        if (mNativePtr == 0) {
            throw new IOException("could not make LottieDrawable from json");
        }

        final long nativeSize = nNativeByteSize(mNativePtr);
        NativeAllocationRegistry registry = new NativeAllocationRegistry(
                LottieDrawable.class.getClassLoader(), nGetNativeFinalizer(), nativeSize);
        registry.registerNativeAllocation(this, mNativePtr);
    }

    /**
     * Factory for LottieDrawable, throws IOException if native Skottie Builder fails to parse
     */
    public static LottieDrawable makeLottieDrawable(@NonNull String animationJson)
            throws IOException {
        return new LottieDrawable(animationJson);
    }



    /**
     * Draw the current frame to the Canvas.
     * @hide
     */
    @Override
    public void draw(@NonNull Canvas canvas) {
        if (mNativePtr == 0) {
            throw new IllegalStateException("called draw on empty LottieDrawable");
        }

        nDraw(mNativePtr, canvas.getNativeCanvasWrapper());
    }

    /**
     * Start the animation. Needs to be called before draw calls.
     * @hide
     */
    @Override
    public void start() {
        if (mNativePtr == 0) {
            throw new IllegalStateException("called start on empty LottieDrawable");
        }

        if (nStart(mNativePtr)) {
            invalidateSelf();
        }
    }

    /**
     * Stops the animation playback. Does not release anything.
     * @hide
     */
    @Override
    public void stop() {
        if (mNativePtr == 0) {
            throw new IllegalStateException("called stop on empty LottieDrawable");
        }
        nStop(mNativePtr);
    }

    /**
     *  Return whether the animation is currently running.
     */
    @Override
    public boolean isRunning() {
        if (mNativePtr == 0) {
            throw new IllegalStateException("called isRunning on empty LottieDrawable");
        }
        return nIsRunning(mNativePtr);
    }

    @Override
    public int getOpacity() {
        // We assume translucency to avoid checking each pixel.
        return PixelFormat.TRANSLUCENT;
    }

    @Override
    public void setAlpha(int alpha) {
        //TODO
    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {
        //TODO
    }

    private static native long nCreate(String json);
    private static native void nDraw(long nativeInstance, long nativeCanvas);
    @FastNative
    private static native long nGetNativeFinalizer();
    @FastNative
    private static native long nNativeByteSize(long nativeInstance);
    @FastNative
    private static native boolean nIsRunning(long nativeInstance);
    @FastNative
    private static native boolean nStart(long nativeInstance);
    @FastNative
    private static native boolean nStop(long nativeInstance);

}
+0 −4
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ cc_defaults {
                "external/skia/src/utils",
                "external/skia/src/gpu",
                "external/skia/src/shaders",
                "external/skia/modules/skottie",
            ],
        },
        host: {
@@ -375,7 +374,6 @@ cc_defaults {
        "external/skia/src/effects",
        "external/skia/src/image",
        "external/skia/src/images",
        "external/skia/modules/skottie",
    ],

    shared_libs: [
@@ -402,7 +400,6 @@ cc_defaults {
                "jni/BitmapRegionDecoder.cpp",
                "jni/GIFMovie.cpp",
                "jni/GraphicsStatsService.cpp",
                "jni/LottieDrawable.cpp",
                "jni/Movie.cpp",
                "jni/MovieImpl.cpp",
                "jni/pdf/PdfDocument.cpp",
@@ -510,7 +507,6 @@ cc_defaults {
        "hwui/BlurDrawLooper.cpp",
        "hwui/Canvas.cpp",
        "hwui/ImageDecoder.cpp",
        "hwui/LottieDrawable.cpp",
        "hwui/MinikinSkia.cpp",
        "hwui/MinikinUtils.cpp",
        "hwui/PaintImpl.cpp",
+0 −4
Original line number Diff line number Diff line
@@ -736,10 +736,6 @@ double SkiaCanvas::drawAnimatedImage(AnimatedImageDrawable* imgDrawable) {
    return imgDrawable->drawStaging(mCanvas);
}

void SkiaCanvas::drawLottie(LottieDrawable* lottieDrawable) {
    lottieDrawable->drawStaging(mCanvas);
}

void SkiaCanvas::drawVectorDrawable(VectorDrawableRoot* vectorDrawable) {
    vectorDrawable->drawStaging(this);
}
+0 −1
Original line number Diff line number Diff line
@@ -145,7 +145,6 @@ public:
                               float dstTop, float dstRight, float dstBottom,
                               const Paint* paint) override;
    virtual double drawAnimatedImage(AnimatedImageDrawable* imgDrawable) override;
    virtual void drawLottie(LottieDrawable* lottieDrawable) override;

    virtual void drawVectorDrawable(VectorDrawableRoot* vectorDrawable) override;

+0 −2
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
extern int register_android_graphics_Graphics(JNIEnv* env);
extern int register_android_graphics_ImageDecoder(JNIEnv*);
extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*);
extern int register_android_graphics_drawable_LottieDrawable(JNIEnv*);
extern int register_android_graphics_Interpolator(JNIEnv* env);
extern int register_android_graphics_MaskFilter(JNIEnv* env);
extern int register_android_graphics_Movie(JNIEnv* env);
@@ -117,7 +116,6 @@ extern int register_android_view_ThreadedRenderer(JNIEnv* env);
            REG_JNI(register_android_graphics_HardwareRendererObserver),
            REG_JNI(register_android_graphics_ImageDecoder),
            REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable),
            REG_JNI(register_android_graphics_drawable_LottieDrawable),
            REG_JNI(register_android_graphics_Interpolator),
            REG_JNI(register_android_graphics_MaskFilter),
            REG_JNI(register_android_graphics_Matrix),
Loading