SurfaceFlinger: use setActiveConfigWithConstraints
Remove setActiveConfig and use setActiveConfigWithConstraints
instead. Use the return parameter of setActiveConfigWithConstraints to know
whether a refresh is required and when.
Fixes: 142753004
Bug: 141329414
Test: observe refresh rate switching thru systrace
Change-Id: Ie67a3be9180e7a367fc9e73425598d53a5fd6578
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index d480f7c..d8dad0b 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -247,8 +247,8 @@
// the refresh period and whatever closest timestamp we have.
std::lock_guard lock(displayData.lastHwVsyncLock);
nsecs_t now = systemTime(CLOCK_MONOTONIC);
- auto vsyncPeriod = getActiveConfig(displayId)->getVsyncPeriod();
- return now - ((now - displayData.lastHwVsync) % vsyncPeriod);
+ auto vsyncPeriodNanos = getDisplayVsyncPeriod(displayId);
+ return now - ((now - displayData.lastHwVsync) % vsyncPeriodNanos);
}
bool HWComposer::isConnected(DisplayId displayId) const {
@@ -291,6 +291,23 @@
return config;
}
+// Composer 2.4
+
+bool HWComposer::isVsyncPeriodSwitchSupported(DisplayId displayId) const {
+ return mDisplayData.at(displayId).hwcDisplay->isVsyncPeriodSwitchSupported();
+}
+
+nsecs_t HWComposer::getDisplayVsyncPeriod(DisplayId displayId) const {
+ nsecs_t vsyncPeriodNanos;
+ auto error = mDisplayData.at(displayId).hwcDisplay->getDisplayVsyncPeriod(&vsyncPeriodNanos);
+ if (error != HWC2::Error::None) {
+ LOG_DISPLAY_ERROR(displayId, "Failed to get Vsync Period");
+ return 0;
+ }
+
+ return vsyncPeriodNanos;
+}
+
int HWComposer::getActiveConfigIndex(DisplayId displayId) const {
RETURN_IF_INVALID_DISPLAY(displayId, -1);
@@ -541,7 +558,9 @@
return NO_ERROR;
}
-status_t HWComposer::setActiveConfig(DisplayId displayId, size_t configId) {
+status_t HWComposer::setActiveConfigWithConstraints(
+ DisplayId displayId, size_t configId, const HWC2::VsyncPeriodChangeConstraints& constraints,
+ HWC2::VsyncPeriodChangeTimeline* outTimeline) {
RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
auto& displayData = mDisplayData[displayId];
@@ -550,7 +569,9 @@
return BAD_INDEX;
}
- auto error = displayData.hwcDisplay->setActiveConfig(displayData.configMap[configId]);
+ auto error =
+ displayData.hwcDisplay->setActiveConfigWithConstraints(displayData.configMap[configId],
+ constraints, outTimeline);
RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
return NO_ERROR;
}
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index e87c5c3..077e452 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -102,9 +102,6 @@
// set power mode
virtual status_t setPowerMode(DisplayId displayId, int mode) = 0;
- // set active config
- virtual status_t setActiveConfig(DisplayId displayId, size_t configId) = 0;
-
// Sets a color transform to be applied to the result of composition
virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0;
@@ -180,6 +177,14 @@
virtual bool isUsingVrComposer() const = 0;
+ // Composer 2.4
+ virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0;
+ virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0;
+ virtual status_t setActiveConfigWithConstraints(
+ DisplayId displayId, size_t configId,
+ const HWC2::VsyncPeriodChangeConstraints& constraints,
+ HWC2::VsyncPeriodChangeTimeline* outTimeline) = 0;
+
// for debugging ----------------------------------------------------------
virtual void dump(std::string& out) const = 0;
@@ -232,9 +237,6 @@
// set power mode
status_t setPowerMode(DisplayId displayId, int mode) override;
- // set active config
- status_t setActiveConfig(DisplayId displayId, size_t configId) override;
-
// Sets a color transform to be applied to the result of composition
status_t setColorTransform(DisplayId displayId, const mat4& transform) override;
@@ -305,6 +307,13 @@
bool isUsingVrComposer() const override;
+ // Composer 2.4
+ bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override;
+ nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override;
+ status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId,
+ const HWC2::VsyncPeriodChangeConstraints& constraints,
+ HWC2::VsyncPeriodChangeTimeline* outTimeline) override;
+
// for debugging ----------------------------------------------------------
void dump(std::string& out) const override;