[SurfaceFlinger] Allow DispSync to be GMock'd
Move the DispSync implementation into an 'impl' namespace to match the
other GMock related changes I've done. The DispSync in the previous
namespace is now the abstract interface.
SurfaceFlinger is adjusted slightly to create an instance of the
impl::DispSync, but store it in a std::unique_ptr<DispSync> for the
abstract class, with small adjustments to the code to deference the now
pointer.
The existing display transaction unit test is updated to define the
GMock, inject one, and to set the call expectations for a few tests are
added to match how it was called.
Test: atest libsurfaceflinger_unittest
Bug: None
Change-Id: I91b38c5194dbf86a6f0b658f3ab9f227b54d5354
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 399fbd8..31e4444 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -264,7 +264,6 @@
mDebugInTransaction(0),
mLastTransactionTime(0),
mForceFullDamage(false),
- mPrimaryDispSync("PrimaryDispSync"),
mPrimaryHWVsyncEnabled(false),
mHWVsyncAvailable(false),
mHasPoweredOff(false),
@@ -325,7 +324,13 @@
}
ALOGV("Primary Display Orientation is set to %2d.", mPrimaryDisplayOrientation);
- mPrimaryDispSync.init(SurfaceFlinger::hasSyncFramework, SurfaceFlinger::dispSyncPresentTimeOffset);
+ // Note: We create a local temporary with the real DispSync implementation
+ // type temporarily so we can initialize it with the configured values,
+ // before storing it for more generic use using the interface type.
+ auto primaryDispSync = std::make_unique<impl::DispSync>("PrimaryDispSync");
+ primaryDispSync->init(SurfaceFlinger::hasSyncFramework,
+ SurfaceFlinger::dispSyncPresentTimeOffset);
+ mPrimaryDispSync = std::move(primaryDispSync);
// debugging stuff...
char value[PROPERTY_VALUE_MAX];
@@ -703,14 +708,14 @@
// start the EventThread
mEventThreadSource =
- std::make_unique<DispSyncSource>(&mPrimaryDispSync, SurfaceFlinger::vsyncPhaseOffsetNs,
- true, "app");
+ std::make_unique<DispSyncSource>(mPrimaryDispSync.get(),
+ SurfaceFlinger::vsyncPhaseOffsetNs, true, "app");
mEventThread = std::make_unique<impl::EventThread>(mEventThreadSource.get(),
[this] { resyncWithRateLimit(); },
impl::EventThread::InterceptVSyncsCallback(),
"appEventThread");
mSfEventThreadSource =
- std::make_unique<DispSyncSource>(&mPrimaryDispSync,
+ std::make_unique<DispSyncSource>(mPrimaryDispSync.get(),
SurfaceFlinger::sfVsyncPhaseOffsetNs, true, "sf");
mSFEventThread =
@@ -996,8 +1001,8 @@
// FIXME for now we always return stats for the primary display
memset(stats, 0, sizeof(*stats));
- stats->vsyncTime = mPrimaryDispSync.computeNextRefresh(0);
- stats->vsyncPeriod = mPrimaryDispSync.getPeriod();
+ stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0);
+ stats->vsyncPeriod = mPrimaryDispSync->getPeriod();
return NO_ERROR;
}
@@ -1295,7 +1300,7 @@
void SurfaceFlinger::enableHardwareVsync() {
Mutex::Autolock _l(mHWVsyncLock);
if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
- mPrimaryDispSync.beginResync();
+ mPrimaryDispSync->beginResync();
mEventControlThread->setVsyncEnabled(true);
mPrimaryHWVsyncEnabled = true;
}
@@ -1320,11 +1325,11 @@
const auto activeConfig = getHwComposer().getActiveConfig(displayId);
const nsecs_t period = activeConfig->getVsyncPeriod();
- mPrimaryDispSync.reset();
- mPrimaryDispSync.setPeriod(period);
+ mPrimaryDispSync->reset();
+ mPrimaryDispSync->setPeriod(period);
if (!mPrimaryHWVsyncEnabled) {
- mPrimaryDispSync.beginResync();
+ mPrimaryDispSync->beginResync();
mEventControlThread->setVsyncEnabled(true);
mPrimaryHWVsyncEnabled = true;
}
@@ -1334,7 +1339,7 @@
Mutex::Autolock _l(mHWVsyncLock);
if (mPrimaryHWVsyncEnabled) {
mEventControlThread->setVsyncEnabled(false);
- mPrimaryDispSync.endResync();
+ mPrimaryDispSync->endResync();
mPrimaryHWVsyncEnabled = false;
}
if (makeUnavailable) {
@@ -1379,7 +1384,7 @@
{ // Scope for the lock
Mutex::Autolock _l(mHWVsyncLock);
if (mPrimaryHWVsyncEnabled) {
- needsHwVsync = mPrimaryDispSync.addResyncSample(timestamp);
+ needsHwVsync = mPrimaryDispSync->addResyncSample(timestamp);
}
}
@@ -1506,8 +1511,8 @@
// The present fences returned from vr_hwc are not an accurate
// representation of vsync times.
- mPrimaryDispSync.setIgnorePresentFences(
- getBE().mHwc->isUsingVrComposer() || !hasSyncFramework);
+ mPrimaryDispSync->setIgnorePresentFences(getBE().mHwc->isUsingVrComposer() ||
+ !hasSyncFramework);
// Use phase of 0 since phase is not known.
// Use latency of 0, which will snap to the ideal latency.
@@ -1770,8 +1775,8 @@
auto presentFenceTime = std::make_shared<FenceTime>(mPreviousPresentFence);
getBE().mDisplayTimeline.push(presentFenceTime);
- nsecs_t vsyncPhase = mPrimaryDispSync.computeNextRefresh(0);
- nsecs_t vsyncInterval = mPrimaryDispSync.getPeriod();
+ nsecs_t vsyncPhase = mPrimaryDispSync->computeNextRefresh(0);
+ nsecs_t vsyncInterval = mPrimaryDispSync->getPeriod();
// We use the refreshStartTime which might be sampled a little later than
// when we started doing work for this frame, but that should be okay
@@ -1794,7 +1799,7 @@
});
if (presentFenceTime->isValid()) {
- if (mPrimaryDispSync.addPresentFence(presentFenceTime)) {
+ if (mPrimaryDispSync->addPresentFence(presentFenceTime)) {
enableHardwareVsync();
} else {
disableHardwareVsync(false);
@@ -2873,7 +2878,7 @@
mDrawingState.traverseInZOrder([&](Layer* layer) {
if (layer->hasReadyFrame()) {
frameQueued = true;
- if (layer->shouldPresentNow(mPrimaryDispSync)) {
+ if (layer->shouldPresentNow(*mPrimaryDispSync)) {
mLayersWithQueuedFrames.push_back(layer);
} else {
layer->useEmptyDamage();
@@ -3966,7 +3971,7 @@
if ((index < numArgs) &&
(args[index] == String16("--dispsync"))) {
index++;
- mPrimaryDispSync.dump(result);
+ mPrimaryDispSync->dump(result);
dumpAll = false;
}
@@ -4749,7 +4754,7 @@
// Needs to be shifted to proper binder interface when we productize
case 1016: {
n = data.readInt32();
- mPrimaryDispSync.setRefreshSkipCount(n);
+ mPrimaryDispSync->setRefreshSkipCount(n);
return NO_ERROR;
}
case 1017: {