1 /*
2 * Copyright 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "SurfaceTextureFBO_test"
18 //#define LOG_NDEBUG 0
19
20 #include "SurfaceTextureFBO.h"
21
22 namespace android {
23
24 // This test is intended to verify that proper synchronization is done when
25 // rendering into an FBO.
TEST_F(SurfaceTextureFBOTest,BlitFromCpuFilledBufferToFbo)26 TEST_F(SurfaceTextureFBOTest, BlitFromCpuFilledBufferToFbo) {
27 const int texWidth = 64;
28 const int texHeight = 64;
29
30 ASSERT_EQ(NO_ERROR, native_window_api_connect(mANW.get(),
31 NATIVE_WINDOW_API_CPU));
32 ASSERT_EQ(NO_ERROR, native_window_set_buffers_dimensions(mANW.get(),
33 texWidth, texHeight));
34 ASSERT_EQ(NO_ERROR, native_window_set_buffers_format(mANW.get(),
35 HAL_PIXEL_FORMAT_RGBA_8888));
36 ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
37 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
38
39 android_native_buffer_t* anb;
40 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
41 &anb));
42 ASSERT_TRUE(anb != NULL);
43
44 sp<GraphicBuffer> buf(GraphicBuffer::from(anb));
45
46 // Fill the buffer with green
47 uint8_t* img = NULL;
48 buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
49 fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 0, 255,
50 0, 255);
51 buf->unlock();
52 ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer(),
53 -1));
54
55 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
56
57 glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
58 drawTexture();
59 glBindFramebuffer(GL_FRAMEBUFFER, 0);
60
61 for (int i = 0; i < 4; i++) {
62 SCOPED_TRACE(String8::format("frame %d", i).string());
63
64 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
65 &anb));
66 ASSERT_TRUE(anb != NULL);
67
68 buf = GraphicBuffer::from(anb);
69
70 // Fill the buffer with red
71 ASSERT_EQ(NO_ERROR, buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN,
72 (void**)(&img)));
73 fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 255, 0,
74 0, 255);
75 ASSERT_EQ(NO_ERROR, buf->unlock());
76 ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(),
77 buf->getNativeBuffer(), -1));
78
79 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
80
81 drawTexture();
82
83 EXPECT_TRUE(checkPixel( 24, 39, 255, 0, 0, 255));
84 }
85
86 glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
87
88 EXPECT_TRUE(checkPixel( 24, 39, 0, 255, 0, 255));
89 }
90
91 } // namespace android
92