Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5201031f authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[SurfaceFlinger] Make sure switch the protected state of buffers.

Previously we avoid switching the protected state of buffers if the protected
state is not changed or we fail to switch RenderEngine. However, if we just
switch away from protected state and immediately have screenshot capturing
happen, we end up not switching buffers to unprotected in next round because
we switch RenderEngine to unprotected state. This patch makes sure we always
switch the protected state correctly.

BUG: b/130435822, b/130442144
Test: Verified with Youtube
Test: libcompositionengine_test
Change-Id: I30da95d8172b349cc7897a008fd27ecbc24fb960
parent 0bfc4a0c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ public:
    // Returns the bounds of the surface
    virtual const ui::Size& getSize() const = 0;

    // Returns whether the surface is protected.
    virtual bool isProtected() const = 0;

    // Gets the latest fence to pass to the HWC to signal that the surface
    // buffer is done rendering
    virtual const sp<Fence>& getClientTargetAcquireFence() const = 0;
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public:
    bool isValid() const override;
    void initialize() override;
    const ui::Size& getSize() const override;
    bool isProtected() const override { return mProtected; }

    const sp<Fence>& getClientTargetAcquireFence() const override;
    void setBufferDataspace(ui::Dataspace) override;
@@ -78,6 +79,7 @@ private:
    sp<GraphicBuffer> mGraphicBuffer;
    const sp<DisplaySurface> mDisplaySurface;
    ui::Size mSize;
    bool mProtected{false};
    std::uint32_t mPageFlipCount{0};
};

+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public:
    MOCK_CONST_METHOD0(isValid, bool());
    MOCK_METHOD0(initialize, void());
    MOCK_CONST_METHOD0(getSize, const ui::Size&());
    MOCK_CONST_METHOD0(isProtected, bool());
    MOCK_CONST_METHOD0(getClientTargetAcquireFence, const sp<Fence>&());
    MOCK_METHOD1(setDisplaySize, void(const ui::Size&));
    MOCK_METHOD1(setProtected, void(bool));
+3 −0
Original line number Diff line number Diff line
@@ -101,6 +101,9 @@ void RenderSurface::setProtected(bool useProtected) {
    }
    const int status = native_window_set_usage(mNativeWindow.get(), usageFlags);
    ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for protected content: %d", status);
    if (status == NO_ERROR) {
        mProtected = useProtected;
    }
}

status_t RenderSurface::beginFrame(bool mustRecompose) {
+24 −0
Original line number Diff line number Diff line
@@ -143,16 +143,40 @@ TEST_F(RenderSurfaceTest, setBufferDataspaceAppliesChange) {
 */

TEST_F(RenderSurfaceTest, setProtectedTrueEnablesProtection) {
    EXPECT_FALSE(mSurface.isProtected());
    EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED))
            .WillOnce(Return(NO_ERROR));

    mSurface.setProtected(true);
    EXPECT_TRUE(mSurface.isProtected());
}

TEST_F(RenderSurfaceTest, setProtectedFalseDisablesProtection) {
    EXPECT_FALSE(mSurface.isProtected());
    EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR));

    mSurface.setProtected(false);
    EXPECT_FALSE(mSurface.isProtected());
}

TEST_F(RenderSurfaceTest, setProtectedEnableAndDisable) {
    EXPECT_FALSE(mSurface.isProtected());
    EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED))
            .WillOnce(Return(NO_ERROR));
    EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER)).WillOnce(Return(NO_ERROR));

    mSurface.setProtected(true);
    EXPECT_TRUE(mSurface.isProtected());
    mSurface.setProtected(false);
    EXPECT_FALSE(mSurface.isProtected());
}

TEST_F(RenderSurfaceTest, setProtectedEnableWithError) {
    EXPECT_FALSE(mSurface.isProtected());
    EXPECT_CALL(*mNativeWindow, setUsage(GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_PROTECTED))
            .WillOnce(Return(INVALID_OPERATION));
    mSurface.setProtected(true);
    EXPECT_FALSE(mSurface.isProtected());
}

/* ------------------------------------------------------------------------
Loading