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 5a16a62950
)
This commit is contained in:
parent
e0d3e7073a
commit
b64d875152
@ -3283,8 +3283,8 @@ status_t SurfaceFlinger::captureScreenImplLocked(
|
|||||||
sp<Surface> sur = new Surface(producer, false);
|
sp<Surface> sur = new Surface(producer, false);
|
||||||
ANativeWindow* window = sur.get();
|
ANativeWindow* window = sur.get();
|
||||||
|
|
||||||
status_t result = NO_ERROR;
|
status_t result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
|
||||||
if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) == NO_ERROR) {
|
if (result == NO_ERROR) {
|
||||||
uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
|
uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
|
||||||
GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
|
GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
|
||||||
|
|
||||||
@ -3374,7 +3374,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(
|
|||||||
result = BAD_VALUE;
|
result = BAD_VALUE;
|
||||||
}
|
}
|
||||||
// queueBuffer takes ownership of syncFd
|
// queueBuffer takes ownership of syncFd
|
||||||
window->queueBuffer(window, buffer, syncFd);
|
result = window->queueBuffer(window, buffer, syncFd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = BAD_VALUE;
|
result = BAD_VALUE;
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <android/native_window.h>
|
||||||
|
|
||||||
#include <binder/IMemory.h>
|
#include <binder/IMemory.h>
|
||||||
|
|
||||||
#include <gui/ISurfaceComposer.h>
|
#include <gui/ISurfaceComposer.h>
|
||||||
@ -53,21 +55,23 @@ static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc,
|
|||||||
class ScreenCapture : public RefBase {
|
class ScreenCapture : public RefBase {
|
||||||
public:
|
public:
|
||||||
static void captureScreen(sp<ScreenCapture>* sc) {
|
static void captureScreen(sp<ScreenCapture>* sc) {
|
||||||
sp<IMemoryHeap> heap;
|
sp<IGraphicBufferProducer> producer;
|
||||||
uint32_t w=0, h=0;
|
sp<IGraphicBufferConsumer> consumer;
|
||||||
PixelFormat fmt=0;
|
BufferQueue::createBufferQueue(&producer, &consumer);
|
||||||
|
IGraphicBufferProducer::QueueBufferOutput bufferOutput;
|
||||||
|
sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
|
||||||
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
|
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
|
||||||
sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
|
sp<IBinder> display(sf->getBuiltInDisplay(
|
||||||
ASSERT_EQ(NO_ERROR, sf->captureScreen(display, &heap, &w, &h, &fmt, 0, 0,
|
ISurfaceComposer::eDisplayIdMain));
|
||||||
0, INT_MAX));
|
ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
|
||||||
ASSERT_TRUE(heap != NULL);
|
0, INT_MAX, false));
|
||||||
ASSERT_EQ(PIXEL_FORMAT_RGBA_8888, fmt);
|
*sc = new ScreenCapture(cpuConsumer);
|
||||||
*sc = new ScreenCapture(w, h, heap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
|
void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
|
||||||
const uint8_t* img = reinterpret_cast<const uint8_t*>(mHeap->base());
|
ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
|
||||||
const uint8_t* pixel = img + (4 * (y*mWidth + x));
|
const uint8_t* img = static_cast<const uint8_t*>(mBuf.data);
|
||||||
|
const uint8_t* pixel = img + (4 * (y * mBuf.stride + x));
|
||||||
if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
|
if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
|
||||||
String8 err(String8::format("pixel @ (%3d, %3d): "
|
String8 err(String8::format("pixel @ (%3d, %3d): "
|
||||||
"expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
|
"expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
|
||||||
@ -77,15 +81,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScreenCapture(uint32_t w, uint32_t h, const sp<IMemoryHeap>& heap) :
|
ScreenCapture(const sp<CpuConsumer>& cc) :
|
||||||
mWidth(w),
|
mCC(cc) {
|
||||||
mHeight(h),
|
EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf));
|
||||||
mHeap(heap)
|
}
|
||||||
{}
|
|
||||||
|
|
||||||
const uint32_t mWidth;
|
~ScreenCapture() {
|
||||||
const uint32_t mHeight;
|
mCC->unlockBuffer(mBuf);
|
||||||
sp<IMemoryHeap> mHeap;
|
}
|
||||||
|
|
||||||
|
sp<CpuConsumer> mCC;
|
||||||
|
CpuConsumer::LockedBuffer mBuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LayerUpdateTest : public ::testing::Test {
|
class LayerUpdateTest : public ::testing::Test {
|
||||||
|
Loading…
Reference in New Issue
Block a user