Merge "Make sure profiling is done only for views that are actually measured, laid out and drawn." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
63cca69157
@@ -1420,8 +1420,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
|||||||
static final int MEASURED_DIMENSION_SET = 0x00000800;
|
static final int MEASURED_DIMENSION_SET = 0x00000800;
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
static final int FORCE_LAYOUT = 0x00001000;
|
static final int FORCE_LAYOUT = 0x00001000;
|
||||||
|
/** {@hide} */
|
||||||
private static final int LAYOUT_REQUIRED = 0x00002000;
|
static final int LAYOUT_REQUIRED = 0x00002000;
|
||||||
|
|
||||||
private static final int PRESSED = 0x00004000;
|
private static final int PRESSED = 0x00004000;
|
||||||
|
|
||||||
|
|||||||
@@ -934,65 +934,76 @@ public class ViewDebug {
|
|||||||
|
|
||||||
private static void profileViewAndChildren(final View view, BufferedWriter out)
|
private static void profileViewAndChildren(final View view, BufferedWriter out)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final long durationMeasure = profileViewOperation(view, new ViewOperation<Void>() {
|
profileViewAndChildren(view, out, true);
|
||||||
public Void[] pre() {
|
}
|
||||||
forceLayout(view);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void forceLayout(View view) {
|
private static void profileViewAndChildren(final View view, BufferedWriter out, boolean root)
|
||||||
view.forceLayout();
|
throws IOException {
|
||||||
if (view instanceof ViewGroup) {
|
|
||||||
ViewGroup group = (ViewGroup) view;
|
|
||||||
final int count = group.getChildCount();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
forceLayout(group.getChildAt(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(Void... data) {
|
long durationMeasure =
|
||||||
view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec);
|
(root || (view.mPrivateFlags & View.MEASURED_DIMENSION_SET) != 0) ? profileViewOperation(
|
||||||
}
|
view, new ViewOperation<Void>() {
|
||||||
|
public Void[] pre() {
|
||||||
|
forceLayout(view);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void post(Void... data) {
|
private void forceLayout(View view) {
|
||||||
}
|
view.forceLayout();
|
||||||
});
|
if (view instanceof ViewGroup) {
|
||||||
|
ViewGroup group = (ViewGroup) view;
|
||||||
|
final int count = group.getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
forceLayout(group.getChildAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final long durationLayout = profileViewOperation(view, new ViewOperation<Void>() {
|
public void run(Void... data) {
|
||||||
public Void[] pre() {
|
view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec);
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void run(Void... data) {
|
public void post(Void... data) {
|
||||||
view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom);
|
}
|
||||||
}
|
})
|
||||||
|
: 0;
|
||||||
|
long durationLayout =
|
||||||
|
(root || (view.mPrivateFlags & View.LAYOUT_REQUIRED) != 0) ? profileViewOperation(
|
||||||
|
view, new ViewOperation<Void>() {
|
||||||
|
public Void[] pre() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void post(Void... data) {
|
public void run(Void... data) {
|
||||||
}
|
view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom);
|
||||||
});
|
}
|
||||||
|
|
||||||
final long durationDraw = profileViewOperation(view, new ViewOperation<Object>() {
|
public void post(Void... data) {
|
||||||
public Object[] pre() {
|
}
|
||||||
final DisplayMetrics metrics = view.getResources().getDisplayMetrics();
|
}) : 0;
|
||||||
final Bitmap bitmap =
|
long durationDraw =
|
||||||
Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels,
|
(root || (view.mPrivateFlags & View.DRAWN) != 0) ? profileViewOperation(view,
|
||||||
Bitmap.Config.RGB_565);
|
new ViewOperation<Object>() {
|
||||||
final Canvas canvas = new Canvas(bitmap);
|
public Object[] pre() {
|
||||||
return new Object[] {
|
final DisplayMetrics metrics =
|
||||||
bitmap, canvas
|
view.getResources().getDisplayMetrics();
|
||||||
};
|
final Bitmap bitmap =
|
||||||
}
|
Bitmap.createBitmap(metrics.widthPixels,
|
||||||
|
metrics.heightPixels, Bitmap.Config.RGB_565);
|
||||||
|
final Canvas canvas = new Canvas(bitmap);
|
||||||
|
return new Object[] {
|
||||||
|
bitmap, canvas
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void run(Object... data) {
|
public void run(Object... data) {
|
||||||
view.draw((Canvas) data[1]);
|
view.draw((Canvas) data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void post(Object... data) {
|
|
||||||
((Bitmap) data[0]).recycle();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
public void post(Object... data) {
|
||||||
|
((Bitmap) data[0]).recycle();
|
||||||
|
}
|
||||||
|
}) : 0;
|
||||||
out.write(String.valueOf(durationMeasure));
|
out.write(String.valueOf(durationMeasure));
|
||||||
out.write(' ');
|
out.write(' ');
|
||||||
out.write(String.valueOf(durationLayout));
|
out.write(String.valueOf(durationLayout));
|
||||||
@@ -1003,7 +1014,7 @@ public class ViewDebug {
|
|||||||
ViewGroup group = (ViewGroup) view;
|
ViewGroup group = (ViewGroup) view;
|
||||||
final int count = group.getChildCount();
|
final int count = group.getChildCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
profileViewAndChildren(group.getChildAt(i), out);
|
profileViewAndChildren(group.getChildAt(i), out, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1033,7 +1044,10 @@ public class ViewDebug {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
latch.await(CAPTURE_TIMEOUT, TimeUnit.MILLISECONDS);
|
if (!latch.await(CAPTURE_TIMEOUT, TimeUnit.MILLISECONDS)) {
|
||||||
|
Log.w("View", "Could not complete the profiling of the view " + view);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.w("View", "Could not complete the profiling of the view " + view);
|
Log.w("View", "Could not complete the profiling of the view " + view);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|||||||
Reference in New Issue
Block a user