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_set_buffers_dimensions(mANW.get(),
31 texWidth, texHeight));
32 ASSERT_EQ(NO_ERROR, native_window_set_buffers_format(mANW.get(),
33 HAL_PIXEL_FORMAT_RGBA_8888));
34 ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
35 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
36
37 android_native_buffer_t* anb;
38 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
39 &anb));
40 ASSERT_TRUE(anb != NULL);
41
42 sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
43
44 // Fill the buffer with green
45 uint8_t* img = NULL;
46 buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
47 fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 0, 255,
48 0, 255);
49 buf->unlock();
50 ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer(),
51 -1));
52
53 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
54
55 glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
56 drawTexture();
57 glBindFramebuffer(GL_FRAMEBUFFER, 0);
58
59 for (int i = 0; i < 4; i++) {
60 SCOPED_TRACE(String8::format("frame %d", i).string());
61
62 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
63 &anb));
64 ASSERT_TRUE(anb != NULL);
65
66 buf = new GraphicBuffer(anb, false);
67
68 // Fill the buffer with red
69 ASSERT_EQ(NO_ERROR, buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN,
70 (void**)(&img)));
71 fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 255, 0,
72 0, 255);
73 ASSERT_EQ(NO_ERROR, buf->unlock());
74 ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(),
75 buf->getNativeBuffer(), -1));
76
77 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
78
79 drawTexture();
80
81 EXPECT_TRUE(checkPixel( 24, 39, 255, 0, 0, 255));
82 }
83
84 glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
85
86 EXPECT_TRUE(checkPixel( 24, 39, 0, 255, 0, 255));
87 }
88
89 } // namespace android
90