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

Commit c0c225a8 authored by Tenghui Zhu's avatar Tenghui Zhu Committed by android-build-merger
Browse files

Merge "Add systrace for VectorDrawable inflation and draw" into oc-mr1-dev

am: dbe5afd9

Change-Id: I906a1762d0f768fdb1cac2147a29ae9e0ab8ffe2
parents 9a98142b dbe5afd9
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Shader;
import android.os.Trace;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
@@ -605,11 +606,14 @@ public class VectorDrawable extends Drawable {
    public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser,
            @NonNull AttributeSet attrs, @Nullable Theme theme)
            throws XmlPullParserException, IOException {
        try {
            Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "VectorDrawable#inflate");
            if (mVectorState.mRootGroup != null || mVectorState.mNativeTree != null) {
                // This VD has been used to display other VD resource content, clean up.
                if (mVectorState.mRootGroup != null) {
                    // Subtract the native allocation for all the nodes.
                VMRuntime.getRuntime().registerNativeFree(mVectorState.mRootGroup.getNativeSize());
                    VMRuntime.getRuntime().registerNativeFree(
                            mVectorState.mRootGroup.getNativeSize());
                    // Remove child nodes' reference to tree
                    mVectorState.mRootGroup.setTree(null);
                }
@@ -637,6 +641,9 @@ public class VectorDrawable extends Drawable {
            state.onTreeConstructionFinished();
            // Update local properties.
            updateLocalState(r);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    }

    private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
+6 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "SkShader.h"
#include <utils/Log.h>
#include "utils/Macros.h"
#include "utils/TraceUtils.h"
#include "utils/VectorDrawableUtils.h"

#include <math.h>
@@ -593,14 +594,17 @@ void Tree::draw(SkCanvas* canvas) {
void Tree::updateBitmapCache(Bitmap& bitmap, bool useStagingData) {
    SkBitmap outCache;
    bitmap.getSkBitmap(&outCache);
    int cacheWidth = outCache.width();
    int cacheHeight = outCache.height();
    ATRACE_FORMAT("VectorDrawable repaint %dx%d", cacheWidth, cacheHeight);
    outCache.eraseColor(SK_ColorTRANSPARENT);
    SkCanvas outCanvas(outCache);
    float viewportWidth = useStagingData ?
            mStagingProperties.getViewportWidth() : mProperties.getViewportWidth();
    float viewportHeight = useStagingData ?
            mStagingProperties.getViewportHeight() : mProperties.getViewportHeight();
    float scaleX = outCache.width() / viewportWidth;
    float scaleY = outCache.height() / viewportHeight;
    float scaleX = cacheWidth / viewportWidth;
    float scaleY = cacheHeight / viewportHeight;
    outCanvas.scale(scaleX, scaleY);
    mRootNode->draw(&outCanvas, useStagingData);
}