SurfaceFlinger and libgui: Support for child layers.
Add support for parenting Layers in a tree. Layers
follow scene-graph style rules, that is to say:
1. A child is cropped to the final bounds of the parent.
2. A child inherits the parent's transform (including position)
3. A child's Z ordering is relative to the parent and bounded between
the parents siblings.
4. A childs lifetime is bounded by it's parents lifetime.
Test: New tests in Transaction_test plus manual testing with later branches.
Change-Id: I96f8ad863665b9a70b6f845561344c297b7e6eff
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 3959341..bf224ae 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -42,6 +42,7 @@
#include "FrameTracker.h"
#include "Client.h"
+#include "LayerVector.h"
#include "MonitoredProducer.h"
#include "SurfaceFlinger.h"
#include "SurfaceFlingerConsumer.h"
@@ -168,6 +169,7 @@
bool setFinalCrop(const Rect& crop);
bool setLayerStack(uint32_t layerStack);
bool setDataSpace(android_dataspace dataSpace);
+ uint32_t getLayerStack() const;
void deferTransactionUntil(const sp<IBinder>& handle, uint64_t frameNumber);
bool setOverrideScalingMode(int32_t overrideScalingMode);
@@ -219,6 +221,14 @@
virtual bool isVisible() const;
/*
+ * isHiddenByPolicy - true if this layer has been forced invisible.
+ * just because this is false, doesn't mean isVisible() is true.
+ * For example if this layer has no active buffer, it may not be hidden by
+ * policy, but it still can not be visible.
+ */
+ virtual bool isHiddenByPolicy() const;
+
+ /*
* isFixedSize - true if content has a fixed size
*/
virtual bool isFixedSize() const;
@@ -422,6 +432,26 @@
bool getTransformToDisplayInverse() const;
+ Transform getTransform() const;
+
+ void traverseInReverseZOrder(const std::function<void(Layer*)>& exec);
+ void traverseInZOrder(const std::function<void(Layer*)>& exec);
+
+ void addChild(const sp<Layer>& layer);
+ // Returns index if removed, or negative value otherwise
+ // for symmetry with Vector::remove
+ ssize_t removeChild(const sp<Layer>& layer);
+ sp<Layer> getParent() const { return mParent.promote(); }
+ bool hasParent() const { return getParent() != nullptr; }
+
+ Rect computeScreenBounds(bool reduceTransparentRegion = true) const;
+ bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
+
+ // Copy the current list of children to the drawing state. Called by
+ // SurfaceFlinger to complete a transaction.
+ void commitChildList();
+
+ int32_t getZ() const;
protected:
// constant
sp<SurfaceFlinger> mFlinger;
@@ -462,7 +492,12 @@
bool needsFiltering(const sp<const DisplayDevice>& hw) const;
uint32_t getEffectiveUsage(uint32_t usage) const;
+
gfx::FloatRect computeCrop(const sp<const DisplayDevice>& hw) const;
+ // Compute the initial crop as specified by parent layers and the SurfaceControl
+ // for this layer. Does not include buffer crop from the IGraphicBufferProducer
+ // client, as that should not affect child clipping. Returns in screen space.
+ Rect computeInitialCrop(const sp<const DisplayDevice>& hw) const;
bool isCropped() const;
static bool getOpacityForFormat(uint32_t format);
@@ -478,6 +513,8 @@
// Loads the corresponding system property once per process
static bool latchUnsignaledBuffers();
+ void setParent(const sp<Layer>& layer);
+
// -----------------------------------------------------------------------
class SyncPoint
@@ -532,6 +569,8 @@
void popPendingState(State* stateToCommit);
bool applyPendingStates(State* stateToCommit);
+ void clearSyncPoints();
+
// Returns mCurrentScaling mode (originating from the
// Client) or mOverrideScalingMode mode (originating from
// the Surface Controller) if set.
@@ -662,6 +701,13 @@
bool mAutoRefresh;
bool mFreezePositionUpdates;
+
+ // Child list about to be committed/used for editing.
+ LayerVector mCurrentChildren;
+ // Child list used for rendering.
+ LayerVector mDrawingChildren;
+
+ wp<Layer> mParent;
};
// ---------------------------------------------------------------------------