diff options
author | Jamie Gennis <jgennis@google.com> | 2011-03-09 17:05:02 -0800 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2011-03-10 16:25:48 -0800 |
commit | f72606ce3ea8cb787e5c71325f08b1898e0718d9 (patch) | |
tree | e81f8fb6a932f9660d8c65bde57fed694a18aacc /libs | |
parent | 87e8ab372bd722c5c1a00ff5262acccee5dae5e5 (diff) | |
download | frameworks_base-f72606ce3ea8cb787e5c71325f08b1898e0718d9.zip frameworks_base-f72606ce3ea8cb787e5c71325f08b1898e0718d9.tar.gz frameworks_base-f72606ce3ea8cb787e5c71325f08b1898e0718d9.tar.bz2 |
SurfaceFlinger: Respect the PROTECTED gralloc bit.
This change makes SurfaceFlinger treat layers for which the active
buffer has the GRALLOC_USAGE_PROTECTED bit set as if they have the
'secure' flag set.
Change-Id: Ic60b6513a63e4bb92ec6ce9fd12fd39b4ba5f674
Bug: 4081304
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); +} + } |