blob: 2b8f204563cd21c3c6be1eeeddaf948a5ef80236 [file] [log] [blame]
Jamie Gennis134f0422011-03-08 12:18:54 -08001/*
2 * Copyright (C) 2011 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
Jamie Gennis5c0c93a2011-03-14 15:34:04 -070017#include <EGL/egl.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080018#include <gtest/gtest.h>
Jamie Gennis5c0c93a2011-03-14 15:34:04 -070019#include <gui/SurfaceTextureClient.h>
Mathias Agopian7a5b22c2011-04-26 14:57:10 -070020#include <utils/threads.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080021
22namespace android {
23
24class SurfaceTextureClientTest : public ::testing::Test {
25protected:
Mathias Agopian7a5b22c2011-04-26 14:57:10 -070026 SurfaceTextureClientTest():
27 mEglDisplay(EGL_NO_DISPLAY),
28 mEglSurface(EGL_NO_SURFACE),
29 mEglContext(EGL_NO_CONTEXT) {
30 }
31
Jamie Gennis134f0422011-03-08 12:18:54 -080032 virtual void SetUp() {
33 mST = new SurfaceTexture(123);
34 mSTC = new SurfaceTextureClient(mST);
Jamie Gennis8b69def2011-04-06 15:43:16 -070035 mANW = mSTC;
Mathias Agopian7a5b22c2011-04-26 14:57:10 -070036
37 // We need a valid GL context so we can test updateTexImage()
38 // This initializes EGL and create a dummy GL context with a
39 // pbuffer render target.
40 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
41 ASSERT_EQ(EGL_SUCCESS, eglGetError());
42 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
43
44 EGLint majorVersion, minorVersion;
45 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
46 ASSERT_EQ(EGL_SUCCESS, eglGetError());
47
48 EGLConfig myConfig;
49 EGLint numConfigs = 0;
50 EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(),
51 &myConfig, 1, &numConfigs));
52 ASSERT_EQ(EGL_SUCCESS, eglGetError());
53
54 EGLint pbufferAttribs[] = {
55 EGL_WIDTH, 16,
56 EGL_HEIGHT, 16,
57 EGL_NONE };
58 mEglSurface = eglCreatePbufferSurface(mEglDisplay, myConfig, pbufferAttribs);
59 ASSERT_EQ(EGL_SUCCESS, eglGetError());
60 ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
61
62 mEglContext = eglCreateContext(mEglDisplay, myConfig, EGL_NO_CONTEXT, 0);
63 ASSERT_EQ(EGL_SUCCESS, eglGetError());
64 ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
65
66 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext));
67 ASSERT_EQ(EGL_SUCCESS, eglGetError());
Jamie Gennis134f0422011-03-08 12:18:54 -080068 }
69
70 virtual void TearDown() {
71 mST.clear();
72 mSTC.clear();
Jamie Gennis8b69def2011-04-06 15:43:16 -070073 mANW.clear();
74
Mathias Agopian7a5b22c2011-04-26 14:57:10 -070075 eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
76 eglDestroyContext(mEglDisplay, mEglContext);
77 eglDestroySurface(mEglDisplay, mEglSurface);
78 eglTerminate(mEglDisplay);
79 }
80
81 virtual EGLint const* getConfigAttribs() {
82 static EGLint sDefaultConfigAttribs[] = {
83 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
84 EGL_NONE
85 };
86
87 return sDefaultConfigAttribs;
Jamie Gennis134f0422011-03-08 12:18:54 -080088 }
89
90 sp<SurfaceTexture> mST;
91 sp<SurfaceTextureClient> mSTC;
Jamie Gennis8b69def2011-04-06 15:43:16 -070092 sp<ANativeWindow> mANW;
93
Mathias Agopian7a5b22c2011-04-26 14:57:10 -070094 EGLDisplay mEglDisplay;
95 EGLSurface mEglSurface;
96 EGLContext mEglContext;
Jamie Gennis134f0422011-03-08 12:18:54 -080097};
98
Jamie Gennisbae774e2011-03-14 15:08:53 -070099TEST_F(SurfaceTextureClientTest, GetISurfaceTextureIsNotNull) {
100 sp<ISurfaceTexture> ist(mSTC->getISurfaceTexture());
101 ASSERT_TRUE(ist != NULL);
102}
103
Jamie Gennis134f0422011-03-08 12:18:54 -0800104TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) {
Jamie Gennis134f0422011-03-08 12:18:54 -0800105 int result = -123;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700106 int err = mANW->query(mANW.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
Jamie Gennis134f0422011-03-08 12:18:54 -0800107 &result);
108 EXPECT_EQ(NO_ERROR, err);
109 EXPECT_EQ(0, result);
110}
111
Jamie Gennis391bbe22011-03-14 15:00:06 -0700112TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) {
Jamie Gennis391bbe22011-03-14 15:00:06 -0700113 int result = -123;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700114 int err = mANW->query(mANW.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
Jamie Gennis391bbe22011-03-14 15:00:06 -0700115 EXPECT_EQ(NO_ERROR, err);
116 EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result);
117}
118
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700119TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) {
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700120 ANativeWindow_Buffer buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700121 ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(mANW.get(), &buf, NULL));
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700122}
123
Jamie Gennis1b528fb2011-04-25 16:41:11 -0700124TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceSucceeds) {
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700125 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
126 ASSERT_EQ(EGL_SUCCESS, eglGetError());
127 ASSERT_NE(EGL_NO_DISPLAY, dpy);
128
129 EGLint majorVersion;
130 EGLint minorVersion;
131 EXPECT_TRUE(eglInitialize(dpy, &majorVersion, &minorVersion));
132 ASSERT_EQ(EGL_SUCCESS, eglGetError());
133
134 EGLConfig myConfig = {0};
135 EGLint numConfigs = 0;
136 EGLint configAttribs[] = {
137 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
138 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
139 EGL_RED_SIZE, 8,
140 EGL_GREEN_SIZE, 8,
141 EGL_BLUE_SIZE, 8,
142 EGL_ALPHA_SIZE, 8,
143 EGL_DEPTH_SIZE, 16,
144 EGL_STENCIL_SIZE, 8,
145 EGL_NONE };
146 EXPECT_TRUE(eglChooseConfig(dpy, configAttribs, &myConfig, 1,
147 &numConfigs));
148 ASSERT_EQ(EGL_SUCCESS, eglGetError());
149
Jamie Gennis8b69def2011-04-06 15:43:16 -0700150 EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, mANW.get(),
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700151 NULL);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700152 EXPECT_NE(EGL_NO_SURFACE, eglSurface);
153 EXPECT_EQ(EGL_SUCCESS, eglGetError());
Jamie Gennis5c0c93a2011-03-14 15:34:04 -0700154
155 eglTerminate(dpy);
156}
157
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700158TEST_F(SurfaceTextureClientTest, BufferGeometryInvalidSizesFail) {
Jamie Gennis8b69def2011-04-06 15:43:16 -0700159 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, 0, 0));
160 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, -1, 0));
161 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, -1));
162 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, -1, 0));
163 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 0, 8, 0));
164 EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), 8, 0, 0));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700165}
166
167TEST_F(SurfaceTextureClientTest, DefaultGeometryValues) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700168 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700169 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700170 EXPECT_EQ(1, buf->width);
171 EXPECT_EQ(1, buf->height);
172 EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700173 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700174}
175
176TEST_F(SurfaceTextureClientTest, BufferGeometryCanBeSet) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700177 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700178 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, PIXEL_FORMAT_RGB_565));
179 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700180 EXPECT_EQ(16, buf->width);
181 EXPECT_EQ(8, buf->height);
182 EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700183 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700184}
185
186TEST_F(SurfaceTextureClientTest, BufferGeometryDefaultSizeSetFormat) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700187 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700188 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
189 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700190 EXPECT_EQ(1, buf->width);
191 EXPECT_EQ(1, buf->height);
192 EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700193 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700194}
195
196TEST_F(SurfaceTextureClientTest, BufferGeometrySetSizeDefaultFormat) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700197 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700198 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
199 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700200 EXPECT_EQ(16, buf->width);
201 EXPECT_EQ(8, buf->height);
202 EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700203 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700204}
205
206TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeUnset) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700207 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700208 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
209 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700210 EXPECT_EQ(16, buf->width);
211 EXPECT_EQ(8, buf->height);
212 EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700213 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
214 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, 0));
215 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700216 EXPECT_EQ(1, buf->width);
217 EXPECT_EQ(1, buf->height);
218 EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700219 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700220}
221
222TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeChangedWithoutFormat) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700223 ANativeWindowBuffer* buf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700224 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
225 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700226 EXPECT_EQ(1, buf->width);
227 EXPECT_EQ(1, buf->height);
228 EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700229 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
230 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
231 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700232 EXPECT_EQ(16, buf->width);
233 EXPECT_EQ(8, buf->height);
234 EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700235 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700236}
237
238TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSize) {
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700239 sp<SurfaceTexture> st(mST);
Iliyan Malchev697526b2011-05-01 11:33:26 -0700240 ANativeWindowBuffer* buf;
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700241 EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
Jamie Gennis8b69def2011-04-06 15:43:16 -0700242 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700243 EXPECT_EQ(16, buf->width);
244 EXPECT_EQ(8, buf->height);
245 EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700246 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700247}
248
249TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeAfterDequeue) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700250 ANativeWindowBuffer* buf[2];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700251 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
252 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
253 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700254 EXPECT_NE(buf[0], buf[1]);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700255 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
256 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
257 EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
258 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
259 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700260 EXPECT_NE(buf[0], buf[1]);
261 EXPECT_EQ(16, buf[0]->width);
262 EXPECT_EQ(16, buf[1]->width);
263 EXPECT_EQ(8, buf[0]->height);
264 EXPECT_EQ(8, buf[1]->height);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700265 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
266 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700267}
268
269TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeVsGeometry) {
Iliyan Malchev697526b2011-05-01 11:33:26 -0700270 ANativeWindowBuffer* buf[2];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700271 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
272 EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
273 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
274 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700275 EXPECT_NE(buf[0], buf[1]);
276 EXPECT_EQ(16, buf[0]->width);
277 EXPECT_EQ(16, buf[1]->width);
278 EXPECT_EQ(8, buf[0]->height);
279 EXPECT_EQ(8, buf[1]->height);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700280 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
281 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
282 EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 12, 24, 0));
283 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
284 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700285 EXPECT_NE(buf[0], buf[1]);
286 EXPECT_EQ(12, buf[0]->width);
287 EXPECT_EQ(12, buf[1]->width);
288 EXPECT_EQ(24, buf[0]->height);
289 EXPECT_EQ(24, buf[1]->height);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700290 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
291 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700292}
293
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700294TEST_F(SurfaceTextureClientTest, SurfaceTextureTooManyUpdateTexImage) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700295 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700296 ASSERT_EQ(OK, mST->setSynchronousMode(false));
297 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700298
Jamie Gennis8b69def2011-04-06 15:43:16 -0700299 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
300 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
301 EXPECT_EQ(OK, mST->updateTexImage());
302 EXPECT_EQ(OK, mST->updateTexImage());
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700303
Jamie Gennis8b69def2011-04-06 15:43:16 -0700304 ASSERT_EQ(OK, mST->setSynchronousMode(true));
305 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700306
Jamie Gennis8b69def2011-04-06 15:43:16 -0700307 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
308 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
309 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
310 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700311
Jamie Gennis8b69def2011-04-06 15:43:16 -0700312 EXPECT_EQ(OK, mST->updateTexImage());
313 EXPECT_EQ(OK, mST->updateTexImage());
314 EXPECT_EQ(OK, mST->updateTexImage());
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700315}
316
317TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeSlowRetire) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700318 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700319 ASSERT_EQ(OK, mST->setSynchronousMode(true));
320 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
321 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
322 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
323 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700324 EXPECT_NE(buf[0], buf[1]);
325 EXPECT_NE(buf[1], buf[2]);
326 EXPECT_NE(buf[2], buf[0]);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700327 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
328 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
329 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
330 EXPECT_EQ(OK, mST->updateTexImage());
331 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
332 EXPECT_EQ(OK, mST->updateTexImage());
333 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
334 EXPECT_EQ(OK, mST->updateTexImage());
335 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700336}
337
338TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeFastRetire) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700339 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700340 ASSERT_EQ(OK, mST->setSynchronousMode(true));
341 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
342 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
343 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
344 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700345 EXPECT_NE(buf[0], buf[1]);
346 EXPECT_NE(buf[1], buf[2]);
347 EXPECT_NE(buf[2], buf[0]);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700348 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
349 EXPECT_EQ(OK, mST->updateTexImage());
350 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
351 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
352 EXPECT_EQ(OK, mST->updateTexImage());
353 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
354 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
355 EXPECT_EQ(OK, mST->updateTexImage());
356 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700357}
358
359TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDQQR) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700360 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700361 ASSERT_EQ(OK, mST->setSynchronousMode(true));
362 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700363
Jamie Gennis8b69def2011-04-06 15:43:16 -0700364 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
365 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
366 EXPECT_EQ(OK, mST->updateTexImage());
367 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700368
Jamie Gennis8b69def2011-04-06 15:43:16 -0700369 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700370 EXPECT_NE(buf[0], buf[1]);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700371 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
372 EXPECT_EQ(OK, mST->updateTexImage());
373 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700374
Jamie Gennis8b69def2011-04-06 15:43:16 -0700375 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700376 EXPECT_NE(buf[1], buf[2]);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700377 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
378 EXPECT_EQ(OK, mST->updateTexImage());
379 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700380}
381
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700382// XXX: We currently have no hardware that properly handles dequeuing the
383// buffer that is currently bound to the texture.
384TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeDequeueCurrent) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700385 android_native_buffer_t* buf[3];
386 android_native_buffer_t* firstBuf;
Jamie Gennis8b69def2011-04-06 15:43:16 -0700387 ASSERT_EQ(OK, mST->setSynchronousMode(true));
388 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
389 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &firstBuf));
390 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), firstBuf));
391 EXPECT_EQ(OK, mST->updateTexImage());
392 EXPECT_EQ(mST->getCurrentBuffer().get(), firstBuf);
393 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
394 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
395 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
396 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
397 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
398 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700399 EXPECT_NE(buf[0], buf[1]);
400 EXPECT_NE(buf[1], buf[2]);
401 EXPECT_NE(buf[2], buf[0]);
402 EXPECT_EQ(firstBuf, buf[2]);
403}
404
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700405TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700406 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700407 ASSERT_EQ(OK, mST->setSynchronousMode(true));
408 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
Jamie Gennisc2c8dfd2011-05-23 18:44:04 -0700409
Jamie Gennis8b69def2011-04-06 15:43:16 -0700410 // We should be able to dequeue all the buffers before we've queued mANWy.
411 EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
412 EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
413 EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700414
Jamie Gennis8b69def2011-04-06 15:43:16 -0700415 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
416 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700417
Jamie Gennis8b69def2011-04-06 15:43:16 -0700418 EXPECT_EQ(OK, mST->updateTexImage());
419 EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700420
Jamie Gennis8b69def2011-04-06 15:43:16 -0700421 EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700422
Jamie Gennisc2c8dfd2011-05-23 18:44:04 -0700423 // Once we've queued a buffer, however we should not be able to dequeue more
424 // than (buffer-count - MIN_UNDEQUEUED_BUFFERS), which is 2 in this case.
Jamie Gennis8b69def2011-04-06 15:43:16 -0700425 EXPECT_EQ(-EBUSY, mANW->dequeueBuffer(mANW.get(), &buf[1]));
Jamie Gennisc2c8dfd2011-05-23 18:44:04 -0700426
Jamie Gennis8b69def2011-04-06 15:43:16 -0700427 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
428 ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700429}
430
Jamie Gennis8dda6b72011-05-24 18:39:46 -0700431// XXX: This is not expected to pass until the synchronization hacks are removed
432// from the SurfaceTexture class.
433TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeWaitRetire) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700434 class MyThread : public Thread {
Jamie Gennis8b69def2011-04-06 15:43:16 -0700435 sp<SurfaceTexture> mST;
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700436 EGLContext ctx;
437 EGLSurface sur;
438 EGLDisplay dpy;
439 bool mBufferRetired;
440 Mutex mLock;
441 virtual bool threadLoop() {
442 eglMakeCurrent(dpy, sur, sur, ctx);
443 usleep(20000);
444 Mutex::Autolock _l(mLock);
Jamie Gennis8b69def2011-04-06 15:43:16 -0700445 mST->updateTexImage();
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700446 mBufferRetired = true;
447 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
448 return false;
449 }
450 public:
Jamie Gennis8b69def2011-04-06 15:43:16 -0700451 MyThread(const sp<SurfaceTexture>& mST)
452 : mST(mST), mBufferRetired(false) {
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700453 ctx = eglGetCurrentContext();
454 sur = eglGetCurrentSurface(EGL_DRAW);
455 dpy = eglGetCurrentDisplay();
456 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
457 }
458 ~MyThread() {
459 eglMakeCurrent(dpy, sur, sur, ctx);
460 }
461 void bufferDequeued() {
462 Mutex::Autolock _l(mLock);
463 EXPECT_EQ(true, mBufferRetired);
464 }
465 };
466
467 android_native_buffer_t* buf[3];
Jamie Gennis8b69def2011-04-06 15:43:16 -0700468 ASSERT_EQ(OK, mST->setSynchronousMode(true));
469 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700470 // dequeue/queue/update so we have a current buffer
Jamie Gennis8b69def2011-04-06 15:43:16 -0700471 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
472 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
473 mST->updateTexImage();
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700474
Jamie Gennis8b69def2011-04-06 15:43:16 -0700475 MyThread* thread = new MyThread(mST);
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700476 sp<Thread> threadBase(thread);
477
Jamie Gennis8b69def2011-04-06 15:43:16 -0700478 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
479 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
Mathias Agopiane1220792011-05-04 18:28:07 -0700480 thread->run();
Jamie Gennis8b69def2011-04-06 15:43:16 -0700481 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
482 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
483 //ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
484 //ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
Mathias Agopian7a5b22c2011-04-26 14:57:10 -0700485 thread->bufferDequeued();
486 thread->requestExitAndWait();
487}
488
Jamie Gennis52226042011-06-07 15:23:23 -0700489TEST_F(SurfaceTextureClientTest, GetTransformMatrixReturnsVerticalFlip) {
Jamie Gennis52226042011-06-07 15:23:23 -0700490 android_native_buffer_t* buf[3];
491 float mtx[16] = {};
Jamie Gennis8b69def2011-04-06 15:43:16 -0700492 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
493 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
494 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
495 ASSERT_EQ(OK, mST->updateTexImage());
496 mST->getTransformMatrix(mtx);
Jamie Gennis52226042011-06-07 15:23:23 -0700497
498 EXPECT_EQ(1.f, mtx[0]);
499 EXPECT_EQ(0.f, mtx[1]);
500 EXPECT_EQ(0.f, mtx[2]);
501 EXPECT_EQ(0.f, mtx[3]);
502
503 EXPECT_EQ(0.f, mtx[4]);
504 EXPECT_EQ(-1.f, mtx[5]);
505 EXPECT_EQ(0.f, mtx[6]);
506 EXPECT_EQ(0.f, mtx[7]);
507
508 EXPECT_EQ(0.f, mtx[8]);
509 EXPECT_EQ(0.f, mtx[9]);
510 EXPECT_EQ(1.f, mtx[10]);
511 EXPECT_EQ(0.f, mtx[11]);
512
513 EXPECT_EQ(0.f, mtx[12]);
514 EXPECT_EQ(1.f, mtx[13]);
515 EXPECT_EQ(0.f, mtx[14]);
516 EXPECT_EQ(1.f, mtx[15]);
Jamie Gennis134f0422011-03-08 12:18:54 -0800517}
Jamie Gennis52226042011-06-07 15:23:23 -0700518
519TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffers) {
Jamie Gennis52226042011-06-07 15:23:23 -0700520 android_native_buffer_t* buf[3];
521 float mtx[16] = {};
Jamie Gennis8b69def2011-04-06 15:43:16 -0700522 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
523 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
524 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
525 ASSERT_EQ(OK, mST->updateTexImage());
526 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
527 mST->getTransformMatrix(mtx);
Jamie Gennis52226042011-06-07 15:23:23 -0700528
529 EXPECT_EQ(1.f, mtx[0]);
530 EXPECT_EQ(0.f, mtx[1]);
531 EXPECT_EQ(0.f, mtx[2]);
532 EXPECT_EQ(0.f, mtx[3]);
533
534 EXPECT_EQ(0.f, mtx[4]);
535 EXPECT_EQ(-1.f, mtx[5]);
536 EXPECT_EQ(0.f, mtx[6]);
537 EXPECT_EQ(0.f, mtx[7]);
538
539 EXPECT_EQ(0.f, mtx[8]);
540 EXPECT_EQ(0.f, mtx[9]);
541 EXPECT_EQ(1.f, mtx[10]);
542 EXPECT_EQ(0.f, mtx[11]);
543
544 EXPECT_EQ(0.f, mtx[12]);
545 EXPECT_EQ(1.f, mtx[13]);
546 EXPECT_EQ(0.f, mtx[14]);
547 EXPECT_EQ(1.f, mtx[15]);
548}
549
550TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWithCrop) {
Jamie Gennis52226042011-06-07 15:23:23 -0700551 android_native_buffer_t* buf[3];
552 float mtx[16] = {};
553 android_native_rect_t crop;
554 crop.left = 0;
555 crop.top = 0;
556 crop.right = 5;
557 crop.bottom = 5;
558
Jamie Gennis8b69def2011-04-06 15:43:16 -0700559 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
560 ASSERT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 8, 8, 0));
561 ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
562 ASSERT_EQ(OK, native_window_set_crop(mANW.get(), &crop));
563 ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
564 ASSERT_EQ(OK, mST->updateTexImage());
565 ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
566 mST->getTransformMatrix(mtx);
Jamie Gennis52226042011-06-07 15:23:23 -0700567
568 // This accounts for the 1 texel shrink for each edge that's included in the
569 // transform matrix to avoid texturing outside the crop region.
570 EXPECT_EQ(.5f, mtx[0]);
571 EXPECT_EQ(0.f, mtx[1]);
572 EXPECT_EQ(0.f, mtx[2]);
573 EXPECT_EQ(0.f, mtx[3]);
574
575 EXPECT_EQ(0.f, mtx[4]);
576 EXPECT_EQ(-.5f, mtx[5]);
577 EXPECT_EQ(0.f, mtx[6]);
578 EXPECT_EQ(0.f, mtx[7]);
579
580 EXPECT_EQ(0.f, mtx[8]);
581 EXPECT_EQ(0.f, mtx[9]);
582 EXPECT_EQ(1.f, mtx[10]);
583 EXPECT_EQ(0.f, mtx[11]);
584
585 EXPECT_EQ(0.f, mtx[12]);
586 EXPECT_EQ(.5f, mtx[13]);
587 EXPECT_EQ(0.f, mtx[14]);
588 EXPECT_EQ(1.f, mtx[15]);
589}
590
Jamie Gennisa6f35dd2011-06-12 13:56:15 -0700591// This test verifies that the buffer format can be queried immediately after
592// it is set.
Jamie Gennis07ed1a92011-06-14 17:04:29 -0700593TEST_F(SurfaceTextureClientTest, QueryFormatAfterSettingWorks) {
Jamie Gennisa6f35dd2011-06-12 13:56:15 -0700594 sp<ANativeWindow> anw(mSTC);
595 int fmts[] = {
596 // RGBA_8888 should not come first, as it's the default
597 HAL_PIXEL_FORMAT_RGBX_8888,
598 HAL_PIXEL_FORMAT_RGBA_8888,
599 HAL_PIXEL_FORMAT_RGB_888,
600 HAL_PIXEL_FORMAT_RGB_565,
601 HAL_PIXEL_FORMAT_BGRA_8888,
602 HAL_PIXEL_FORMAT_RGBA_5551,
603 HAL_PIXEL_FORMAT_RGBA_4444,
604 HAL_PIXEL_FORMAT_YV12,
605 };
606
607 const int numFmts = (sizeof(fmts) / sizeof(fmts[0]));
608 for (int i = 0; i < numFmts; i++) {
609 int fmt = -1;
610 ASSERT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, fmts[i]));
611 ASSERT_EQ(OK, anw->query(anw.get(), NATIVE_WINDOW_FORMAT, &fmt));
612 EXPECT_EQ(fmts[i], fmt);
613 }
614}
615
Jamie Gennisc8251a02011-07-11 19:00:51 -0700616class MultiSurfaceTextureClientTest : public ::testing::Test {
617
618public:
619 MultiSurfaceTextureClientTest() :
620 mEglDisplay(EGL_NO_DISPLAY),
621 mEglContext(EGL_NO_CONTEXT) {
622 for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) {
623 mEglSurfaces[i] = EGL_NO_CONTEXT;
624 }
625 }
626
627protected:
628
629 enum { NUM_SURFACE_TEXTURES = 32 };
630
631 virtual void SetUp() {
632 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
633 ASSERT_EQ(EGL_SUCCESS, eglGetError());
634 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
635
636 EGLint majorVersion, minorVersion;
637 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
638 ASSERT_EQ(EGL_SUCCESS, eglGetError());
639
640 EGLConfig myConfig;
641 EGLint numConfigs = 0;
642 EGLint configAttribs[] = {
643 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
644 EGL_NONE
645 };
646 EXPECT_TRUE(eglChooseConfig(mEglDisplay, configAttribs, &myConfig, 1,
647 &numConfigs));
648 ASSERT_EQ(EGL_SUCCESS, eglGetError());
649
650 mEglContext = eglCreateContext(mEglDisplay, myConfig, EGL_NO_CONTEXT,
651 0);
652 ASSERT_EQ(EGL_SUCCESS, eglGetError());
653 ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
654
655 for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) {
656 sp<SurfaceTexture> st(new SurfaceTexture(i));
657 sp<SurfaceTextureClient> stc(new SurfaceTextureClient(st));
658 mEglSurfaces[i] = eglCreateWindowSurface(mEglDisplay, myConfig,
659 static_cast<ANativeWindow*>(stc.get()), NULL);
660 ASSERT_EQ(EGL_SUCCESS, eglGetError());
661 ASSERT_NE(EGL_NO_SURFACE, mEglSurfaces[i]);
662 }
663 }
664
665 virtual void TearDown() {
666 eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
667 EGL_NO_CONTEXT);
668
669 for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) {
670 if (mEglSurfaces[i] != EGL_NO_SURFACE) {
671 eglDestroySurface(mEglDisplay, mEglSurfaces[i]);
672 }
673 }
674
675 if (mEglContext != EGL_NO_CONTEXT) {
676 eglDestroyContext(mEglDisplay, mEglContext);
677 }
678
679 if (mEglDisplay != EGL_NO_DISPLAY) {
680 eglTerminate(mEglDisplay);
681 }
682 }
683
684 EGLDisplay mEglDisplay;
685 EGLSurface mEglSurfaces[NUM_SURFACE_TEXTURES];
686 EGLContext mEglContext;
687};
688
689// XXX: This test is disabled because it causes a hang on some devices. See bug
690// 5015672.
691TEST_F(MultiSurfaceTextureClientTest, DISABLED_MakeCurrentBetweenSurfacesWorks) {
692 for (int iter = 0; iter < 8; iter++) {
693 for (int i = 0; i < NUM_SURFACE_TEXTURES; i++) {
694 eglMakeCurrent(mEglDisplay, mEglSurfaces[i], mEglSurfaces[i],
695 mEglContext);
696 glClear(GL_COLOR_BUFFER_BIT);
697 eglSwapBuffers(mEglDisplay, mEglSurfaces[i]);
698 }
699 }
700}
701
Jamie Gennis52226042011-06-07 15:23:23 -0700702} // namespace android