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
17 #include <cstdint>
18 #include "android/hardware_buffer.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "system/graphics.h"
22 #include "ui/GraphicBuffer.h"
23 #include "util/EglDisplayContext.h"
24 #include "util/EglProgram.h"
25 #include "util/EglSurfaceTexture.h"
26 #include "util/EglUtil.h"
27 #include "utils/Errors.h"
28
29 namespace android {
30 namespace companion {
31 namespace virtualcamera {
32 namespace {
33
34 using ::testing::IsNull;
35
36 constexpr int kWidth = 64;
37 constexpr int kHeight = 64;
38 constexpr char kGlExtYuvTarget[] = "GL_EXT_YUV_target";
39
TEST(EglDisplayContextTest,SuccessfulInitialization)40 TEST(EglDisplayContextTest, SuccessfulInitialization) {
41 EglDisplayContext displayContext;
42
43 EXPECT_TRUE(displayContext.isInitialized());
44 }
45
46 class EglTest : public ::testing::Test {
47 public:
SetUp()48 void SetUp() override {
49 ASSERT_TRUE(mEglDisplayContext.isInitialized());
50 ASSERT_TRUE(mEglDisplayContext.makeCurrent());
51 }
52
53 private:
54 EglDisplayContext mEglDisplayContext;
55 };
56
TEST_F(EglTest,EglTestPatternProgramSuccessfulInit)57 TEST_F(EglTest, EglTestPatternProgramSuccessfulInit) {
58 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
59 GTEST_SKIP() << "Skipping test because of missing required GL extension "
60 << kGlExtYuvTarget;
61 }
62
63 EglTestPatternProgram eglTestPatternProgram;
64
65 // Verify the shaders compiled and linked successfully.
66 EXPECT_TRUE(eglTestPatternProgram.isInitialized());
67 }
68
TEST_F(EglTest,EglTextureProgramYuvSuccessfulInit)69 TEST_F(EglTest, EglTextureProgramYuvSuccessfulInit) {
70 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
71 GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget;
72 }
73
74 EglTextureProgram eglTextureProgram(EglTextureProgram::TextureFormat::YUV);
75
76 // Verify the shaders compiled and linked successfully.
77 EXPECT_TRUE(eglTextureProgram.isInitialized());
78 }
79
TEST_F(EglTest,EglTextureProgramRgbaSuccessfulInit)80 TEST_F(EglTest, EglTextureProgramRgbaSuccessfulInit) {
81 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
82 GTEST_SKIP() << "Skipping test because of missing required GL extension "
83 << kGlExtYuvTarget;
84 }
85
86 EglTextureProgram eglTextureProgram(EglTextureProgram::TextureFormat::RGBA);
87
88 // Verify the shaders compiled and linked successfully.
89 EXPECT_TRUE(eglTextureProgram.isInitialized());
90 }
91
TEST_F(EglTest,EglSurfaceCurrentBufferNullAfterInit)92 TEST_F(EglTest, EglSurfaceCurrentBufferNullAfterInit) {
93 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
94 GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget;
95 }
96
97 EglSurfaceTexture surfaceTexture(kWidth, kHeight);
98 surfaceTexture.updateTexture();
99 sp<GraphicBuffer> buffer = surfaceTexture.getCurrentBuffer();
100
101 EXPECT_THAT(buffer, IsNull());
102 }
103
104 } // namespace
105 } // namespace virtualcamera
106 } // namespace companion
107 } // namespace android
108