blob: 813be75f855041477af134dc1c89f40f561c7114 [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 Sebechlebsky288900f2024-05-24 14:47:54 +020058 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
59 GTEST_SKIP() << "Skipping test because of missing required GL extension "
60 << kGlExtYuvTarget;
61 }
62
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010063 EglTestPatternProgram eglTestPatternProgram;
64
65 // Verify the shaders compiled and linked successfully.
66 EXPECT_TRUE(eglTestPatternProgram.isInitialized());
67}
68
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +010069TEST_F(EglTest, EglTextureProgramYuvSuccessfulInit) {
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010070 if (!isGlExtensionSupported(kGlExtYuvTarget)) {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010071 GTEST_SKIP() << "Skipping test because of missing required GL extension " << kGlExtYuvTarget;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010072 }
73
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +010074 EglTextureProgram eglTextureProgram(EglTextureProgram::TextureFormat::YUV);
75
76 // Verify the shaders compiled and linked successfully.
77 EXPECT_TRUE(eglTextureProgram.isInitialized());
78}
79
80TEST_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);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010087
88 // Verify the shaders compiled and linked successfully.
89 EXPECT_TRUE(eglTextureProgram.isInitialized());
90}
91
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010092TEST_F(EglTest, EglSurfaceCurrentBufferNullAfterInit) {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010093 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
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +0100101 EXPECT_THAT(buffer, IsNull());
Jan Sebechlebsky96772402023-11-23 15:56:58 +0100102}
103
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100104} // namespace
105} // namespace virtualcamera
106} // namespace companion
107} // namespace android