summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/DisplayDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/DisplayDevice.cpp')
-rw-r--r--services/surfaceflinger/DisplayDevice.cpp189
1 files changed, 122 insertions, 67 deletions
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 4445eea604..a915b615d9 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -24,7 +24,6 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-#include <android-base/stringprintf.h>
#include <compositionengine/CompositionEngine.h>
#include <compositionengine/Display.h>
#include <compositionengine/DisplayColorProfile.h>
@@ -49,8 +48,6 @@ namespace android {
namespace hal = hardware::graphics::composer::hal;
-using android::base::StringAppendF;
-
ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;
DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
@@ -91,11 +88,15 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers));
}
+ mCompositionDisplay->setPredictCompositionStrategy(mFlinger->mPredictCompositionStrategy);
+ mCompositionDisplay->setTreat170mAsSrgb(mFlinger->mTreat170mAsSrgb);
mCompositionDisplay->createDisplayColorProfile(
- compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut,
- std::move(args.hdrCapabilities),
- args.supportedPerFrameMetadata,
- args.hwcColorModes});
+ compositionengine::DisplayColorProfileCreationArgsBuilder()
+ .setHasWideColorGamut(args.hasWideColorGamut)
+ .setHdrCapabilities(std::move(args.hdrCapabilities))
+ .setSupportedPerFrameMetadata(args.supportedPerFrameMetadata)
+ .setHwcColorModes(std::move(args.hwcColorModes))
+ .Build());
if (!mCompositionDisplay->isValid()) {
ALOGE("Composition Display did not validate!");
@@ -116,11 +117,11 @@ void DisplayDevice::disconnect() {
}
int DisplayDevice::getWidth() const {
- return mCompositionDisplay->getState().displaySpace.bounds.getWidth();
+ return mCompositionDisplay->getState().displaySpace.getBounds().width;
}
int DisplayDevice::getHeight() const {
- return mCompositionDisplay->getState().displaySpace.bounds.getHeight();
+ return mCompositionDisplay->getState().displaySpace.getBounds().height;
}
void DisplayDevice::setDisplayName(const std::string& displayName) {
@@ -139,7 +140,38 @@ uint32_t DisplayDevice::getPageFlipCount() const {
return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
}
-// ----------------------------------------------------------------------------
+auto DisplayDevice::getInputInfo() const -> InputInfo {
+ gui::DisplayInfo info;
+ info.displayId = getLayerStack().id;
+
+ // The physical orientation is set when the orientation of the display panel is
+ // different than the default orientation of the device. Other services like
+ // InputFlinger do not know about this, so we do not need to expose the physical
+ // orientation of the panel outside of SurfaceFlinger.
+ const ui::Rotation inversePhysicalOrientation = ui::ROTATION_0 - mPhysicalOrientation;
+ auto width = getWidth();
+ auto height = getHeight();
+ if (inversePhysicalOrientation == ui::ROTATION_90 ||
+ inversePhysicalOrientation == ui::ROTATION_270) {
+ std::swap(width, height);
+ }
+ const ui::Transform undoPhysicalOrientation(ui::Transform::toRotationFlags(
+ inversePhysicalOrientation),
+ width, height);
+ const auto& displayTransform = undoPhysicalOrientation * getTransform();
+ // Send the inverse display transform to input so it can convert display coordinates to
+ // logical display.
+ info.transform = displayTransform.inverse();
+
+ info.logicalWidth = getLayerStackSpaceRect().width();
+ info.logicalHeight = getLayerStackSpaceRect().height();
+
+ return {.info = info,
+ .transform = displayTransform,
+ .receivesInput = receivesInput(),
+ .isSecure = isSecure()};
+}
+
void DisplayDevice::setPowerMode(hal::PowerMode mode) {
mPowerMode = mode;
getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
@@ -163,7 +195,7 @@ void DisplayDevice::setActiveMode(DisplayModeId id) {
ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
mActiveMode = mode;
if (mRefreshRateConfigs) {
- mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
+ mRefreshRateConfigs->setActiveModeId(mActiveMode->getId());
}
if (mRefreshRateOverlay) {
mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
@@ -194,12 +226,18 @@ const DisplayModes& DisplayDevice::getSupportedModes() const {
}
DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
- const auto it = std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
- [&](DisplayModePtr mode) { return mode->getId() == modeId; });
+ const DisplayModePtr nullMode;
+ return mSupportedModes.get(modeId).value_or(std::cref(nullMode));
+}
+
+std::optional<DisplayModeId> DisplayDevice::translateModeId(hal::HWConfigId hwcId) const {
+ const auto it =
+ std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
+ [hwcId](const auto& pair) { return pair.second->getHwcId() == hwcId; });
if (it != mSupportedModes.end()) {
- return *it;
+ return it->second->getId();
}
- return nullptr;
+ return {};
}
nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
@@ -232,7 +270,7 @@ ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
}
void DisplayDevice::setLayerStack(ui::LayerStack stack) {
- mCompositionDisplay->setLayerStackFilter(stack, isInternal());
+ mCompositionDisplay->setLayerFilter({stack, isInternal()});
if (mRefreshRateOverlay) {
mRefreshRateOverlay->setLayerStack(stack);
}
@@ -259,65 +297,83 @@ void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpace
sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
}
+ // We need to take care of display rotation for globalTransform for case if the panel is not
+ // installed aligned with device orientation.
+ const auto transformOrientation = orientation + mPhysicalOrientation;
+
+ const auto& state = getCompositionDisplay()->getState();
+
+ // If the layer stack and destination frames have never been set, then configure them to be the
+ // same as the physical device, taking into account the total transform.
if (!orientedDisplaySpaceRect.isValid()) {
- // The destination frame can be invalid if it has never been set,
- // in that case we assume the whole display size.
- orientedDisplaySpaceRect = getCompositionDisplay()->getState().displaySpace.bounds;
+ ui::Size bounds = state.displaySpace.getBounds();
+ bounds.rotate(transformOrientation);
+ orientedDisplaySpaceRect = Rect(bounds);
}
-
if (layerStackSpaceRect.isEmpty()) {
- // The layerStackSpaceRect can be invalid if it has never been set, in that case
- // we assume the whole framebuffer size.
- layerStackSpaceRect = getCompositionDisplay()->getState().framebufferSpace.bounds;
- if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
- std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom);
- }
+ ui::Size bounds = state.framebufferSpace.getBounds();
+ bounds.rotate(transformOrientation);
+ layerStackSpaceRect = Rect(bounds);
}
-
- // We need to take care of display rotation for globalTransform for case if the panel is not
- // installed aligned with device orientation.
- const auto transformOrientation = orientation + mPhysicalOrientation;
getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
orientedDisplaySpaceRect);
}
+void DisplayDevice::stageBrightness(float brightness) {
+ mStagedBrightness = brightness;
+}
+
+void DisplayDevice::persistBrightness(bool needsComposite) {
+ if (needsComposite && mStagedBrightness && mBrightness != *mStagedBrightness) {
+ getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
+ mBrightness = *mStagedBrightness;
+ }
+ mStagedBrightness = std::nullopt;
+}
+
+std::optional<float> DisplayDevice::getStagedBrightness() const {
+ return mStagedBrightness;
+}
+
ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
return sPrimaryDisplayRotationFlags;
}
std::string DisplayDevice::getDebugName() const {
- const char* type = "virtual";
+ using namespace std::string_literals;
+
+ std::string name = "Display "s + to_string(getId()) + " ("s;
+
if (mConnectionType) {
- type = isInternal() ? "internal" : "external";
+ name += isInternal() ? "internal"s : "external"s;
+ } else {
+ name += "virtual"s;
}
- return base::StringPrintf("DisplayDevice{%s, %s%s, \"%s\"}", to_string(getId()).c_str(), type,
- isPrimary() ? ", primary" : "", mDisplayName.c_str());
+ if (isPrimary()) {
+ name += ", primary"s;
+ }
+
+ return name + ", \""s + mDisplayName + "\")"s;
}
void DisplayDevice::dump(std::string& result) const {
- StringAppendF(&result, "+ %s\n", getDebugName().c_str());
- StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(),
- static_cast<int32_t>(mPowerMode));
- const auto activeMode = getActiveMode();
- StringAppendF(&result, " activeMode=%s\n",
- activeMode ? to_string(*activeMode).c_str() : "none");
-
- result.append(" supportedModes=\n");
-
- for (const auto& mode : mSupportedModes) {
- result.append(" ");
- result.append(to_string(*mode));
- result.append("\n");
- }
- StringAppendF(&result, " deviceProductInfo=");
- if (mDeviceProductInfo) {
- mDeviceProductInfo->dump(result);
- } else {
- result.append("{}");
+ using namespace std::string_literals;
+
+ result += getDebugName();
+
+ if (!isVirtual()) {
+ result += "\n deviceProductInfo="s;
+ if (mDeviceProductInfo) {
+ mDeviceProductInfo->dump(result);
+ } else {
+ result += "{}"s;
+ }
}
- result.append("\n");
- getCompositionDisplay()->dump(result);
+
+ result += "\n powerMode="s;
+ result += to_string(mPowerMode);
+ result += '\n';
if (mRefreshRateConfigs) {
mRefreshRateConfigs->dump(result);
@@ -336,8 +392,8 @@ bool DisplayDevice::isSecure() const {
return mCompositionDisplay->isSecure();
}
-const Rect& DisplayDevice::getBounds() const {
- return mCompositionDisplay->getState().displaySpace.bounds;
+const Rect DisplayDevice::getBounds() const {
+ return mCompositionDisplay->getState().displaySpace.getBoundsAsRect();
}
const Region& DisplayDevice::getUndefinedRegion() const {
@@ -349,7 +405,7 @@ bool DisplayDevice::needsFiltering() const {
}
ui::LayerStack DisplayDevice::getLayerStack() const {
- return mCompositionDisplay->getState().layerStackId;
+ return mCompositionDisplay->getState().layerFilter.layerStack;
}
ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
@@ -361,11 +417,11 @@ const ui::Transform& DisplayDevice::getTransform() const {
}
const Rect& DisplayDevice::getLayerStackSpaceRect() const {
- return mCompositionDisplay->getState().layerStackSpace.content;
+ return mCompositionDisplay->getState().layerStackSpace.getContent();
}
const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
- return mCompositionDisplay->getState().orientedDisplaySpace.content;
+ return mCompositionDisplay->getState().orientedDisplaySpace.getContent();
}
bool DisplayDevice::hasWideColorGamut() const {
@@ -414,9 +470,8 @@ void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
return;
}
- const auto [lowFps, highFps] = mRefreshRateConfigs->getSupportedRefreshRateRange();
- mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*mFlinger, lowFps.getIntValue(),
- highFps.getIntValue(), showSpinnner);
+ const auto fpsRange = mRefreshRateConfigs->getSupportedRefreshRateRange();
+ mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(fpsRange, showSpinnner);
mRefreshRateOverlay->setLayerStack(getLayerStack());
mRefreshRateOverlay->setViewport(getSize());
mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
@@ -436,9 +491,9 @@ bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredMod
return false;
}
-void DisplayDevice::onInvalidate() {
+void DisplayDevice::animateRefreshRateOverlay() {
if (mRefreshRateOverlay) {
- mRefreshRateOverlay->onInvalidate();
+ mRefreshRateOverlay->animate();
}
}
@@ -453,7 +508,7 @@ bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info) {
std::scoped_lock lock(mActiveModeLock);
if (mDesiredActiveModeChanged) {
// If a mode change is pending, just cache the latest request in mDesiredActiveMode
- const Scheduler::ModeEvent prevConfig = mDesiredActiveMode.event;
+ const auto prevConfig = mDesiredActiveMode.event;
mDesiredActiveMode = info;
mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
return false;
@@ -478,7 +533,7 @@ std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode
void DisplayDevice::clearDesiredActiveModeState() {
std::scoped_lock lock(mActiveModeLock);
- mDesiredActiveMode.event = Scheduler::ModeEvent::None;
+ mDesiredActiveMode.event = scheduler::DisplayModeEvent::None;
mDesiredActiveModeChanged = false;
}