am fe5984f4: Merge "Corrects invalidation logic for layered views" into jb-dev
* commit 'fe5984f43a5be9f95d1febb806f3aee8601c7ff4': Corrects invalidation logic for layered views
This commit is contained in:
@@ -3938,59 +3938,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
||||
// through
|
||||
final boolean drawAnimation = (child.mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION;
|
||||
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (!HardwareRenderer.RENDER_DIRTY_REGIONS) {
|
||||
if (dirty == null) {
|
||||
if (child.mLayerType != LAYER_TYPE_NONE) {
|
||||
mPrivateFlags |= INVALIDATED;
|
||||
mPrivateFlags &= ~DRAWING_CACHE_VALID;
|
||||
child.mLocalDirtyRect.setEmpty();
|
||||
}
|
||||
do {
|
||||
View view = null;
|
||||
if (parent instanceof View) {
|
||||
view = (View) parent;
|
||||
if (view.mLayerType != LAYER_TYPE_NONE) {
|
||||
view.mLocalDirtyRect.setEmpty();
|
||||
if (view.getParent() instanceof View) {
|
||||
final View grandParent = (View) view.getParent();
|
||||
grandParent.mPrivateFlags |= INVALIDATED;
|
||||
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
|
||||
}
|
||||
}
|
||||
if ((view.mPrivateFlags & DIRTY_MASK) != 0) {
|
||||
// already marked dirty - we're done
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawAnimation) {
|
||||
if (view != null) {
|
||||
view.mPrivateFlags |= DRAW_ANIMATION;
|
||||
} else if (parent instanceof ViewRootImpl) {
|
||||
((ViewRootImpl) parent).mIsAnimating = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof ViewRootImpl) {
|
||||
((ViewRootImpl) parent).invalidate();
|
||||
parent = null;
|
||||
} else if (view != null) {
|
||||
if ((view.mPrivateFlags & DRAWN) == DRAWN ||
|
||||
(view.mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) {
|
||||
view.mPrivateFlags &= ~DRAWING_CACHE_VALID;
|
||||
view.mPrivateFlags |= DIRTY;
|
||||
parent = view.mParent;
|
||||
} else {
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
} while (parent != null);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check whether the child that requests the invalidate is fully opaque
|
||||
// Views being animated or transformed are not considered opaque because we may
|
||||
// be invalidating their old position and need the parent to paint behind them.
|
||||
@@ -4025,12 +3972,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
||||
View view = null;
|
||||
if (parent instanceof View) {
|
||||
view = (View) parent;
|
||||
if (view.mLayerType != LAYER_TYPE_NONE &&
|
||||
view.getParent() instanceof View) {
|
||||
final View grandParent = (View) view.getParent();
|
||||
grandParent.mPrivateFlags |= INVALIDATED;
|
||||
grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawAnimation) {
|
||||
@@ -4103,6 +4044,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
||||
location[CHILD_TOP_INDEX] = top;
|
||||
|
||||
if (mLayerType != LAYER_TYPE_NONE) {
|
||||
mPrivateFlags |= INVALIDATED;
|
||||
mLocalDirtyRect.union(dirty);
|
||||
}
|
||||
|
||||
@@ -4121,6 +4063,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
||||
}
|
||||
|
||||
if (mLayerType != LAYER_TYPE_NONE) {
|
||||
mPrivateFlags |= INVALIDATED;
|
||||
mLocalDirtyRect.union(dirty);
|
||||
}
|
||||
|
||||
|
||||
@@ -675,5 +675,14 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="ViewLayerInvalidationActivity"
|
||||
android:label="_ViewLayerInvalidation">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
**
|
||||
** Copyright 2012, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/nestedStatus"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/invalidateStatus"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/container">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/textview"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/textviewa"/>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container1">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/textview1"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container2">
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container2a">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/textview2"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container3">
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container3a">
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/container3b">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is some text"
|
||||
android:id="@+id/textview3"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.test.hwui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ViewLayerInvalidationActivity extends Activity {
|
||||
|
||||
int currentColor = Color.WHITE;
|
||||
boolean nestedLayersOn = false;
|
||||
ArrayList<LinearLayout> linearLayouts = new ArrayList<LinearLayout>();
|
||||
ArrayList<LinearLayout> topLayouts = new ArrayList<LinearLayout>();
|
||||
ArrayList<TextView> textViews = new ArrayList<TextView>();
|
||||
LinearLayout container = null;
|
||||
boolean randomInvalidates = false;
|
||||
TextView nestedStatusTV, invalidateStatusTV;
|
||||
static final String NO_NESTING = "Nested Layer: NO ";
|
||||
static final String NESTING = "Nested Layers: YES ";
|
||||
static final String NO_INVALIDATING = "Random Invalidating: NO ";
|
||||
static final String INVALIDATING = "Random Invalidating: YES ";
|
||||
static final int TEXT_COLOR_INTERVAL = 400;
|
||||
static final int INVALIDATING_INTERVAL = 1000;
|
||||
static final int NESTING_INTERVAL = 2000;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.view_layer_invalidation);
|
||||
|
||||
container = (LinearLayout) findViewById(R.id.container);
|
||||
final LinearLayout container1 = (LinearLayout) findViewById(R.id.container1);
|
||||
final LinearLayout container2 = (LinearLayout) findViewById(R.id.container2);
|
||||
final LinearLayout container3 = (LinearLayout) findViewById(R.id.container3);
|
||||
nestedStatusTV = (TextView) findViewById(R.id.nestedStatus);
|
||||
invalidateStatusTV = (TextView) findViewById(R.id.invalidateStatus);
|
||||
final TextView tva = (TextView) findViewById(R.id.textviewa);
|
||||
|
||||
topLayouts.add(container1);
|
||||
topLayouts.add(container2);
|
||||
topLayouts.add(container3);
|
||||
|
||||
collectLinearLayouts(container);
|
||||
collectTextViews(container);
|
||||
|
||||
nestedStatusTV.setText(NO_NESTING);
|
||||
invalidateStatusTV.setText(NO_INVALIDATING);
|
||||
|
||||
tva.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
container1.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
container2.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
container3.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
|
||||
container.postDelayed(textColorSetter, TEXT_COLOR_INTERVAL);
|
||||
container.postDelayed(nestedLayerSetter, NESTING_INTERVAL);
|
||||
container.postDelayed(randomInvalidatesSetter, INVALIDATING_INTERVAL);
|
||||
}
|
||||
|
||||
private Runnable textColorSetter = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
currentColor = (currentColor == Color.WHITE) ? Color.RED : Color.WHITE;
|
||||
for (TextView tv : textViews) {
|
||||
tv.setTextColor(currentColor);
|
||||
}
|
||||
if (randomInvalidates) {
|
||||
randomInvalidator(container);
|
||||
}
|
||||
container.postDelayed(textColorSetter, TEXT_COLOR_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable randomInvalidatesSetter = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
randomInvalidates = !randomInvalidates;
|
||||
invalidateStatusTV.setText(randomInvalidates ? INVALIDATING : NO_INVALIDATING);
|
||||
container.postDelayed(randomInvalidatesSetter, INVALIDATING_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable nestedLayerSetter = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nestedLayersOn = !nestedLayersOn;
|
||||
nestedStatusTV.setText(nestedLayersOn ? NESTING : NO_NESTING);
|
||||
for (LinearLayout layout : linearLayouts) {
|
||||
layout.setLayerType(nestedLayersOn ?
|
||||
View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
|
||||
}
|
||||
if (!nestedLayersOn) {
|
||||
for (LinearLayout layout : topLayouts) {
|
||||
layout.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
}
|
||||
}
|
||||
container.postDelayed(nestedLayerSetter, NESTING_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Invalidates views based on random chance (50%). This is meant to test
|
||||
* invalidating several items in the hierarchy at the same time, which can cause artifacts
|
||||
* if our invalidation-propagation logic is not sound.
|
||||
*/
|
||||
private void randomInvalidator(ViewGroup parent) {
|
||||
for (int i = 0; i < parent.getChildCount(); ++i) {
|
||||
View child = parent.getChildAt(i);
|
||||
if (Math.random() < .5) {
|
||||
child.invalidate();
|
||||
}
|
||||
if (child instanceof ViewGroup) {
|
||||
randomInvalidator((ViewGroup) child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectLinearLayouts(View view) {
|
||||
if (!(view instanceof LinearLayout)) {
|
||||
return;
|
||||
}
|
||||
LinearLayout parent = (LinearLayout) view;
|
||||
linearLayouts.add(parent);
|
||||
for (int i = 0; i < parent.getChildCount(); ++i) {
|
||||
collectLinearLayouts(parent.getChildAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void collectTextViews(View view) {
|
||||
if (view instanceof TextView) {
|
||||
textViews.add((TextView) view);
|
||||
return;
|
||||
}
|
||||
if (!(view instanceof ViewGroup)) {
|
||||
return;
|
||||
}
|
||||
ViewGroup parent = (ViewGroup) view;
|
||||
for (int i = 0; i < parent.getChildCount(); ++i) {
|
||||
collectTextViews(parent.getChildAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user