Skip to content

Commit d6c938f

Browse files
author
Jamie Gennis
committed
SurfaceTexture: add a blit-to-FBO test
This change adds a test for blitting (via GL rendering) from a SurfaceTexture to an FBO. Change-Id: Ib3386fcc3f37153277f3e37a26347441bb80ab58
1 parent be6ab57 commit d6c938f

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

libs/gui/tests/SurfaceTexture_test.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,20 @@ void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
536536
}
537537
}
538538

539+
void fillRGBA8BufferSolid(uint8_t* buf, int w, int h, int stride, uint8_t r,
540+
uint8_t g, uint8_t b, uint8_t a) {
541+
const size_t PIXEL_SIZE = 4;
542+
for (int y = 0; y < h; y++) {
543+
for (int x = 0; x < h; x++) {
544+
off_t offset = (y * stride + x) * PIXEL_SIZE;
545+
buf[offset + 0] = r;
546+
buf[offset + 1] = g;
547+
buf[offset + 2] = b;
548+
buf[offset + 3] = a;
549+
}
550+
}
551+
}
552+
539553
TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferNpot) {
540554
const int texWidth = 64;
541555
const int texHeight = 66;
@@ -1616,4 +1630,101 @@ TEST_F(SurfaceTextureGLThreadToGLTest,
16161630
}
16171631
}
16181632

1633+
class SurfaceTextureFBOTest : public SurfaceTextureGLTest {
1634+
protected:
1635+
1636+
virtual void SetUp() {
1637+
SurfaceTextureGLTest::SetUp();
1638+
1639+
glGenFramebuffers(1, &mFbo);
1640+
ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
1641+
1642+
glGenTextures(1, &mFboTex);
1643+
glBindTexture(GL_TEXTURE_2D, mFboTex);
1644+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getSurfaceWidth(),
1645+
getSurfaceHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1646+
glBindTexture(GL_TEXTURE_2D, 0);
1647+
ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
1648+
1649+
glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
1650+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1651+
GL_TEXTURE_2D, mFboTex, 0);
1652+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
1653+
ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
1654+
}
1655+
1656+
virtual void TearDown() {
1657+
SurfaceTextureGLTest::TearDown();
1658+
1659+
glDeleteTextures(1, &mFboTex);
1660+
glDeleteFramebuffers(1, &mFbo);
1661+
}
1662+
1663+
GLuint mFbo;
1664+
GLuint mFboTex;
1665+
};
1666+
1667+
// This test is intended to verify that proper synchronization is done when
1668+
// rendering into an FBO.
1669+
TEST_F(SurfaceTextureFBOTest, BlitFromCpuFilledBufferToFbo) {
1670+
const int texWidth = 64;
1671+
const int texHeight = 64;
1672+
1673+
ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
1674+
texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
1675+
ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
1676+
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
1677+
1678+
android_native_buffer_t* anb;
1679+
ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
1680+
ASSERT_TRUE(anb != NULL);
1681+
1682+
sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
1683+
ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
1684+
1685+
// Fill the buffer with green
1686+
uint8_t* img = NULL;
1687+
buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
1688+
fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 0, 255,
1689+
0, 255);
1690+
buf->unlock();
1691+
ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
1692+
1693+
ASSERT_EQ(NO_ERROR, mST->updateTexImage());
1694+
1695+
glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
1696+
drawTexture();
1697+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
1698+
1699+
for (int i = 0; i < 4; i++) {
1700+
SCOPED_TRACE(String8::format("frame %d", i).string());
1701+
1702+
ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
1703+
ASSERT_TRUE(anb != NULL);
1704+
1705+
buf = new GraphicBuffer(anb, false);
1706+
ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(),
1707+
buf->getNativeBuffer()));
1708+
1709+
// Fill the buffer with red
1710+
ASSERT_EQ(NO_ERROR, buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN,
1711+
(void**)(&img)));
1712+
fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 255, 0,
1713+
0, 255);
1714+
ASSERT_EQ(NO_ERROR, buf->unlock());
1715+
ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(),
1716+
buf->getNativeBuffer()));
1717+
1718+
ASSERT_EQ(NO_ERROR, mST->updateTexImage());
1719+
1720+
drawTexture();
1721+
1722+
EXPECT_TRUE(checkPixel( 24, 39, 255, 0, 0, 255));
1723+
}
1724+
1725+
glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
1726+
1727+
EXPECT_TRUE(checkPixel( 24, 39, 0, 255, 0, 255));
1728+
}
1729+
16191730
} // namespace android

0 commit comments

Comments
 (0)