SF: Restructure message refresh
Test: Compile/Run manually
Merged-In: I321a79acd52dc956a0006d0dccd7b17cbf4e2443
Change-Id: I321a79acd52dc956a0006d0dccd7b17cbf4e2443
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 19d2f21..916576a 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -620,7 +620,6 @@
getBE().compositionInfo.mBufferSlot = mActiveBufferSlot;
getBE().compositionInfo.mBuffer = mActiveBuffer;
getBE().compositionInfo.hwc.fence = acquireFence;
- getBE().compositionInfo.updateBuffer = true;
}
bool BufferLayer::isOpaque(const Layer::State& s) const {
diff --git a/services/surfaceflinger/LayerBE.h b/services/surfaceflinger/LayerBE.h
index 767a3b3..fafe165 100644
--- a/services/surfaceflinger/LayerBE.h
+++ b/services/surfaceflinger/LayerBE.h
@@ -64,7 +64,6 @@
sp<GraphicBuffer> mBuffer = nullptr;
int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
LayerBE* layer = nullptr;
- bool updateBuffer = false;
struct {
std::shared_ptr<LayerContainer> hwcLayer;
bool skipGeometry = true;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e70344e..a7c35ef 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1417,11 +1417,8 @@
refreshNeeded |= handleMessageInvalidate();
refreshNeeded |= mRepaintEverything;
- const nsecs_t refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
-
- preComposition(refreshStartTime);
+ preComposition();
rebuildLayerStacks();
-
calculateWorkingSet();
if (refreshNeeded) {
@@ -1554,14 +1551,20 @@
mRefreshPending = false;
- nsecs_t refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
- setUpHWComposer();
+
+ beginFrame();
+ for (auto compositionInfo : getBE().mCompositionInfo) {
+ setUpHWComposer(compositionInfo);
+ }
+ prepareFrame();
doDebugFlashRegions();
doTracing("handleRefresh");
logLayerStats();
doComposition();
- postComposition(refreshStartTime);
+ postComposition();
+
+ getBE().mCompositionInfo.clear();
mPreviousPresentFence = getBE().mHwc->getPresentFence(HWC_DISPLAY_PRIMARY);
@@ -1648,14 +1651,14 @@
}
}
-void SurfaceFlinger::preComposition(nsecs_t refreshStartTime)
+void SurfaceFlinger::preComposition()
{
ATRACE_CALL();
ALOGV("preComposition");
bool needExtraInvalidate = false;
mDrawingState.traverseInZOrder([&](Layer* layer) {
- if (layer->onPreComposition(refreshStartTime)) {
+ if (layer->onPreComposition(mRefreshStartTime)) {
needExtraInvalidate = true;
}
});
@@ -1724,7 +1727,7 @@
getBE().mCompositorTiming.presentLatency = snappedCompositeToPresentLatency;
}
-void SurfaceFlinger::postComposition(nsecs_t refreshStartTime)
+void SurfaceFlinger::postComposition()
{
ATRACE_CALL();
ALOGV("postComposition");
@@ -1756,11 +1759,11 @@
nsecs_t vsyncPhase = mPrimaryDispSync.computeNextRefresh(0);
nsecs_t vsyncInterval = mPrimaryDispSync.getPeriod();
- // We use the refreshStartTime which might be sampled a little later than
+ // We use the mRefreshStartTime which might be sampled a little later than
// when we started doing work for this frame, but that should be okay
// since updateCompositorTiming has snapping logic.
updateCompositorTiming(
- vsyncPhase, vsyncInterval, refreshStartTime, presentFenceTime);
+ vsyncPhase, vsyncInterval, mRefreshStartTime, presentFenceTime);
CompositorTiming compositorTiming;
{
std::lock_guard<std::mutex> lock(getBE().mCompositorTimingLock);
@@ -2074,18 +2077,16 @@
"[SF] Failed to set surface damage: %s (%d)",
to_string(error).c_str(), static_cast<int32_t>(error));
- if (compositionInfo.updateBuffer) {
- error = (*compositionInfo.hwc.hwcLayer)->setBuffer(compositionInfo.mBufferSlot,
- compositionInfo.mBuffer, compositionInfo.hwc.fence);
- ALOGE_IF(error != HWC2::Error::None,
- "[SF] Failed to set buffer: %s (%d)",
- to_string(error).c_str(), static_cast<int32_t>(error));
- }
+ error = (*compositionInfo.hwc.hwcLayer)->setBuffer(compositionInfo.mBufferSlot,
+ compositionInfo.mBuffer, compositionInfo.hwc.fence);
+ ALOGE_IF(error != HWC2::Error::None,
+ "[SF] Failed to set buffer: %s (%d)",
+ to_string(error).c_str(), static_cast<int32_t>(error));
}
-void SurfaceFlinger::setUpHWComposer() {
- ATRACE_CALL();
- ALOGV("setUpHWComposer");
+void SurfaceFlinger::beginFrame()
+{
+ mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
bool dirty = !mDisplays[dpy]->getDirtyRegion(false).isEmpty();
@@ -2115,38 +2116,10 @@
mDisplays[dpy]->lastCompositionHadVisibleLayers = !empty;
}
}
+}
- {
- ATRACE_NAME("Programming_HWCOMPOSER");
- for (auto compositionInfo : getBE().mCompositionInfo) {
- ALOGV("[SF] hwcLayer=%p(%lu), compositionType=%d",
- static_cast<HWC2::Layer*>(*compositionInfo.hwc.hwcLayer),
- compositionInfo.hwc.hwcLayer.use_count(), compositionInfo.compositionType);
-
- switch (compositionInfo.compositionType)
- {
- case HWC2::Composition::Invalid:
- case HWC2::Composition::Client:
- case HWC2::Composition::Cursor:
- break;
-
- case HWC2::Composition::Sideband:
- configureSidebandComposition(compositionInfo);
- break;
-
- case HWC2::Composition::SolidColor:
- configureHwcCommonData(compositionInfo);
- break;
-
- case HWC2::Composition::Device:
- configureHwcCommonData(compositionInfo);
- configureDeviceComposition(compositionInfo);
- break;
- }
- }
- getBE().mCompositionInfo.clear();
- }
-
+void SurfaceFlinger::prepareFrame()
+{
for (size_t displayId = 0; displayId < mDisplays.size(); ++displayId) {
auto& displayDevice = mDisplays[displayId];
if (!displayDevice->isDisplayOn()) {
@@ -2159,6 +2132,32 @@
}
}
+void SurfaceFlinger::setUpHWComposer(const CompositionInfo& compositionInfo) {
+ ATRACE_CALL();
+ ALOGV("setUpHWComposer");
+
+ switch (compositionInfo.compositionType)
+ {
+ case HWC2::Composition::Invalid:
+ case HWC2::Composition::Client:
+ case HWC2::Composition::Cursor:
+ break;
+
+ case HWC2::Composition::Sideband:
+ configureSidebandComposition(compositionInfo);
+ break;
+
+ case HWC2::Composition::SolidColor:
+ configureHwcCommonData(compositionInfo);
+ break;
+
+ case HWC2::Composition::Device:
+ configureHwcCommonData(compositionInfo);
+ configureDeviceComposition(compositionInfo);
+ break;
+ }
+}
+
void SurfaceFlinger::doComposition() {
ATRACE_CALL();
ALOGV("doComposition");
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 2a2b36b..edce989 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -615,8 +615,8 @@
void computeVisibleRegions(const sp<const DisplayDevice>& displayDevice,
Region& dirtyRegion, Region& opaqueRegion);
- void preComposition(nsecs_t refreshStartTime);
- void postComposition(nsecs_t refreshStartTime);
+ void preComposition();
+ void postComposition();
void updateCompositorTiming(
nsecs_t vsyncPhase, nsecs_t vsyncInterval, nsecs_t compositeTime,
std::shared_ptr<FenceTime>& presentFenceTime);
@@ -634,7 +634,18 @@
mat4 computeSaturationMatrix() const;
void calculateWorkingSet();
- void setUpHWComposer();
+ /*
+ * beginFrame - This function handles any pre-frame processing that needs to be
+ * prior to any CompositionInfo handling and is not dependent on data in
+ * CompositionInfo
+ */
+ void beginFrame();
+ /* prepareFrame - This function will call into the DisplayDevice to prepare a
+ * frame after CompositionInfo has been programmed. This provides a mechanism
+ * to prepare the hardware composer
+ */
+ void prepareFrame();
+ void setUpHWComposer(const CompositionInfo& compositionInfo);
void doComposition();
void doDebugFlashRegions();
void doTracing(const char* where);
@@ -812,6 +823,7 @@
Mutex mHWVsyncLock;
bool mPrimaryHWVsyncEnabled;
bool mHWVsyncAvailable;
+ nsecs_t mRefreshStartTime;
std::atomic<bool> mRefreshPending{false};