Skip to content

Commit bd17bd3

Browse files
author
Romain Guy
committed
Ensure we have a GL context before deleting View layers
Bug #7391098 The existing code was doing a make current to guarantee we have a current context. This can however fail when the surface is destroyed which could lead to GL calls without an EGL context, and therefore potential leaks. This change fixes the issue by using a technique found in HardwareRenderer.destroyHardwareResources(). If the surface is not available then we use a special 1x1 pbuffer as a way to get a valid context. Change-Id: I716d3799bf90120d793d76e90a83956837ecd491
1 parent 3a2d6aa commit bd17bd3

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

core/java/android/view/HardwareRenderer.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,30 +1525,6 @@ void setSurfaceTexture(HardwareLayer layer, SurfaceTexture surfaceTexture) {
15251525
((GLES20TextureLayer) layer).setSurfaceTexture(surfaceTexture);
15261526
}
15271527

1528-
@Override
1529-
void destroyLayers(View view) {
1530-
if (view != null && isEnabled() && checkCurrent() != SURFACE_STATE_ERROR) {
1531-
if (mCanvas != null) {
1532-
mCanvas.clearLayerUpdates();
1533-
}
1534-
destroyHardwareLayer(view);
1535-
GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_LAYERS);
1536-
}
1537-
}
1538-
1539-
private static void destroyHardwareLayer(View view) {
1540-
view.destroyLayer(true);
1541-
1542-
if (view instanceof ViewGroup) {
1543-
ViewGroup group = (ViewGroup) view;
1544-
1545-
int count = group.getChildCount();
1546-
for (int i = 0; i < count; i++) {
1547-
destroyHardwareLayer(group.getChildAt(i));
1548-
}
1549-
}
1550-
}
1551-
15521528
@Override
15531529
boolean safelyRun(Runnable action) {
15541530
boolean needsContext = true;
@@ -1573,6 +1549,35 @@ boolean safelyRun(Runnable action) {
15731549
return true;
15741550
}
15751551

1552+
@Override
1553+
void destroyLayers(final View view) {
1554+
if (view != null) {
1555+
safelyRun(new Runnable() {
1556+
@Override
1557+
public void run() {
1558+
if (mCanvas != null) {
1559+
mCanvas.clearLayerUpdates();
1560+
}
1561+
destroyHardwareLayer(view);
1562+
GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_LAYERS);
1563+
}
1564+
});
1565+
}
1566+
}
1567+
1568+
private static void destroyHardwareLayer(View view) {
1569+
view.destroyLayer(true);
1570+
1571+
if (view instanceof ViewGroup) {
1572+
ViewGroup group = (ViewGroup) view;
1573+
1574+
int count = group.getChildCount();
1575+
for (int i = 0; i < count; i++) {
1576+
destroyHardwareLayer(group.getChildAt(i));
1577+
}
1578+
}
1579+
}
1580+
15761581
@Override
15771582
void destroyHardwareResources(final View view) {
15781583
if (view != null) {

0 commit comments

Comments
 (0)