Loading services/surfaceflinger/DisplayHardware/HWC2.cpp +5 −12 Original line number Diff line number Diff line Loading @@ -143,8 +143,8 @@ Error Device::createVirtualDisplay(uint32_t width, uint32_t height, return error; } auto display = std::make_unique<impl::Display>(*mComposer.get(), mPowerAdvisor, mCapabilities, displayId, DisplayType::Virtual); auto display = std::make_unique<impl::Display>(*mComposer.get(), mCapabilities, displayId, DisplayType::Virtual); display->setConnected(true); *outDisplay = display.get(); mDisplays.emplace(displayId, std::move(display)); Loading Loading @@ -182,8 +182,8 @@ void Device::onHotplug(hwc2_display_t displayId, Connection connection) { return; } auto newDisplay = std::make_unique<impl::Display>(*mComposer.get(), mPowerAdvisor, mCapabilities, displayId, displayType); auto newDisplay = std::make_unique<impl::Display>(*mComposer.get(), mCapabilities, displayId, displayType); newDisplay->setConnected(true); mDisplays.emplace(displayId, std::move(newDisplay)); } else if (connection == Connection::Disconnected) { Loading Loading @@ -254,11 +254,10 @@ float Display::Config::Builder::getDefaultDensity() { } namespace impl { Display::Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor, Display::Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type) : mComposer(composer), mPowerAdvisor(advisor), mCapabilities(capabilities), mId(id), mIsConnected(false), Loading Loading @@ -636,12 +635,6 @@ Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent) { // When the color mode is switched to DISPLAY_P3, we want to boost the GPU frequency // so that GPU composition can finish in time. When color mode is switched from // DISPLAY_P3, we want to reset GPU frequency. const bool expensiveRenderingExpected = (mode == ColorMode::DISPLAY_P3); mPowerAdvisor.setExpensiveRenderingExpected(mId, expensiveRenderingExpected); auto intError = mComposer.setColorMode(mId, mode, renderIntent); return static_cast<Error>(intError); } Loading services/surfaceflinger/DisplayHardware/HWC2.h +2 −7 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ #include <unordered_set> #include <vector> #include "PowerAdvisor.h" namespace android { struct DisplayedFrameStats; class Fence; Loading Loading @@ -125,7 +123,6 @@ private: std::unique_ptr<android::Hwc2::Composer> mComposer; std::unordered_set<Capability> mCapabilities; std::unordered_map<hwc2_display_t, std::unique_ptr<Display>> mDisplays; android::Hwc2::impl::PowerAdvisor mPowerAdvisor; bool mRegisteredCallback = false; }; Loading Loading @@ -273,9 +270,8 @@ namespace impl { class Display : public HWC2::Display { public: Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type); Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type); ~Display() override; // Required by HWC2 Loading Loading @@ -352,7 +348,6 @@ private: // this HWC2::Display, so these references are guaranteed to be valid for // the lifetime of this object. android::Hwc2::Composer& mComposer; android::Hwc2::PowerAdvisor& mPowerAdvisor; const std::unordered_set<Capability>& mCapabilities; hwc2_display_t mId; Loading services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ PowerAdvisor::~PowerAdvisor() = default; PowerAdvisor::PowerAdvisor() = default; void PowerAdvisor::setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) { void PowerAdvisor::setExpensiveRenderingExpected(DisplayId displayId, bool expected) { if (expected) { mExpensiveDisplays.insert(displayId); } else { Loading services/surfaceflinger/DisplayHardware/PowerAdvisor.h +6 −4 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ #undef HWC2_INCLUDE_STRINGIFICATION #undef HWC2_USE_CPP11 #include <unordered_set> #include <android/hardware/power/1.3/IPower.h> #include <utils/StrongPointer.h> #include <unordered_set> #include "DisplayIdentification.h" namespace android { namespace Hwc2 { Loading @@ -34,7 +36,7 @@ class PowerAdvisor { public: virtual ~PowerAdvisor(); virtual void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) = 0; virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; }; namespace impl { Loading @@ -48,12 +50,12 @@ public: PowerAdvisor(); ~PowerAdvisor() override; void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) override; void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; private: sp<V1_3::IPower> getPowerHal(); std::unordered_set<hwc2_display_t> mExpensiveDisplays; std::unordered_set<DisplayId> mExpensiveDisplays; bool mNotifiedExpensiveRendering = false; bool mReconnectPowerHal = false; }; Loading services/surfaceflinger/SurfaceFlinger.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -3364,6 +3364,16 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<DisplayDevice>& displayDevice, // Perform some cleanup steps if we used client composition. if (hasClientComposition) { clientCompositionDisplay.clearRegion = clearRegion; // We boost GPU frequency here because there will be color spaces conversion // and it's expensive. We boost the GPU frequency so that GPU composition can // finish in time. We must reset GPU frequency afterwards, because high frequency // consumes extra battery. const bool expensiveRenderingExpected = clientCompositionDisplay.outputDataspace == Dataspace::DISPLAY_P3; if (expensiveRenderingExpected && displayId) { mPowerAdvisor.setExpensiveRenderingExpected(*displayId, true); } if (!debugRegion.isEmpty()) { Region::const_iterator it = debugRegion.begin(); Region::const_iterator end = debugRegion.end(); Loading @@ -3379,6 +3389,9 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<DisplayDevice>& displayDevice, } renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers, buf->getNativeBuffer(), std::move(fd), readyFence); if (expensiveRenderingExpected && displayId) { mPowerAdvisor.setExpensiveRenderingExpected(*displayId, false); } } return true; } Loading Loading
services/surfaceflinger/DisplayHardware/HWC2.cpp +5 −12 Original line number Diff line number Diff line Loading @@ -143,8 +143,8 @@ Error Device::createVirtualDisplay(uint32_t width, uint32_t height, return error; } auto display = std::make_unique<impl::Display>(*mComposer.get(), mPowerAdvisor, mCapabilities, displayId, DisplayType::Virtual); auto display = std::make_unique<impl::Display>(*mComposer.get(), mCapabilities, displayId, DisplayType::Virtual); display->setConnected(true); *outDisplay = display.get(); mDisplays.emplace(displayId, std::move(display)); Loading Loading @@ -182,8 +182,8 @@ void Device::onHotplug(hwc2_display_t displayId, Connection connection) { return; } auto newDisplay = std::make_unique<impl::Display>(*mComposer.get(), mPowerAdvisor, mCapabilities, displayId, displayType); auto newDisplay = std::make_unique<impl::Display>(*mComposer.get(), mCapabilities, displayId, displayType); newDisplay->setConnected(true); mDisplays.emplace(displayId, std::move(newDisplay)); } else if (connection == Connection::Disconnected) { Loading Loading @@ -254,11 +254,10 @@ float Display::Config::Builder::getDefaultDensity() { } namespace impl { Display::Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor, Display::Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type) : mComposer(composer), mPowerAdvisor(advisor), mCapabilities(capabilities), mId(id), mIsConnected(false), Loading Loading @@ -636,12 +635,6 @@ Error Display::setClientTarget(uint32_t slot, const sp<GraphicBuffer>& target, Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent) { // When the color mode is switched to DISPLAY_P3, we want to boost the GPU frequency // so that GPU composition can finish in time. When color mode is switched from // DISPLAY_P3, we want to reset GPU frequency. const bool expensiveRenderingExpected = (mode == ColorMode::DISPLAY_P3); mPowerAdvisor.setExpensiveRenderingExpected(mId, expensiveRenderingExpected); auto intError = mComposer.setColorMode(mId, mode, renderIntent); return static_cast<Error>(intError); } Loading
services/surfaceflinger/DisplayHardware/HWC2.h +2 −7 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ #include <unordered_set> #include <vector> #include "PowerAdvisor.h" namespace android { struct DisplayedFrameStats; class Fence; Loading Loading @@ -125,7 +123,6 @@ private: std::unique_ptr<android::Hwc2::Composer> mComposer; std::unordered_set<Capability> mCapabilities; std::unordered_map<hwc2_display_t, std::unique_ptr<Display>> mDisplays; android::Hwc2::impl::PowerAdvisor mPowerAdvisor; bool mRegisteredCallback = false; }; Loading Loading @@ -273,9 +270,8 @@ namespace impl { class Display : public HWC2::Display { public: Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type); Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities, hwc2_display_t id, DisplayType type); ~Display() override; // Required by HWC2 Loading Loading @@ -352,7 +348,6 @@ private: // this HWC2::Display, so these references are guaranteed to be valid for // the lifetime of this object. android::Hwc2::Composer& mComposer; android::Hwc2::PowerAdvisor& mPowerAdvisor; const std::unordered_set<Capability>& mCapabilities; hwc2_display_t mId; Loading
services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ PowerAdvisor::~PowerAdvisor() = default; PowerAdvisor::PowerAdvisor() = default; void PowerAdvisor::setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) { void PowerAdvisor::setExpensiveRenderingExpected(DisplayId displayId, bool expected) { if (expected) { mExpensiveDisplays.insert(displayId); } else { Loading
services/surfaceflinger/DisplayHardware/PowerAdvisor.h +6 −4 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ #undef HWC2_INCLUDE_STRINGIFICATION #undef HWC2_USE_CPP11 #include <unordered_set> #include <android/hardware/power/1.3/IPower.h> #include <utils/StrongPointer.h> #include <unordered_set> #include "DisplayIdentification.h" namespace android { namespace Hwc2 { Loading @@ -34,7 +36,7 @@ class PowerAdvisor { public: virtual ~PowerAdvisor(); virtual void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) = 0; virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; }; namespace impl { Loading @@ -48,12 +50,12 @@ public: PowerAdvisor(); ~PowerAdvisor() override; void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) override; void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; private: sp<V1_3::IPower> getPowerHal(); std::unordered_set<hwc2_display_t> mExpensiveDisplays; std::unordered_set<DisplayId> mExpensiveDisplays; bool mNotifiedExpensiveRendering = false; bool mReconnectPowerHal = false; }; Loading
services/surfaceflinger/SurfaceFlinger.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -3364,6 +3364,16 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<DisplayDevice>& displayDevice, // Perform some cleanup steps if we used client composition. if (hasClientComposition) { clientCompositionDisplay.clearRegion = clearRegion; // We boost GPU frequency here because there will be color spaces conversion // and it's expensive. We boost the GPU frequency so that GPU composition can // finish in time. We must reset GPU frequency afterwards, because high frequency // consumes extra battery. const bool expensiveRenderingExpected = clientCompositionDisplay.outputDataspace == Dataspace::DISPLAY_P3; if (expensiveRenderingExpected && displayId) { mPowerAdvisor.setExpensiveRenderingExpected(*displayId, true); } if (!debugRegion.isEmpty()) { Region::const_iterator it = debugRegion.begin(); Region::const_iterator end = debugRegion.end(); Loading @@ -3379,6 +3389,9 @@ bool SurfaceFlinger::doComposeSurfaces(const sp<DisplayDevice>& displayDevice, } renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers, buf->getNativeBuffer(), std::move(fd), readyFence); if (expensiveRenderingExpected && displayId) { mPowerAdvisor.setExpensiveRenderingExpected(*displayId, false); } } return true; } Loading