summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author ztenghui <ztenghui@google.com> 2017-09-13 10:32:50 -0700
committer Tenghui Zhu <ztenghui@google.com> 2017-09-22 19:44:24 +0000
commit3d30ca1d3c9cbb8e7c6f4194b7e5f79fd44cd0b3 (patch)
tree839703f4c764d960d8951f7882932450fb9a89d8
parente8041834b1de4322456c40436240650482217bc9 (diff)
Add systrace for VectorDrawable inflation and draw
We didn't trace the draw from cache. Here we add trace for draw into bitmap, which is normally heavy. fix: 65060698 Bug: 65060698 Test: run test app and get systrace and check Change-Id: Ia81127c4aa285b3277e9c9edbdf356d85cb28b5e (cherry picked from commit cf0c41dbc221c2619212c7e25e6d90a9c4d05b05)
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java61
-rw-r--r--libs/hwui/VectorDrawable.cpp8
2 files changed, 40 insertions, 29 deletions
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index c3ef45088f8e..ceac3253e178 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -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,38 +606,44 @@ public class VectorDrawable extends Drawable {
public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser,
@NonNull AttributeSet attrs, @Nullable Theme theme)
throws XmlPullParserException, IOException {
- 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());
- // Remove child nodes' reference to tree
- mVectorState.mRootGroup.setTree(null);
- }
- mVectorState.mRootGroup = new VGroup();
- if (mVectorState.mNativeTree != null) {
- // Subtract the native allocation for the tree wrapper, which contains root node
- // as well as rendering related data.
- VMRuntime.getRuntime().registerNativeFree(mVectorState.NATIVE_ALLOCATION_SIZE);
- mVectorState.mNativeTree.release();
+ 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());
+ // Remove child nodes' reference to tree
+ mVectorState.mRootGroup.setTree(null);
+ }
+ mVectorState.mRootGroup = new VGroup();
+ if (mVectorState.mNativeTree != null) {
+ // Subtract the native allocation for the tree wrapper, which contains root node
+ // as well as rendering related data.
+ VMRuntime.getRuntime().registerNativeFree(mVectorState.NATIVE_ALLOCATION_SIZE);
+ mVectorState.mNativeTree.release();
+ }
+ mVectorState.createNativeTree(mVectorState.mRootGroup);
}
- mVectorState.createNativeTree(mVectorState.mRootGroup);
- }
- final VectorDrawableState state = mVectorState;
- state.setDensity(Drawable.resolveDensity(r, 0));
+ final VectorDrawableState state = mVectorState;
+ state.setDensity(Drawable.resolveDensity(r, 0));
- final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.VectorDrawable);
- updateStateFromTypedArray(a);
- a.recycle();
+ final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.VectorDrawable);
+ updateStateFromTypedArray(a);
+ a.recycle();
- mDpiScaledDirty = true;
+ mDpiScaledDirty = true;
- state.mCacheDirty = true;
- inflateChildElements(r, parser, attrs, theme);
+ state.mCacheDirty = true;
+ inflateChildElements(r, parser, attrs, theme);
- state.onTreeConstructionFinished();
- // Update local properties.
- updateLocalState(r);
+ state.onTreeConstructionFinished();
+ // Update local properties.
+ updateLocalState(r);
+ } finally {
+ Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
+ }
}
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index 8a1de02e6a0c..ca179c9a25d2 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -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);
}