Defer layer rendering to avoid stalls
Bug #7326824
When a layer is taken out of the cache and initialized it gets cleared
to prepare it for future rendering. This triggers the following sequence
of operations:
glBindFramebuffer(layer.fbo)
attach texture storage to FBO
glClear()
glBindFramebuffer(defaultFbo)
The clear forces a resolve on tilers which stalls the CPU for a little
while, thus producing jank during animations. This change moves the
clear to the next frame when we know we will have to execute a resolve
anyway.
Change-Id: Ic1939c25df20ed65a4c48dc81ee549b2cd8b6ec3
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index f2e7f66..3484d41 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -18,6 +18,8 @@
#include <ui/Rect.h>
+#include <private/hwui/DrawGlInfo.h>
+
#include "LayerCache.h"
#include "LayerRenderer.h"
#include "Matrix.h"
@@ -41,7 +43,8 @@
initViewport(width, height);
}
-int LayerRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) {
+status_t LayerRenderer::prepareDirty(float left, float top, float right, float bottom,
+ bool opaque) {
LAYER_RENDERER_LOGD("Rendering into layer, fbo = %d", mLayer->getFbo());
glBindFramebuffer(GL_FRAMEBUFFER, mLayer->getFbo());
@@ -63,6 +66,20 @@
return OpenGLRenderer::prepareDirty(dirty.left, dirty.top, dirty.right, dirty.bottom, opaque);
}
+status_t LayerRenderer::clear(float left, float top, float right, float bottom, bool opaque) {
+ if (mLayer->isDirty()) {
+ getCaches().disableScissor();
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ getCaches().resetScissor();
+ mLayer->setDirty(false);
+
+ return DrawGlInfo::kStatusDone;
+ }
+
+ return OpenGLRenderer::clear(left, top, right, bottom, opaque);
+}
+
void LayerRenderer::finish() {
OpenGLRenderer::finish();
@@ -201,6 +218,7 @@
layer->setAlpha(255, SkXfermode::kSrcOver_Mode);
layer->setBlend(!isOpaque);
layer->setColorFilter(NULL);
+ layer->setDirty(true);
layer->region.clear();
GLuint previousFbo;
@@ -229,9 +247,6 @@
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
layer->getTexture(), 0);
- caches.disableScissor();
- glClear(GL_COLOR_BUFFER_BIT);
-
glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
return layer;