blob: 589e312108ede91300892930d10714ae385b2637 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
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 Sebechlebsky96772402023-11-23 15:56:58 +010017#include <cstdint>
18#include "android/hardware_buffer.h"
19#include "gmock/gmock.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010020#include "gtest/gtest.h"
Jan Sebechlebsky96772402023-11-23 15:56:58 +010021#include "system/graphics.h"
22#include "ui/GraphicBuffer.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010023#include "util/EglDisplayContext.h"
24#include "util/EglProgram.h"
Jan Sebechlebsky96772402023-11-23 15:56:58 +010025#include "util/EglSurfaceTexture.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010026#include "util/EglUtil.h"
Jan Sebechlebsky96772402023-11-23 15:56:58 +010027#include "utils/Errors.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010028
29namespace android {
30namespace companion {
31namespace virtualcamera {
32namespace {
33
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010034using ::testing::IsNull;
Jan Sebechlebsky96772402023-11-23 15:56:58 +010035
36constexpr int kWidth = 64;
37constexpr int kHeight = 64;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010038constexpr char kGlExtYuvTarget[] = "GL_EXT_YUV_target";
39
40TEST(EglDisplayContextTest, SuccessfulInitialization) {
41 EglDisplayContext displayContext;
42
43 EXPECT_TRUE(displayContext.isInitialized());
44}
45
Jan Sebechlebsky96772402023-11-23 15:56:58 +010046class EglTest : public ::testing::Test {
47public:
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010048 void SetUp() override {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010049 ASSERT_TRUE(mEglDisplayContext.isInitialized());
50 ASSERT_TRUE(mEglDisplayContext.makeCurrent());
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010051 }
52
Jan Sebechlebsky96772402023-11-23 15:56:58 +010053private:
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010054 EglDisplayContext mEglDisplayContext;
55};
56
Jan Sebechlebsky96772402023-11-23 15:56:58 +010057TEST_F(EglTest, EglTestPatternProgramSuccessfulInit) {
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010058 EglTestPatternProgram eglTestPatternProgram;
59
60 // Verify the shaders compiled and linked successfully.
61 EXPECT_TRUE(eglTestPatternProgram.isInitialized());
62}
63
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +010064TEST_F(EglTest, EglTextureProgramYuvSuccessfulInit) {
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010065 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010066 GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010067 }
68
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +010069 EglTextureProgram eglTextureProgram(EglTextureProgram::TextureFormat::YUV);
70
71 // Verify the shaders compiled and linked successfully.
72 EXPECT_TRUE(eglTextureProgram.isInitialized());
73}
74
75TEST_F(EglTest, EglTextureProgramRgbaSuccessfulInit) {
76 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
77 GTEST_SKIP() << "Skipping test because of missing required GL extension "
78 << kGlExtYuvTarget;
79 }
80
81 EglTextureProgram eglTextureProgram(EglTextureProgram::TextureFormat::RGBA);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010082
83 // Verify the shaders compiled and linked successfully.
84 EXPECT_TRUE(eglTextureProgram.isInitialized());
85}
86
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010087TEST_F(EglTest, EglSurfaceCurrentBufferNullAfterInit) {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010088 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
89 GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget;
90 }
91
92 EglSurfaceTexture surfaceTexture(kWidth, kHeight);
93 surfaceTexture.updateTexture();
94 sp<GraphicBuffer> buffer = surfaceTexture.getCurrentBuffer();
95
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010096 EXPECT_THAT(buffer, IsNull());
Jan Sebechlebsky96772402023-11-23 15:56:58 +010097}
98
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010099} // namespace
100} // namespace virtualcamera
101} // namespace companion
102} // namespace android