Merge "Return early when we cannot allocate a hardware layer Bug #5462308"
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 61b13d5..a2f9b36 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -10114,8 +10114,20 @@
mLocalDirtyRect.setEmpty();
}
+ // The layer is not valid if the underlying GPU resources cannot be allocated
+ if (!mHardwareLayer.isValid()) {
+ return null;
+ }
+
HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas;
final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas);
+
+ // Make sure all the GPU resources have been properly allocated
+ if (canvas == null) {
+ mHardwareLayer.end(currentCanvas);
+ return null;
+ }
+
mAttachInfo.mHardwareCanvas = canvas;
try {
canvas.setViewport(width, height);
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index dfcc5ea..e38b479 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -216,7 +216,8 @@
layer->allocateTexture(GL_RGBA, GL_UNSIGNED_BYTE);
if (glGetError() != GL_NO_ERROR) {
- LOGD("Could not allocate texture");
+ LOGD("Could not allocate texture for layer (fbo=%d %dx%d)",
+ fbo, width, height);
glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
Caches::getInstance().fboCache.put(fbo);