diff options
author | Jamie Gennis <jgennis@google.com> | 2011-03-10 18:06:32 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-03-10 18:06:32 -0800 |
commit | b2e606f5f175906ab8c578cb9ba03c728154c50c (patch) | |
tree | 5aaaa42fab675f167ce3c362341ec11877fd6e74 /libs | |
parent | e90c4998b514f738b3655e55b51a38119b8c5f23 (diff) | |
parent | f72606ce3ea8cb787e5c71325f08b1898e0718d9 (diff) | |
download | frameworks_base-b2e606f5f175906ab8c578cb9ba03c728154c50c.zip frameworks_base-b2e606f5f175906ab8c578cb9ba03c728154c50c.tar.gz frameworks_base-b2e606f5f175906ab8c578cb9ba03c728154c50c.tar.bz2 |
Merge "SurfaceFlinger: Respect the PROTECTED gralloc bit." into honeycomb-mr1
Diffstat (limited to 'libs')
-rw-r--r-- | libs/surfaceflinger_client/tests/Surface_test.cpp | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/libs/surfaceflinger_client/tests/Surface_test.cpp b/libs/surfaceflinger_client/tests/Surface_test.cpp index b39631c..74ebf4e 100644 --- a/libs/surfaceflinger_client/tests/Surface_test.cpp +++ b/libs/surfaceflinger_client/tests/Surface_test.cpp @@ -15,22 +15,19 @@ */ #include <gtest/gtest.h> + +#include <binder/IMemory.h> #include <surfaceflinger/ISurfaceComposer.h> #include <surfaceflinger/Surface.h> #include <surfaceflinger/SurfaceComposerClient.h> - #include <utils/String8.h> namespace android { class SurfaceTest : public ::testing::Test { protected: - virtual sp<SurfaceComposerClient> getSurfaceComposerClient() { - return sp<SurfaceComposerClient>(new SurfaceComposerClient); - } - virtual void SetUp() { - mComposerClient = getSurfaceComposerClient(); + mComposerClient = new SurfaceComposerClient; ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); mSurfaceControl = mComposerClient->createSurface(getpid(), @@ -77,4 +74,60 @@ TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) { EXPECT_EQ(1, result); } +// This test probably doesn't belong here. +TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersFail) { + sp<ANativeWindow> anw(mSurface); + + // Verify the screenshot works with no protected buffers. + sp<IMemoryHeap> heap; + uint32_t w=0, h=0; + PixelFormat fmt=0; + sp<ISurfaceComposer> sf(ComposerService::getComposerService()); + ASSERT_EQ(NO_ERROR, sf->captureScreen(0, &heap, &w, &h, &fmt, 64, 64, 0, + 40000)); + ASSERT_TRUE(heap != NULL); + + // Set the PROTECTED usage bit and verify that the screenshot fails. Note + // that we need to dequeue a buffer in order for it to actually get + // allocated in SurfaceFlinger. + ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), + GRALLOC_USAGE_PROTECTED)); + ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3)); + android_native_buffer_t* buf = 0; + for (int i = 0; i < 4; i++) { + // Loop to make sure SurfaceFlinger has retired a protected buffer. + ASSERT_EQ(NO_ERROR, anw->dequeueBuffer(anw.get(), &buf)); + ASSERT_EQ(NO_ERROR, anw->lockBuffer(anw.get(), buf)); + ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf)); + } + heap = 0; + w = h = fmt = 0; + ASSERT_EQ(INVALID_OPERATION, sf->captureScreen(0, &heap, &w, &h, &fmt, + 64, 64, 0, 40000)); + ASSERT_TRUE(heap == NULL); + + // XXX: This should not be needed, but it seems that the new buffers don't + // correctly show up after the upcoming dequeue/lock/queue loop without it. + // We should look into this at some point. + ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3)); + + // Un-set the PROTECTED usage bit and verify that the screenshot works + // again. Note that we have to change the buffers geometry to ensure that + // the buffers get reallocated, as the new usage bits are a subset of the + // old. + ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), 0)); + ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(anw.get(), 32, 32, 0)); + for (int i = 0; i < 4; i++) { + // Loop to make sure SurfaceFlinger has retired a protected buffer. + ASSERT_EQ(NO_ERROR, anw->dequeueBuffer(anw.get(), &buf)); + ASSERT_EQ(NO_ERROR, anw->lockBuffer(anw.get(), buf)); + ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf)); + } + heap = 0; + w = h = fmt = 0; + ASSERT_EQ(NO_ERROR, sf->captureScreen(0, &heap, &w, &h, &fmt, 64, 64, 0, + 40000)); + ASSERT_TRUE(heap != NULL); +} + } |