From 67b431ca7d8b36b368e4d8691334597584b4fdba Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Wed, 16 Nov 2022 01:54:05 +0000 Subject: SF: Track display info required for frontend updates Instead of recreating display info every time we need to update input, keep track of a subset of display info that is required for both input updates and geometry updates. The layer stack to display info is updated every time display state changes. Bug: 238781169 Test: presubmit Change-Id: I965d319bf1e10cf891c62526e309ae603e267dea --- services/surfaceflinger/DisplayDevice.cpp | 7 +++-- services/surfaceflinger/DisplayDevice.h | 11 ++----- .../surfaceflinger/FrontEnd/FrontEndDisplayInfo.h | 35 ++++++++++++++++++++++ services/surfaceflinger/SurfaceFlinger.cpp | 35 +++++----------------- services/surfaceflinger/SurfaceFlinger.h | 2 ++ 5 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 services/surfaceflinger/FrontEnd/FrontEndDisplayInfo.h diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 9868c8ead8..c5f5372f19 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -41,6 +41,7 @@ #include "Display/DisplaySnapshot.h" #include "DisplayDevice.h" +#include "FrontEnd/FrontEndDisplayInfo.h" #include "Layer.h" #include "RefreshRateOverlay.h" #include "SurfaceFlinger.h" @@ -131,7 +132,7 @@ void DisplayDevice::setDisplayName(const std::string& displayName) { } } -auto DisplayDevice::getInputInfo() const -> InputInfo { +auto DisplayDevice::getFrontEndInfo() const -> FrontEndDisplayInfo { gui::DisplayInfo info; info.displayId = getLayerStack().id; @@ -160,7 +161,9 @@ auto DisplayDevice::getInputInfo() const -> InputInfo { return {.info = info, .transform = displayTransform, .receivesInput = receivesInput(), - .isSecure = isSecure()}; + .isSecure = isSecure(), + .isPrimary = isPrimary(), + .rotationFlags = ui::Transform::toRotationFlags(mOrientation)}; } void DisplayDevice::setPowerMode(hal::PowerMode mode) { diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 1602a71709..afa13e5795 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -45,11 +45,11 @@ #include "DisplayHardware/DisplayMode.h" #include "DisplayHardware/Hal.h" #include "DisplayHardware/PowerAdvisor.h" +#include "FrontEnd/FrontEndDisplayInfo.h" #include "Scheduler/RefreshRateSelector.h" #include "ThreadContext.h" #include "TracedOrdinal.h" #include "Utils/Dumper.h" - namespace android { class Fence; @@ -167,14 +167,7 @@ public: void setDisplayName(const std::string& displayName); const std::string& getDisplayName() const { return mDisplayName; } - struct InputInfo { - gui::DisplayInfo info; - ui::Transform transform; - bool receivesInput; - bool isSecure; - }; - - InputInfo getInputInfo() const; + surfaceflinger::FrontEndDisplayInfo getFrontEndInfo() const; /* ------------------------------------------------------------------------ * Display power mode management. diff --git a/services/surfaceflinger/FrontEnd/FrontEndDisplayInfo.h b/services/surfaceflinger/FrontEnd/FrontEndDisplayInfo.h new file mode 100644 index 0000000000..95e69b33e2 --- /dev/null +++ b/services/surfaceflinger/FrontEnd/FrontEndDisplayInfo.h @@ -0,0 +1,35 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +// TODO (b/259553365) fix namespace to be consistent with other components +namespace android::surfaceflinger { + +// Display information needed to populate input and calculate layer geometry. +struct FrontEndDisplayInfo { + gui::DisplayInfo info; + ui::Transform transform; + bool receivesInput; + bool isSecure; + // TODO(b/238781169) can eliminate once sPrimaryDisplayRotationFlags is removed. + bool isPrimary; + ui::Transform::RotationFlags rotationFlags; +}; + +} // namespace android::surfaceflinger diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 13bfd6235a..16cfefdbe2 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -3122,6 +3122,10 @@ void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; if (displayTransactionNeeded) { processDisplayChangesLocked(); + mFrontEndDisplayInfos.clear(); + for (const auto& [_, display] : mDisplays) { + mFrontEndDisplayInfos.try_emplace(display->getLayerStack(), display->getFrontEndInfo()); + } } mForceTransactionDisplayChange = displayTransactionNeeded; @@ -3291,29 +3295,6 @@ void SurfaceFlinger::persistDisplayBrightness(bool needsComposite) { void SurfaceFlinger::buildWindowInfos(std::vector& outWindowInfos, std::vector& outDisplayInfos) { - display::DisplayMap displayInputInfos; - - for (const auto& [_, display] : FTL_FAKE_GUARD(mStateLock, mDisplays)) { - const auto layerStack = display->getLayerStack(); - const auto info = display->getInputInfo(); - - const auto [it, emplaced] = displayInputInfos.try_emplace(layerStack, info); - if (emplaced) { - continue; - } - - // If the layer stack is mirrored on multiple displays, the first display that is configured - // to receive input takes precedence. - auto& otherInfo = it->second; - if (otherInfo.receivesInput) { - ALOGW_IF(display->receivesInput(), - "Multiple displays claim to accept input for the same layer stack: %u", - layerStack.id); - } else { - otherInfo = info; - } - } - static size_t sNumWindowInfos = 0; outWindowInfos.reserve(sNumWindowInfos); sNumWindowInfos = 0; @@ -3321,8 +3302,8 @@ void SurfaceFlinger::buildWindowInfos(std::vector& outWindowInfos, mDrawingState.traverseInReverseZOrder([&](Layer* layer) { if (!layer->needsInputInfo()) return; - const auto opt = displayInputInfos.get(layer->getLayerStack()) - .transform([](const DisplayDevice::InputInfo& info) { + const auto opt = mFrontEndDisplayInfos.get(layer->getLayerStack()) + .transform([](const FrontEndDisplayInfo& info) { return Layer::InputDisplayArgs{&info.transform, info.isSecure}; }); @@ -3331,8 +3312,8 @@ void SurfaceFlinger::buildWindowInfos(std::vector& outWindowInfos, sNumWindowInfos = outWindowInfos.size(); - outDisplayInfos.reserve(displayInputInfos.size()); - for (const auto& [_, info] : displayInputInfos) { + outDisplayInfos.reserve(mFrontEndDisplayInfos.size()); + for (const auto& [_, info] : mFrontEndDisplayInfos) { outDisplayInfos.push_back(info.info); } } diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 0706598782..09ecfd13c8 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -66,6 +66,7 @@ #include "DisplayIdGenerator.h" #include "Effects/Daltonizer.h" #include "FlagManager.h" +#include "FrontEnd/FrontEndDisplayInfo.h" #include "FrontEnd/LayerCreationArgs.h" #include "FrontEnd/TransactionHandler.h" #include "LayerVector.h" @@ -1366,6 +1367,7 @@ private: } mPowerHintSessionMode; TransactionHandler mTransactionHandler; + display::DisplayMap mFrontEndDisplayInfos; }; class SurfaceComposerAIDL : public gui::BnSurfaceComposer { -- cgit v1.2.3-59-g8ed1b