summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java
index 5b11c2b..ce66285 100644
--- a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java
+++ b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java
@@ -21,6 +21,8 @@ import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.util.Log;
+import com.android.ex.camera2.utils.SysTrace;
+
/**
* Manage the auto focus state machine for CameraDevice.
*
@@ -72,6 +74,10 @@ public class AutoFocusStateMachine {
private int mCurrentAfMode = AF_UNINITIALIZED;
private int mCurrentAfTrigger = AF_UNINITIALIZED;
+ private int mCurrentAfCookie = AF_UNINITIALIZED;
+ private String mCurrentAfTrace = "";
+ private int mLastAfCookie = 0;
+
public AutoFocusStateMachine(AutoFocusStateListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener should not be null");
@@ -146,9 +152,11 @@ public class AutoFocusStateMachine {
switch (afState) {
case CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED:
mListener.onAutoFocusSuccess(result, /*locked*/true);
+ endTraceAsync();
break;
case CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED:
mListener.onAutoFocusFail(result, /*locked*/true);
+ endTraceAsync();
break;
case CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED:
mListener.onAutoFocusSuccess(result, /*locked*/false);
@@ -195,6 +203,8 @@ public class AutoFocusStateMachine {
throw new IllegalStateException("AF mode was not enabled");
}
+ beginTraceAsync("AFSM_lockAutoFocus");
+
mCurrentAfTrigger = CaptureRequest.CONTROL_AF_TRIGGER_START;
repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode);
@@ -275,6 +285,8 @@ public class AutoFocusStateMachine {
CaptureRequest.Builder requestBuilder) {
if (VERBOSE_LOGGING) Log.v(TAG, "setActiveAutoFocus");
+ beginTraceAsync("AFSM_setActiveAutoFocus");
+
mCurrentAfMode = CaptureRequest.CONTROL_AF_MODE_AUTO;
repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode);
@@ -311,4 +323,27 @@ public class AutoFocusStateMachine {
repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode);
}
+
+ private synchronized void beginTraceAsync(String sectionName) {
+ if (mCurrentAfCookie != AF_UNINITIALIZED) {
+ // Terminate any currently active async sections before beginning another section
+ SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie);
+ }
+
+ mLastAfCookie++;
+ mCurrentAfCookie = mLastAfCookie;
+ mCurrentAfTrace = sectionName;
+
+ SysTrace.beginSectionAsync(sectionName, mCurrentAfCookie);
+ }
+
+ private synchronized void endTraceAsync() {
+ if (mCurrentAfCookie == AF_UNINITIALIZED) {
+ Log.w(TAG, "endTraceAsync - no current trace active");
+ return;
+ }
+
+ SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie);
+ mCurrentAfCookie = AF_UNINITIALIZED;
+ }
}