Skip to content

Commit 40e0383

Browse files
committed
Fix issue #5384631: hw windows not resizing correctly
When the SystemUi becomes visible, the activity window resizes. The hardware renderer was not begin resized to suit, so it was drawing to a surface larger than that of the activity window, and some of the rendering (like the action bar) appeared off the screen. The fix is to keep track of the surface size in HardwareRenderer and to recreate the surface when the size changes. This change also removes the BUFFER_CHANGE flag from WindowManager.LayoutParams. The only reason the flag existed was to trigger a hardware surface recreation, but checking the old/new size is a more direct way of handling this. Change-Id: I9d6bf6385794886d1d93c60609c170864cdcdfab
1 parent 11a6705 commit 40e0383

3 files changed

Lines changed: 48 additions & 21 deletions

File tree

core/java/android/view/HardwareRenderer.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public static boolean isAvailable() {
183183
*/
184184
abstract void setup(int width, int height);
185185

186+
/**
187+
* Gets the current width of the surface. This is the width that the surface
188+
* was last set to in a call to {@link #setup(int, int)}.
189+
*
190+
* @return the current width of the surface
191+
*/
192+
abstract int getWidth();
193+
194+
/**
195+
* Gets the current height of the surface. This is the height that the surface
196+
* was last set to in a call to {@link #setup(int, int)}.
197+
*
198+
* @return the current width of the surface
199+
*/
200+
abstract int getHeight();
201+
186202
/**
187203
* Interface used to receive callbacks whenever a view is drawn by
188204
* a hardware renderer instance.
@@ -362,6 +378,7 @@ static abstract class GlRenderer extends HardwareRenderer {
362378
static EGLDisplay sEglDisplay;
363379
static EGLConfig sEglConfig;
364380
static final Object[] sEglLock = new Object[0];
381+
int mWidth = -1, mHeight = -1;
365382

366383
static final ThreadLocal<EGLContext> sEglContextStorage = new ThreadLocal<EGLContext>();
367384

@@ -714,9 +731,21 @@ boolean validate() {
714731
void setup(int width, int height) {
715732
if (validate()) {
716733
mCanvas.setViewport(width, height);
734+
mWidth = width;
735+
mHeight = height;
717736
}
718737
}
719738

739+
@Override
740+
int getWidth() {
741+
return mWidth;
742+
}
743+
744+
@Override
745+
int getHeight() {
746+
return mHeight;
747+
}
748+
720749
boolean canDraw() {
721750
return mGl != null && mCanvas != null;
722751
}

core/java/android/view/ViewRootImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,6 @@ private void performTraversals() {
860860
CompatibilityInfo compatibilityInfo = mCompatibilityInfo.get();
861861
if (compatibilityInfo.supportsScreen() == mLastInCompatMode) {
862862
params = lp;
863-
windowAttributesChanges |= WindowManager.LayoutParams.BUFFER_CHANGED;
864863
fullRedrawNeeded = true;
865864
mLayoutRequested = true;
866865
if (mLastInCompatMode) {
@@ -1078,7 +1077,6 @@ private void performTraversals() {
10781077
~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
10791078
resizeMode;
10801079
params = lp;
1081-
windowAttributesChanges |= WindowManager.LayoutParams.BUFFER_CHANGED;
10821080
}
10831081
}
10841082
}
@@ -1375,13 +1373,15 @@ private void performTraversals() {
13751373
}
13761374
}
13771375

1378-
if (hwInitialized || ((windowShouldResize || (params != null &&
1379-
(windowAttributesChanges & WindowManager.LayoutParams.BUFFER_CHANGED) != 0)) &&
1380-
mAttachInfo.mHardwareRenderer != null &&
1381-
mAttachInfo.mHardwareRenderer.isEnabled())) {
1382-
mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight);
1383-
if (!hwInitialized && mAttachInfo.mHardwareRenderer.isEnabled()) {
1384-
mAttachInfo.mHardwareRenderer.invalidate(mHolder);
1376+
if (mAttachInfo.mHardwareRenderer != null &&
1377+
mAttachInfo.mHardwareRenderer.isEnabled()) {
1378+
if (hwInitialized || windowShouldResize ||
1379+
mWidth != mAttachInfo.mHardwareRenderer.getWidth() ||
1380+
mHeight != mAttachInfo.mHardwareRenderer.getHeight()) {
1381+
mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight);
1382+
if (!hwInitialized) {
1383+
mAttachInfo.mHardwareRenderer.invalidate(mHolder);
1384+
}
13851385
}
13861386
}
13871387

core/java/android/view/WindowManager.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,6 @@ public LayoutParams(Parcel in) {
12601260
/** {@hide} */
12611261
public static final int PRIVATE_FLAGS_CHANGED = 1<<16;
12621262
/** {@hide} */
1263-
public static final int BUFFER_CHANGED = 1<<17;
1264-
/** {@hide} */
12651263
public static final int EVERYTHING_CHANGED = 0xffffffff;
12661264

12671265
// internal buffer to backup/restore parameters under compatibility mode.
@@ -1272,11 +1270,11 @@ public final int copyFrom(LayoutParams o) {
12721270

12731271
if (width != o.width) {
12741272
width = o.width;
1275-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1273+
changes |= LAYOUT_CHANGED;
12761274
}
12771275
if (height != o.height) {
12781276
height = o.height;
1279-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1277+
changes |= LAYOUT_CHANGED;
12801278
}
12811279
if (x != o.x) {
12821280
x = o.x;
@@ -1288,27 +1286,27 @@ public final int copyFrom(LayoutParams o) {
12881286
}
12891287
if (horizontalWeight != o.horizontalWeight) {
12901288
horizontalWeight = o.horizontalWeight;
1291-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1289+
changes |= LAYOUT_CHANGED;
12921290
}
12931291
if (verticalWeight != o.verticalWeight) {
12941292
verticalWeight = o.verticalWeight;
1295-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1293+
changes |= LAYOUT_CHANGED;
12961294
}
12971295
if (horizontalMargin != o.horizontalMargin) {
12981296
horizontalMargin = o.horizontalMargin;
1299-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1297+
changes |= LAYOUT_CHANGED;
13001298
}
13011299
if (verticalMargin != o.verticalMargin) {
13021300
verticalMargin = o.verticalMargin;
1303-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1301+
changes |= LAYOUT_CHANGED;
13041302
}
13051303
if (type != o.type) {
13061304
type = o.type;
13071305
changes |= TYPE_CHANGED;
13081306
}
13091307
if (flags != o.flags) {
13101308
flags = o.flags;
1311-
changes |= FLAGS_CHANGED | BUFFER_CHANGED;
1309+
changes |= FLAGS_CHANGED;
13121310
}
13131311
if (privateFlags != o.privateFlags) {
13141312
privateFlags = o.privateFlags;
@@ -1320,11 +1318,11 @@ public final int copyFrom(LayoutParams o) {
13201318
}
13211319
if (gravity != o.gravity) {
13221320
gravity = o.gravity;
1323-
changes |= LAYOUT_CHANGED | BUFFER_CHANGED;
1321+
changes |= LAYOUT_CHANGED;
13241322
}
13251323
if (format != o.format) {
13261324
format = o.format;
1327-
changes |= FORMAT_CHANGED | BUFFER_CHANGED;
1325+
changes |= FORMAT_CHANGED;
13281326
}
13291327
if (windowAnimations != o.windowAnimations) {
13301328
windowAnimations = o.windowAnimations;
@@ -1363,7 +1361,7 @@ public final int copyFrom(LayoutParams o) {
13631361

13641362
if (screenOrientation != o.screenOrientation) {
13651363
screenOrientation = o.screenOrientation;
1366-
changes |= SCREEN_ORIENTATION_CHANGED | BUFFER_CHANGED;
1364+
changes |= SCREEN_ORIENTATION_CHANGED;
13671365
}
13681366

13691367
if (systemUiVisibility != o.systemUiVisibility

0 commit comments

Comments
 (0)