Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 17 | #include <cstdint> |
| 18 | #include "android/hardware_buffer.h" |
| 19 | #include "gmock/gmock.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 20 | #include "gtest/gtest.h" |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 21 | #include "system/graphics.h" |
| 22 | #include "ui/GraphicBuffer.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 23 | #include "util/EglDisplayContext.h" |
| 24 | #include "util/EglProgram.h" |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 25 | #include "util/EglSurfaceTexture.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 26 | #include "util/EglUtil.h" |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 27 | #include "utils/Errors.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace companion { |
| 31 | namespace virtualcamera { |
| 32 | namespace { |
| 33 | |
Jan Sebechlebsky | 9ae496f | 2023-12-05 15:56:28 +0100 | [diff] [blame^] | 34 | using ::testing::IsNull; |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 35 | |
| 36 | constexpr int kWidth = 64; |
| 37 | constexpr int kHeight = 64; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 38 | constexpr char kGlExtYuvTarget[] = "GL_EXT_YUV_target"; |
| 39 | |
| 40 | TEST(EglDisplayContextTest, SuccessfulInitialization) { |
| 41 | EglDisplayContext displayContext; |
| 42 | |
| 43 | EXPECT_TRUE(displayContext.isInitialized()); |
| 44 | } |
| 45 | |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 46 | class EglTest : public ::testing::Test { |
| 47 | public: |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 48 | void SetUp() override { |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 49 | ASSERT_TRUE(mEglDisplayContext.isInitialized()); |
| 50 | ASSERT_TRUE(mEglDisplayContext.makeCurrent()); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 53 | private: |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 54 | EglDisplayContext mEglDisplayContext; |
| 55 | }; |
| 56 | |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 57 | TEST_F(EglTest, EglTestPatternProgramSuccessfulInit) { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 58 | EglTestPatternProgram eglTestPatternProgram; |
| 59 | |
| 60 | // Verify the shaders compiled and linked successfully. |
| 61 | EXPECT_TRUE(eglTestPatternProgram.isInitialized()); |
| 62 | } |
| 63 | |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 64 | TEST_F(EglTest, EglTextureProgramSuccessfulInit) { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 65 | if (!isGlExtensionSupported(kGlExtYuvTarget)) { |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 66 | GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | EglTextureProgram eglTextureProgram; |
| 70 | |
| 71 | // Verify the shaders compiled and linked successfully. |
| 72 | EXPECT_TRUE(eglTextureProgram.isInitialized()); |
| 73 | } |
| 74 | |
Jan Sebechlebsky | 9ae496f | 2023-12-05 15:56:28 +0100 | [diff] [blame^] | 75 | TEST_F(EglTest, EglSurfaceCurrentBufferNullAfterInit) { |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 76 | if (!isGlExtensionSupported(kGlExtYuvTarget)) { |
| 77 | GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget; |
| 78 | } |
| 79 | |
| 80 | EglSurfaceTexture surfaceTexture(kWidth, kHeight); |
| 81 | surfaceTexture.updateTexture(); |
| 82 | sp<GraphicBuffer> buffer = surfaceTexture.getCurrentBuffer(); |
| 83 | |
Jan Sebechlebsky | 9ae496f | 2023-12-05 15:56:28 +0100 | [diff] [blame^] | 84 | EXPECT_THAT(buffer, IsNull()); |
Jan Sebechlebsky | 9677240 | 2023-11-23 15:56:58 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 87 | } // namespace |
| 88 | } // namespace virtualcamera |
| 89 | } // namespace companion |
| 90 | } // namespace android |