[sf] optimize snapshot updates
Modify the snapshot update logic so its easier to maintain. Instead of
walking the tree and updating all the snapshots, this cl introduces a
preliminary step of walking though all the requested changes and
updating the affected snapshots by merging the changes to the snapshot.
This is followed by walking down the tree and updating properties that
are dependent on the parent snapshots.
If the changes are confined to buffer updates, then the fast path avoids
walking down the tree.
Bug: 238781169
Test: presubmit
Change-Id: Ic9aa66c376bf7ea80e38b321dd08b8d0f69559a9
diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
index bde2d05..5738262 100644
--- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
+++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+// #define LOG_NDEBUG 0
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#undef LOG_TAG
-#define LOG_TAG "RequestedLayerState"
+#define LOG_TAG "SurfaceFlinger"
#include <log/log.h>
#include <private/android_filesystem_config.h>
@@ -132,12 +133,16 @@
const half oldAlpha = color.a;
const bool hadBuffer = externalTexture != nullptr;
uint64_t oldFramenumber = hadBuffer ? bufferData->frameNumber : 0;
+ const ui::Size oldBufferSize = hadBuffer
+ ? ui::Size(externalTexture->getWidth(), externalTexture->getHeight())
+ : ui::Size();
const bool hadSideStream = sidebandStream != nullptr;
const layer_state_t& clientState = resolvedComposerState.state;
const bool hadBlur = hasBlur();
uint64_t clientChanges = what | layer_state_t::diff(clientState);
layer_state_t::merge(clientState);
what = clientChanges;
+ LLOGV(layerId, "requested=%" PRIu64 "flags=%" PRIu64, clientState.what, clientChanges);
if (clientState.what & layer_state_t::eFlagsChanged) {
if ((oldFlags ^ flags) & layer_state_t::eLayerHidden) {
@@ -154,6 +159,13 @@
const bool hasBuffer = externalTexture != nullptr;
if (hasBuffer || hasBuffer != hadBuffer) {
changes |= RequestedLayerState::Changes::Buffer;
+ const ui::Size newBufferSize = hasBuffer
+ ? ui::Size(externalTexture->getWidth(), externalTexture->getHeight())
+ : ui::Size();
+ if (oldBufferSize != newBufferSize) {
+ changes |= RequestedLayerState::Changes::BufferSize;
+ changes |= RequestedLayerState::Changes::Geometry;
+ }
}
if (hasBuffer != hadBuffer) {
@@ -281,7 +293,7 @@
// child layers.
if (static_cast<int32_t>(gameMode) != requestedGameMode) {
gameMode = static_cast<gui::GameMode>(requestedGameMode);
- changes |= RequestedLayerState::Changes::AffectsChildren;
+ changes |= RequestedLayerState::Changes::GameMode;
}
}
}
@@ -372,7 +384,7 @@
return (flags & layer_state_t::eLayerHidden) == layer_state_t::eLayerHidden;
};
half4 RequestedLayerState::getColor() const {
- if ((sidebandStream != nullptr) || (externalTexture != nullptr)) {
+ if (sidebandStream || externalTexture) {
return {0._hf, 0._hf, 0._hf, color.a};
}
return color;