forked from flutter-team-archive/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathandroid_context_gl_impeller_unittests.cc
More file actions
130 lines (116 loc) · 4.74 KB
/
Copy pathandroid_context_gl_impeller_unittests.cc
File metadata and controls
130 lines (116 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/android/android_context_gl_impeller.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
using ::testing::_;
using ::testing::AllOf;
using ::testing::ByMove;
using ::testing::Field;
using ::testing::Matcher;
using ::testing::Return;
using ::impeller::egl::Config;
using ::impeller::egl::ConfigDescriptor;
namespace {
class MockDisplay : public impeller::egl::Display {
public:
MOCK_METHOD(bool, IsValid, (), (const, override));
MOCK_METHOD(std::unique_ptr<Config>,
ChooseConfig,
(ConfigDescriptor),
(const, override));
};
bool GetEGLConfigForSurface(EGLint surface_bit, EGLConfig* result) {
EGLint attributes[] = {
// clang-format off
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, surface_bit,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_NONE,
// clang-format on
};
EGLint config_count = 0;
return eglChooseConfig(eglGetDisplay(EGL_DEFAULT_DISPLAY), attributes, result,
1, &config_count);
}
} // namespace
class AndroidContextGLImpellerTest : public ::testing::Test {
public:
AndroidContextGLImpellerTest() {}
void SetUp() override {
EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
ASSERT_TRUE(eglInitialize(egl_display, nullptr, nullptr));
}
};
TEST_F(AndroidContextGLImpellerTest, MSAAFirstAttempt) {
EGLConfig window_egl_config, pbuffer_egl_config;
ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config));
ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config));
auto display = std::make_unique<MockDisplay>();
EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
auto first_result =
std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
auto second_result =
std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
EXPECT_CALL(
*display,
ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
Field(&ConfigDescriptor::surface_type,
impeller::egl::SurfaceType::kWindow)))))
.WillOnce(Return(ByMove(std::move(first_result))));
EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
Field(&ConfigDescriptor::surface_type,
impeller::egl::SurfaceType::kPBuffer))))
.WillOnce(Return(ByMove(std::move(second_result))));
ON_CALL(*display, ChooseConfig(_))
.WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
auto context =
std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
ASSERT_TRUE(context);
}
TEST_F(AndroidContextGLImpellerTest, FallbackForEmulator) {
EGLConfig window_egl_config, pbuffer_egl_config;
ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config));
ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config));
auto display = std::make_unique<MockDisplay>();
EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
std::unique_ptr<Config> first_result;
auto second_result =
std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
auto third_result =
std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
EXPECT_CALL(
*display,
ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
Field(&ConfigDescriptor::surface_type,
impeller::egl::SurfaceType::kWindow)))))
.WillOnce(Return(ByMove(std::move(first_result))));
EXPECT_CALL(
*display,
ChooseConfig(Matcher<ConfigDescriptor>(
AllOf(Field(&ConfigDescriptor::samples, impeller::egl::Samples::kOne),
Field(&ConfigDescriptor::surface_type,
impeller::egl::SurfaceType::kWindow)))))
.WillOnce(Return(ByMove(std::move(second_result))));
EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
Field(&ConfigDescriptor::surface_type,
impeller::egl::SurfaceType::kPBuffer))))
.WillOnce(Return(ByMove(std::move(third_result))));
ON_CALL(*display, ChooseConfig(_))
.WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
auto context =
std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
ASSERT_TRUE(context);
}
} // namespace testing
} // namespace flutter