1818
1919#include < ui/Rect.h>
2020
21+ #include < private/hwui/DrawGlInfo.h>
22+
2123#include " LayerCache.h"
2224#include " LayerRenderer.h"
2325#include " Matrix.h"
@@ -41,7 +43,8 @@ void LayerRenderer::setViewport(int width, int height) {
4143 initViewport (width, height);
4244}
4345
44- int LayerRenderer::prepareDirty (float left, float top, float right, float bottom, bool opaque) {
46+ status_t LayerRenderer::prepareDirty (float left, float top, float right, float bottom,
47+ bool opaque) {
4548 LAYER_RENDERER_LOGD (" Rendering into layer, fbo = %d" , mLayer ->getFbo ());
4649
4750 glBindFramebuffer (GL_FRAMEBUFFER, mLayer ->getFbo ());
@@ -63,6 +66,20 @@ int LayerRenderer::prepareDirty(float left, float top, float right, float bottom
6366 return OpenGLRenderer::prepareDirty (dirty.left , dirty.top , dirty.right , dirty.bottom , opaque);
6467}
6568
69+ status_t LayerRenderer::clear (float left, float top, float right, float bottom, bool opaque) {
70+ if (mLayer ->isDirty ()) {
71+ getCaches ().disableScissor ();
72+ glClear (GL_COLOR_BUFFER_BIT);
73+
74+ getCaches ().resetScissor ();
75+ mLayer ->setDirty (false );
76+
77+ return DrawGlInfo::kStatusDone ;
78+ }
79+
80+ return OpenGLRenderer::clear (left, top, right, bottom, opaque);
81+ }
82+
6683void LayerRenderer::finish () {
6784 OpenGLRenderer::finish ();
6885
@@ -201,6 +218,7 @@ Layer* LayerRenderer::createLayer(uint32_t width, uint32_t height, bool isOpaque
201218 layer->setAlpha (255 , SkXfermode::kSrcOver_Mode );
202219 layer->setBlend (!isOpaque);
203220 layer->setColorFilter (NULL );
221+ layer->setDirty (true );
204222 layer->region .clear ();
205223
206224 GLuint previousFbo;
@@ -229,9 +247,6 @@ Layer* LayerRenderer::createLayer(uint32_t width, uint32_t height, bool isOpaque
229247 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
230248 layer->getTexture (), 0 );
231249
232- caches.disableScissor ();
233- glClear (GL_COLOR_BUFFER_BIT);
234-
235250 glBindFramebuffer (GL_FRAMEBUFFER, previousFbo);
236251
237252 return layer;
0 commit comments