diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/Trace.java | 56 | ||||
| -rw-r--r-- | core/java/android/view/Surface.java | 8 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 24 |
3 files changed, 70 insertions, 18 deletions
diff --git a/core/java/android/os/Trace.java b/core/java/android/os/Trace.java index 59d0f7a..ed51818 100644 --- a/core/java/android/os/Trace.java +++ b/core/java/android/os/Trace.java @@ -16,6 +16,8 @@ package android.os; +import android.util.Log; + /** * Writes trace events to the kernel trace buffer. These trace events can be * collected using the "atrace" program for offline analysis. @@ -27,6 +29,8 @@ package android.os; * @hide */ public final class Trace { + private static final String TAG = "Trace"; + // These tags must be kept in sync with frameworks/native/include/utils/Trace.h. public static final long TRACE_TAG_NEVER = 0; public static final long TRACE_TAG_ALWAYS = 1L << 0; @@ -49,7 +53,11 @@ public final class Trace { public static final String PROPERTY_TRACE_TAG_ENABLEFLAGS = "debug.atrace.tags.enableflags"; - private static long sEnabledTags = nativeGetEnabledTags(); + // This works as a "not ready" flag because TRACE_TAG_ALWAYS is always set. + private static final long TRACE_FLAGS_NOT_READY = 0; + + // Must be volatile to avoid word tearing. + private static volatile long sEnabledTags = TRACE_FLAGS_NOT_READY; private static native long nativeGetEnabledTags(); private static native void nativeTraceCounter(long tag, String name, int value); @@ -57,9 +65,17 @@ public final class Trace { private static native void nativeTraceEnd(long tag); static { + // We configure two separate change callbacks, one in Trace.cpp and one here. The + // native callback reads the tags from the system property, and this callback + // reads the value that the native code retrieved. It's essential that the native + // callback executes first. + // + // The system provides ordering through a priority level. Callbacks made through + // SystemProperties.addChangeCallback currently have a negative priority, while + // our native code is using a priority of zero. SystemProperties.addChangeCallback(new Runnable() { @Override public void run() { - sEnabledTags = nativeGetEnabledTags(); + cacheEnabledTags(); } }); } @@ -68,13 +84,41 @@ public final class Trace { } /** + * Caches a copy of the enabled-tag bits. The "master" copy is held by the native code, + * and comes from the PROPERTY_TRACE_TAG_ENABLEFLAGS property. + * <p> + * If the native code hasn't yet read the property, we will cause it to do one-time + * initialization. We don't want to do this during class init, because this class is + * preloaded, so all apps would be stuck with whatever the zygote saw. (The zygote + * doesn't see the system-property update broadcasts.) + * <p> + * We want to defer initialization until the first use by an app, post-zygote. + * <p> + * We're okay if multiple threads call here simultaneously -- the native state is + * synchronized, and sEnabledTags is volatile (prevents word tearing). + */ + private static long cacheEnabledTags() { + long tags = nativeGetEnabledTags(); + if (tags == TRACE_FLAGS_NOT_READY) { + Log.w(TAG, "Unexpected value from nativeGetEnabledTags: " + tags); + // keep going + } + sEnabledTags = tags; + return tags; + } + + /** * Returns true if a trace tag is enabled. * * @param traceTag The trace tag to check. * @return True if the trace tag is valid. */ public static boolean isTagEnabled(long traceTag) { - return (sEnabledTags & traceTag) != 0; + long tags = sEnabledTags; + if (tags == TRACE_FLAGS_NOT_READY) { + tags = cacheEnabledTags(); + } + return (tags & traceTag) != 0; } /** @@ -85,7 +129,7 @@ public final class Trace { * @param counterValue The counter value. */ public static void traceCounter(long traceTag, String counterName, int counterValue) { - if ((sEnabledTags & traceTag) != 0) { + if (isTagEnabled(traceTag)) { nativeTraceCounter(traceTag, counterName, counterValue); } } @@ -98,7 +142,7 @@ public final class Trace { * @param methodName The method name to appear in the trace. */ public static void traceBegin(long traceTag, String methodName) { - if ((sEnabledTags & traceTag) != 0) { + if (isTagEnabled(traceTag)) { nativeTraceBegin(traceTag, methodName); } } @@ -110,7 +154,7 @@ public final class Trace { * @param traceTag The trace tag. */ public static void traceEnd(long traceTag) { - if ((sEnabledTags & traceTag) != 0) { + if (isTagEnabled(traceTag)) { nativeTraceEnd(traceTag); } } diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 183b012..550a740 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -758,6 +758,7 @@ public class Surface implements Parcelable { public float density; public float xDpi; public float yDpi; + public boolean secure; public PhysicalDisplayInfo() { } @@ -778,7 +779,8 @@ public class Surface implements Parcelable { && refreshRate == other.refreshRate && density == other.density && xDpi == other.xDpi - && yDpi == other.yDpi; + && yDpi == other.yDpi + && secure == other.secure; } @Override @@ -793,13 +795,15 @@ public class Surface implements Parcelable { density = other.density; xDpi = other.xDpi; yDpi = other.yDpi; + secure = other.secure; } // For debugging purposes @Override public String toString() { return "PhysicalDisplayInfo{" + width + " x " + height + ", " + refreshRate + " fps, " - + "density " + density + ", " + xDpi + " x " + yDpi + " dpi}"; + + "density " + density + ", " + xDpi + " x " + yDpi + " dpi, secure " + secure + + "}"; } } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index aa54a29..a3360bc 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -29,14 +29,12 @@ import android.content.res.CompatibilityInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Point; import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.Rect; -import android.graphics.RectF; import android.graphics.Region; import android.graphics.drawable.Drawable; import android.media.AudioManager; @@ -859,7 +857,7 @@ public final class ViewRootImpl implements ViewParent, if (dirty == null) { invalidate(); return null; - } else if (dirty.isEmpty()) { + } else if (dirty.isEmpty() && !mIsAnimating) { return null; } @@ -888,14 +886,14 @@ public final class ViewRootImpl implements ViewParent, // Intersect with the bounds of the window to skip // updates that lie outside of the visible region final float appScale = mAttachInfo.mApplicationScale; - if (localDirty.intersect(0, 0, - (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f))) { - if (!mWillDrawSoon) { - scheduleTraversals(); - } - } else { + final boolean intersected = localDirty.intersect(0, 0, + (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); + if (!intersected) { localDirty.setEmpty(); } + if (!mWillDrawSoon && (intersected || mIsAnimating)) { + scheduleTraversals(); + } return null; } @@ -1438,7 +1436,13 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateCanvas(layerCanvas); } - mView.draw(layerCanvas); + DisplayList displayList = mView.mDisplayList; + if (displayList != null) { + layerCanvas.drawDisplayList(displayList, null, + DisplayList.FLAG_CLIP_CHILDREN); + } else { + mView.draw(layerCanvas); + } drawAccessibilityFocusedDrawableIfNeeded(layerCanvas); |
