summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2020-01-13 17:32:31 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-01-13 17:32:31 +0000
commit75bdb2e8aa7dc82c43d1afbc6e233cfe7fd7d2db (patch)
treea057623efed07838f4bd82a26926425781dc439d
parent3ea3c1197fb1142775dda88ed5eedb9fef3d02a0 (diff)
parente3ed2f91ae8ce539800f2eb3c63a7ff59c646723 (diff)
Merge "SurfaceFlinger: Make LayerHistory virtual class"
-rw-r--r--services/surfaceflinger/Scheduler/LayerHistory.cpp4
-rw-r--r--services/surfaceflinger/Scheduler/LayerHistory.h39
-rw-r--r--services/surfaceflinger/Scheduler/Scheduler.cpp4
-rw-r--r--services/surfaceflinger/Scheduler/Scheduler.h2
-rw-r--r--services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp4
-rw-r--r--services/surfaceflinger/tests/unittests/TestableScheduler.h10
6 files changed, 42 insertions, 21 deletions
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index 146ec1bce0..cf79d9fcf7 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -34,7 +34,7 @@
#include "LayerInfo.h"
#include "SchedulerUtils.h"
-namespace android::scheduler {
+namespace android::scheduler::impl {
namespace {
@@ -157,4 +157,4 @@ void LayerHistory::clear() {
mActiveLayersEnd = 0;
}
-} // namespace android::scheduler
+} // namespace android::scheduler::impl
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.h b/services/surfaceflinger/Scheduler/LayerHistory.h
index 745c4c16ee..d92e5c3136 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.h
+++ b/services/surfaceflinger/Scheduler/LayerHistory.h
@@ -32,33 +32,51 @@ class TestableScheduler;
namespace scheduler {
+class LayerHistoryTest;
class LayerInfo;
-// Records per-layer history of scheduling-related information (primarily present time),
-// heuristically categorizes layers as active or inactive, and summarizes stats about
-// active layers (primarily maximum refresh rate). See go/content-fps-detection-in-scheduler.
class LayerHistory {
public:
- LayerHistory();
- ~LayerHistory();
+ virtual ~LayerHistory() = default;
// Layers are unregistered when the weak reference expires.
- void registerLayer(Layer*, float lowRefreshRate, float highRefreshRate);
+ virtual void registerLayer(Layer*, float lowRefreshRate, float highRefreshRate) = 0;
// Marks the layer as active, and records the given state to its history.
- void record(Layer*, nsecs_t presentTime, nsecs_t now);
+ virtual void record(Layer*, nsecs_t presentTime, nsecs_t now) = 0;
struct Summary {
float maxRefreshRate; // Maximum refresh rate among recently active layers.
};
// Rebuilds sets of active/inactive layers, and accumulates stats for active layers.
- Summary summarize(nsecs_t now);
+ virtual Summary summarize(nsecs_t now) = 0;
+
+ virtual void clear() = 0;
+};
+
+namespace impl {
+// Records per-layer history of scheduling-related information (primarily present time),
+// heuristically categorizes layers as active or inactive, and summarizes stats about
+// active layers (primarily maximum refresh rate). See go/content-fps-detection-in-scheduler.
+class LayerHistory : public android::scheduler::LayerHistory {
+public:
+ LayerHistory();
+ virtual ~LayerHistory();
+
+ // Layers are unregistered when the weak reference expires.
+ void registerLayer(Layer*, float lowRefreshRate, float highRefreshRate) override;
+
+ // Marks the layer as active, and records the given state to its history.
+ void record(Layer*, nsecs_t presentTime, nsecs_t now) override;
+
+ // Rebuilds sets of active/inactive layers, and accumulates stats for active layers.
+ android::scheduler::LayerHistory::Summary summarize(nsecs_t now) override;
- void clear();
+ void clear() override;
private:
- friend class LayerHistoryTest;
+ friend class android::scheduler::LayerHistoryTest;
friend TestableScheduler;
using LayerPair = std::pair<wp<Layer>, std::unique_ptr<LayerInfo>>;
@@ -90,5 +108,6 @@ private:
const bool mTraceEnabled;
};
+} // namespace impl
} // namespace scheduler
} // namespace android
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index ff9cf86604..73dc753c7e 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -108,7 +108,7 @@ Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function,
using namespace sysprop;
if (property_get_bool("debug.sf.use_smart_90_for_video", 0) || use_smart_90_for_video(false)) {
- mLayerHistory.emplace();
+ mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
}
const int setIdleTimerMs = property_get_int32("debug.sf.set_idle_timer_ms", 0);
@@ -493,7 +493,7 @@ void Scheduler::dump(std::string& result) const {
const bool supported = mRefreshRateConfigs.refreshRateSwitchingSupported();
StringAppendF(&result, "+ Refresh rate switching: %s\n", states[supported]);
- StringAppendF(&result, "+ Content detection: %s\n", states[mLayerHistory.has_value()]);
+ StringAppendF(&result, "+ Content detection: %s\n", states[mLayerHistory != nullptr]);
StringAppendF(&result, "+ Idle timer: %s\n",
mIdleTimer ? mIdleTimer->dump().c_str() : states[0]);
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 2cdb757f42..c6430c30f5 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -193,7 +193,7 @@ private:
std::unique_ptr<EventControlThread> mEventControlThread;
// Used to choose refresh rate if content detection is enabled.
- std::optional<scheduler::LayerHistory> mLayerHistory;
+ std::unique_ptr<scheduler::LayerHistory> mLayerHistory;
// Whether to use idle timer callbacks that support the kernel timer.
const bool mSupportKernelTimer;
diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
index d95252b67f..f055fe72ac 100644
--- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp
@@ -29,8 +29,8 @@ protected:
LayerHistoryTest() { mFlinger.resetScheduler(mScheduler); }
- LayerHistory& history() { return *mScheduler->mutableLayerHistory(); }
- const LayerHistory& history() const { return *mScheduler->mutableLayerHistory(); }
+ impl::LayerHistory& history() { return *mScheduler->mutableLayerHistory(); }
+ const impl::LayerHistory& history() const { return *mScheduler->mutableLayerHistory(); }
size_t layerCount() const { return mScheduler->layerHistorySize(); }
size_t activeLayerCount() const NO_THREAD_SAFETY_ANALYSIS { return history().mActiveLayersEnd; }
diff --git a/services/surfaceflinger/tests/unittests/TestableScheduler.h b/services/surfaceflinger/tests/unittests/TestableScheduler.h
index fa095aa916..a67c24c2d6 100644
--- a/services/surfaceflinger/tests/unittests/TestableScheduler.h
+++ b/services/surfaceflinger/tests/unittests/TestableScheduler.h
@@ -30,14 +30,14 @@ class TestableScheduler : public Scheduler, private ISchedulerCallback {
public:
explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs)
: Scheduler([](bool) {}, configs, *this) {
- mLayerHistory.emplace();
+ mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
}
TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
std::unique_ptr<EventControlThread> eventControlThread,
const scheduler::RefreshRateConfigs& configs)
: Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs, *this) {
- mLayerHistory.emplace();
+ mLayerHistory = std::make_unique<scheduler::impl::LayerHistory>();
}
// Used to inject mock event thread.
@@ -46,7 +46,7 @@ public:
}
size_t layerHistorySize() const NO_THREAD_SAFETY_ANALYSIS {
- return mLayerHistory->mLayerInfos.size();
+ return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get())->mLayerInfos.size();
}
/* ------------------------------------------------------------------------
@@ -57,7 +57,9 @@ public:
auto& mutableEventControlThread() { return mEventControlThread; }
auto& mutablePrimaryDispSync() { return mPrimaryDispSync; }
auto& mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
- auto& mutableLayerHistory() { return mLayerHistory; }
+ auto mutableLayerHistory() {
+ return static_cast<scheduler::impl::LayerHistory*>(mLayerHistory.get());
+ }
~TestableScheduler() {
// All these pointer and container clears help ensure that GMock does