Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
android_context_gl_impeller_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6#include "gmock/gmock.h"
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12using ::testing::_;
13using ::testing::AllOf;
14using ::testing::ByMove;
15using ::testing::Field;
16using ::testing::Matcher;
17using ::testing::Return;
18
19using ::impeller::egl::Config;
20using ::impeller::egl::ConfigDescriptor;
21
22namespace {
24 public:
25 MOCK_METHOD(bool, IsValid, (), (const, override));
26 MOCK_METHOD(std::unique_ptr<Config>,
27 ChooseConfig,
28 (ConfigDescriptor),
29 (const, override));
30};
31
32bool GetEGLConfigForSurface(EGLint surface_bit, EGLConfig* result) {
33 EGLint attributes[] = {
34 // clang-format off
35 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
36 EGL_SURFACE_TYPE, surface_bit,
37 EGL_RED_SIZE, 8,
38 EGL_GREEN_SIZE, 8,
39 EGL_BLUE_SIZE, 8,
40 EGL_ALPHA_SIZE, 8,
41 EGL_DEPTH_SIZE, 24,
42 EGL_STENCIL_SIZE, 8,
43 EGL_NONE,
44 // clang-format on
45 };
46 EGLint config_count = 0;
47 return eglChooseConfig(eglGetDisplay(EGL_DEFAULT_DISPLAY), attributes, result,
48 1, &config_count);
49}
50
51} // namespace
52
53class AndroidContextGLImpellerTest : public ::testing::Test {
54 public:
56
57 void SetUp() override {
58 EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
59 ASSERT_TRUE(eglInitialize(egl_display, nullptr, nullptr));
60 }
61};
62
64 EGLConfig window_egl_config, pbuffer_egl_config;
65 ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config));
66 ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config));
67
68 auto display = std::make_unique<MockDisplay>();
69 EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
70 auto first_result =
71 std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
72 auto second_result =
73 std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
74 EXPECT_CALL(
75 *display,
76 ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
77 Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
78 Field(&ConfigDescriptor::surface_type,
80 .WillOnce(Return(ByMove(std::move(first_result))));
81 EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
82 Field(&ConfigDescriptor::surface_type,
84 .WillOnce(Return(ByMove(std::move(second_result))));
85 ON_CALL(*display, ChooseConfig(_))
86 .WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
87 auto context =
88 std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
89 ASSERT_TRUE(context);
90}
91
92TEST_F(AndroidContextGLImpellerTest, FallbackForEmulator) {
93 EGLConfig window_egl_config, pbuffer_egl_config;
94 ASSERT_TRUE(GetEGLConfigForSurface(EGL_WINDOW_BIT, &window_egl_config));
95 ASSERT_TRUE(GetEGLConfigForSurface(EGL_PBUFFER_BIT, &pbuffer_egl_config));
96
97 auto display = std::make_unique<MockDisplay>();
98 EXPECT_CALL(*display, IsValid).WillRepeatedly(Return(true));
99 std::unique_ptr<Config> first_result;
100 std::unique_ptr<Config> second_result;
101 auto third_result =
102 std::make_unique<Config>(ConfigDescriptor(), window_egl_config);
103 auto fourth_result =
104 std::make_unique<Config>(ConfigDescriptor(), pbuffer_egl_config);
105 EXPECT_CALL(
106 *display,
107 ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
108 Field(&ConfigDescriptor::api, impeller::egl::API::kOpenGLES3),
109 Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
110 Field(&ConfigDescriptor::surface_type,
112 .WillOnce(Return(ByMove(std::move(first_result))));
113 EXPECT_CALL(
114 *display,
115 ChooseConfig(Matcher<ConfigDescriptor>(AllOf(
116 Field(&ConfigDescriptor::api, impeller::egl::API::kOpenGLES2),
117 Field(&ConfigDescriptor::samples, impeller::egl::Samples::kFour),
118 Field(&ConfigDescriptor::surface_type,
120 .WillOnce(Return(ByMove(std::move(second_result))));
121 EXPECT_CALL(
122 *display,
123 ChooseConfig(Matcher<ConfigDescriptor>(
124 AllOf(Field(&ConfigDescriptor::samples, impeller::egl::Samples::kOne),
125 Field(&ConfigDescriptor::surface_type,
127 .WillOnce(Return(ByMove(std::move(third_result))));
128 EXPECT_CALL(*display, ChooseConfig(Matcher<ConfigDescriptor>(
129 Field(&ConfigDescriptor::surface_type,
131 .WillOnce(Return(ByMove(std::move(fourth_result))));
132 ON_CALL(*display, ChooseConfig(_))
133 .WillByDefault(Return(ByMove(std::unique_ptr<Config>())));
134 auto context =
135 std::make_unique<AndroidContextGLImpeller>(std::move(display), true);
136 ASSERT_TRUE(context);
137}
138
139} // namespace testing
140} // namespace flutter
A connection to an EGL display. Only one connection per application instance is sufficient.
Definition display.h:28
TEST_F(DisplayListTest, Defaults)