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

Commit 3341f189 authored by Peiyong Lin's avatar Peiyong Lin Committed by android-build-merger
Browse files

Merge "[SurfaceFlinger] Make sure switch the protected state of buffers." into qt-dev

am: 6902bb6c

Change-Id: I636eca9f7f3ad8f86966df6882b376a60fd46156
parents 09edbc26 6902bb6c
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