Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 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 "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 | |
| 29 | namespace android { |
| 30 | |
| 31 | class MultiTextureConsumerTest : public GLTest { |
| 32 | protected: |
| 33 | enum { TEX_ID = 123 }; |
| 34 | |
| 35 | virtual void SetUp() { |
| 36 | GLTest::SetUp(); |
Jim Shargo | d30823a | 2024-07-27 02:49:39 +0000 | [diff] [blame] | 37 | mGlConsumer = new GLConsumer(TEX_ID, GLConsumer::TEXTURE_EXTERNAL, true, false); |
| 38 | mSurface = mGlConsumer->getSurface(); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 39 | mANW = mSurface.get(); |
| 40 | |
| 41 | } |
| 42 | virtual void TearDown() { |
| 43 | GLTest::TearDown(); |
| 44 | } |
| 45 | virtual EGLint const* getContextAttribs() { |
Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 46 | return nullptr; |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 47 | } |
| 48 | virtual EGLint const* getConfigAttribs() { |
| 49 | static EGLint sDefaultConfigAttribs[] = { |
| 50 | EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
| 51 | EGL_RED_SIZE, 8, |
| 52 | EGL_GREEN_SIZE, 8, |
| 53 | EGL_BLUE_SIZE, 8, |
| 54 | EGL_ALPHA_SIZE, 8, |
| 55 | EGL_NONE }; |
| 56 | |
| 57 | return sDefaultConfigAttribs; |
| 58 | } |
| 59 | sp<GLConsumer> mGlConsumer; |
| 60 | sp<Surface> mSurface; |
| 61 | ANativeWindow* mANW; |
| 62 | }; |
| 63 | |
| 64 | TEST_F(MultiTextureConsumerTest, EGLImageTargetWorks) { |
| 65 | ANativeWindow_Buffer buffer; |
| 66 | |
| 67 | ASSERT_EQ(native_window_set_usage(mANW, GRALLOC_USAGE_SW_WRITE_OFTEN), NO_ERROR); |
| 68 | ASSERT_EQ(native_window_set_buffers_format(mANW, HAL_PIXEL_FORMAT_RGBA_8888), NO_ERROR); |
| 69 | |
| 70 | glShadeModel(GL_FLAT); |
| 71 | glDisable(GL_DITHER); |
| 72 | glDisable(GL_CULL_FACE); |
| 73 | glViewport(0, 0, getSurfaceWidth(), getSurfaceHeight()); |
| 74 | glOrthof(0, getSurfaceWidth(), 0, getSurfaceHeight(), 0, 1); |
| 75 | glEnableClientState(GL_VERTEX_ARRAY); |
| 76 | glColor4f(1, 1, 1, 1); |
| 77 | |
| 78 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID); |
| 79 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 80 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 81 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 82 | glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 83 | |
| 84 | uint32_t texel = 0x80808080; |
| 85 | glBindTexture(GL_TEXTURE_2D, TEX_ID+1); |
| 86 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &texel); |
| 87 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 88 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 89 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 90 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 91 | |
| 92 | glActiveTexture(GL_TEXTURE1); |
| 93 | glBindTexture(GL_TEXTURE_2D, TEX_ID+1); |
| 94 | glEnable(GL_TEXTURE_2D); |
| 95 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 96 | |
| 97 | glActiveTexture(GL_TEXTURE0); |
| 98 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID); |
| 99 | glEnable(GL_TEXTURE_EXTERNAL_OES); |
| 100 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 101 | |
| 102 | glClear(GL_COLOR_BUFFER_BIT); |
| 103 | for (int i=0 ; i<8 ; i++) { |
Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 104 | mSurface->lock(&buffer, nullptr); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 105 | memset(buffer.bits, (i&7) * 0x20, buffer.stride * buffer.height * 4); |
| 106 | mSurface->unlockAndPost(); |
| 107 | |
| 108 | mGlConsumer->updateTexImage(); |
| 109 | |
| 110 | GLfloat vertices[][2] = { {i*16.0f, 0}, {(i+1)*16.0f, 0}, {(i+1)*16.0f, 16.0f}, {i*16.0f, 16.0f} }; |
| 111 | glVertexPointer(2, GL_FLOAT, 0, vertices); |
| 112 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 113 | |
| 114 | ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError()); |
| 115 | } |
| 116 | |
| 117 | for (int i=0 ; i<8 ; i++) { |
| 118 | EXPECT_TRUE(checkPixel(i*16 + 8, 8, i*16, i*16, i*16, i*16, 0)); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | } // namespace android |