Skip to content

Commit 296a5b4

Browse files
chethaaseAndroid (Google) Code Review
authored andcommitted
Merge "Re-enable DisplayList properties."
2 parents 895eb28 + 9420abd commit 296a5b4

File tree

9 files changed

+549
-80
lines changed

9 files changed

+549
-80
lines changed

core/java/android/view/DisplayList.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package android.view;
1818

19+
import android.graphics.Matrix;
20+
1921
/**
2022
* A display lists records a series of graphics related operation and can replay
2123
* them later. Display lists are usually built by recording operations on a
@@ -117,12 +119,26 @@ public abstract class DisplayList {
117119
public abstract void setClipChildren(boolean clipChildren);
118120

119121
/**
120-
* Set the application scale on the DisplayList. This scale is incurred by applications that
121-
* are auto-scaled for compatibility reasons. By default, the value is 1 (unscaled).
122+
* Set the static matrix on the DisplayList. This matrix exists if a custom ViewGroup
123+
* overrides
124+
* {@link ViewGroup#getChildStaticTransformation(View, android.view.animation.Transformation)}
125+
* and also has {@link ViewGroup#setStaticTransformationsEnabled(boolean)} set to true.
126+
* This matrix will be concatenated with any other matrices in the DisplayList to position
127+
* the view appropriately.
128+
*
129+
* @param matrix The matrix
130+
*/
131+
public abstract void setStaticMatrix(Matrix matrix);
132+
133+
/**
134+
* Set the Animation matrix on the DisplayList. This matrix exists if an Animation is
135+
* currently playing on a View, and is set on the DisplayList during at draw() time. When
136+
* the Animation finishes, the matrix should be cleared by sending <code>null</code>
137+
* for the matrix parameter.
122138
*
123-
* @param scale The scaling factor
139+
* @param matrix The matrix, null indicates that the matrix should be cleared.
124140
*/
125-
public abstract void setApplicationScale(float scale);
141+
public abstract void setAnimationMatrix(Matrix matrix);
126142

127143
/**
128144
* Sets the alpha value for the DisplayList

core/java/android/view/GLES20DisplayList.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.view;
1818

1919
import android.graphics.Bitmap;
20+
import android.graphics.Matrix;
2021

2122
import java.util.ArrayList;
2223

@@ -119,9 +120,18 @@ public void setClipChildren(boolean clipChildren) {
119120
}
120121

121122
@Override
122-
public void setApplicationScale(float scale) {
123+
public void setStaticMatrix(Matrix matrix) {
123124
try {
124-
nSetApplicationScale(getNativeDisplayList(), scale);
125+
nSetStaticMatrix(getNativeDisplayList(), matrix.native_instance);
126+
} catch (IllegalStateException e) {
127+
// invalid DisplayList okay: we'll set current values the next time we render to it
128+
}
129+
}
130+
131+
@Override
132+
public void setAnimationMatrix(Matrix matrix) {
133+
try {
134+
nSetAnimationMatrix(getNativeDisplayList(), matrix.native_instance);
125135
} catch (IllegalStateException e) {
126136
// invalid DisplayList okay: we'll set current values the next time we render to it
127137
}
@@ -335,6 +345,8 @@ private static native void nSetLeftTopRightBottom(int displayList, int left, int
335345
private static native void nSetTransformationInfo(int displayList, float alpha,
336346
float translationX, float translationY, float rotation, float rotationX,
337347
float rotationY, float scaleX, float scaleY);
348+
private static native void nSetStaticMatrix(int displayList, int nativeMatrix);
349+
private static native void nSetAnimationMatrix(int displayList, int animationMatrix);
338350

339351

340352
///////////////////////////////////////////////////////////////////////////

core/java/android/view/View.java

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11529,12 +11529,34 @@ void setDisplayListProperties(DisplayList displayList) {
1152911529
displayList.setClipChildren(
1153011530
(((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0);
1153111531
}
11532-
if (mAttachInfo != null && mAttachInfo.mScalingRequired &&
11533-
mAttachInfo.mApplicationScale != 1.0f) {
11534-
displayList.setApplicationScale(1f / mAttachInfo.mApplicationScale);
11532+
float alpha = 1;
11533+
if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags &
11534+
ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
11535+
ViewGroup parentVG = (ViewGroup) mParent;
11536+
final boolean hasTransform =
11537+
parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation);
11538+
if (hasTransform) {
11539+
Transformation transform = parentVG.mChildTransformation;
11540+
final int transformType = parentVG.mChildTransformation.getTransformationType();
11541+
if (transformType != Transformation.TYPE_IDENTITY) {
11542+
if ((transformType & Transformation.TYPE_ALPHA) != 0) {
11543+
alpha = transform.getAlpha();
11544+
}
11545+
if ((transformType & Transformation.TYPE_MATRIX) != 0) {
11546+
displayList.setStaticMatrix(transform.getMatrix());
11547+
}
11548+
}
11549+
}
1153511550
}
1153611551
if (mTransformationInfo != null) {
11537-
displayList.setTransformationInfo(mTransformationInfo.mAlpha,
11552+
alpha *= mTransformationInfo.mAlpha;
11553+
if (alpha < 1) {
11554+
final int multipliedAlpha = (int) (255 * alpha);
11555+
if (onSetAlpha(multipliedAlpha)) {
11556+
alpha = 1;
11557+
}
11558+
}
11559+
displayList.setTransformationInfo(alpha,
1153811560
mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY,
1153911561
mTransformationInfo.mRotation, mTransformationInfo.mRotationX,
1154011562
mTransformationInfo.mRotationY, mTransformationInfo.mScaleX,
@@ -11548,6 +11570,8 @@ void setDisplayListProperties(DisplayList displayList) {
1154811570
displayList.setPivotX(getPivotX());
1154911571
displayList.setPivotY(getPivotY());
1155011572
}
11573+
} else if (alpha < 1) {
11574+
displayList.setAlpha(alpha);
1155111575
}
1155211576
}
1155311577
}
@@ -11580,6 +11604,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1158011604
if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 ||
1158111605
(flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) {
1158211606
caching = true;
11607+
// Auto-scaled apps are not hw-accelerated, no need to set scaling flag on DisplayList
1158311608
if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired;
1158411609
} else {
1158511610
caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated;
@@ -11590,7 +11615,8 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1159011615
more = drawAnimation(parent, drawingTime, a, scalingRequired);
1159111616
concatMatrix = a.willChangeTransformationMatrix();
1159211617
transformToApply = parent.mChildTransformation;
11593-
} else if ((flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
11618+
} else if (!useDisplayListProperties &&
11619+
(flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
1159411620
final boolean hasTransform =
1159511621
parent.getChildStaticTransformation(this, parent.mChildTransformation);
1159611622
if (hasTransform) {
@@ -11658,6 +11684,17 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1165811684
}
1165911685
}
1166011686
useDisplayListProperties &= hasDisplayList;
11687+
if (useDisplayListProperties) {
11688+
displayList = getDisplayList();
11689+
if (!displayList.isValid()) {
11690+
// Uncommon, but possible. If a view is removed from the hierarchy during the call
11691+
// to getDisplayList(), the display list will be marked invalid and we should not
11692+
// try to use it again.
11693+
displayList = null;
11694+
hasDisplayList = false;
11695+
useDisplayListProperties = false;
11696+
}
11697+
}
1166111698

1166211699
final boolean hasNoCache = cache == null || hasDisplayList;
1166311700
final boolean offsetForScroll = cache == null && !hasDisplayList &&
@@ -11675,6 +11712,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1167511712
}
1167611713
if (scalingRequired) {
1167711714
if (useDisplayListProperties) {
11715+
// TODO: Might not need this if we put everything inside the DL
1167811716
restoreTo = canvas.save();
1167911717
}
1168011718
// mAttachInfo cannot be null, otherwise scalingRequired == false
@@ -11684,7 +11722,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1168411722
}
1168511723

1168611724
float alpha = useDisplayListProperties ? 1 : getAlpha();
11687-
if (transformToApply != null || alpha < 1.0f || !hasIdentityMatrix()) {
11725+
if (transformToApply != null || alpha < 1 || !hasIdentityMatrix()) {
1168811726
if (transformToApply != null || !childHasIdentityMatrix) {
1168911727
int transX = 0;
1169011728
int transY = 0;
@@ -11696,16 +11734,20 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1169611734

1169711735
if (transformToApply != null) {
1169811736
if (concatMatrix) {
11699-
// Undo the scroll translation, apply the transformation matrix,
11700-
// then redo the scroll translate to get the correct result.
11701-
canvas.translate(-transX, -transY);
11702-
canvas.concat(transformToApply.getMatrix());
11703-
canvas.translate(transX, transY);
11737+
if (useDisplayListProperties) {
11738+
displayList.setAnimationMatrix(transformToApply.getMatrix());
11739+
} else {
11740+
// Undo the scroll translation, apply the transformation matrix,
11741+
// then redo the scroll translate to get the correct result.
11742+
canvas.translate(-transX, -transY);
11743+
canvas.concat(transformToApply.getMatrix());
11744+
canvas.translate(transX, transY);
11745+
}
1170411746
parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION;
1170511747
}
1170611748

1170711749
float transformAlpha = transformToApply.getAlpha();
11708-
if (transformAlpha < 1.0f) {
11750+
if (transformAlpha < 1) {
1170911751
alpha *= transformToApply.getAlpha();
1171011752
parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION;
1171111753
}
@@ -11718,7 +11760,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1171811760
}
1171911761
}
1172011762

11721-
if (alpha < 1.0f) {
11763+
if (alpha < 1) {
1172211764
parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION;
1172311765
if (hasNoCache) {
1172411766
final int multipliedAlpha = (int) (255 * alpha);
@@ -11728,7 +11770,9 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1172811770
layerType != LAYER_TYPE_NONE) {
1172911771
layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
1173011772
}
11731-
if (layerType == LAYER_TYPE_NONE) {
11773+
if (useDisplayListProperties) {
11774+
displayList.setAlpha(alpha * getAlpha());
11775+
} else if (layerType == LAYER_TYPE_NONE) {
1173211776
final int scrollX = hasDisplayList ? 0 : sx;
1173311777
final int scrollY = hasDisplayList ? 0 : sy;
1173411778
canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft,
@@ -11758,7 +11802,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1175811802
}
1175911803
}
1176011804

11761-
if (hasDisplayList) {
11805+
if (!useDisplayListProperties && hasDisplayList) {
1176211806
displayList = getDisplayList();
1176311807
if (!displayList.isValid()) {
1176411808
// Uncommon, but possible. If a view is removed from the hierarchy during the call
@@ -11815,7 +11859,7 @@ boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
1181511859
cachePaint.setDither(false);
1181611860
parent.mCachePaint = cachePaint;
1181711861
}
11818-
if (alpha < 1.0f) {
11862+
if (alpha < 1) {
1181911863
cachePaint.setAlpha((int) (alpha * 255));
1182011864
parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE;
1182111865
} else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) {

core/jni/android_view_GLES20DisplayList.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ static void android_view_GLES20DisplayList_setCaching(JNIEnv* env,
4545
displayList->setCaching(caching);
4646
}
4747

48-
static void android_view_GLES20DisplayList_setApplicationScale(JNIEnv* env,
49-
jobject clazz, DisplayList* displayList, float scale) {
50-
displayList->setApplicationScale(scale);
48+
static void android_view_GLES20DisplayList_setStaticMatrix(JNIEnv* env,
49+
jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
50+
displayList->setStaticMatrix(matrix);
51+
}
52+
53+
static void android_view_GLES20DisplayList_setAnimationMatrix(JNIEnv* env,
54+
jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
55+
displayList->setAnimationMatrix(matrix);
5156
}
5257

5358
static void android_view_GLES20DisplayList_setClipChildren(JNIEnv* env,
@@ -175,33 +180,32 @@ const char* const kClassPathName = "android/view/GLES20DisplayList";
175180

176181
static JNINativeMethod gMethods[] = {
177182
#ifdef USE_OPENGL_RENDERER
178-
{ "nSetCaching", "(IZ)V", (void*) android_view_GLES20DisplayList_setCaching },
179-
{ "nSetApplicationScale", "(IF)V",
180-
(void*) android_view_GLES20DisplayList_setApplicationScale },
181-
{ "nSetClipChildren", "(IZ)V", (void*) android_view_GLES20DisplayList_setClipChildren },
182-
{ "nSetAlpha", "(IF)V", (void*) android_view_GLES20DisplayList_setAlpha },
183-
{ "nSetTranslationX", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationX },
184-
{ "nSetTranslationY", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationY },
185-
{ "nSetRotation", "(IF)V", (void*) android_view_GLES20DisplayList_setRotation },
186-
{ "nSetRotationX", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationX },
187-
{ "nSetRotationY", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationY },
188-
{ "nSetScaleX", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleX },
189-
{ "nSetScaleY", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleY },
190-
{ "nSetTransformationInfo", "(IFFFFFFFF)V",
183+
{ "nSetCaching", "(IZ)V", (void*) android_view_GLES20DisplayList_setCaching },
184+
{ "nSetStaticMatrix", "(II)V", (void*) android_view_GLES20DisplayList_setStaticMatrix },
185+
{ "nSetAnimationMatrix", "(II)V", (void*) android_view_GLES20DisplayList_setAnimationMatrix },
186+
{ "nSetClipChildren", "(IZ)V", (void*) android_view_GLES20DisplayList_setClipChildren },
187+
{ "nSetAlpha", "(IF)V", (void*) android_view_GLES20DisplayList_setAlpha },
188+
{ "nSetTranslationX", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationX },
189+
{ "nSetTranslationY", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationY },
190+
{ "nSetRotation", "(IF)V", (void*) android_view_GLES20DisplayList_setRotation },
191+
{ "nSetRotationX", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationX },
192+
{ "nSetRotationY", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationY },
193+
{ "nSetScaleX", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleX },
194+
{ "nSetScaleY", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleY },
195+
{ "nSetTransformationInfo","(IFFFFFFFF)V",
191196
(void*) android_view_GLES20DisplayList_setTransformationInfo },
192-
{ "nSetPivotX", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotX },
193-
{ "nSetPivotY", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotY },
194-
{ "nSetCameraDistance", "(IF)V",
195-
(void*) android_view_GLES20DisplayList_setCameraDistance },
196-
{ "nSetLeft", "(II)V", (void*) android_view_GLES20DisplayList_setLeft },
197-
{ "nSetTop", "(II)V", (void*) android_view_GLES20DisplayList_setTop },
198-
{ "nSetRight", "(II)V", (void*) android_view_GLES20DisplayList_setRight },
199-
{ "nSetBottom", "(II)V", (void*) android_view_GLES20DisplayList_setBottom },
200-
{ "nSetLeftTop", "(III)V", (void*) android_view_GLES20DisplayList_setLeftTop },
201-
{ "nSetLeftTopRightBottom", "(IIIII)V",
197+
{ "nSetPivotX", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotX },
198+
{ "nSetPivotY", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotY },
199+
{ "nSetCameraDistance", "(IF)V", (void*) android_view_GLES20DisplayList_setCameraDistance },
200+
{ "nSetLeft", "(II)V", (void*) android_view_GLES20DisplayList_setLeft },
201+
{ "nSetTop", "(II)V", (void*) android_view_GLES20DisplayList_setTop },
202+
{ "nSetRight", "(II)V", (void*) android_view_GLES20DisplayList_setRight },
203+
{ "nSetBottom", "(II)V", (void*) android_view_GLES20DisplayList_setBottom },
204+
{ "nSetLeftTop", "(III)V", (void*) android_view_GLES20DisplayList_setLeftTop },
205+
{ "nSetLeftTopRightBottom","(IIIII)V",
202206
(void*) android_view_GLES20DisplayList_setLeftTopRightBottom },
203-
{ "nOffsetLeftRight", "(II)V", (void*) android_view_GLES20DisplayList_offsetLeftRight },
204-
{ "nOffsetTopBottom", "(II)V", (void*) android_view_GLES20DisplayList_offsetTopBottom },
207+
{ "nOffsetLeftRight", "(II)V", (void*) android_view_GLES20DisplayList_offsetLeftRight },
208+
{ "nOffsetTopBottom", "(II)V", (void*) android_view_GLES20DisplayList_offsetTopBottom },
205209

206210
#endif
207211
};

0 commit comments

Comments
 (0)