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

Commit 299659dd authored by John Reck's avatar John Reck
Browse files

Convert VD/AVD to FastNative

Test: build & boots
Change-Id: I6519ba245eca1a43fb00de36c91a05a9740c8c5f
parent c36f2cd5
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -188,17 +188,20 @@ static const JNINativeMethod gMethods[] = {
    {"nCreateAnimatorSet", "()J", (void*)createAnimatorSet},
    {"nSetVectorDrawableTarget", "(JJ)V", (void*)setVectorDrawableTarget},
    {"nAddAnimator", "(JJJJJII)V", (void*)addAnimator},
    {"nCreateGroupPropertyHolder", "!(JIFF)J", (void*)createGroupPropertyHolder},
    {"nCreatePathDataPropertyHolder", "!(JJJ)J", (void*)createPathDataPropertyHolder},
    {"nCreatePathColorPropertyHolder", "!(JIII)J", (void*)createPathColorPropertyHolder},
    {"nCreatePathPropertyHolder", "!(JIFF)J", (void*)createPathPropertyHolder},
    {"nCreateRootAlphaPropertyHolder", "!(JFF)J", (void*)createRootAlphaPropertyHolder},
    {"nSetPropertyHolderData", "(J[FI)V", (void*)setFloatPropertyHolderData},
    {"nSetPropertyHolderData", "(J[II)V", (void*)setIntPropertyHolderData},
    {"nStart", "(JLandroid/graphics/drawable/AnimatedVectorDrawable$VectorDrawableAnimatorRT;I)V", (void*)start},
    {"nReverse", "(JLandroid/graphics/drawable/AnimatedVectorDrawable$VectorDrawableAnimatorRT;I)V", (void*)reverse},
    {"nEnd", "!(J)V", (void*)end},
    {"nReset", "!(J)V", (void*)reset},

    // ------------- @FastNative -------------------

    {"nCreateGroupPropertyHolder", "(JIFF)J", (void*)createGroupPropertyHolder},
    {"nCreatePathDataPropertyHolder", "(JJJ)J", (void*)createPathDataPropertyHolder},
    {"nCreatePathColorPropertyHolder", "(JIII)J", (void*)createPathColorPropertyHolder},
    {"nCreatePathPropertyHolder", "(JIFF)J", (void*)createPathPropertyHolder},
    {"nCreateRootAlphaPropertyHolder", "(JFF)J", (void*)createRootAlphaPropertyHolder},
    {"nEnd", "(J)V", (void*)end},
    {"nReset", "(J)V", (void*)reset},
};

const char* const kClassPathName = "android/graphics/drawable/AnimatedVectorDrawable$VectorDrawableAnimatorRT";
+55 −53
Original line number Diff line number Diff line
@@ -350,64 +350,66 @@ static void setTrimPathOffset(JNIEnv*, jobject, jlong fullPathPtr, jfloat trimPa
}

static const JNINativeMethod gMethods[] = {
        {"nCreateTree", "!(J)J", (void*)createTree},
        {"nCreateTreeFromCopy", "!(JJ)J", (void*)createTreeFromCopy},
        {"nSetRendererViewportSize", "!(JFF)V", (void*)setTreeViewportSize},
        {"nSetRootAlpha", "!(JF)Z", (void*)setRootAlpha},
        {"nGetRootAlpha", "!(J)F", (void*)getRootAlpha},
        {"nSetAllowCaching", "!(JZ)V", (void*)setAllowCaching},

        {"nDraw", "(JJJLandroid/graphics/Rect;ZZ)I", (void*)draw},
        {"nCreateFullPath", "!()J", (void*)createEmptyFullPath},
        {"nCreateFullPath", "!(J)J", (void*)createFullPath},
        {"nUpdateFullPathProperties", "!(JFIFIFFFFFIII)V", (void*)updateFullPathPropertiesAndStrokeStyles},
        {"nUpdateFullPathFillGradient", "!(JJ)V", (void*)updateFullPathFillGradient},
        {"nUpdateFullPathStrokeGradient", "!(JJ)V", (void*)updateFullPathStrokeGradient},
        {"nGetFullPathProperties", "(J[BI)Z", (void*)getFullPathProperties},
        {"nGetGroupProperties", "(J[FI)Z", (void*)getGroupProperties},

        {"nCreateClipPath", "!()J", (void*)createEmptyClipPath},
        {"nCreateClipPath", "!(J)J", (void*)createClipPath},
        {"nCreateGroup", "!()J", (void*)createEmptyGroup},
        {"nCreateGroup", "!(J)J", (void*)createGroup},
        {"nSetName", "(JLjava/lang/String;)V", (void*)setNodeName},
        {"nUpdateGroupProperties", "!(JFFFFFFF)V", (void*)updateGroupProperties},

        {"nAddChild", "!(JJ)V", (void*)addChild},
        {"nSetPathString", "(JLjava/lang/String;I)V", (void*)setPathString},
        {"nSetName", "(JLjava/lang/String;)V", (void*)setNodeName},

        {"nGetRotation", "!(J)F", (void*)getRotation},
        {"nSetRotation", "!(JF)V", (void*)setRotation},
        {"nGetPivotX", "!(J)F", (void*)getPivotX},
        {"nSetPivotX", "!(JF)V", (void*)setPivotX},
        {"nGetPivotY", "!(J)F", (void*)getPivotY},
        {"nSetPivotY", "!(JF)V", (void*)setPivotY},
        {"nGetScaleX", "!(J)F", (void*)getScaleX},
        {"nSetScaleX", "!(JF)V", (void*)setScaleX},
        {"nGetScaleY", "!(J)F", (void*)getScaleY},
        {"nSetScaleY", "!(JF)V", (void*)setScaleY},
        {"nGetTranslateX", "!(J)F", (void*)getTranslateX},
        {"nSetTranslateX", "!(JF)V", (void*)setTranslateX},
        {"nGetTranslateY", "!(J)F", (void*)getTranslateY},
        {"nSetTranslateY", "!(JF)V", (void*)setTranslateY},

        {"nSetPathData", "!(JJ)V", (void*)setPathData},
        {"nGetStrokeWidth", "!(J)F", (void*)getStrokeWidth},
        {"nSetStrokeWidth", "!(JF)V", (void*)setStrokeWidth},
        {"nGetStrokeColor", "!(J)I", (void*)getStrokeColor},
        {"nSetStrokeColor", "!(JI)V", (void*)setStrokeColor},
        {"nGetStrokeAlpha", "!(J)F", (void*)getStrokeAlpha},
        {"nSetStrokeAlpha", "!(JF)V", (void*)setStrokeAlpha},
        {"nGetFillColor", "!(J)I", (void*)getFillColor},
        {"nSetFillColor", "!(JI)V", (void*)setFillColor},
        {"nGetFillAlpha", "!(J)F", (void*)getFillAlpha},
        {"nSetFillAlpha", "!(JF)V", (void*)setFillAlpha},
        {"nGetTrimPathStart", "!(J)F", (void*)getTrimPathStart},
        {"nSetTrimPathStart", "!(JF)V", (void*)setTrimPathStart},
        {"nGetTrimPathEnd", "!(J)F", (void*)getTrimPathEnd},
        {"nSetTrimPathEnd", "!(JF)V", (void*)setTrimPathEnd},
        {"nGetTrimPathOffset", "!(J)F", (void*)getTrimPathOffset},
        {"nSetTrimPathOffset", "!(JF)V", (void*)setTrimPathOffset},
        // ------------- @FastNative ----------------

        {"nCreateTree", "(J)J", (void*)createTree},
        {"nCreateTreeFromCopy", "(JJ)J", (void*)createTreeFromCopy},
        {"nSetRendererViewportSize", "(JFF)V", (void*)setTreeViewportSize},
        {"nSetRootAlpha", "(JF)Z", (void*)setRootAlpha},
        {"nGetRootAlpha", "(J)F", (void*)getRootAlpha},
        {"nSetAllowCaching", "(JZ)V", (void*)setAllowCaching},

        {"nCreateFullPath", "()J", (void*)createEmptyFullPath},
        {"nCreateFullPath", "(J)J", (void*)createFullPath},
        {"nUpdateFullPathProperties", "(JFIFIFFFFFIII)V", (void*)updateFullPathPropertiesAndStrokeStyles},
        {"nUpdateFullPathFillGradient", "(JJ)V", (void*)updateFullPathFillGradient},
        {"nUpdateFullPathStrokeGradient", "(JJ)V", (void*)updateFullPathStrokeGradient},

        {"nCreateClipPath", "()J", (void*)createEmptyClipPath},
        {"nCreateClipPath", "(J)J", (void*)createClipPath},
        {"nCreateGroup", "()J", (void*)createEmptyGroup},
        {"nCreateGroup", "(J)J", (void*)createGroup},
        {"nUpdateGroupProperties", "(JFFFFFFF)V", (void*)updateGroupProperties},

        {"nAddChild", "(JJ)V", (void*)addChild},
        {"nGetRotation", "(J)F", (void*)getRotation},
        {"nSetRotation", "(JF)V", (void*)setRotation},
        {"nGetPivotX", "(J)F", (void*)getPivotX},
        {"nSetPivotX", "(JF)V", (void*)setPivotX},
        {"nGetPivotY", "(J)F", (void*)getPivotY},
        {"nSetPivotY", "(JF)V", (void*)setPivotY},
        {"nGetScaleX", "(J)F", (void*)getScaleX},
        {"nSetScaleX", "(JF)V", (void*)setScaleX},
        {"nGetScaleY", "(J)F", (void*)getScaleY},
        {"nSetScaleY", "(JF)V", (void*)setScaleY},
        {"nGetTranslateX", "(J)F", (void*)getTranslateX},
        {"nSetTranslateX", "(JF)V", (void*)setTranslateX},
        {"nGetTranslateY", "(J)F", (void*)getTranslateY},
        {"nSetTranslateY", "(JF)V", (void*)setTranslateY},

        {"nSetPathData", "(JJ)V", (void*)setPathData},
        {"nGetStrokeWidth", "(J)F", (void*)getStrokeWidth},
        {"nSetStrokeWidth", "(JF)V", (void*)setStrokeWidth},
        {"nGetStrokeColor", "(J)I", (void*)getStrokeColor},
        {"nSetStrokeColor", "(JI)V", (void*)setStrokeColor},
        {"nGetStrokeAlpha", "(J)F", (void*)getStrokeAlpha},
        {"nSetStrokeAlpha", "(JF)V", (void*)setStrokeAlpha},
        {"nGetFillColor", "(J)I", (void*)getFillColor},
        {"nSetFillColor", "(JI)V", (void*)setFillColor},
        {"nGetFillAlpha", "(J)F", (void*)getFillAlpha},
        {"nSetFillAlpha", "(JF)V", (void*)setFillAlpha},
        {"nGetTrimPathStart", "(J)F", (void*)getTrimPathStart},
        {"nSetTrimPathStart", "(JF)V", (void*)setTrimPathStart},
        {"nGetTrimPathEnd", "(J)F", (void*)getTrimPathEnd},
        {"nSetTrimPathEnd", "(JF)V", (void*)setTrimPathEnd},
        {"nGetTrimPathOffset", "(J)F", (void*)getTrimPathOffset},
        {"nSetTrimPathOffset", "(JF)V", (void*)setTrimPathOffset},
};

int register_android_graphics_drawable_VectorDrawable(JNIEnv* env) {
+16 −5
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ import android.view.View;
import com.android.internal.R;

import com.android.internal.util.VirtualRefBasePtr;

import dalvik.annotation.optimization.FastNative;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -1723,22 +1726,30 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
    private static native void nAddAnimator(long setPtr, long propertyValuesHolder,
            long nativeInterpolator, long startDelay, long duration, int repeatCount,
            int repeatMode);
    private static native void nSetPropertyHolderData(long nativePtr, float[] data, int length);
    private static native void nSetPropertyHolderData(long nativePtr, int[] data, int length);
    private static native void nStart(long animatorSetPtr, VectorDrawableAnimatorRT set, int id);
    private static native void nReverse(long animatorSetPtr, VectorDrawableAnimatorRT set, int id);

    // ------------- @FastNative -------------------

    @FastNative
    private static native long nCreateGroupPropertyHolder(long nativePtr, int propertyId,
            float startValue, float endValue);

    @FastNative
    private static native long nCreatePathDataPropertyHolder(long nativePtr, long startValuePtr,
            long endValuePtr);
    @FastNative
    private static native long nCreatePathColorPropertyHolder(long nativePtr, int propertyId,
            int startValue, int endValue);
    @FastNative
    private static native long nCreatePathPropertyHolder(long nativePtr, int propertyId,
            float startValue, float endValue);
    @FastNative
    private static native long nCreateRootAlphaPropertyHolder(long nativePtr, float startValue,
            float endValue);
    private static native void nSetPropertyHolderData(long nativePtr, float[] data, int length);
    private static native void nSetPropertyHolderData(long nativePtr, int[] data, int length);
    private static native void nStart(long animatorSetPtr, VectorDrawableAnimatorRT set, int id);
    private static native void nReverse(long animatorSetPtr, VectorDrawableAnimatorRT set, int id);
    @FastNative
    private static native void nEnd(long animatorSetPtr);
    @FastNative
    private static native void nReset(long animatorSetPtr);
}
+60 −8
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;

import dalvik.annotation.optimization.FastNative;
import dalvik.system.VMRuntime;

/**
@@ -2150,41 +2151,61 @@ public class VectorDrawable extends Drawable {
        abstract Property getProperty(String propertyName);
    }

    private static native int nDraw(long rendererPtr, long canvasWrapperPtr,
            long colorFilterPtr, Rect bounds, boolean needsMirroring, boolean canReuseCache);
    private static native boolean nGetFullPathProperties(long pathPtr, byte[] properties,
            int length);
    private static native void nSetName(long nodePtr, String name);
    private static native boolean nGetGroupProperties(long groupPtr, float[] properties,
            int length);
    private static native void nSetPathString(long pathPtr, String pathString, int length);

    // ------------- @FastNative ------------------

    @FastNative
    private static native long nCreateTree(long rootGroupPtr);
    @FastNative
    private static native long nCreateTreeFromCopy(long treeToCopy, long rootGroupPtr);
    @FastNative
    private static native void nSetRendererViewportSize(long rendererPtr, float viewportWidth,
            float viewportHeight);
    @FastNative
    private static native boolean nSetRootAlpha(long rendererPtr, float alpha);
    @FastNative
    private static native float nGetRootAlpha(long rendererPtr);
    @FastNative
    private static native void nSetAllowCaching(long rendererPtr, boolean allowCaching);

    private static native int nDraw(long rendererPtr, long canvasWrapperPtr,
            long colorFilterPtr, Rect bounds, boolean needsMirroring, boolean canReuseCache);
    @FastNative
    private static native long nCreateFullPath();
    @FastNative
    private static native long nCreateFullPath(long nativeFullPathPtr);
    private static native boolean nGetFullPathProperties(long pathPtr, byte[] properties,
            int length);

    @FastNative
    private static native void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
            int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
            float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
            int strokeLineJoin, int fillType);
    @FastNative
    private static native void nUpdateFullPathFillGradient(long pathPtr, long fillGradientPtr);
    @FastNative
    private static native void nUpdateFullPathStrokeGradient(long pathPtr, long strokeGradientPtr);

    @FastNative
    private static native long nCreateClipPath();
    @FastNative
    private static native long nCreateClipPath(long clipPathPtr);

    @FastNative
    private static native long nCreateGroup();
    @FastNative
    private static native long nCreateGroup(long groupPtr);
    private static native void nSetName(long nodePtr, String name);
    private static native boolean nGetGroupProperties(long groupPtr, float[] properties,
            int length);
    @FastNative
    private static native void nUpdateGroupProperties(long groupPtr, float rotate, float pivotX,
            float pivotY, float scaleX, float scaleY, float translateX, float translateY);

    @FastNative
    private static native void nAddChild(long groupPtr, long nodePtr);
    private static native void nSetPathString(long pathPtr, String pathString, int length);

    /**
     * The setters and getters below for paths and groups are here temporarily, and will be
@@ -2193,37 +2214,68 @@ public class VectorDrawable extends Drawable {
     * for VD during animation, and these setters and getters will be obsolete.
     */
    // Setters and getters during animation.
    @FastNative
    private static native float nGetRotation(long groupPtr);
    @FastNative
    private static native void nSetRotation(long groupPtr, float rotation);
    @FastNative
    private static native float nGetPivotX(long groupPtr);
    @FastNative
    private static native void nSetPivotX(long groupPtr, float pivotX);
    @FastNative
    private static native float nGetPivotY(long groupPtr);
    @FastNative
    private static native void nSetPivotY(long groupPtr, float pivotY);
    @FastNative
    private static native float nGetScaleX(long groupPtr);
    @FastNative
    private static native void nSetScaleX(long groupPtr, float scaleX);
    @FastNative
    private static native float nGetScaleY(long groupPtr);
    @FastNative
    private static native void nSetScaleY(long groupPtr, float scaleY);
    @FastNative
    private static native float nGetTranslateX(long groupPtr);
    @FastNative
    private static native void nSetTranslateX(long groupPtr, float translateX);
    @FastNative
    private static native float nGetTranslateY(long groupPtr);
    @FastNative
    private static native void nSetTranslateY(long groupPtr, float translateY);

    // Setters and getters for VPath during animation.
    @FastNative
    private static native void nSetPathData(long pathPtr, long pathDataPtr);
    @FastNative
    private static native float nGetStrokeWidth(long pathPtr);
    @FastNative
    private static native void nSetStrokeWidth(long pathPtr, float width);
    @FastNative
    private static native int nGetStrokeColor(long pathPtr);
    @FastNative
    private static native void nSetStrokeColor(long pathPtr, int strokeColor);
    @FastNative
    private static native float nGetStrokeAlpha(long pathPtr);
    @FastNative
    private static native void nSetStrokeAlpha(long pathPtr, float alpha);
    @FastNative
    private static native int nGetFillColor(long pathPtr);
    @FastNative
    private static native void nSetFillColor(long pathPtr, int fillColor);
    @FastNative
    private static native float nGetFillAlpha(long pathPtr);
    @FastNative
    private static native void nSetFillAlpha(long pathPtr, float fillAlpha);
    @FastNative
    private static native float nGetTrimPathStart(long pathPtr);
    @FastNative
    private static native void nSetTrimPathStart(long pathPtr, float trimPathStart);
    @FastNative
    private static native float nGetTrimPathEnd(long pathPtr);
    @FastNative
    private static native void nSetTrimPathEnd(long pathPtr, float trimPathEnd);
    @FastNative
    private static native float nGetTrimPathOffset(long pathPtr);
    @FastNative
    private static native void nSetTrimPathOffset(long pathPtr, float trimPathOffset);
}