From b64d87515212d795405c6b3622dd365202eb4c39 Mon Sep 17 00:00:00 2001 From: Michael Lentine Date: Thu, 21 May 2015 13:48:24 -0700 Subject: [PATCH] Fix surfaceflinger tests. Update the screenshot code and add correct return values to surface flinger's capturescreenshot function. Buf: 18138368 Change-Id: Ieb42d289088589f941502fbd69da7aa939265e07 (cherry picked from commit 5a16a62950de06d48769e29f0c68a154ed7a7a89) --- services/surfaceflinger/SurfaceFlinger.cpp | 6 +-- .../surfaceflinger/tests/Transaction_test.cpp | 44 +++++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 715b92f11..89be4dc74 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -3283,8 +3283,8 @@ status_t SurfaceFlinger::captureScreenImplLocked( sp sur = new Surface(producer, false); ANativeWindow* window = sur.get(); - status_t result = NO_ERROR; - if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) == NO_ERROR) { + status_t result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); + if (result == NO_ERROR) { uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; @@ -3374,7 +3374,7 @@ status_t SurfaceFlinger::captureScreenImplLocked( result = BAD_VALUE; } // queueBuffer takes ownership of syncFd - window->queueBuffer(window, buffer, syncFd); + result = window->queueBuffer(window, buffer, syncFd); } } else { result = BAD_VALUE; diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp index 4d363c8a0..dcde51201 100644 --- a/services/surfaceflinger/tests/Transaction_test.cpp +++ b/services/surfaceflinger/tests/Transaction_test.cpp @@ -16,6 +16,8 @@ #include +#include + #include #include @@ -53,21 +55,23 @@ static void fillSurfaceRGBA8(const sp& sc, class ScreenCapture : public RefBase { public: static void captureScreen(sp* sc) { - sp heap; - uint32_t w=0, h=0; - PixelFormat fmt=0; + sp producer; + sp consumer; + BufferQueue::createBufferQueue(&producer, &consumer); + IGraphicBufferProducer::QueueBufferOutput bufferOutput; + sp cpuConsumer = new CpuConsumer(consumer, 1); sp sf(ComposerService::getComposerService()); - sp display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); - ASSERT_EQ(NO_ERROR, sf->captureScreen(display, &heap, &w, &h, &fmt, 0, 0, - 0, INT_MAX)); - ASSERT_TRUE(heap != NULL); - ASSERT_EQ(PIXEL_FORMAT_RGBA_8888, fmt); - *sc = new ScreenCapture(w, h, heap); + sp display(sf->getBuiltInDisplay( + ISurfaceComposer::eDisplayIdMain)); + ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0, + 0, INT_MAX, false)); + *sc = new ScreenCapture(cpuConsumer); } void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) { - const uint8_t* img = reinterpret_cast(mHeap->base()); - const uint8_t* pixel = img + (4 * (y*mWidth + x)); + ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format); + const uint8_t* img = static_cast(mBuf.data); + const uint8_t* pixel = img + (4 * (y * mBuf.stride + x)); if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { String8 err(String8::format("pixel @ (%3d, %3d): " "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", @@ -77,15 +81,17 @@ public: } private: - ScreenCapture(uint32_t w, uint32_t h, const sp& heap) : - mWidth(w), - mHeight(h), - mHeap(heap) - {} + ScreenCapture(const sp& cc) : + mCC(cc) { + EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf)); + } - const uint32_t mWidth; - const uint32_t mHeight; - sp mHeap; + ~ScreenCapture() { + mCC->unlockBuffer(mBuf); + } + + sp mCC; + CpuConsumer::LockedBuffer mBuf; }; class LayerUpdateTest : public ::testing::Test {