fix transition from full overlays to fb
we need to clear the whole framebuffer in that situation because
we can't trust the content of the FB when partial (fb preserving)
updates are used.
Bug: 5318492
Change-Id: I3f0e01b0fb665a34e44d88ad9f0f54a5d990060b
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 1703448..0ef03bb 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -876,24 +876,21 @@
}
}
- Region expandDirty = setupHardwareComposer(mDirtyRegion);
- mDirtyRegion.orSelf(expandDirty);
- mSwapRegion.orSelf(mDirtyRegion);
+ setupHardwareComposer(mDirtyRegion);
composeSurfaces(mDirtyRegion);
- // clear the dirty regions
+ // update the swap region and clear the dirty region
+ mSwapRegion.orSelf(mDirtyRegion);
mDirtyRegion.clear();
}
-Region SurfaceFlinger::setupHardwareComposer(const Region& dirty)
+void SurfaceFlinger::setupHardwareComposer(Region& dirtyInOut)
{
- Region dirtyOut(dirty);
-
const DisplayHardware& hw(graphicPlane(0).displayHardware());
HWComposer& hwc(hw.getHwComposer());
hwc_layer_t* const cur(hwc.getLayers());
if (!cur) {
- return dirtyOut;
+ return;
}
const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
@@ -916,53 +913,62 @@
const sp<LayerBase>& layer(layers[i]);
layer->setPerFrameData(&cur[i]);
}
+ const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER);
status_t err = hwc.prepare();
LOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
if (err == NO_ERROR) {
+ // what's happening here is tricky.
+ // we want to clear all the layers with the CLEAR_FB flags
+ // that are opaque.
+ // however, since some GPU are efficient at preserving
+ // the backbuffer, we want to take advantage of that so we do the
+ // clear only in the dirty region (other areas will be preserved
+ // on those GPUs).
+ // NOTE: on non backbuffer preserving GPU, the dirty region
+ // has already been expanded as needed, so the code is correct
+ // there too.
+ //
+ // However, the content of the framebuffer cannot be trusted when
+ // we switch to/from FB/OVERLAY, in which case we need to
+ // expand the dirty region to those areas too.
+ //
+ // Note also that there is a special case when switching from
+ // "no layers in FB" to "some layers in FB", where we need to redraw
+ // the entire FB, since some areas might contain uninitialized
+ // data.
+ //
+ // Also we want to make sure to not clear areas that belong to
+ // layers above that won't redraw (we would just erasing them),
+ // that is, we can't erase anything outside the dirty region.
+
Region transparent;
- for (size_t i=0 ; i<count ; i++) {
- // what's happening here is tricky.
- // we want to clear all the layers with the CLEAR_FB flags
- // that are opaque.
- // however, since some GPU are efficient at preserving
- // the backbuffer, we want to take advantage of that so we do the
- // clear only in the dirty region (other areas will be preserved
- // on those GPUs).
- // NOTE: on non backbuffer preserving GPU, the dirty region
- // has already been expanded as needed, so the code is correct
- // there too.
- // However, the content of the framebuffer cannot be trusted when
- // we switch to/from FB/OVERLAY, in which case we need to
- // expand the dirty region to those areas too.
- //
- // Also we want to make sure to not clear areas that belong to
- // layers above that won't redraw (we would just erasing them),
- // that is, we can't erase anything outside the dirty region.
- const sp<LayerBase>& layer(layers[i]);
- if ((cur[i].hints & HWC_HINT_CLEAR_FB) && layer->isOpaque()) {
- transparent.orSelf(layer->visibleRegionScreen);
+ if (!fbLayerCount && hwc.getLayerCount(HWC_FRAMEBUFFER)) {
+ transparent.set(hw.getBounds());
+ dirtyInOut = transparent;
+ } else {
+ for (size_t i=0 ; i<count ; i++) {
+ const sp<LayerBase>& layer(layers[i]);
+ if ((cur[i].hints & HWC_HINT_CLEAR_FB) && layer->isOpaque()) {
+ transparent.orSelf(layer->visibleRegionScreen);
+ }
+ bool isOverlay = (cur[i].compositionType != HWC_FRAMEBUFFER);
+ if (isOverlay != layer->isOverlay()) {
+ // we transitioned to/from overlay, so add this layer
+ // to the dirty region so the framebuffer can be either
+ // cleared or redrawn.
+ dirtyInOut.orSelf(layer->visibleRegionScreen);
+ }
+ layer->setOverlay(isOverlay);
}
-
- bool isOverlay = (cur[i].compositionType != HWC_FRAMEBUFFER) &&
- !(cur[i].flags & HWC_SKIP_LAYER);
-
- if (isOverlay != layer->isOverlay()) {
- // we transitioned to/from overlay, so add this layer
- // to the dirty region so the framebuffer can be either
- // cleared or redrawn.
- dirtyOut.orSelf(layer->visibleRegionScreen);
- }
- layer->setOverlay(isOverlay);
+ // don't erase stuff outside the dirty region
+ transparent.andSelf(dirtyInOut);
}
-
/*
* clear the area of the FB that need to be transparent
*/
- // don't erase stuff outside the dirty region
- transparent.andSelf(dirtyOut);
if (!transparent.isEmpty()) {
glClearColor(0,0,0,0);
Region::const_iterator it = transparent.begin();
@@ -976,7 +982,6 @@
}
}
}
- return dirtyOut;
}
void SurfaceFlinger::composeSurfaces(const Region& dirty)
@@ -997,8 +1002,7 @@
const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
size_t count = layers.size();
for (size_t i=0 ; i<count ; i++) {
- if (cur && (cur[i].compositionType != HWC_FRAMEBUFFER) &&
- !(cur[i].flags & HWC_SKIP_LAYER)) {
+ if (cur && (cur[i].compositionType != HWC_FRAMEBUFFER)) {
continue;
}
const sp<LayerBase>& layer(layers[i]);