summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Doris Liu <tianliu@google.com> 2016-05-27 22:16:59 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-05-27 22:17:00 +0000
commitfceaa60e249575021e41b873673e12d9b4123fbe (patch)
tree5c04403f2fc0cd8abef6c6ac9dd0440de6350939
parenta7d66aa6b86865b223bd3b0d906b9a0f95e7c3b5 (diff)
parent028029730bf2d177f84316d2d444d409eba4b6cb (diff)
Merge "Copy native tree's property when mutate vector drawable" into nyc-dev
-rw-r--r--core/jni/android_graphics_drawable_VectorDrawable.cpp8
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java13
-rw-r--r--libs/hwui/VectorDrawable.cpp2
-rw-r--r--libs/hwui/VectorDrawable.h8
4 files changed, 28 insertions, 3 deletions
diff --git a/core/jni/android_graphics_drawable_VectorDrawable.cpp b/core/jni/android_graphics_drawable_VectorDrawable.cpp
index 9e69f79e4ffc..045f127e830e 100644
--- a/core/jni/android_graphics_drawable_VectorDrawable.cpp
+++ b/core/jni/android_graphics_drawable_VectorDrawable.cpp
@@ -36,6 +36,13 @@ static jlong createTree(JNIEnv*, jobject, jlong groupPtr) {
return reinterpret_cast<jlong>(tree);
}
+static jlong createTreeFromCopy(JNIEnv*, jobject, jlong treePtr, jlong groupPtr) {
+ VectorDrawable::Group* rootGroup = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
+ VectorDrawable::Tree* treeToCopy = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
+ VectorDrawable::Tree* tree = new VectorDrawable::Tree(treeToCopy, rootGroup);
+ return reinterpret_cast<jlong>(tree);
+}
+
static jlong createEmptyFullPath(JNIEnv*, jobject) {
VectorDrawable::FullPath* newPath = new VectorDrawable::FullPath();
return reinterpret_cast<jlong>(newPath);
@@ -344,6 +351,7 @@ 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},
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index dd33e98cddf1..f5592fa7e407 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -804,7 +804,7 @@ public class VectorDrawable extends Drawable {
mTintMode = copy.mTintMode;
mAutoMirrored = copy.mAutoMirrored;
mRootGroup = new VGroup(copy.mRootGroup, mVGTargetsMap);
- createNativeTree(mRootGroup);
+ createNativeTreeFromCopy(copy, mRootGroup);
mBaseWidth = copy.mBaseWidth;
mBaseHeight = copy.mBaseHeight;
@@ -826,6 +826,16 @@ public class VectorDrawable extends Drawable {
VMRuntime.getRuntime().registerNativeAllocation(NATIVE_ALLOCATION_SIZE);
}
+ // Create a new native tree with the given root group, and copy the properties from the
+ // given VectorDrawableState's native tree.
+ private void createNativeTreeFromCopy(VectorDrawableState copy, VGroup rootGroup) {
+ mNativeTree = new VirtualRefBasePtr(nCreateTreeFromCopy(
+ copy.mNativeTree.get(), rootGroup.mNativePtr));
+ // Register tree size
+ VMRuntime.getRuntime().registerNativeAllocation(NATIVE_ALLOCATION_SIZE);
+ }
+
+
void onTreeConstructionFinished() {
mRootGroup.setTree(mNativeTree);
mAllocationOfAllNodes = mRootGroup.getNativeSize();
@@ -1777,6 +1787,7 @@ public class VectorDrawable extends Drawable {
}
private static native long nCreateTree(long rootGroupPtr);
+ private static native long nCreateTreeFromCopy(long treeToCopy, long rootGroupPtr);
private static native void nSetRendererViewportSize(long rendererPtr, float viewportWidth,
float viewportHeight);
private static native boolean nSetRootAlpha(long rendererPtr, float alpha);
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index f0348e4977ae..2b7994139641 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -530,7 +530,7 @@ SkPaint* Tree::updatePaint(SkPaint* outPaint, TreeProperties* prop) {
if (prop->getRootAlpha() == 1.0f && prop->getColorFilter() == nullptr) {
return nullptr;
} else {
- outPaint->setColorFilter(mStagingProperties.getColorFilter());
+ outPaint->setColorFilter(prop->getColorFilter());
outPaint->setFilterQuality(kLow_SkFilterQuality);
outPaint->setAlpha(prop->getRootAlpha() * 255);
return outPaint;
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h
index b33f26c1a79d..a5d1d4b86673 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -542,6 +542,12 @@ public:
Tree(Group* rootNode) : mRootNode(rootNode) {
mRootNode->setPropertyChangedListener(&mPropertyChangedListener);
}
+
+ // Copy properties from the tree and use the give node as the root node
+ Tree(const Tree* copy, Group* rootNode) : Tree(rootNode) {
+ mStagingProperties.syncAnimatableProperties(*copy->stagingProperties());
+ mStagingProperties.syncNonAnimatableProperties(*copy->stagingProperties());
+ }
// Draws the VD onto a bitmap cache, then the bitmap cache will be rendered onto the input
// canvas. Returns the number of pixels needed for the bitmap cache.
int draw(Canvas* outCanvas, SkColorFilter* colorFilter,
@@ -666,7 +672,7 @@ public:
};
void onPropertyChanged(TreeProperties* prop);
TreeProperties* mutateStagingProperties() { return &mStagingProperties; }
- const TreeProperties* stagingProperties() { return &mStagingProperties; }
+ const TreeProperties* stagingProperties() const { return &mStagingProperties; }
PushStagingFunctor* getFunctor() { return &mFunctor;}
// This should only be called from animations on RT