Merge "Offload Luma Sampling IPC to background thread" into sc-v2-dev

This commit is contained in:
Lucas Dupin
2021-07-27 17:26:16 +00:00
committed by Android (Google) Code Review
3 changed files with 20 additions and 7 deletions

View File

@@ -98,6 +98,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
public class NavigationBarView extends FrameLayout implements
@@ -354,6 +355,7 @@ public class NavigationBarView extends FrameLayout implements
mEdgeBackGestureHandler = Dependency.get(EdgeBackGestureHandler.Factory.class)
.create(mContext);
mEdgeBackGestureHandler.setStateChangeCallback(this::updateStates);
Executor backgroundExecutor = Dependency.get(Dependency.BACKGROUND_EXECUTOR);
mRegionSamplingHelper = new RegionSamplingHelper(this,
new RegionSamplingHelper.SamplingCallback() {
@Override
@@ -376,7 +378,7 @@ public class NavigationBarView extends FrameLayout implements
public boolean isSamplingEnabled() {
return isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode);
}
});
}, backgroundExecutor);
mNavBarOverlayController = Dependency.get(NavigationBarOverlayController.class);
if (mNavBarOverlayController.isNavigationBarOverlayEnabled()) {

View File

@@ -58,6 +58,7 @@ import com.android.systemui.plugins.NavigationEdgeBackPlugin;
import com.android.systemui.statusbar.VibratorHelper;
import java.io.PrintWriter;
import java.util.concurrent.Executor;
public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPlugin {
@@ -349,6 +350,7 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
.getDimension(R.dimen.navigation_edge_action_drag_threshold);
setVisibility(GONE);
Executor backgroundExecutor = Dependency.get(Dependency.BACKGROUND_EXECUTOR);
boolean isPrimaryDisplay = mContext.getDisplayId() == DEFAULT_DISPLAY;
mRegionSamplingHelper = new RegionSamplingHelper(this,
new RegionSamplingHelper.SamplingCallback() {
@@ -366,7 +368,7 @@ public class NavigationBarEdgePanel extends View implements NavigationEdgeBackPl
public boolean isSamplingEnabled() {
return isPrimaryDisplay;
}
});
}, backgroundExecutor);
mRegionSamplingHelper.setWindowVisible(true);
mShowProtection = !isPrimaryDisplay;
}

View File

@@ -30,6 +30,7 @@ import android.view.ViewTreeObserver;
import com.android.systemui.R;
import java.io.PrintWriter;
import java.util.concurrent.Executor;
/**
* A helper class to sample regions on the screen and inspect its luminosity.
@@ -52,6 +53,7 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
*/
private final Rect mRegisteredSamplingBounds = new Rect();
private final SamplingCallback mCallback;
private final Executor mBackgroundExecutor;
private boolean mSamplingEnabled = false;
private boolean mSamplingListenerRegistered = false;
@@ -82,7 +84,9 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
}
};
public RegionSamplingHelper(View sampledView, SamplingCallback samplingCallback) {
public RegionSamplingHelper(View sampledView, SamplingCallback samplingCallback,
Executor backgroundExecutor) {
mBackgroundExecutor = backgroundExecutor;
mSamplingListener = new CompositionSamplingListener(
sampledView.getContext().getMainExecutor()) {
@Override
@@ -183,10 +187,13 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
// We only want to reregister if something actually changed
unregisterSamplingListener();
mSamplingListenerRegistered = true;
CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
stopLayerControl, mSamplingRequestBounds);
SurfaceControl registeredStopLayer = stopLayerControl;
mBackgroundExecutor.execute(() -> {
CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
registeredStopLayer, mSamplingRequestBounds);
});
mRegisteredSamplingBounds.set(mSamplingRequestBounds);
mRegisteredStopLayer = stopLayerControl;
mRegisteredStopLayer = registeredStopLayer;
}
mFirstSamplingAfterStart = false;
} else {
@@ -199,7 +206,9 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
mSamplingListenerRegistered = false;
mRegisteredStopLayer = null;
mRegisteredSamplingBounds.setEmpty();
CompositionSamplingListener.unregister(mSamplingListener);
mBackgroundExecutor.execute(() -> {
CompositionSamplingListener.unregister(mSamplingListener);
});
}
}