diff options
author | Konstantin Lopyrev <klopyrev@google.com> | 2010-08-06 15:01:52 -0700 |
---|---|---|
committer | Konstantin Lopyrev <klopyrev@google.com> | 2010-08-06 15:41:33 -0700 |
commit | c6dc45700bf0c18708b0ad2f695ea85fadcbf131 (patch) | |
tree | 615e03b421bbf0ccdbdd7a03d0c2a4083233c2eb | |
parent | f9624764711f9806cd8a8a95c4a0613995bab04a (diff) | |
download | frameworks_base-c6dc45700bf0c18708b0ad2f695ea85fadcbf131.zip frameworks_base-c6dc45700bf0c18708b0ad2f695ea85fadcbf131.tar.gz frameworks_base-c6dc45700bf0c18708b0ad2f695ea85fadcbf131.tar.bz2 |
Make sure profiling is done only for views that are actually measured, laid out and drawn.
Change-Id: I88c66e882be2781d079c51b6580a19c4e359c5b1
-rw-r--r-- | core/java/android/view/View.java | 4 | ||||
-rw-r--r-- | core/java/android/view/ViewDebug.java | 118 |
2 files changed, 68 insertions, 54 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c3f81a2..8007710 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -1420,8 +1420,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility static final int MEASURED_DIMENSION_SET = 0x00000800; /** {@hide} */ static final int FORCE_LAYOUT = 0x00001000; - - private static final int LAYOUT_REQUIRED = 0x00002000; + /** {@hide} */ + static final int LAYOUT_REQUIRED = 0x00002000; private static final int PRESSED = 0x00004000; diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java index 5dd45f9..09939a6 100644 --- a/core/java/android/view/ViewDebug.java +++ b/core/java/android/view/ViewDebug.java @@ -934,65 +934,76 @@ public class ViewDebug { private static void profileViewAndChildren(final View view, BufferedWriter out) throws IOException { - final long durationMeasure = profileViewOperation(view, new ViewOperation<Void>() { - public Void[] pre() { - forceLayout(view); - return null; - } - - 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)); - } - } - } + profileViewAndChildren(view, out, true); + } - public void run(Void... data) { - view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec); - } + private static void profileViewAndChildren(final View view, BufferedWriter out, boolean root) + throws IOException { - public void post(Void... data) { - } - }); + long durationMeasure = + (root || (view.mPrivateFlags & View.MEASURED_DIMENSION_SET) != 0) ? profileViewOperation( + view, new ViewOperation<Void>() { + public Void[] pre() { + forceLayout(view); + return null; + } - final long durationLayout = profileViewOperation(view, new ViewOperation<Void>() { - public Void[] pre() { - return null; - } + 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)); + } + } + } - public void run(Void... data) { - view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom); - } + public void run(Void... data) { + view.measure(view.mOldWidthMeasureSpec, view.mOldHeightMeasureSpec); + } - public void post(Void... data) { - } - }); + public void post(Void... data) { + } + }) + : 0; + long durationLayout = + (root || (view.mPrivateFlags & View.LAYOUT_REQUIRED) != 0) ? profileViewOperation( + view, new ViewOperation<Void>() { + public Void[] pre() { + return null; + } - final long durationDraw = profileViewOperation(view, new ViewOperation<Object>() { - public Object[] pre() { - final DisplayMetrics metrics = 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(Void... data) { + view.layout(view.mLeft, view.mTop, view.mRight, view.mBottom); + } - public void run(Object... data) { - view.draw((Canvas) data[1]); - } + public void post(Void... data) { + } + }) : 0; + long durationDraw = + (root || (view.mPrivateFlags & View.DRAWN) != 0) ? profileViewOperation(view, + new ViewOperation<Object>() { + public Object[] pre() { + final DisplayMetrics metrics = + 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 post(Object... data) { - ((Bitmap) data[0]).recycle(); - } - }); + public void run(Object... data) { + view.draw((Canvas) data[1]); + } + public void post(Object... data) { + ((Bitmap) data[0]).recycle(); + } + }) : 0; out.write(String.valueOf(durationMeasure)); out.write(' '); out.write(String.valueOf(durationLayout)); @@ -1003,7 +1014,7 @@ public class ViewDebug { ViewGroup group = (ViewGroup) view; final int count = group.getChildCount(); 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 { - 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) { Log.w("View", "Could not complete the profiling of the view " + view); Thread.currentThread().interrupt(); |