blob: d0b72186d5ac5555d6091e235e9c0795b796e2b1 [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 Sebechlebsky96772402023-11-23 15:56:58 +010064TEST_F(EglTest, EglTextureProgramSuccessfulInit) {
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
69 EglTextureProgram eglTextureProgram;
70
71 // Verify the shaders compiled and linked successfully.
72 EXPECT_TRUE(eglTextureProgram.isInitialized());
73}
74
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010075TEST_F(EglTest, EglSurfaceCurrentBufferNullAfterInit) {
Jan Sebechlebsky96772402023-11-23 15:56:58 +010076 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 Sebechlebsky9ae496f2023-12-05 15:56:28 +010084 EXPECT_THAT(buffer, IsNull());
Jan Sebechlebsky96772402023-11-23 15:56:58 +010085}
86
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010087} // namespace
88} // namespace virtualcamera
89} // namespace companion
90} // namespace android