blob: 1eb6ef6f5eb4f47c199c7493d460529e845f8426 [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 "MultiTextureConsumer_test"
18//#define LOG_NDEBUG 0
19
20#include "GLTest.h"
21
22#include <gui/GLConsumer.h>
23#include <gui/Surface.h>
24
25#include <android/native_window.h>
26
27#include <GLES/glext.h>
28
29namespace android {
30
31class MultiTextureConsumerTest : public GLTest {
32protected:
33 enum { TEX_ID = 123 };
34
35 virtual void SetUp() {
36 GLTest::SetUp();
Dan Stoza5603a2f2014-04-07 13:41:37 -070037 sp<IGraphicBufferProducer> producer;
38 sp<IGraphicBufferConsumer> consumer;
39 BufferQueue::createBufferQueue(&producer, &consumer);
40 mGlConsumer = new GLConsumer(consumer, TEX_ID);
41 mSurface = new Surface(producer);
Dan Stozacb1fcde2013-12-03 12:37:36 -080042 mANW = mSurface.get();
43
44 }
45 virtual void TearDown() {
46 GLTest::TearDown();
47 }
48 virtual EGLint const* getContextAttribs() {
49 return NULL;
50 }
51 virtual EGLint const* getConfigAttribs() {
52 static EGLint sDefaultConfigAttribs[] = {
53 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
54 EGL_RED_SIZE, 8,
55 EGL_GREEN_SIZE, 8,
56 EGL_BLUE_SIZE, 8,
57 EGL_ALPHA_SIZE, 8,
58 EGL_NONE };
59
60 return sDefaultConfigAttribs;
61 }
62 sp<GLConsumer> mGlConsumer;
63 sp<Surface> mSurface;
64 ANativeWindow* mANW;
65};
66
67TEST_F(MultiTextureConsumerTest, EGLImageTargetWorks) {
68 ANativeWindow_Buffer buffer;
69
70 ASSERT_EQ(native_window_set_usage(mANW, GRALLOC_USAGE_SW_WRITE_OFTEN), NO_ERROR);
71 ASSERT_EQ(native_window_set_buffers_format(mANW, HAL_PIXEL_FORMAT_RGBA_8888), NO_ERROR);
72
73 glShadeModel(GL_FLAT);
74 glDisable(GL_DITHER);
75 glDisable(GL_CULL_FACE);
76 glViewport(0, 0, getSurfaceWidth(), getSurfaceHeight());
77 glOrthof(0, getSurfaceWidth(), 0, getSurfaceHeight(), 0, 1);
78 glEnableClientState(GL_VERTEX_ARRAY);
79 glColor4f(1, 1, 1, 1);
80
81 glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
82 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
83 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
84 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
85 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
86
87 uint32_t texel = 0x80808080;
88 glBindTexture(GL_TEXTURE_2D, TEX_ID+1);
89 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &texel);
90 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
91 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
92 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
93 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
94
95 glActiveTexture(GL_TEXTURE1);
96 glBindTexture(GL_TEXTURE_2D, TEX_ID+1);
97 glEnable(GL_TEXTURE_2D);
98 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
99
100 glActiveTexture(GL_TEXTURE0);
101 glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
102 glEnable(GL_TEXTURE_EXTERNAL_OES);
103 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
104
105 glClear(GL_COLOR_BUFFER_BIT);
106 for (int i=0 ; i<8 ; i++) {
107 mSurface->lock(&buffer, NULL);
108 memset(buffer.bits, (i&7) * 0x20, buffer.stride * buffer.height * 4);
109 mSurface->unlockAndPost();
110
111 mGlConsumer->updateTexImage();
112
113 GLfloat vertices[][2] = { {i*16.0f, 0}, {(i+1)*16.0f, 0}, {(i+1)*16.0f, 16.0f}, {i*16.0f, 16.0f} };
114 glVertexPointer(2, GL_FLOAT, 0, vertices);
115 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
116
117 ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
118 }
119
120 for (int i=0 ; i<8 ; i++) {
121 EXPECT_TRUE(checkPixel(i*16 + 8, 8, i*16, i*16, i*16, i*16, 0));
122 }
123}
124
125} // namespace android