blob: f34561f6681ac21603bb5f84c3eb7b536e86c432 [file] [log] [blame]
Dan Stozacb1fcde2013-12-03 12:37:36 -08001/*
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
22namespace android {
23
24// This test is intended to verify that proper synchronization is done when
25// rendering into an FBO.
26TEST_F(SurfaceTextureFBOTest, BlitFromCpuFilledBufferToFbo) {
27 const int texWidth = 64;
28 const int texHeight = 64;
29
Pablo Ceballos583b1b32015-09-03 18:23:52 -070030 ASSERT_EQ(NO_ERROR, native_window_api_connect(mANW.get(),
31 NATIVE_WINDOW_API_CPU));
Dan Stozaf8cebe52015-04-20 12:09:38 -070032 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));
Dan Stozacb1fcde2013-12-03 12:37:36 -080036 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));
Yi Konga03e0442018-07-17 11:16:57 -070042 ASSERT_TRUE(anb != nullptr);
Dan Stozacb1fcde2013-12-03 12:37:36 -080043
Mathias Agopianf543e5a2017-04-03 17:16:41 -070044 sp<GraphicBuffer> buf(GraphicBuffer::from(anb));
Dan Stozacb1fcde2013-12-03 12:37:36 -080045
46 // Fill the buffer with green
Yi Konga03e0442018-07-17 11:16:57 -070047 uint8_t* img = nullptr;
Dan Stozacb1fcde2013-12-03 12:37:36 -080048 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));
Yi Konga03e0442018-07-17 11:16:57 -070066 ASSERT_TRUE(anb != nullptr);
Dan Stozacb1fcde2013-12-03 12:37:36 -080067
Mathias Agopianf543e5a2017-04-03 17:16:41 -070068 buf = GraphicBuffer::from(anb);
Dan Stozacb1fcde2013-12-03 12:37:36 -080069
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