Skip to content

Commit 7910708

Browse files
XSJoJoAndroid (Google) Code Review
authored andcommitted
Merge "Add option to enable scrim SRC optimization" into lmp-dev
2 parents e2ff1a4 + 0e66439 commit 7910708

5 files changed

Lines changed: 55 additions & 29 deletions

File tree

packages/SystemUI/res/values/config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
<!-- Show camera affordance on Keyguard -->
8282
<bool name="config_keyguardShowCameraAffordance">true</bool>
8383

84+
<!-- Whether we should use SRC drawing mode when drawing the scrim behind. If this flag is set,
85+
we change the canvas opacity so libhwui doesn't call glClear on our surface, and then we
86+
draw the scrim with SRC to overwrite the whole buffer, which saves us a layer of overdraw.
87+
However, SRC performs poorly on some devices, where it is more efficient to
88+
glClear + SRC_OVER, in which case this flag should be disabled. -->
89+
<bool name="config_status_bar_scrim_behind_use_src">true</bool>
90+
8491
<!-- The length of the vibration when the notification pops open. -->
8592
<integer name="one_finger_pop_duration_ms">10</integer>
8693

packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ScrimView(Context context, AttributeSet attrs, int defStyleAttr, int defS
7070

7171
@Override
7272
protected void onDraw(Canvas canvas) {
73-
if (mDrawAsSrc || !mIsEmpty) {
73+
if (mDrawAsSrc || (!mIsEmpty && mViewAlpha > 0f)) {
7474
PorterDuff.Mode mode = mDrawAsSrc ? PorterDuff.Mode.SRC : PorterDuff.Mode.SRC_OVER;
7575
int color = mScrimColor;
7676
color = Color.argb((int) (Color.alpha(color) * mViewAlpha), Color.red(color),

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ public void run() {
430430
private boolean mVisible;
431431
private boolean mWaitingForKeyguardExit;
432432
private boolean mDozing;
433+
private boolean mScrimSrcModeEnabled;
433434

434435
private Interpolator mLinearOutSlowIn;
435436
private Interpolator mLinearInterpolator = new LinearInterpolator();
@@ -569,6 +570,8 @@ public void start() {
569570
mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
570571
.getDefaultDisplay();
571572
updateDisplaySize();
573+
mScrimSrcModeEnabled = mContext.getResources().getBoolean(
574+
R.bool.config_status_bar_scrim_behind_use_src);
572575
super.start(); // calls createAndAddWindows()
573576

574577
mMediaSessionManager
@@ -737,7 +740,7 @@ public void onClick(View v) {
737740

738741
ScrimView scrimBehind = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_behind);
739742
ScrimView scrimInFront = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_in_front);
740-
mScrimController = new ScrimController(scrimBehind, scrimInFront);
743+
mScrimController = new ScrimController(scrimBehind, scrimInFront, mScrimSrcModeEnabled);
741744
mScrimController.setBackDropView(mBackdrop);
742745
mStatusBarView.setScrimController(mScrimController);
743746

@@ -1870,7 +1873,9 @@ public void updateMediaMetaData(boolean metaDataChanged) {
18701873
if (mBackdropBack.getDrawable() != null) {
18711874
Drawable drawable = mBackdropBack.getDrawable();
18721875
mBackdropFront.setImageDrawable(drawable);
1873-
mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode);
1876+
if (mScrimSrcModeEnabled) {
1877+
mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode);
1878+
}
18741879
mBackdropFront.setAlpha(1f);
18751880
mBackdropFront.setVisibility(View.VISIBLE);
18761881
} else {
@@ -1885,7 +1890,9 @@ public void updateMediaMetaData(boolean metaDataChanged) {
18851890
} else {
18861891
mBackdropBack.setImageBitmap(artworkBitmap);
18871892
}
1888-
mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode);
1893+
if (mScrimSrcModeEnabled) {
1894+
mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode);
1895+
}
18891896

18901897
if (mBackdropFront.getVisibility() == View.VISIBLE) {
18911898
if (DEBUG_MEDIA) {
@@ -2134,6 +2141,10 @@ public String getCurrentMediaNotificationKey() {
21342141
return mMediaNotificationKey;
21352142
}
21362143

2144+
public boolean isScrimSrcModeEnabled() {
2145+
return mScrimSrcModeEnabled;
2146+
}
2147+
21372148
/**
21382149
* All changes to the status bar and notifications funnel through here and are batched.
21392150
*/

packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
7474
private final Interpolator mInterpolator = new DecelerateInterpolator();
7575
private final Interpolator mLinearOutSlowInInterpolator;
7676
private BackDropView mBackDropView;
77+
private boolean mScrimSrcEnabled;
7778

78-
public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront) {
79+
public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, boolean scrimSrcEnabled) {
7980
mScrimBehind = scrimBehind;
8081
mScrimInFront = scrimInFront;
8182
final Context context = scrimBehind.getContext();
8283
mUnlockMethodCache = UnlockMethodCache.getInstance(context);
8384
mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
8485
android.R.interpolator.linear_out_slow_in);
8586
mDozeParameters = new DozeParameters(context);
87+
mScrimSrcEnabled = scrimSrcEnabled;
8688
}
8789

8890
public void setKeyguardShowing(boolean showing) {
@@ -384,7 +386,7 @@ public void run() {
384386
}
385387

386388
private void updateScrimBehindDrawingMode() {
387-
boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE;
389+
boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE && mScrimSrcEnabled;
388390
mScrimBehind.setDrawAsSrc(asSrc);
389391
}
390392
}

packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class StatusBarWindowView extends FrameLayout {
5555
public StatusBarWindowView(Context context, AttributeSet attrs) {
5656
super(context, attrs);
5757
setMotionEventSplittingEnabled(false);
58-
setWillNotDraw(false);
5958
mTransparentSrcPaint.setColor(0);
6059
mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
6160
}
@@ -105,11 +104,16 @@ protected void onAttachedToWindow () {
105104
// We need to ensure that our window doesn't suffer from overdraw which would normally
106105
// occur if our window is translucent. Since we are drawing the whole window anyway with
107106
// the scrim, we don't need the window to be cleared in the beginning.
108-
IBinder windowToken = getWindowToken();
109-
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
110-
lp.token = windowToken;
111-
setLayoutParams(lp);
112-
WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
107+
if (mService.isScrimSrcModeEnabled()) {
108+
IBinder windowToken = getWindowToken();
109+
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
110+
lp.token = windowToken;
111+
setLayoutParams(lp);
112+
WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
113+
setWillNotDraw(false);
114+
} else {
115+
setWillNotDraw(!DEBUG);
116+
}
113117
}
114118

115119
@Override
@@ -199,23 +203,25 @@ public boolean onTouchEvent(MotionEvent ev) {
199203
@Override
200204
public void onDraw(Canvas canvas) {
201205
super.onDraw(canvas);
202-
// We need to ensure that our window is always drawn fully even when we have paddings,
203-
// since we simulate it to be opaque.
204-
int paddedBottom = getHeight() - getPaddingBottom();
205-
int paddedRight = getWidth() - getPaddingRight();
206-
if (getPaddingTop() != 0) {
207-
canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
208-
}
209-
if (getPaddingBottom() != 0) {
210-
canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
211-
}
212-
if (getPaddingLeft() != 0) {
213-
canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
214-
mTransparentSrcPaint);
215-
}
216-
if (getPaddingRight() != 0) {
217-
canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
218-
mTransparentSrcPaint);
206+
if (mService.isScrimSrcModeEnabled()) {
207+
// We need to ensure that our window is always drawn fully even when we have paddings,
208+
// since we simulate it to be opaque.
209+
int paddedBottom = getHeight() - getPaddingBottom();
210+
int paddedRight = getWidth() - getPaddingRight();
211+
if (getPaddingTop() != 0) {
212+
canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
213+
}
214+
if (getPaddingBottom() != 0) {
215+
canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
216+
}
217+
if (getPaddingLeft() != 0) {
218+
canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
219+
mTransparentSrcPaint);
220+
}
221+
if (getPaddingRight() != 0) {
222+
canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
223+
mTransparentSrcPaint);
224+
}
219225
}
220226
if (DEBUG) {
221227
Paint pt = new Paint();

0 commit comments

Comments
 (0)