Merge "[RenderEngine] relax locking conditions of image cache." into qt-r1-dev
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc
index 032d072..f1426b6 100644
--- a/cmds/atrace/atrace.rc
+++ b/cmds/atrace/atrace.rc
@@ -47,6 +47,8 @@
chmod 0666 /sys/kernel/tracing/events/power/clock_set_rate/enable
chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency_limits/enable
chmod 0666 /sys/kernel/tracing/events/power/cpu_frequency_limits/enable
+ chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_frequency/enable
+ chmod 0666 /sys/kernel/tracing/events/power/gpu_frequency/enable
chmod 0666 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
chmod 0666 /sys/kernel/tracing/events/cpufreq_interactive/enable
chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
diff --git a/cmds/installd/migrate_legacy_obb_data.sh b/cmds/installd/migrate_legacy_obb_data.sh
index 4f8a1ec..ef9be5c 100644
--- a/cmds/installd/migrate_legacy_obb_data.sh
+++ b/cmds/installd/migrate_legacy_obb_data.sh
@@ -20,6 +20,14 @@
exit 0
fi
+rm -rf /data/media/0/Android/obb/test_probe
+touch /sdcard/Android/obb/test_probe
+if ! test -f /data/media/0/Android/obb/test_probe ; then
+ log -p i -t migrate_legacy_obb_data "No support for 'unshared_obb'. Not migrating"
+ rm -rf /data/media/0/Android/obb/test_probe
+ exit 0
+fi
+
log -p i -t migrate_legacy_obb_data "Migrating legacy obb data."
rm -rf /data/media/0/Android/obb
cp -F -p -R -P -d /data/media/obb /data/media/0/Android
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 1c5fa52..24b6c2d 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -37,6 +37,7 @@
#include <memory>
#include <string>
+#include <thread>
// TODO(b/37049319) Get this from a header once one exists
extern "C" {
@@ -163,17 +164,20 @@
void GraphicsEnv::hintActivityLaunch() {
ATRACE_CALL();
- // If there's already graphics driver preloaded in the process, just send
- // the stats info to GpuStats directly through async binder.
- std::lock_guard<std::mutex> lock(mStatsLock);
- if (mGpuStats.glDriverToSend) {
- mGpuStats.glDriverToSend = false;
- sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime);
- }
- if (mGpuStats.vkDriverToSend) {
- mGpuStats.vkDriverToSend = false;
- sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime);
- }
+ std::thread trySendGpuStatsThread([this]() {
+ // If there's already graphics driver preloaded in the process, just send
+ // the stats info to GpuStats directly through async binder.
+ std::lock_guard<std::mutex> lock(mStatsLock);
+ if (mGpuStats.glDriverToSend) {
+ mGpuStats.glDriverToSend = false;
+ sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime);
+ }
+ if (mGpuStats.vkDriverToSend) {
+ mGpuStats.vkDriverToSend = false;
+ sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime);
+ }
+ });
+ trySendGpuStatsThread.detach();
}
void GraphicsEnv::setGpuStats(const std::string& driverPackageName,
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index 9c311a3..92ab410 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -936,6 +936,15 @@
}
}
+ // Make sure to merge the damage rect from the frame we're about
+ // to drop into the new frame's damage rect.
+ if (last.mSurfaceDamage.bounds() == Rect::INVALID_RECT ||
+ item.mSurfaceDamage.bounds() == Rect::INVALID_RECT) {
+ item.mSurfaceDamage = Region::INVALID_REGION;
+ } else {
+ item.mSurfaceDamage |= last.mSurfaceDamage;
+ }
+
// Overwrite the droppable buffer with the incoming one
mCore->mQueue.editItemAt(mCore->mQueue.size() - 1) = item;
frameReplacedListener = mCore->mConsumerListener;
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index e6eb327..9fe5de8 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1920,7 +1920,8 @@
return OK;
}
-status_t Surface::attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer) {
+status_t Surface::attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer,
+ Dataspace dataspace) {
if (buffer == nullptr) {
return BAD_VALUE;
}
@@ -1929,6 +1930,11 @@
if (err != OK) {
return err;
}
+ ui::Dataspace tmpDataspace = surface->getBuffersDataSpace();
+ err = surface->setBuffersDataSpace(dataspace);
+ if (err != OK) {
+ return err;
+ }
err = surface->attachBuffer(buffer->getNativeBuffer());
if (err != OK) {
return err;
@@ -1937,6 +1943,10 @@
if (err != OK) {
return err;
}
+ err = surface->setBuffersDataSpace(tmpDataspace);
+ if (err != OK) {
+ return err;
+ }
err = surface->disconnect(NATIVE_WINDOW_API_CPU);
return err;
}
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index 0c471bb..5c6a1ee 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -292,7 +292,8 @@
ui::Dataspace getBuffersDataSpace();
- static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer);
+ static status_t attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer,
+ ui::Dataspace dataspace);
protected:
enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
diff --git a/libs/sensor/SensorManager.cpp b/libs/sensor/SensorManager.cpp
index 5840d51..96d5eb9 100644
--- a/libs/sensor/SensorManager.cpp
+++ b/libs/sensor/SensorManager.cpp
@@ -94,7 +94,7 @@
SensorManager::SensorManager(const String16& opPackageName)
: mSensorList(nullptr), mOpPackageName(opPackageName), mDirectConnectionHandle(1) {
- // okay we're not locked here, but it's not needed during construction
+ Mutex::Autolock _l(mLock);
assertStateLocked();
}
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index bda7e43..1318bc0 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1231,6 +1231,14 @@
if (parent != nullptr && parent->isHiddenByPolicy()) {
return true;
}
+ if (usingRelativeZ(LayerVector::StateSet::Drawing)) {
+ auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote();
+ if (zOrderRelativeOf != nullptr) {
+ if (zOrderRelativeOf->isHiddenByPolicy()) {
+ return true;
+ }
+ }
+ }
return s.flags & layer_state_t::eLayerHidden;
}
@@ -1612,7 +1620,7 @@
return mDrawingState.z;
}
-bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
+bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const {
const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
const State& state = useDrawing ? mDrawingState : mCurrentState;
return state.zOrderRelativeOf != nullptr;
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 6db6beb..ec7389e 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -826,7 +826,7 @@
protected:
// -----------------------------------------------------------------------
- bool usingRelativeZ(LayerVector::StateSet stateSet);
+ bool usingRelativeZ(LayerVector::StateSet stateSet) const;
bool mPremultipliedAlpha{true};
String8 mName;
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 72bbf5d..07fdead 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -44,11 +44,14 @@
enum class samplingStep {
noWorkNeeded,
idleTimerWaiting,
+ waitForQuietFrame,
waitForZeroPhase,
waitForSamplePhase,
sample
};
+constexpr auto timeForRegionSampling = 5000000ns;
+constexpr auto maxRegionSamplingSkips = 10;
constexpr auto defaultRegionSamplingOffset = -3ms;
constexpr auto defaultRegionSamplingPeriod = 100ms;
constexpr auto defaultRegionSamplingTimerTimeout = 100ms;
@@ -215,9 +218,9 @@
void RegionSamplingThread::checkForStaleLuma() {
std::lock_guard lock(mThreadControlMutex);
- if (mDiscardedFrames) {
+ if (mDiscardedFrames > 0) {
ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::waitForZeroPhase));
- mDiscardedFrames = false;
+ mDiscardedFrames = 0;
mPhaseCallback->startVsyncListener();
}
}
@@ -235,13 +238,25 @@
auto now = std::chrono::nanoseconds(systemTime(SYSTEM_TIME_MONOTONIC));
if (lastSampleTime + mTunables.mSamplingPeriod > now) {
ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::idleTimerWaiting));
- mDiscardedFrames = true;
+ if (mDiscardedFrames == 0) mDiscardedFrames++;
return;
}
+ if (mDiscardedFrames < maxRegionSamplingSkips) {
+ // If there is relatively little time left for surfaceflinger
+ // until the next vsync deadline, defer this sampling work
+ // to a later frame, when hopefully there will be more time.
+ DisplayStatInfo stats;
+ mScheduler.getDisplayStatInfo(&stats);
+ if (std::chrono::nanoseconds(stats.vsyncTime) - now < timeForRegionSampling) {
+ ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::waitForQuietFrame));
+ mDiscardedFrames++;
+ return;
+ }
+ }
ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::sample));
- mDiscardedFrames = false;
+ mDiscardedFrames = 0;
lastSampleTime = now;
mIdleTimer.reset();
diff --git a/services/surfaceflinger/RegionSamplingThread.h b/services/surfaceflinger/RegionSamplingThread.h
index 3c6fcf3..96ffe20 100644
--- a/services/surfaceflinger/RegionSamplingThread.h
+++ b/services/surfaceflinger/RegionSamplingThread.h
@@ -117,7 +117,7 @@
std::condition_variable_any mCondition;
bool mRunning GUARDED_BY(mThreadControlMutex) = true;
bool mSampleRequested GUARDED_BY(mThreadControlMutex) = false;
- bool mDiscardedFrames GUARDED_BY(mThreadControlMutex) = false;
+ uint32_t mDiscardedFrames GUARDED_BY(mThreadControlMutex) = 0;
std::chrono::nanoseconds lastSampleTime GUARDED_BY(mThreadControlMutex);
std::mutex mSamplingMutex;
diff --git a/services/surfaceflinger/Scheduler/DispSync.cpp b/services/surfaceflinger/Scheduler/DispSync.cpp
index 81be372..83fd42b 100644
--- a/services/surfaceflinger/Scheduler/DispSync.cpp
+++ b/services/surfaceflinger/Scheduler/DispSync.cpp
@@ -92,8 +92,12 @@
mPeriod = period;
if (!mModelLocked && referenceTimeChanged) {
for (auto& eventListener : mEventListeners) {
- eventListener.mLastEventTime =
- mReferenceTime - mPeriod + mPhase + eventListener.mPhase;
+ eventListener.mLastEventTime = mReferenceTime + mPhase + eventListener.mPhase;
+ // If mLastEventTime is after mReferenceTime (can happen when positive phase offsets
+ // are used) we treat it as like it happened in previous period.
+ if (eventListener.mLastEventTime > mReferenceTime) {
+ eventListener.mLastEventTime -= mPeriod;
+ }
}
}
if (mTraceDetailedInfo) {
diff --git a/services/surfaceflinger/Scheduler/DispSyncSource.cpp b/services/surfaceflinger/Scheduler/DispSyncSource.cpp
index 026b557..5faf46e 100644
--- a/services/surfaceflinger/Scheduler/DispSyncSource.cpp
+++ b/services/surfaceflinger/Scheduler/DispSyncSource.cpp
@@ -78,6 +78,10 @@
// Normalize phaseOffset to [-period, period)
const int numPeriods = phaseOffset / period;
phaseOffset -= numPeriods * period;
+ if (mPhaseOffset == phaseOffset) {
+ return;
+ }
+
mPhaseOffset = phaseOffset;
tracePhaseOffset();
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index e762af3..f80c233 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -46,11 +46,13 @@
LayerHistory::~LayerHistory() = default;
std::unique_ptr<LayerHistory::LayerHandle> LayerHistory::createLayer(const std::string name,
+ float minRefreshRate,
float maxRefreshRate) {
const int64_t id = sNextId++;
std::lock_guard lock(mLock);
- mInactiveLayerInfos.emplace(id, std::make_shared<LayerInfo>(name, maxRefreshRate));
+ mInactiveLayerInfos.emplace(id,
+ std::make_shared<LayerInfo>(name, minRefreshRate, maxRefreshRate));
return std::make_unique<LayerHistory::LayerHandle>(*this, id);
}
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.h b/services/surfaceflinger/Scheduler/LayerHistory.h
index 2569b46..5598cc1 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.h
+++ b/services/surfaceflinger/Scheduler/LayerHistory.h
@@ -53,7 +53,8 @@
~LayerHistory();
// When the layer is first created, register it.
- std::unique_ptr<LayerHandle> createLayer(const std::string name, float maxRefreshRate);
+ std::unique_ptr<LayerHandle> createLayer(const std::string name, float minRefreshRate,
+ float maxRefreshRate);
// Method for inserting layers and their requested present time into the unordered map.
void insert(const std::unique_ptr<LayerHandle>& layerHandle, nsecs_t presentTime, bool isHdr);
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp
index 3104724..e782dd5 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.cpp
+++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp
@@ -24,9 +24,10 @@
namespace android {
namespace scheduler {
-LayerInfo::LayerInfo(const std::string name, float maxRefreshRate)
+LayerInfo::LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate)
: mName(name),
mMinRefreshDuration(1e9f / maxRefreshRate),
+ mLowActivityRefreshDuration(1e9f / minRefreshRate),
mRefreshRateHistory(mMinRefreshDuration) {}
LayerInfo::~LayerInfo() = default;
@@ -47,9 +48,10 @@
const nsecs_t timeDiff = lastPresentTime - mLastPresentTime;
mLastPresentTime = lastPresentTime;
// Ignore time diff that are too high - those are stale values
- if (timeDiff > TIME_EPSILON_NS.count()) return;
+ if (timeDiff > OBSOLETE_TIME_EPSILON_NS.count()) return;
const nsecs_t refreshDuration = (timeDiff > 0) ? timeDiff : mMinRefreshDuration;
- mRefreshRateHistory.insertRefreshRate(refreshDuration);
+ const int fps = 1e9f / refreshDuration;
+ mRefreshRateHistory.insertRefreshRate(fps);
}
} // namespace scheduler
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.h b/services/surfaceflinger/Scheduler/LayerInfo.h
index 90d4269..66df9dc 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.h
+++ b/services/surfaceflinger/Scheduler/LayerInfo.h
@@ -46,7 +46,7 @@
public:
explicit RefreshRateHistory(nsecs_t minRefreshDuration)
: mMinRefreshDuration(minRefreshDuration) {}
- void insertRefreshRate(nsecs_t refreshRate) {
+ void insertRefreshRate(int refreshRate) {
mElements.push_back(refreshRate);
if (mElements.size() > HISTORY_SIZE) {
mElements.pop_front();
@@ -54,13 +54,13 @@
}
float getRefreshRateAvg() const {
- nsecs_t refreshDuration = mMinRefreshDuration;
- if (mElements.size() > 0) {
- refreshDuration = scheduler::calculate_mean(mElements);
+ if (mElements.empty()) {
+ return 1e9f / mMinRefreshDuration;
}
- return 1e9f / refreshDuration;
+ return scheduler::calculate_mean(mElements);
}
+
void clearHistory() { mElements.clear(); }
private:
@@ -96,8 +96,9 @@
return false;
}
- // The last update should not be older than TIME_EPSILON_NS nanoseconds.
- const int64_t obsoleteEpsilon = systemTime() - scheduler::TIME_EPSILON_NS.count();
+ // The last update should not be older than OBSOLETE_TIME_EPSILON_NS nanoseconds.
+ const int64_t obsoleteEpsilon =
+ systemTime() - scheduler::OBSOLETE_TIME_EPSILON_NS.count();
if (mElements.at(mElements.size() - 1) < obsoleteEpsilon) {
return false;
}
@@ -105,6 +106,25 @@
return true;
}
+ bool isLowActivityLayer() const {
+ // We want to make sure that we received more than two frames from the layer
+ // in order to check low activity.
+ if (mElements.size() < 2) {
+ return false;
+ }
+
+ const int64_t obsoleteEpsilon =
+ systemTime() - scheduler::LOW_ACTIVITY_EPSILON_NS.count();
+ // Check the frame before last to determine whether there is low activity.
+ // If that frame is older than LOW_ACTIVITY_EPSILON_NS, the layer is sending
+ // infrequent updates.
+ if (mElements.at(mElements.size() - 2) < obsoleteEpsilon) {
+ return true;
+ }
+
+ return false;
+ }
+
void clearHistory() { mElements.clear(); }
private:
@@ -114,7 +134,7 @@
};
public:
- LayerInfo(const std::string name, float maxRefreshRate);
+ LayerInfo(const std::string name, float minRefreshRate, float maxRefreshRate);
~LayerInfo();
LayerInfo(const LayerInfo&) = delete;
@@ -144,6 +164,10 @@
// Calculate the average refresh rate.
float getDesiredRefreshRate() const {
std::lock_guard lock(mLock);
+
+ if (mPresentTimeHistory.isLowActivityLayer()) {
+ return 1e9f / mLowActivityRefreshDuration;
+ }
return mRefreshRateHistory.getRefreshRateAvg();
}
@@ -175,6 +199,7 @@
private:
const std::string mName;
const nsecs_t mMinRefreshDuration;
+ const nsecs_t mLowActivityRefreshDuration;
mutable std::mutex mLock;
nsecs_t mLastUpdatedTime GUARDED_BY(mLock) = 0;
nsecs_t mLastPresentTime GUARDED_BY(mLock) = 0;
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index bb24f73..cfdbd91 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -330,8 +330,11 @@
: RefreshRateType::PERFORMANCE;
const auto refreshRate = mRefreshRateConfigs.getRefreshRate(refreshRateType);
- const uint32_t fps = (refreshRate) ? refreshRate->fps : 0;
- return mLayerHistory.createLayer(name, fps);
+ const uint32_t performanceFps = (refreshRate) ? refreshRate->fps : 0;
+
+ const auto defaultRefreshRate = mRefreshRateConfigs.getRefreshRate(RefreshRateType::DEFAULT);
+ const uint32_t defaultFps = (defaultRefreshRate) ? defaultRefreshRate->fps : 0;
+ return mLayerHistory.createLayer(name, defaultFps, performanceFps);
}
void Scheduler::addLayerPresentTimeAndHDR(
@@ -520,22 +523,19 @@
return RefreshRateType::PERFORMANCE;
}
- // Content detection is on, find the appropriate refresh rate
- // Start with the smallest refresh rate which is within a margin of the content
- RefreshRateType currRefreshRateType = RefreshRateType::PERFORMANCE;
- constexpr float MARGIN = 0.05f;
- auto iter = mRefreshRateConfigs.getRefreshRates().cbegin();
- while (iter != mRefreshRateConfigs.getRefreshRates().cend()) {
- if (iter->second->fps >= mContentRefreshRate * (1 - MARGIN)) {
- currRefreshRateType = iter->first;
- break;
- }
- ++iter;
- }
+ // Content detection is on, find the appropriate refresh rate with minimal error
+ auto iter = min_element(mRefreshRateConfigs.getRefreshRates().cbegin(),
+ mRefreshRateConfigs.getRefreshRates().cend(),
+ [rate = mContentRefreshRate](const auto& l, const auto& r) -> bool {
+ return std::abs(l.second->fps - static_cast<float>(rate)) <
+ std::abs(r.second->fps - static_cast<float>(rate));
+ });
+ RefreshRateType currRefreshRateType = iter->first;
// Some content aligns better on higher refresh rate. For example for 45fps we should choose
// 90Hz config. However we should still prefer a lower refresh rate if the content doesn't
// align well with both
+ constexpr float MARGIN = 0.05f;
float ratio = mRefreshRateConfigs.getRefreshRate(currRefreshRateType)->fps /
float(mContentRefreshRate);
if (std::abs(std::round(ratio) - ratio) > MARGIN) {
diff --git a/services/surfaceflinger/Scheduler/SchedulerUtils.h b/services/surfaceflinger/Scheduler/SchedulerUtils.h
index d3b1bd0..ced1899 100644
--- a/services/surfaceflinger/Scheduler/SchedulerUtils.h
+++ b/services/surfaceflinger/Scheduler/SchedulerUtils.h
@@ -36,13 +36,16 @@
static constexpr int SCREEN_OFF_CONFIG_ID = -1;
static constexpr uint32_t HWC2_SCREEN_OFF_CONFIG_ID = 0xffffffff;
-// This number is used when we try to determine how long does a given layer stay relevant.
-// The value is set based on testing different scenarios.
-static constexpr std::chrono::nanoseconds TIME_EPSILON_NS = 200ms;
-
// This number is used when we try to determine how long do we keep layer information around
-// before we remove it.
-static constexpr std::chrono::nanoseconds OBSOLETE_TIME_EPSILON_NS = 200ms;
+// before we remove it. It is also used to determine how long the layer stays relevant.
+// This time period captures infrequent updates when playing YouTube video with static image,
+// or waiting idle in messaging app, when cursor is blinking.
+static constexpr std::chrono::nanoseconds OBSOLETE_TIME_EPSILON_NS = 1200ms;
+
+// Layer is considered low activity if the buffers come more than LOW_ACTIVITY_EPSILON_NS
+// apart. This is helping SF to vote for lower refresh rates when there is not activity
+// in screen.
+static constexpr std::chrono::nanoseconds LOW_ACTIVITY_EPSILON_NS = 250ms;
// Calculates the statistical mean (average) in the data structure (array, vector). The
// function does not modify the contents of the array.
diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.cpp b/services/surfaceflinger/Scheduler/VSyncModulator.cpp
index 381308a..7a3bf8e 100644
--- a/services/surfaceflinger/Scheduler/VSyncModulator.cpp
+++ b/services/surfaceflinger/Scheduler/VSyncModulator.cpp
@@ -102,7 +102,7 @@
VSyncModulator::Offsets VSyncModulator::getOffsets() {
std::lock_guard<std::mutex> lock(mMutex);
- return mOffsetMap.at(mOffsetType);
+ return mOffsets;
}
VSyncModulator::Offsets VSyncModulator::getNextOffsets() {
@@ -129,50 +129,36 @@
void VSyncModulator::updateOffsetsLocked() {
const Offsets desired = getNextOffsets();
- const Offsets current = mOffsetMap.at(mOffsetType);
- bool changed = false;
- if (desired.sf != current.sf) {
- if (mSfConnectionHandle != nullptr) {
- mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf);
- } else {
- mSfEventThread->setPhaseOffset(desired.sf);
- }
- changed = true;
- }
- if (desired.app != current.app) {
- if (mAppConnectionHandle != nullptr) {
- mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app);
- } else {
- mAppEventThread->setPhaseOffset(desired.app);
- }
- changed = true;
+ if (mSfConnectionHandle != nullptr) {
+ mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf);
}
- if (changed) {
- updateOffsetType();
+ if (mAppConnectionHandle != nullptr) {
+ mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app);
}
+
+ flushOffsets();
}
-void VSyncModulator::updateOffsetType() {
- mOffsetType = getNextOffsetType();
+void VSyncModulator::flushOffsets() {
+ OffsetType type = getNextOffsetType();
+ mOffsets = mOffsetMap.at(type);
if (!mTraceDetailedInfo) {
return;
}
- OffsetType type = mOffsetType;
- Offsets offsets = mOffsetMap.at(type);
ATRACE_INT("Vsync-EarlyOffsetsOn",
- offsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::Early);
+ mOffsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::Early);
ATRACE_INT("Vsync-EarlyGLOffsetsOn",
- offsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::EarlyGl);
+ mOffsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::EarlyGl);
ATRACE_INT("Vsync-LateOffsetsOn",
- offsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::Late);
+ mOffsets.fpsMode == RefreshRateType::DEFAULT && type == OffsetType::Late);
ATRACE_INT("Vsync-HighFpsEarlyOffsetsOn",
- offsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::Early);
+ mOffsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::Early);
ATRACE_INT("Vsync-HighFpsEarlyGLOffsetsOn",
- offsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::EarlyGl);
+ mOffsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::EarlyGl);
ATRACE_INT("Vsync-HighFpsLateOffsetsOn",
- offsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::Late);
+ mOffsets.fpsMode == RefreshRateType::PERFORMANCE && type == OffsetType::Late);
}
} // namespace android
diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.h b/services/surfaceflinger/Scheduler/VSyncModulator.h
index c6374be..ddbd221 100644
--- a/services/surfaceflinger/Scheduler/VSyncModulator.h
+++ b/services/surfaceflinger/Scheduler/VSyncModulator.h
@@ -68,12 +68,6 @@
void setPhaseOffsets(Offsets early, Offsets earlyGl, Offsets late,
nsecs_t thresholdForNextVsync) EXCLUDES(mMutex);
- // Sets handles to the SF and app event threads.
- void setEventThreads(EventThread* sfEventThread, EventThread* appEventThread) {
- mSfEventThread = sfEventThread;
- mAppEventThread = appEventThread;
- }
-
// Sets the scheduler and vsync connection handlers.
void setSchedulerAndHandles(Scheduler* scheduler,
Scheduler::ConnectionHandle* appConnectionHandle,
@@ -114,21 +108,18 @@
// Updates offsets and persists them into the scheduler framework.
void updateOffsets() EXCLUDES(mMutex);
void updateOffsetsLocked() REQUIRES(mMutex);
- // Updates the internal offset type.
- void updateOffsetType() REQUIRES(mMutex);
+ // Updates the internal offsets and offset type.
+ void flushOffsets() REQUIRES(mMutex);
mutable std::mutex mMutex;
std::unordered_map<OffsetType, Offsets> mOffsetMap GUARDED_BY(mMutex);
nsecs_t mThresholdForNextVsync;
- EventThread* mSfEventThread = nullptr;
- EventThread* mAppEventThread = nullptr;
-
Scheduler* mScheduler = nullptr;
Scheduler::ConnectionHandle* mAppConnectionHandle = nullptr;
Scheduler::ConnectionHandle* mSfConnectionHandle = nullptr;
- OffsetType mOffsetType GUARDED_BY(mMutex) = OffsetType::Late;
+ Offsets mOffsets GUARDED_BY(mMutex) = {Scheduler::RefreshRateType::DEFAULT, 0, 0};
std::atomic<Scheduler::TransactionStart> mTransactionStart =
Scheduler::TransactionStart::NORMAL;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 60c6e4e..94eeef5 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -311,6 +311,9 @@
wideColorGamutCompositionPixelFormat =
static_cast<ui::PixelFormat>(wcg_composition_pixel_format(ui::PixelFormat::RGBA_8888));
+ mColorSpaceAgnosticDataspace =
+ static_cast<ui::Dataspace>(color_space_agnostic_dataspace(Dataspace::UNKNOWN));
+
useContextPriority = use_context_priority(true);
auto tmpPrimaryDisplayOrientation = primary_display_orientation(
@@ -1879,7 +1882,14 @@
RenderIntent renderIntent;
pickColorMode(displayDevice, &colorMode, &targetDataspace, &renderIntent);
display->setColorMode(colorMode, targetDataspace, renderIntent);
+
+ if (isHdrColorMode(colorMode)) {
+ targetDataspace = Dataspace::UNKNOWN;
+ } else if (mColorSpaceAgnosticDataspace != Dataspace::UNKNOWN) {
+ targetDataspace = mColorSpaceAgnosticDataspace;
+ }
}
+
for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
if (layer->isHdrY410()) {
layer->forceClientComposition(displayDevice);
@@ -1906,9 +1916,7 @@
const auto& displayState = display->getState();
layer->setPerFrameData(displayDevice, displayState.transform, displayState.viewport,
- displayDevice->getSupportedPerFrameMetadata(),
- isHdrColorMode(displayState.colorMode) ? Dataspace::UNKNOWN
- : targetDataspace);
+ displayDevice->getSupportedPerFrameMetadata(), targetDataspace);
}
}
@@ -4699,6 +4707,16 @@
StringAppendF(&result, "Scheduler enabled.");
StringAppendF(&result, "+ Smart 90 for video detection: %s\n\n",
mUseSmart90ForVideo ? "on" : "off");
+ StringAppendF(&result, "Allowed Display Configs: ");
+ for (int32_t configId : mAllowedDisplayConfigs) {
+ for (auto refresh : mRefreshRateConfigs.getRefreshRates()) {
+ if (refresh.second && refresh.second->configId == configId) {
+ StringAppendF(&result, "%dHz, ", refresh.second->fps);
+ }
+ }
+ }
+ StringAppendF(&result, "(config override by backdoor: %s)\n\n",
+ mDebugDisplayConfigSetByBackdoor ? "yes" : "no");
mScheduler->dump(mAppConnectionHandle, result);
}
@@ -5665,6 +5683,11 @@
captureOrientation = fromSurfaceComposerRotation(
static_cast<ISurfaceComposer::Rotation>(display->getOrientation()));
+ if (captureOrientation == ui::Transform::orientation_flags::ROT_90) {
+ captureOrientation = ui::Transform::orientation_flags::ROT_270;
+ } else if (captureOrientation == ui::Transform::orientation_flags::ROT_270) {
+ captureOrientation = ui::Transform::orientation_flags::ROT_90;
+ }
*outDataspace =
pickDataspaceFromColorMode(display->getCompositionDisplay()->getState().colorMode);
}
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6d4b2d7..556a4b9 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -1115,6 +1115,7 @@
ui::Dataspace mDefaultCompositionDataspace;
ui::Dataspace mWideColorGamutCompositionDataspace;
+ ui::Dataspace mColorSpaceAgnosticDataspace;
SurfaceFlingerBE mBE;
std::unique_ptr<compositionengine::CompositionEngine> mCompositionEngine;
diff --git a/services/surfaceflinger/SurfaceFlingerProperties.cpp b/services/surfaceflinger/SurfaceFlingerProperties.cpp
index 2b33ba1..237208d 100644
--- a/services/surfaceflinger/SurfaceFlingerProperties.cpp
+++ b/services/surfaceflinger/SurfaceFlingerProperties.cpp
@@ -218,6 +218,14 @@
return static_cast<int32_t>(defaultValue);
}
+int64_t color_space_agnostic_dataspace(Dataspace defaultValue) {
+ auto temp = SurfaceFlingerProperties::color_space_agnostic_dataspace();
+ if (temp.has_value()) {
+ return *temp;
+ }
+ return static_cast<int64_t>(defaultValue);
+}
+
int32_t set_idle_timer_ms(int32_t defaultValue) {
auto temp = SurfaceFlingerProperties::set_idle_timer_ms();
if (temp.has_value()) {
diff --git a/services/surfaceflinger/SurfaceFlingerProperties.h b/services/surfaceflinger/SurfaceFlingerProperties.h
index 1964ccd..b5418d6 100644
--- a/services/surfaceflinger/SurfaceFlingerProperties.h
+++ b/services/surfaceflinger/SurfaceFlingerProperties.h
@@ -70,6 +70,9 @@
int32_t wcg_composition_pixel_format(
android::hardware::graphics::common::V1_2::PixelFormat defaultValue);
+int64_t color_space_agnostic_dataspace(
+ android::hardware::graphics::common::V1_2::Dataspace defaultValue);
+
int32_t set_idle_timer_ms(int32_t defaultValue);
int32_t set_touch_timer_ms(int32_t defaultValue);
diff --git a/services/surfaceflinger/TransactionCompletedThread.cpp b/services/surfaceflinger/TransactionCompletedThread.cpp
index 5cf8eb1..fd466de 100644
--- a/services/surfaceflinger/TransactionCompletedThread.cpp
+++ b/services/surfaceflinger/TransactionCompletedThread.cpp
@@ -197,8 +197,14 @@
}
transactionStats->latchTime = handle->latchTime;
- transactionStats->surfaceStats.emplace_back(handle->surfaceControl, handle->acquireTime,
- handle->previousReleaseFence);
+ // If the layer has already been destroyed, don't add the SurfaceControl to the callback.
+ // The client side keeps a sp<> to the SurfaceControl so if the SurfaceControl has been
+ // destroyed the client side is dead and there won't be anyone to send the callback to.
+ sp<IBinder> surfaceControl = handle->surfaceControl.promote();
+ if (surfaceControl) {
+ transactionStats->surfaceStats.emplace_back(surfaceControl, handle->acquireTime,
+ handle->previousReleaseFence);
+ }
return NO_ERROR;
}
diff --git a/services/surfaceflinger/TransactionCompletedThread.h b/services/surfaceflinger/TransactionCompletedThread.h
index 21e2678..e849f71 100644
--- a/services/surfaceflinger/TransactionCompletedThread.h
+++ b/services/surfaceflinger/TransactionCompletedThread.h
@@ -49,7 +49,7 @@
sp<ITransactionCompletedListener> listener;
std::vector<CallbackId> callbackIds;
- sp<IBinder> surfaceControl;
+ wp<IBinder> surfaceControl;
bool releasePreviousBuffer = false;
sp<Fence> previousReleaseFence;
diff --git a/services/surfaceflinger/sysprop/SurfaceFlingerProperties.sysprop b/services/surfaceflinger/sysprop/SurfaceFlingerProperties.sysprop
index decabd5..f18f33c 100644
--- a/services/surfaceflinger/sysprop/SurfaceFlingerProperties.sysprop
+++ b/services/surfaceflinger/sysprop/SurfaceFlingerProperties.sysprop
@@ -251,6 +251,20 @@
prop_name: "ro.surface_flinger.wcg_composition_pixel_format"
}
+# colorSpaceAgnosticDataspace specifies the data space that
+# SurfaceFlinger expects for surfaces which are color space agnostic.
+# The variable works only when useColorManagement is specified. If
+# unspecified, the data space follows what SurfaceFlinger expects for
+# surfaces when useColorManagement is specified.
+
+prop {
+ api_name: "color_space_agnostic_dataspace"
+ type: Long
+ scope: System
+ access: Readonly
+ prop_name: "ro.surface_flinger.color_space_agnostic_dataspace"
+}
+
# Return the native panel primary data. The data includes red, green,
# blue and white. The primary format is CIE 1931 XYZ color space.
# If unspecified, the primaries is sRGB gamut by default.
diff --git a/services/surfaceflinger/sysprop/api/system-current.txt b/services/surfaceflinger/sysprop/api/system-current.txt
index 6ae3ac1..89323c2 100644
--- a/services/surfaceflinger/sysprop/api/system-current.txt
+++ b/services/surfaceflinger/sysprop/api/system-current.txt
@@ -2,6 +2,7 @@
package android.sysprop {
public final class SurfaceFlingerProperties {
+ method public static java.util.Optional<java.lang.Long> color_space_agnostic_dataspace();
method public static java.util.Optional<java.lang.Long> default_composition_dataspace();
method public static java.util.Optional<java.lang.Integer> default_composition_pixel_format();
method public static java.util.List<java.lang.Double> display_primary_blue();
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index f83b3ea..d5f6534 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -1115,6 +1115,56 @@
}
}
+TEST_P(LayerTypeTransactionTest, HideRelativeParentHidesLayer) {
+ sp<SurfaceControl> parent =
+ LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */,
+ ISurfaceComposerClient::eFXSurfaceColor);
+ sp<SurfaceControl> relativeParent =
+ LayerTransactionTest::createLayer("RelativeParent", 0 /* buffer width */,
+ 0 /* buffer height */, ISurfaceComposerClient::eFXSurfaceColor);
+
+ sp<SurfaceControl> childLayer;
+ ASSERT_NO_FATAL_FAILURE(
+ childLayer = LayerTransactionTest::createLayer("childLayer", 0 /* buffer width */,
+ 0 /* buffer height */,
+ ISurfaceComposerClient::eFXSurfaceColor,
+ parent.get()));
+ Transaction()
+ .setColor(childLayer, half3{1.0f, 0.0f, 0.0f})
+ .setColor(parent, half3{0.0f, 0.0f, 0.0f})
+ .setColor(relativeParent, half3{0.0f, 1.0f, 0.0f})
+ .show(childLayer)
+ .show(parent)
+ .show(relativeParent)
+ .setLayer(parent, mLayerZBase - 1)
+ .setLayer(relativeParent, mLayerZBase)
+ .apply();
+
+ Transaction()
+ .setRelativeLayer(childLayer, relativeParent->getHandle(), 1)
+ .apply();
+
+ {
+ SCOPED_TRACE("setLayer above");
+ // Set layer should get applied and place the child above.
+ std::unique_ptr<ScreenCapture> screenshot;
+ ScreenCapture::captureScreen(&screenshot);
+ screenshot->expectColor(Rect(0, 0, 20, 30), Color::RED);
+ }
+
+ Transaction()
+ .hide(relativeParent)
+ .apply();
+
+ {
+ SCOPED_TRACE("hide relative parent");
+ // The relative should no longer be visible.
+ std::unique_ptr<ScreenCapture> screenshot;
+ ScreenCapture::captureScreen(&screenshot);
+ screenshot->expectColor(Rect(0, 0, 20, 30), Color::BLACK);
+ }
+}
+
void LayerRenderTypeTransactionTest::setRelativeZGroupHelper(uint32_t layerType) {
sp<SurfaceControl> layerR;
sp<SurfaceControl> layerG;
diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
index 2b1dfa8..7ec9066 100644
--- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
@@ -25,6 +25,7 @@
protected:
std::unique_ptr<LayerHistory> mLayerHistory;
+ static constexpr float MIN_REFRESH_RATE = 30.f;
static constexpr float MAX_REFRESH_RATE = 90.f;
};
@@ -36,7 +37,7 @@
namespace {
TEST_F(LayerHistoryTest, oneLayer) {
std::unique_ptr<LayerHistory::LayerHandle> testLayer =
- mLayerHistory->createLayer("TestLayer", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("TestLayer", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(testLayer, true);
mLayerHistory->insert(testLayer, 0, false /*isHDR*/);
@@ -60,7 +61,7 @@
TEST_F(LayerHistoryTest, oneHDRLayer) {
std::unique_ptr<LayerHistory::LayerHandle> testLayer =
- mLayerHistory->createLayer("TestHDRLayer", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("TestHDRLayer", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(testLayer, true);
mLayerHistory->insert(testLayer, 0, true /*isHDR*/);
@@ -74,7 +75,7 @@
TEST_F(LayerHistoryTest, explicitTimestamp) {
std::unique_ptr<LayerHistory::LayerHandle> test30FpsLayer =
- mLayerHistory->createLayer("30FpsLayer", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("30FpsLayer", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(test30FpsLayer, true);
nsecs_t startTime = systemTime();
@@ -87,13 +88,13 @@
TEST_F(LayerHistoryTest, multipleLayers) {
std::unique_ptr<LayerHistory::LayerHandle> testLayer =
- mLayerHistory->createLayer("TestLayer", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("TestLayer", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(testLayer, true);
std::unique_ptr<LayerHistory::LayerHandle> test30FpsLayer =
- mLayerHistory->createLayer("30FpsLayer", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("30FpsLayer", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(test30FpsLayer, true);
std::unique_ptr<LayerHistory::LayerHandle> testLayer2 =
- mLayerHistory->createLayer("TestLayer2", MAX_REFRESH_RATE);
+ mLayerHistory->createLayer("TestLayer2", MIN_REFRESH_RATE, MAX_REFRESH_RATE);
mLayerHistory->setVisibility(testLayer2, true);
nsecs_t startTime = systemTime();
@@ -119,8 +120,8 @@
mLayerHistory->insert(testLayer2, 0, false /*isHDR*/);
}
EXPECT_FLOAT_EQ(MAX_REFRESH_RATE, mLayerHistory->getDesiredRefreshRateAndHDR().first);
- // After 100 ms frames become obsolete.
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
+ // After 1200 ms frames become obsolete.
+ std::this_thread::sleep_for(std::chrono::milliseconds(1500));
// Insert the 31st frame.
mLayerHistory->insert(test30FpsLayer, startTime + (30 * 33333333), false /*isHDR*/);
EXPECT_FLOAT_EQ(30.f, mLayerHistory->getDesiredRefreshRateAndHDR().first);