Revert "SurfaceFlinger: protect state members in Layer"

State update transactions must be atomic. The fine-grained lock on each
Layer implied otherwise. Revert the fine grained lock as being
unhelpful.

Unfortunately there does not seem to be a way to use Clang thread
annotations to specify the desired locking behavior.

Note that the parent CL addresses the locking problem that led to the
bug.

This reverts commit 83729883eecd31a9907bc79bc21998a90f17105c.

Bug: 119481871
Test: SurfaceFlinger unit tests
Test: go/wm-smoke
Change-Id: I361741f8d10102aeb57f164c847c6063ff93dd14
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index fb75e4c..2e75088 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -55,7 +55,6 @@
 #include "RenderArea.h"
 
 using namespace android::surfaceflinger;
-using StateSet = android::LayerVector::StateSet;
 
 namespace android {
 
@@ -240,7 +239,7 @@
     // also the rendered size of the layer prior to any transformations. Parent
     // or local matrix transformations will not affect the size of the buffer,
     // but may affect it's on-screen size or clipping.
-    virtual bool setSize(uint32_t w, uint32_t h) EXCLUDES(mStateMutex);
+    virtual bool setSize(uint32_t w, uint32_t h);
     // Set a 2x2 transformation matrix on the layer. This transform
     // will be applied after parent transforms, but before any final
     // producer specified transform.
@@ -255,76 +254,58 @@
 
     // setPosition operates in parent buffer space (pre parent-transform) or display
     // space for top-level layers.
-    virtual bool setPosition(float x, float y, bool immediate) EXCLUDES(mStateMutex);
+    virtual bool setPosition(float x, float y, bool immediate);
     // Buffer space
-    virtual bool setCrop_legacy(const Rect& crop, bool immediate) EXCLUDES(mStateMutex);
+    virtual bool setCrop_legacy(const Rect& crop, bool immediate);
 
     // TODO(b/38182121): Could we eliminate the various latching modes by
     // using the layer hierarchy?
     // -----------------------------------------------------------------------
-    virtual bool setLayer(int32_t z) EXCLUDES(mStateMutex);
-    virtual bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ)
-            EXCLUDES(mStateMutex);
+    virtual bool setLayer(int32_t z);
+    virtual bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ);
 
-    virtual bool setAlpha(float alpha) EXCLUDES(mStateMutex);
-    virtual bool setColor(const half3& color) EXCLUDES(mStateMutex);
+    virtual bool setAlpha(float alpha);
+    virtual bool setColor(const half3& color);
 
     // Set rounded corner radius for this layer and its children.
     //
     // We only support 1 radius per layer in the hierarchy, where parent layers have precedence.
     // The shape of the rounded corner rectangle is specified by the crop rectangle of the layer
     // from which we inferred the rounded corner radius.
-    virtual bool setCornerRadius(float cornerRadius) EXCLUDES(mStateMutex);
-    virtual bool setTransparentRegionHint(const Region& transparent) EXCLUDES(mStateMutex);
-    virtual bool setFlags(uint8_t flags, uint8_t mask) EXCLUDES(mStateMutex);
-    virtual bool setLayerStack(uint32_t layerStack) EXCLUDES(mStateMutex);
-    virtual uint32_t getLayerStack() const EXCLUDES(mStateMutex);
+    virtual bool setCornerRadius(float cornerRadius);
+    virtual bool setTransparentRegionHint(const Region& transparent);
+    virtual bool setFlags(uint8_t flags, uint8_t mask);
+    virtual bool setLayerStack(uint32_t layerStack);
+    virtual uint32_t getLayerStack() const;
     virtual void deferTransactionUntil_legacy(const sp<IBinder>& barrierHandle,
                                               uint64_t frameNumber);
-    virtual void deferTransactionUntil_legacy(const sp<Layer>& barrierLayer, uint64_t frameNumber)
-            EXCLUDES(mStateMutex);
-    virtual bool setOverrideScalingMode(int32_t overrideScalingMode) EXCLUDES(mStateMutex);
-    virtual void setInfo(int32_t type, int32_t appId) EXCLUDES(mStateMutex);
-    virtual bool reparentChildren(const sp<IBinder>& layer) EXCLUDES(mStateMutex);
+    virtual void deferTransactionUntil_legacy(const sp<Layer>& barrierLayer, uint64_t frameNumber);
+    virtual bool setOverrideScalingMode(int32_t overrideScalingMode);
+    virtual void setInfo(int32_t type, int32_t appId);
+    virtual bool reparentChildren(const sp<IBinder>& layer);
     virtual void setChildrenDrawingParent(const sp<Layer>& layer);
-    virtual bool reparent(const sp<IBinder>& newParentHandle) EXCLUDES(mStateMutex);
+    virtual bool reparent(const sp<IBinder>& newParentHandle);
     virtual bool detachChildren();
     bool attachChildren();
     bool isLayerDetached() const { return mLayerDetached; }
-    virtual bool setColorTransform(const mat4& matrix) EXCLUDES(mStateMutex);
-    mat4 getColorTransform() const EXCLUDES(mStateMutex);
-    virtual mat4 getColorTransformLocked() const REQUIRES(mStateMutex);
-    virtual bool hasColorTransform() const EXCLUDES(mStateMutex);
-    ;
+    virtual bool setColorTransform(const mat4& matrix);
+    virtual mat4 getColorTransform() const;
+    virtual bool hasColorTransform() const;
 
     // Used only to set BufferStateLayer state
-    virtual bool setTransform(uint32_t /*transform*/) EXCLUDES(mStateMutex) { return false; };
-    virtual bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/)
-            EXCLUDES(mStateMutex) {
-        return false;
-    };
-    virtual bool setCrop(const Rect& /*crop*/) EXCLUDES(mStateMutex) { return false; };
-    virtual bool setFrame(const Rect& /*frame*/) EXCLUDES(mStateMutex) { return false; };
-    virtual bool setBuffer(const sp<GraphicBuffer>& /*buffer*/) EXCLUDES(mStateMutex) {
-        return false;
-    };
-    virtual bool setAcquireFence(const sp<Fence>& /*fence*/) EXCLUDES(mStateMutex) {
-        return false;
-    };
-    virtual bool setDataspace(ui::Dataspace /*dataspace*/) EXCLUDES(mStateMutex) { return false; };
-    virtual bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/) EXCLUDES(mStateMutex) {
-        return false;
-    };
-    virtual bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/) EXCLUDES(mStateMutex) {
-        return false;
-    };
-    virtual bool setApi(int32_t /*api*/) EXCLUDES(mStateMutex) { return false; };
-    virtual bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/)
-            EXCLUDES(mStateMutex) {
-        return false;
-    };
+    virtual bool setTransform(uint32_t /*transform*/) { return false; };
+    virtual bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/) { return false; };
+    virtual bool setCrop(const Rect& /*crop*/) { return false; };
+    virtual bool setFrame(const Rect& /*frame*/) { return false; };
+    virtual bool setBuffer(const sp<GraphicBuffer>& /*buffer*/) { return false; };
+    virtual bool setAcquireFence(const sp<Fence>& /*fence*/) { return false; };
+    virtual bool setDataspace(ui::Dataspace /*dataspace*/) { return false; };
+    virtual bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/) { return false; };
+    virtual bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/) { return false; };
+    virtual bool setApi(int32_t /*api*/) { return false; };
+    virtual bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/) { return false; };
     virtual bool setTransactionCompletedListeners(
-            const std::vector<sp<CallbackHandle>>& /*handles*/) EXCLUDES(mStateMutex) {
+            const std::vector<sp<CallbackHandle>>& /*handles*/) {
         return false;
     };
 
@@ -343,21 +324,18 @@
     virtual void useSurfaceDamage() {}
     virtual void useEmptyDamage() {}
 
-    uint32_t getTransactionFlags() const EXCLUDES(mStateMutex);
-    uint32_t getTransactionFlags(uint32_t flags) EXCLUDES(mStateMutex);
-    uint32_t setTransactionFlags(uint32_t flags) REQUIRES(mStateMutex);
+    uint32_t getTransactionFlags() const { return mTransactionFlags; }
+    uint32_t getTransactionFlags(uint32_t flags);
+    uint32_t setTransactionFlags(uint32_t flags);
 
-    bool belongsToDisplay(uint32_t layerStack, bool isPrimaryDisplay) const EXCLUDES(mStateMutex) {
+    bool belongsToDisplay(uint32_t layerStack, bool isPrimaryDisplay) const {
         return getLayerStack() == layerStack && (!mPrimaryDisplayOnly || isPrimaryDisplay);
     }
 
     void computeGeometry(const RenderArea& renderArea, renderengine::Mesh& mesh,
-                         bool useIdentityTransform) const REQUIRES(mStateMutex);
-    FloatRect computeBounds(const Region& activeTransparentRegion) const EXCLUDES(mStateMutex);
-    FloatRect computeBoundsLocked(const Region& activeTransparentRegion) const
-            REQUIRES(mStateMutex);
-    FloatRect computeBounds() const EXCLUDES(mStateMutex);
-    FloatRect computeBoundsLocked() const REQUIRES(mStateMutex);
+                         bool useIdentityTransform) const;
+    FloatRect computeBounds(const Region& activeTransparentRegion) const;
+    FloatRect computeBounds() const;
 
     int32_t getSequence() const { return sequence; }
 
@@ -374,21 +352,16 @@
      */
     virtual bool isOpaque(const Layer::State&) const { return false; }
 
-    virtual bool isDrawingOpaque() const EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        return isOpaque(mState.drawing);
-    }
-
     /*
      * isSecure - true if this surface is secure, that is if it prevents
      * screenshots or VNC servers.
      */
-    bool isSecure() const EXCLUDES(mStateMutex);
+    bool isSecure() const;
 
     /*
      * isVisible - true if this layer is visible, false otherwise
      */
-    virtual bool isVisible() const EXCLUDES(mStateMutex) = 0;
+    virtual bool isVisible() const = 0;
 
     /*
      * isHiddenByPolicy - true if this layer has been forced invisible.
@@ -396,7 +369,7 @@
      * For example if this layer has no active buffer, it may not be hidden by
      * policy, but it still can not be visible.
      */
-    bool isHiddenByPolicy() const EXCLUDES(mStateMutex);
+    bool isHiddenByPolicy() const;
 
     /*
      * isProtected - true if the layer may contain protected content in the
@@ -417,8 +390,7 @@
     bool isRemovedFromCurrentState() const;
 
     void writeToProto(LayerProto* layerInfo,
-                      LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing)
-            EXCLUDES(mStateMutex);
+                      LayerVector::StateSet stateSet = LayerVector::StateSet::Drawing);
 
     void writeToProto(LayerProto* layerInfo, DisplayId displayId);
 
@@ -431,32 +403,25 @@
     virtual Region getActiveTransparentRegion(const Layer::State& s) const {
         return s.activeTransparentRegion_legacy;
     }
-
-    virtual Region getDrawingActiveTransparentRegion() const EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        return getActiveTransparentRegion(mState.drawing);
-    }
-
     virtual Rect getCrop(const Layer::State& s) const { return s.crop_legacy; }
 
 protected:
     /*
      * onDraw - draws the surface.
      */
-    virtual void onDraw(const RenderArea& renderArea, const Region& clip, bool useIdentityTransform)
-            EXCLUDES(mStateMutex) = 0;
+    virtual void onDraw(const RenderArea& renderArea, const Region& clip,
+                        bool useIdentityTransform) = 0;
 
 public:
     virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}
 
     virtual bool isHdrY410() const { return false; }
 
-    void setGeometry(const sp<const DisplayDevice>& display, uint32_t z) EXCLUDES(mStateMutex);
+    void setGeometry(const sp<const DisplayDevice>& display, uint32_t z);
     void forceClientComposition(DisplayId displayId);
     bool getForceClientComposition(DisplayId displayId);
     virtual void setPerFrameData(DisplayId displayId, const ui::Transform& transform,
-                                 const Rect& viewport, int32_t supportedPerFrameMetadata)
-            EXCLUDES(mStateMutex) = 0;
+                                 const Rect& viewport, int32_t supportedPerFrameMetadata) = 0;
 
     // callIntoHwc exists so we can update our local state and call
     // acceptDisplayChanges without unnecessarily updating the device's state
@@ -464,7 +429,7 @@
     HWC2::Composition getCompositionType(const std::optional<DisplayId>& displayId) const;
     void setClearClientTarget(DisplayId displayId, bool clear);
     bool getClearClientTarget(DisplayId displayId) const;
-    void updateCursorPosition(const sp<const DisplayDevice>& display) EXCLUDES(mStateMutex);
+    void updateCursorPosition(const sp<const DisplayDevice>& display);
 
     /*
      * called after page-flip
@@ -487,8 +452,7 @@
     virtual bool onPostComposition(const std::optional<DisplayId>& /*displayId*/,
                                    const std::shared_ptr<FenceTime>& /*glDoneFence*/,
                                    const std::shared_ptr<FenceTime>& /*presentFence*/,
-                                   const CompositorTiming& /*compositorTiming*/)
-            EXCLUDES(mStateMutex) {
+                                   const CompositorTiming& /*compositorTiming*/) {
         return false;
     }
 
@@ -500,14 +464,14 @@
      * draw - performs some global clipping optimizations
      * and calls onDraw().
      */
-    void draw(const RenderArea& renderArea, const Region& clip) EXCLUDES(mStateMutex);
-    void draw(const RenderArea& renderArea, bool useIdentityTransform) EXCLUDES(mStateMutex);
+    void draw(const RenderArea& renderArea, const Region& clip);
+    void draw(const RenderArea& renderArea, bool useIdentityTransform);
 
     /*
      * doTransaction - process the transaction. This is a good place to figure
      * out which attributes of the surface have changed.
      */
-    uint32_t doTransaction(uint32_t transactionFlags) EXCLUDES(mStateMutex);
+    uint32_t doTransaction(uint32_t transactionFlags);
 
     /*
      * setVisibleRegion - called to set the new visible region. This gives
@@ -540,17 +504,17 @@
      * to figure out if the content or size of a surface has changed.
      */
     virtual Region latchBuffer(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/,
-                               const sp<Fence>& /*releaseFence*/) EXCLUDES(mStateMutex) {
+                               const sp<Fence>& /*releaseFence*/) {
         return {};
     }
 
     virtual bool isBufferLatched() const { return false; }
 
     /*
-     * called with SurfaceFlinger mStateLock a binder thread when the layer is
+     * called with the state lock from a binder thread when the layer is
      * removed from the current list to the pending removal list
      */
-    void onRemovedFromCurrentState() EXCLUDES(mStateMutex);
+    void onRemovedFromCurrentState();
 
     /*
      * Called when the layer is added back to the current state list.
@@ -570,7 +534,7 @@
     /*
      * Returns if a frame is ready
      */
-    virtual bool hasReadyFrame() const EXCLUDES(mStateMutex) { return false; }
+    virtual bool hasReadyFrame() const { return false; }
 
     virtual int32_t getQueuedFrameCount() const { return 0; }
 
@@ -599,32 +563,17 @@
     }
 
     // -----------------------------------------------------------------------
-    void clearWithOpenGL(const RenderArea& renderArea) const EXCLUDES(mStateMutex);
+    void clearWithOpenGL(const RenderArea& renderArea) const;
 
-    inline const State& getDrawingState() const REQUIRES(mStateMutex) { return mState.drawing; }
+    inline const State& getDrawingState() const { return mDrawingState; }
+    inline const State& getCurrentState() const { return mCurrentState; }
+    inline State& getCurrentState() { return mCurrentState; }
 
-    inline const State& getCurrentState() const REQUIRES(mStateMutex) { return mState.current; }
-
-    inline State& getCurrentState() REQUIRES(mStateMutex) { return mState.current; }
-
-    std::tuple<uint32_t, int32_t> getLayerStackAndZ(StateSet stateSet) EXCLUDES(mStateMutex);
-    wp<Layer> getZOrderRelativeOf(StateSet stateSet) EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        const State& state = (stateSet == StateSet::Current) ? mState.current : mState.drawing;
-
-        return state.zOrderRelativeOf;
-    }
-
-    uint8_t getCurrentFlags() EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        return mState.current.flags;
-    }
-
-    LayerDebugInfo getLayerDebugInfo() const EXCLUDES(mStateMutex);
+    LayerDebugInfo getLayerDebugInfo() const;
 
     /* always call base class first */
     static void miniDumpHeader(std::string& result);
-    void miniDump(std::string& result, DisplayId displayId) const EXCLUDES(mStateMutex);
+    void miniDump(std::string& result, DisplayId displayId) const;
     void dumpFrameStats(std::string& result) const;
     void dumpFrameEvents(std::string& result);
     void clearFrameStats();
@@ -639,29 +588,22 @@
     void addAndGetFrameTimestamps(const NewFrameEventsEntry* newEntry,
                                   FrameEventHistoryDelta* outDelta);
 
-    bool getTransformToDisplayInverse() const EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        return getTransformToDisplayInverseLocked();
-    }
+    virtual bool getTransformToDisplayInverse() const { return false; }
 
-    virtual bool getTransformToDisplayInverseLocked() const REQUIRES(mStateMutex) { return false; }
-
-    ui::Transform getTransform() const EXCLUDES(mStateMutex);
-    ui::Transform getTransformLocked() const REQUIRES(mStateMutex);
+    ui::Transform getTransform() const;
 
     // Returns the Alpha of the Surface, accounting for the Alpha
     // of parent Surfaces in the hierarchy (alpha's will be multiplied
     // down the hierarchy).
-    half getAlpha() const EXCLUDES(mStateMutex);
-    half4 getColor() const REQUIRES(mStateMutex);
+    half getAlpha() const;
+    half4 getColor() const;
 
     // Returns how rounded corners should be drawn for this layer.
     // This will traverse the hierarchy until it reaches its root, finding topmost rounded
     // corner definition and converting it into current layer's coordinates.
     // As of now, only 1 corner radius per display list is supported. Subsequent ones will be
     // ignored.
-    RoundedCornerState getRoundedCornerState() const EXCLUDES(mStateMutex);
-    RoundedCornerState getRoundedCornerStateLocked() const REQUIRES(mStateMutex);
+    RoundedCornerState getRoundedCornerState() const;
 
     void traverseInReverseZOrder(LayerVector::StateSet stateSet,
                                  const LayerVector::Visitor& visitor);
@@ -681,7 +623,7 @@
     ssize_t removeChild(const sp<Layer>& layer);
     sp<Layer> getParent() const { return mCurrentParent.promote(); }
     bool hasParent() const { return getParent() != nullptr; }
-    Rect computeScreenBounds(bool reduceTransparentRegion = true) const EXCLUDES(mStateMutex);
+    Rect computeScreenBounds(bool reduceTransparentRegion = true) const;
     bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
     bool setChildRelativeLayer(const sp<Layer>& childLayer,
             const sp<IBinder>& relativeToHandle, int32_t relativeZ);
@@ -689,23 +631,14 @@
     // Copy the current list of children to the drawing state. Called by
     // SurfaceFlinger to complete a transaction.
     void commitChildList();
-    int32_t getZ() const EXCLUDES(mStateMutex);
-    void pushPendingState() EXCLUDES(mStateMutex);
-    virtual void pushPendingStateLocked() REQUIRES(mStateMutex);
+    int32_t getZ() const;
+    virtual void pushPendingState();
 
     /**
      * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
      * any buffer transformations. If the layer has no buffer then return INVALID_RECT.
      */
-    virtual Rect getBufferSize(const Layer::State&) const REQUIRES(mStateMutex) {
-        return Rect::INVALID_RECT;
-    }
-
-    virtual Rect getBufferSize(StateSet stateSet) const EXCLUDES(mStateMutex) {
-        Mutex::Autolock lock(mStateMutex);
-        const State& state = (stateSet == StateSet::Current) ? mState.current : mState.drawing;
-        return getBufferSize(state);
-    }
+    virtual Rect getBufferSize(const Layer::State&) const { return Rect::INVALID_RECT; }
 
 protected:
     // constant
@@ -734,17 +667,16 @@
     // For unit tests
     friend class TestableSurfaceFlinger;
 
-    void commitTransaction(const State& stateToCommit) REQUIRES(mStateMutex);
+    void commitTransaction(const State& stateToCommit);
 
     uint32_t getEffectiveUsage(uint32_t usage) const;
 
-    virtual FloatRect computeCrop(const sp<const DisplayDevice>& display) const
-            REQUIRES(mStateMutex);
+    virtual FloatRect computeCrop(const sp<const DisplayDevice>& display) 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>& display) const REQUIRES(mStateMutex);
+    Rect computeInitialCrop(const sp<const DisplayDevice>& display) const;
     /**
      * Setup rounded corners coordinates of this layer, taking into account the layer bounds and
      * crop coordinates, transforming them into layer space.
@@ -752,13 +684,13 @@
     void setupRoundedCornersCropCoordinates(Rect win, const FloatRect& roundedCornersCrop) const;
 
     // drawing
-    void clearWithOpenGL(const RenderArea& renderArea, float r, float g, float b, float alpha) const
-            EXCLUDES(mStateMutex);
+    void clearWithOpenGL(const RenderArea& renderArea, float r, float g, float b,
+                         float alpha) const;
     void setParent(const sp<Layer>& layer);
 
     LayerVector makeTraversalList(LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers);
-    void addZOrderRelative(const wp<Layer>& relative) EXCLUDES(mStateMutex);
-    void removeZOrderRelative(const wp<Layer>& relative) EXCLUDES(mStateMutex);
+    void addZOrderRelative(const wp<Layer>& relative);
+    void removeZOrderRelative(const wp<Layer>& relative);
 
     class SyncPoint {
     public:
@@ -794,10 +726,9 @@
     // Returns false if the relevant frame has already been latched
     bool addSyncPoint(const std::shared_ptr<SyncPoint>& point);
 
-    void popPendingState(State* stateToCommit) REQUIRES(mStateMutex);
-    virtual bool applyPendingStates(State* stateToCommit) REQUIRES(mStateMutex);
-    virtual uint32_t doTransactionResize(uint32_t flags, Layer::State* stateToCommit)
-            REQUIRES(mStateMutex);
+    void popPendingState(State* stateToCommit);
+    virtual bool applyPendingStates(State* stateToCommit);
+    virtual uint32_t doTransactionResize(uint32_t flags, Layer::State* stateToCommit);
 
     void clearSyncPoints();
 
@@ -830,15 +761,14 @@
     bool getPremultipledAlpha() const;
 
     bool mPendingHWCDestroy{false};
-    void setInputInfo(const InputWindowInfo& info) EXCLUDES(mStateMutex);
+    void setInputInfo(const InputWindowInfo& info);
 
-    InputWindowInfo fillInputInfo(const Rect& screenBounds) EXCLUDES(mStateMutex);
-    bool hasInput() const EXCLUDES(mStateMutex);
+    InputWindowInfo fillInputInfo(const Rect& screenBounds);
+    bool hasInput() const;
 
 protected:
     // -----------------------------------------------------------------------
-    bool usingRelativeZ(LayerVector::StateSet stateSet) EXCLUDES(mStateMutex);
-    bool usingRelativeZLocked(LayerVector::StateSet stateSet) REQUIRES(mStateMutex);
+    bool usingRelativeZ(LayerVector::StateSet stateSet);
 
     bool mPremultipliedAlpha{true};
     String8 mName;
@@ -846,14 +776,14 @@
 
     bool mPrimaryDisplayOnly = false;
 
+    // these are protected by an external lock
+    State mCurrentState;
+    State mDrawingState;
+    std::atomic<uint32_t> mTransactionFlags{0};
+
     // Accessed from main thread and binder threads
-    mutable Mutex mStateMutex;
-    struct {
-        State current;
-        State drawing;
-        uint32_t transactionFlags{0};
-        Vector<State> pending;
-    } mState GUARDED_BY(mStateMutex);
+    Mutex mPendingStateMutex;
+    Vector<State> mPendingStates;
 
     // Timestamp history for UIAutomation. Thread safe.
     FrameTracker mFrameTracker;
@@ -926,7 +856,7 @@
      * The cropped bounds must be transformed back from parent layer space to child layer space by
      * applying the inverse of the child's transformation.
      */
-    FloatRect cropChildBounds(const FloatRect& childBounds) const REQUIRES(mStateMutex);
+    FloatRect cropChildBounds(const FloatRect& childBounds) const;
 
     /**
      * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return
@@ -934,12 +864,7 @@
      * A layer with an invalid buffer size and no crop is considered to be boundless. The layer
      * bounds are constrained by its parent bounds.
      */
-    Rect getCroppedBufferSize(const Layer::State& s) const REQUIRES(mStateMutex);
-
-    // locked version of public methods
-    bool isSecureLocked() const REQUIRES(mStateMutex);
-    virtual uint32_t getLayerStackLocked() const REQUIRES(mStateMutex);
-    half getAlphaLocked() const REQUIRES(mStateMutex);
+    Rect getCroppedBufferSize(const Layer::State& s) const;
 };
 
 } // namespace android