Skip to content

Commit 3e5e708

Browse files
Reverts "Replaces bespoke call captures from mock gles with gmock (flutter#56995)" (flutter/engine#57016)
Reverts: flutter/engine#56995 Initiated by: jonahwilliams Reason for reverting: compilation error at head. Original PR Author: gaaclarke Reviewed By: {jonahwilliams} This change reverts the following previous change: test exempt: test only code [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent afb249f commit 3e5e708

File tree

8 files changed

+146
-204
lines changed

8 files changed

+146
-204
lines changed

engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@
1212
namespace impeller {
1313
namespace testing {
1414

15-
using ::testing::_;
16-
1715
TEST(BufferBindingsGLESTest, BindUniformData) {
1816
BufferBindingsGLES bindings;
1917
absl::flat_hash_map<std::string, GLint> uniform_bindings;
2018
uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
2119
bindings.SetUniformBindings(std::move(uniform_bindings));
22-
auto mock_gles_impl = std::make_unique<MockGLESImpl>();
23-
24-
EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
25-
26-
std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
20+
std::shared_ptr<MockGLES> mock_gl = MockGLES::Init();
2721
std::vector<BufferResource> bound_buffers;
2822
std::vector<TextureAndSampler> bound_textures;
2923

@@ -45,6 +39,9 @@ TEST(BufferBindingsGLESTest, BindUniformData) {
4539
EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
4640
bound_buffers, Range{0, 0},
4741
Range{0, 1}));
42+
std::vector<std::string> captured_calls = mock_gl->GetCapturedCalls();
43+
EXPECT_TRUE(std::find(captured_calls.begin(), captured_calls.end(),
44+
"glUniform1fv") != captured_calls.end());
4845
}
4946

5047
} // namespace testing

engine/src/flutter/impeller/renderer/backend/gles/test/capabilities_unittests.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,30 @@ TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
3333
}
3434

3535
TEST(CapabilitiesGLES, SupportsDecalSamplerAddressMode) {
36-
auto const extensions = std::vector<const char*>{
37-
"GL_KHR_debug", //
38-
"GL_EXT_texture_border_clamp", //
36+
auto const extensions = std::vector<const unsigned char*>{
37+
reinterpret_cast<const unsigned char*>("GL_KHR_debug"), //
38+
reinterpret_cast<const unsigned char*>("GL_EXT_texture_border_clamp"), //
3939
};
4040
auto mock_gles = MockGLES::Init(extensions);
4141
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
4242
EXPECT_TRUE(capabilities->SupportsDecalSamplerAddressMode());
4343
}
4444

4545
TEST(CapabilitiesGLES, SupportsDecalSamplerAddressModeNotOES) {
46-
auto const extensions = std::vector<const char*>{
47-
"GL_KHR_debug", //
48-
"GL_OES_texture_border_clamp", //
46+
auto const extensions = std::vector<const unsigned char*>{
47+
reinterpret_cast<const unsigned char*>("GL_KHR_debug"), //
48+
reinterpret_cast<const unsigned char*>("GL_OES_texture_border_clamp"), //
4949
};
5050
auto mock_gles = MockGLES::Init(extensions);
5151
auto capabilities = mock_gles->GetProcTable().GetCapabilities();
5252
EXPECT_FALSE(capabilities->SupportsDecalSamplerAddressMode());
5353
}
5454

5555
TEST(CapabilitiesGLES, SupportsFramebufferFetch) {
56-
auto const extensions = std::vector<const char*>{
57-
"GL_KHR_debug", //
58-
"GL_EXT_shader_framebuffer_fetch", //
56+
auto const extensions = std::vector<const unsigned char*>{
57+
reinterpret_cast<const unsigned char*>("GL_KHR_debug"), //
58+
reinterpret_cast<const unsigned char*>(
59+
"GL_EXT_shader_framebuffer_fetch"), //
5960
};
6061
auto mock_gles = MockGLES::Init(extensions);
6162
auto capabilities = mock_gles->GetProcTable().GetCapabilities();

engine/src/flutter/impeller/renderer/backend/gles/test/gpu_tracer_gles_unittests.cc

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,38 @@
1010
namespace impeller {
1111
namespace testing {
1212

13-
using ::testing::_;
14-
1513
#ifdef IMPELLER_DEBUG
1614
TEST(GPUTracerGLES, CanFormatFramebufferErrorMessage) {
17-
auto const extensions = std::vector<const char*>{
18-
"GL_KHR_debug", //
19-
"GL_EXT_disjoint_timer_query", //
15+
auto const extensions = std::vector<const unsigned char*>{
16+
reinterpret_cast<const unsigned char*>("GL_KHR_debug"), //
17+
reinterpret_cast<const unsigned char*>("GL_EXT_disjoint_timer_query"), //
2018
};
21-
auto mock_gles_impl = std::make_unique<MockGLESImpl>();
22-
23-
{
24-
::testing::InSequence seq;
25-
auto gen_queries = [](GLsizei n, GLuint* ids) {
26-
for (int i = 0; i < n; ++i) {
27-
ids[i] = i + 1;
28-
}
29-
};
30-
EXPECT_CALL(*mock_gles_impl, GenQueriesEXT(_, _)).WillOnce(gen_queries);
31-
EXPECT_CALL(*mock_gles_impl, BeginQueryEXT(GL_TIME_ELAPSED_EXT, _));
32-
EXPECT_CALL(*mock_gles_impl, EndQueryEXT(GL_TIME_ELAPSED_EXT));
33-
EXPECT_CALL(*mock_gles_impl,
34-
GetQueryObjectuivEXT(_, GL_QUERY_RESULT_AVAILABLE_EXT, _))
35-
.WillOnce([](GLuint id, GLenum target, GLuint* result) {
36-
*result = GL_TRUE;
37-
});
38-
EXPECT_CALL(*mock_gles_impl,
39-
GetQueryObjectui64vEXT(_, GL_QUERY_RESULT_EXT, _))
40-
.WillOnce([](GLuint id, GLenum target, GLuint64* result) {
41-
*result = 1000u;
42-
});
43-
EXPECT_CALL(*mock_gles_impl, DeleteQueriesEXT(_, _));
44-
EXPECT_CALL(*mock_gles_impl, GenQueriesEXT(_, _)).WillOnce(gen_queries);
45-
EXPECT_CALL(*mock_gles_impl, BeginQueryEXT(GL_TIME_ELAPSED_EXT, _));
46-
}
47-
std::shared_ptr<MockGLES> mock_gles =
48-
MockGLES::Init(std::move(mock_gles_impl), extensions);
19+
auto mock_gles = MockGLES::Init(extensions);
4920
auto tracer =
5021
std::make_shared<GPUTracerGLES>(mock_gles->GetProcTable(), true);
5122
tracer->RecordRasterThread();
5223
tracer->MarkFrameStart(mock_gles->GetProcTable());
5324
tracer->MarkFrameEnd(mock_gles->GetProcTable());
25+
26+
auto calls = mock_gles->GetCapturedCalls();
27+
28+
std::vector<std::string> expected = {"glGenQueriesEXT", "glBeginQueryEXT",
29+
"glEndQueryEXT"};
30+
for (auto i = 0; i < 3; i++) {
31+
EXPECT_EQ(calls[i], expected[i]);
32+
}
33+
34+
// Begin second frame, which prompts the tracer to query the result
35+
// from the previous frame.
5436
tracer->MarkFrameStart(mock_gles->GetProcTable());
37+
38+
calls = mock_gles->GetCapturedCalls();
39+
std::vector<std::string> expected_b = {"glGetQueryObjectuivEXT",
40+
"glGetQueryObjectui64vEXT",
41+
"glDeleteQueriesEXT"};
42+
for (auto i = 0; i < 3; i++) {
43+
EXPECT_EQ(calls[i], expected_b[i]);
44+
}
5545
}
5646

5747
#endif // IMPELLER_DEBUG

engine/src/flutter/impeller/renderer/backend/gles/test/mock_gles.cc

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@ static std::mutex g_test_lock;
1919

2020
static std::weak_ptr<MockGLES> g_mock_gles;
2121

22-
static std::vector<const char*> g_extensions;
22+
static ProcTableGLES::Resolver g_resolver;
2323

24-
static const char* g_version;
24+
static std::vector<const unsigned char*> g_extensions;
25+
26+
static const unsigned char* g_version;
27+
28+
// Has friend visibility into MockGLES to record calls.
29+
void RecordGLCall(const char* name) {
30+
if (auto mock_gles = g_mock_gles.lock()) {
31+
mock_gles->RecordCall(name);
32+
}
33+
}
2534

2635
template <typename T, typename U>
2736
struct CheckSameSignature : std::false_type {};
@@ -32,34 +41,22 @@ struct CheckSameSignature<Ret(Args...), Ret(Args...)> : std::true_type {};
3241
// This is a stub function that does nothing/records nothing.
3342
void doNothing() {}
3443

35-
auto const kMockVendor = "MockGLES";
36-
const auto kMockShadingLanguageVersion = "GLSL ES 1.0";
37-
auto const kExtensions = std::vector<const char*>{
38-
"GL_KHR_debug" //
44+
auto const kMockVendor = (unsigned char*)"MockGLES";
45+
const auto kMockShadingLanguageVersion = (unsigned char*)"GLSL ES 1.0";
46+
auto const kExtensions = std::vector<const unsigned char*>{
47+
(unsigned char*)"GL_KHR_debug" //
3948
};
4049

41-
namespace {
42-
template <typename Func, typename... Args>
43-
void CallMockMethod(Func func, Args&&... args) {
44-
if (auto mock_gles = g_mock_gles.lock()) {
45-
if (mock_gles->GetImpl()) {
46-
(mock_gles->GetImpl()->*func)(std::forward<Args>(args)...);
47-
}
48-
}
49-
}
50-
} // namespace
51-
5250
const unsigned char* mockGetString(GLenum name) {
5351
switch (name) {
5452
case GL_VENDOR:
55-
return reinterpret_cast<const unsigned char*>(kMockVendor);
53+
return kMockVendor;
5654
case GL_VERSION:
57-
return reinterpret_cast<const unsigned char*>(g_version);
55+
return g_version;
5856
case GL_SHADING_LANGUAGE_VERSION:
59-
return reinterpret_cast<const unsigned char*>(
60-
kMockShadingLanguageVersion);
57+
return kMockShadingLanguageVersion;
6158
default:
62-
return reinterpret_cast<const unsigned char*>("");
59+
return (unsigned char*)"";
6360
}
6461
}
6562

@@ -69,9 +66,9 @@ static_assert(CheckSameSignature<decltype(mockGetString), //
6966
const unsigned char* mockGetStringi(GLenum name, GLuint index) {
7067
switch (name) {
7168
case GL_EXTENSIONS:
72-
return reinterpret_cast<const unsigned char*>(g_extensions[index]);
69+
return g_extensions[index];
7370
default:
74-
return reinterpret_cast<const unsigned char*>("");
71+
return (unsigned char*)"";
7572
}
7673
}
7774

@@ -105,73 +102,89 @@ GLenum mockGetError() {
105102
static_assert(CheckSameSignature<decltype(mockGetError), //
106103
decltype(glGetError)>::value);
107104

108-
void mockPopDebugGroupKHR() {}
105+
void mockPopDebugGroupKHR() {
106+
RecordGLCall("PopDebugGroupKHR");
107+
}
109108

110109
static_assert(CheckSameSignature<decltype(mockPopDebugGroupKHR), //
111110
decltype(glPopDebugGroupKHR)>::value);
112111

113112
void mockPushDebugGroupKHR(GLenum source,
114113
GLuint id,
115114
GLsizei length,
116-
const GLchar* message) {}
115+
const GLchar* message) {
116+
RecordGLCall("PushDebugGroupKHR");
117+
}
117118

118119
static_assert(CheckSameSignature<decltype(mockPushDebugGroupKHR), //
119120
decltype(glPushDebugGroupKHR)>::value);
120121

121122
void mockGenQueriesEXT(GLsizei n, GLuint* ids) {
122-
CallMockMethod(&IMockGLESImpl::GenQueriesEXT, n, ids);
123+
RecordGLCall("glGenQueriesEXT");
124+
for (auto i = 0; i < n; i++) {
125+
ids[i] = i + 1;
126+
}
123127
}
124128

125129
static_assert(CheckSameSignature<decltype(mockGenQueriesEXT), //
126130
decltype(glGenQueriesEXT)>::value);
127131

128132
void mockBeginQueryEXT(GLenum target, GLuint id) {
129-
CallMockMethod(&IMockGLESImpl::BeginQueryEXT, target, id);
133+
RecordGLCall("glBeginQueryEXT");
130134
}
131135

132136
static_assert(CheckSameSignature<decltype(mockBeginQueryEXT), //
133137
decltype(glBeginQueryEXT)>::value);
134138

135139
void mockEndQueryEXT(GLuint id) {
136-
CallMockMethod(&IMockGLESImpl::EndQueryEXT, id);
140+
RecordGLCall("glEndQueryEXT");
137141
}
138142

139143
static_assert(CheckSameSignature<decltype(mockEndQueryEXT), //
140144
decltype(glEndQueryEXT)>::value);
141145

142146
void mockGetQueryObjectuivEXT(GLuint id, GLenum target, GLuint* result) {
143-
CallMockMethod(&IMockGLESImpl::GetQueryObjectuivEXT, id, target, result);
147+
RecordGLCall("glGetQueryObjectuivEXT");
148+
*result = GL_TRUE;
144149
}
145150

146151
static_assert(CheckSameSignature<decltype(mockGetQueryObjectuivEXT), //
147152
decltype(glGetQueryObjectuivEXT)>::value);
148153

149154
void mockGetQueryObjectui64vEXT(GLuint id, GLenum target, GLuint64* result) {
150-
CallMockMethod(&IMockGLESImpl::GetQueryObjectui64vEXT, id, target, result);
155+
RecordGLCall("glGetQueryObjectui64vEXT");
156+
*result = 1000u;
151157
}
152158

153159
static_assert(CheckSameSignature<decltype(mockGetQueryObjectui64vEXT), //
154160
decltype(glGetQueryObjectui64vEXT)>::value);
155161

156162
void mockDeleteQueriesEXT(GLsizei size, const GLuint* queries) {
157-
CallMockMethod(&IMockGLESImpl::DeleteQueriesEXT, size, queries);
163+
RecordGLCall("glDeleteQueriesEXT");
158164
}
159165

160166
void mockDeleteTextures(GLsizei size, const GLuint* queries) {
161-
CallMockMethod(&IMockGLESImpl::DeleteTextures, size, queries);
167+
RecordGLCall("glDeleteTextures");
162168
}
163169

164170
static_assert(CheckSameSignature<decltype(mockDeleteQueriesEXT), //
165171
decltype(glDeleteQueriesEXT)>::value);
166172

167173
void mockUniform1fv(GLint location, GLsizei count, const GLfloat* value) {
168-
CallMockMethod(&IMockGLESImpl::Uniform1fv, location, count, value);
174+
RecordGLCall("glUniform1fv");
169175
}
170176
static_assert(CheckSameSignature<decltype(mockUniform1fv), //
171177
decltype(glUniform1fv)>::value);
172178

173179
void mockGenTextures(GLsizei n, GLuint* textures) {
174-
CallMockMethod(&IMockGLESImpl::GenTextures, n, textures);
180+
RecordGLCall("glGenTextures");
181+
if (auto mock_gles = g_mock_gles.lock()) {
182+
std::optional<uint64_t> next_texture;
183+
std::swap(mock_gles->next_texture_, next_texture);
184+
if (next_texture.has_value()) {
185+
textures[0] = next_texture.value();
186+
}
187+
}
175188
}
176189

177190
static_assert(CheckSameSignature<decltype(mockGenTextures), //
@@ -181,35 +194,20 @@ void mockObjectLabelKHR(GLenum identifier,
181194
GLuint name,
182195
GLsizei length,
183196
const GLchar* label) {
184-
CallMockMethod(&IMockGLESImpl::ObjectLabelKHR, identifier, name, length,
185-
label);
197+
RecordGLCall("glObjectLabelKHR");
186198
}
187199
static_assert(CheckSameSignature<decltype(mockObjectLabelKHR), //
188200
decltype(glObjectLabelKHR)>::value);
189201

190-
// static
191-
std::shared_ptr<MockGLES> MockGLES::Init(
192-
std::unique_ptr<MockGLESImpl> impl,
193-
const std::optional<std::vector<const char*>>& extensions) {
194-
FML_CHECK(g_test_lock.try_lock())
195-
<< "MockGLES is already being used by another test.";
196-
g_extensions = extensions.value_or(kExtensions);
197-
g_version = "OpenGL ES 3.0";
198-
auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES());
199-
mock_gles->impl_ = std::move(impl);
200-
g_mock_gles = mock_gles;
201-
return mock_gles;
202-
}
203-
204202
std::shared_ptr<MockGLES> MockGLES::Init(
205-
const std::optional<std::vector<const char*>>& extensions,
203+
const std::optional<std::vector<const unsigned char*>>& extensions,
206204
const char* version_string,
207205
ProcTableGLES::Resolver resolver) {
208206
// If we cannot obtain a lock, MockGLES is already being used elsewhere.
209207
FML_CHECK(g_test_lock.try_lock())
210208
<< "MockGLES is already being used by another test.";
209+
g_version = (unsigned char*)version_string;
211210
g_extensions = extensions.value_or(kExtensions);
212-
g_version = version_string;
213211
auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES(std::move(resolver)));
214212
g_mock_gles = mock_gles;
215213
return mock_gles;

0 commit comments

Comments
 (0)