SF: Cleanup layer construction
Introduce a LayerCreationArg parameter object, and modify all layer
types to use it rather than having the same set of four arguments.
Along the way simplify all constructors by moving to C++11 style default
values defined in the header, and ensure the destructor is defined in
the implementation file (as a default for most layer types, as only
BufferLayer needs a non-default destructor).
Using a uniform parameter object reduces the amount of work needed to
maintain the upcoming factory interface.
Test: Works on marlin.
Test: atest libsurfaceflinger_unittest
Change-Id: Ic09291fd3213ff980bfc600166bf798ba09daa32
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 19c84d0..f9bc1e7 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -64,40 +64,22 @@
std::atomic<int32_t> Layer::sSequence{1};
-Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w,
- uint32_t h, uint32_t flags)
- : contentDirty(false),
- mFlinger(flinger),
- mPremultipliedAlpha(true),
- mName(name),
- mTransactionFlags(0),
- mPendingStateMutex(),
- mPendingStates(),
- mCurrentTransform(0),
- mOverrideScalingMode(-1),
- mCurrentFrameNumber(0),
- mFrameLatencyNeeded(false),
- mNeedsFiltering(false),
- mProtectedByApp(false),
- mClientRef(client),
- mPotentialCursor(false),
- mFreezeGeometryUpdates(false),
- mCurrentChildren(LayerVector::StateSet::Current),
- mDrawingChildren(LayerVector::StateSet::Drawing),
- mBE{this, name.string()} {
-
+Layer::Layer(const LayerCreationArgs& args)
+ : mFlinger(args.flinger),
+ mName(args.name),
+ mClientRef(args.client),
+ mBE{this, args.name.string()} {
mCurrentCrop.makeInvalid();
uint32_t layerFlags = 0;
- if (flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
- if (flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
- if (flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
+ if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
+ if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
+ if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
- mName = name;
mTransactionName = String8("TX - ") + mName;
- mCurrentState.active_legacy.w = w;
- mCurrentState.active_legacy.h = h;
+ mCurrentState.active_legacy.w = args.w;
+ mCurrentState.active_legacy.h = args.h;
mCurrentState.flags = layerFlags;
mCurrentState.active_legacy.transform.set(0, 0);
mCurrentState.crop_legacy.makeInvalid();
@@ -125,7 +107,7 @@
mDrawingState = mCurrentState;
CompositorTiming compositorTiming;
- flinger->getCompositorTiming(&compositorTiming);
+ args.flinger->getCompositorTiming(&compositorTiming);
mFrameEventHistory.initializeCompositorTiming(compositorTiming);
mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
}