Loading services/surfaceflinger/DisplayDevice.cpp +7 −5 Original line number Original line Diff line number Diff line Loading @@ -104,7 +104,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args) mCompositionDisplay->getRenderSurface()->initialize(); mCompositionDisplay->getRenderSurface()->initialize(); setPowerMode(args.initialPowerMode); if (args.initialPowerMode.has_value()) setPowerMode(args.initialPowerMode.value()); // initialize the display orientation transform. // initialize the display orientation transform. setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT); setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT); Loading Loading @@ -183,19 +183,21 @@ void DisplayDevice::setPowerMode(hal::PowerMode mode) { } } mPowerMode = mode; mPowerMode = mode; getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF); getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() && *mPowerMode != hal::PowerMode::OFF); } } void DisplayDevice::enableLayerCaching(bool enable) { void DisplayDevice::enableLayerCaching(bool enable) { getCompositionDisplay()->setLayerCachingEnabled(enable); getCompositionDisplay()->setLayerCachingEnabled(enable); } } hal::PowerMode DisplayDevice::getPowerMode() const { std::optional<hal::PowerMode> DisplayDevice::getPowerMode() const { return mPowerMode; return mPowerMode; } } bool DisplayDevice::isPoweredOn() const { bool DisplayDevice::isPoweredOn() const { return mPowerMode != hal::PowerMode::OFF; return mPowerMode && *mPowerMode != hal::PowerMode::OFF; } } void DisplayDevice::setActiveMode(DisplayModeId id) { void DisplayDevice::setActiveMode(DisplayModeId id) { Loading Loading @@ -384,7 +386,7 @@ void DisplayDevice::dump(std::string& result) const { } } result += "\n powerMode="s; result += "\n powerMode="s; result += to_string(mPowerMode); result += mPowerMode.has_value() ? to_string(mPowerMode.value()) : "OFF(reset)"; result += '\n'; result += '\n'; if (mRefreshRateConfigs) { if (mRefreshRateConfigs) { Loading services/surfaceflinger/DisplayDevice.h +4 −5 Original line number Original line Diff line number Diff line Loading @@ -181,7 +181,7 @@ public: /* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------ * Display power mode management. * Display power mode management. */ */ hardware::graphics::composer::hal::PowerMode getPowerMode() const; std::optional<hardware::graphics::composer::hal::PowerMode> getPowerMode() const; void setPowerMode(hardware::graphics::composer::hal::PowerMode mode); void setPowerMode(hardware::graphics::composer::hal::PowerMode mode); bool isPoweredOn() const; bool isPoweredOn() const; Loading Loading @@ -281,8 +281,8 @@ private: static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; hardware::graphics::composer::hal::PowerMode mPowerMode = // allow initial power mode as null. hardware::graphics::composer::hal::PowerMode::OFF; std::optional<hardware::graphics::composer::hal::PowerMode> mPowerMode; DisplayModePtr mActiveMode; DisplayModePtr mActiveMode; std::optional<float> mStagedBrightness = std::nullopt; std::optional<float> mStagedBrightness = std::nullopt; float mBrightness = -1.f; float mBrightness = -1.f; Loading Loading @@ -366,8 +366,7 @@ struct DisplayDeviceCreationArgs { HdrCapabilities hdrCapabilities; HdrCapabilities hdrCapabilities; int32_t supportedPerFrameMetadata{0}; int32_t supportedPerFrameMetadata{0}; std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; hardware::graphics::composer::hal::PowerMode initialPowerMode{ std::optional<hardware::graphics::composer::hal::PowerMode> initialPowerMode; hardware::graphics::composer::hal::PowerMode::ON}; bool isPrimary{false}; bool isPrimary{false}; DisplayModes supportedModes; DisplayModes supportedModes; DisplayModeId activeModeId; DisplayModeId activeModeId; Loading services/surfaceflinger/SurfaceFlinger.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -2889,7 +2889,8 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); // virtual displays are always considered enabled // virtual displays are always considered enabled creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; creationArgs.initialPowerMode = state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); Loading Loading @@ -4870,8 +4871,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: const auto displayId = display->getPhysicalId(); const auto displayId = display->getPhysicalId(); ALOGD("Setting power mode %d on display %s", mode, to_string(displayId).c_str()); ALOGD("Setting power mode %d on display %s", mode, to_string(displayId).c_str()); const hal::PowerMode currentMode = display->getPowerMode(); std::optional<hal::PowerMode> currentMode = display->getPowerMode(); if (mode == currentMode) { if (currentMode.has_value() && mode == *currentMode) { return; return; } } Loading @@ -4887,7 +4888,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); } } const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); if (currentMode == hal::PowerMode::OFF) { if (*currentMode == hal::PowerMode::OFF) { // Turn on the display // Turn on the display if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { onActiveDisplayChangedLocked(display); onActiveDisplayChangedLocked(display); Loading Loading @@ -4918,7 +4919,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); } } if (isDisplayActiveLocked(display) && currentMode != hal::PowerMode::DOZE_SUSPEND) { if (isDisplayActiveLocked(display) && *currentMode != hal::PowerMode::DOZE_SUSPEND) { mScheduler->disableHardwareVsync(true); mScheduler->disableHardwareVsync(true); mScheduler->onScreenReleased(mAppConnectionHandle); mScheduler->onScreenReleased(mAppConnectionHandle); } } Loading @@ -4932,7 +4933,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { // Update display while dozing // Update display while dozing getHwComposer().setPowerMode(displayId, mode); getHwComposer().setPowerMode(displayId, mode); if (isDisplayActiveLocked(display) && currentMode == hal::PowerMode::DOZE_SUSPEND) { if (isDisplayActiveLocked(display) && *currentMode == hal::PowerMode::DOZE_SUSPEND) { mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->resyncToHardwareVsync(true, refreshRate); mScheduler->resyncToHardwareVsync(true, refreshRate); } } Loading services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -745,6 +745,7 @@ public: mHwcDisplayId(hwcDisplayId) { mHwcDisplayId(hwcDisplayId) { mCreationArgs.connectionType = connectionType; mCreationArgs.connectionType = connectionType; mCreationArgs.isPrimary = isPrimary; mCreationArgs.isPrimary = isPrimary; mCreationArgs.initialPowerMode = hal::PowerMode::ON; } } sp<IBinder> token() const { return mDisplayToken; } sp<IBinder> token() const { return mDisplayToken; } Loading Loading
services/surfaceflinger/DisplayDevice.cpp +7 −5 Original line number Original line Diff line number Diff line Loading @@ -104,7 +104,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args) mCompositionDisplay->getRenderSurface()->initialize(); mCompositionDisplay->getRenderSurface()->initialize(); setPowerMode(args.initialPowerMode); if (args.initialPowerMode.has_value()) setPowerMode(args.initialPowerMode.value()); // initialize the display orientation transform. // initialize the display orientation transform. setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT); setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT); Loading Loading @@ -183,19 +183,21 @@ void DisplayDevice::setPowerMode(hal::PowerMode mode) { } } mPowerMode = mode; mPowerMode = mode; getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF); getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() && *mPowerMode != hal::PowerMode::OFF); } } void DisplayDevice::enableLayerCaching(bool enable) { void DisplayDevice::enableLayerCaching(bool enable) { getCompositionDisplay()->setLayerCachingEnabled(enable); getCompositionDisplay()->setLayerCachingEnabled(enable); } } hal::PowerMode DisplayDevice::getPowerMode() const { std::optional<hal::PowerMode> DisplayDevice::getPowerMode() const { return mPowerMode; return mPowerMode; } } bool DisplayDevice::isPoweredOn() const { bool DisplayDevice::isPoweredOn() const { return mPowerMode != hal::PowerMode::OFF; return mPowerMode && *mPowerMode != hal::PowerMode::OFF; } } void DisplayDevice::setActiveMode(DisplayModeId id) { void DisplayDevice::setActiveMode(DisplayModeId id) { Loading Loading @@ -384,7 +386,7 @@ void DisplayDevice::dump(std::string& result) const { } } result += "\n powerMode="s; result += "\n powerMode="s; result += to_string(mPowerMode); result += mPowerMode.has_value() ? to_string(mPowerMode.value()) : "OFF(reset)"; result += '\n'; result += '\n'; if (mRefreshRateConfigs) { if (mRefreshRateConfigs) { Loading
services/surfaceflinger/DisplayDevice.h +4 −5 Original line number Original line Diff line number Diff line Loading @@ -181,7 +181,7 @@ public: /* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------ * Display power mode management. * Display power mode management. */ */ hardware::graphics::composer::hal::PowerMode getPowerMode() const; std::optional<hardware::graphics::composer::hal::PowerMode> getPowerMode() const; void setPowerMode(hardware::graphics::composer::hal::PowerMode mode); void setPowerMode(hardware::graphics::composer::hal::PowerMode mode); bool isPoweredOn() const; bool isPoweredOn() const; Loading Loading @@ -281,8 +281,8 @@ private: static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; hardware::graphics::composer::hal::PowerMode mPowerMode = // allow initial power mode as null. hardware::graphics::composer::hal::PowerMode::OFF; std::optional<hardware::graphics::composer::hal::PowerMode> mPowerMode; DisplayModePtr mActiveMode; DisplayModePtr mActiveMode; std::optional<float> mStagedBrightness = std::nullopt; std::optional<float> mStagedBrightness = std::nullopt; float mBrightness = -1.f; float mBrightness = -1.f; Loading Loading @@ -366,8 +366,7 @@ struct DisplayDeviceCreationArgs { HdrCapabilities hdrCapabilities; HdrCapabilities hdrCapabilities; int32_t supportedPerFrameMetadata{0}; int32_t supportedPerFrameMetadata{0}; std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; hardware::graphics::composer::hal::PowerMode initialPowerMode{ std::optional<hardware::graphics::composer::hal::PowerMode> initialPowerMode; hardware::graphics::composer::hal::PowerMode::ON}; bool isPrimary{false}; bool isPrimary{false}; DisplayModes supportedModes; DisplayModes supportedModes; DisplayModeId activeModeId; DisplayModeId activeModeId; Loading
services/surfaceflinger/SurfaceFlinger.cpp +7 −6 Original line number Original line Diff line number Diff line Loading @@ -2889,7 +2889,8 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); ALOGV("Display Orientation: %s", toCString(creationArgs.physicalOrientation)); // virtual displays are always considered enabled // virtual displays are always considered enabled creationArgs.initialPowerMode = state.isVirtual() ? hal::PowerMode::ON : hal::PowerMode::OFF; creationArgs.initialPowerMode = state.isVirtual() ? std::make_optional(hal::PowerMode::ON) : std::nullopt; sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); sp<DisplayDevice> display = getFactory().createDisplayDevice(creationArgs); Loading Loading @@ -4870,8 +4871,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: const auto displayId = display->getPhysicalId(); const auto displayId = display->getPhysicalId(); ALOGD("Setting power mode %d on display %s", mode, to_string(displayId).c_str()); ALOGD("Setting power mode %d on display %s", mode, to_string(displayId).c_str()); const hal::PowerMode currentMode = display->getPowerMode(); std::optional<hal::PowerMode> currentMode = display->getPowerMode(); if (mode == currentMode) { if (currentMode.has_value() && mode == *currentMode) { return; return; } } Loading @@ -4887,7 +4888,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); mInterceptor->savePowerModeUpdate(display->getSequenceId(), static_cast<int32_t>(mode)); } } const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); const auto refreshRate = display->refreshRateConfigs().getActiveMode()->getFps(); if (currentMode == hal::PowerMode::OFF) { if (*currentMode == hal::PowerMode::OFF) { // Turn on the display // Turn on the display if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { if (display->isInternal() && (!activeDisplay || !activeDisplay->isPoweredOn())) { onActiveDisplayChangedLocked(display); onActiveDisplayChangedLocked(display); Loading Loading @@ -4918,7 +4919,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { if (SurfaceFlinger::setSchedAttr(false) != NO_ERROR) { ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); ALOGW("Couldn't set uclamp.min on display off: %s\n", strerror(errno)); } } if (isDisplayActiveLocked(display) && currentMode != hal::PowerMode::DOZE_SUSPEND) { if (isDisplayActiveLocked(display) && *currentMode != hal::PowerMode::DOZE_SUSPEND) { mScheduler->disableHardwareVsync(true); mScheduler->disableHardwareVsync(true); mScheduler->onScreenReleased(mAppConnectionHandle); mScheduler->onScreenReleased(mAppConnectionHandle); } } Loading @@ -4932,7 +4933,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal: } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { } else if (mode == hal::PowerMode::DOZE || mode == hal::PowerMode::ON) { // Update display while dozing // Update display while dozing getHwComposer().setPowerMode(displayId, mode); getHwComposer().setPowerMode(displayId, mode); if (isDisplayActiveLocked(display) && currentMode == hal::PowerMode::DOZE_SUSPEND) { if (isDisplayActiveLocked(display) && *currentMode == hal::PowerMode::DOZE_SUSPEND) { mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->resyncToHardwareVsync(true, refreshRate); mScheduler->resyncToHardwareVsync(true, refreshRate); } } Loading
services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -745,6 +745,7 @@ public: mHwcDisplayId(hwcDisplayId) { mHwcDisplayId(hwcDisplayId) { mCreationArgs.connectionType = connectionType; mCreationArgs.connectionType = connectionType; mCreationArgs.isPrimary = isPrimary; mCreationArgs.isPrimary = isPrimary; mCreationArgs.initialPowerMode = hal::PowerMode::ON; } } sp<IBinder> token() const { return mDisplayToken; } sp<IBinder> token() const { return mDisplayToken; } Loading