5 #include "gtest/gtest.h"
7 #include "flutter/fml/logging.h"
9 #include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
10 #include "flutter/shell/platform/linux/testing/mock_epoxy.h"
11 #include "flutter/shell/platform/linux/testing/mock_renderer.h"
13 #include <epoxy/egl.h>
15 TEST(FlRendererTest, BackgroundColor) {
16 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
18 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(
true));
19 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
20 ON_CALL(epoxy, glGetString(GL_VENDOR))
22 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
23 EXPECT_CALL(epoxy, glClearColor(0.2, 0.3, 0.4, 0.5));
25 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
28 FlutterBackingStoreConfig config = {
29 .struct_size =
sizeof(FlutterBackingStoreConfig),
30 .size = {.width = 1024, .height = 1024}};
31 FlutterBackingStore backing_store;
34 const FlutterLayer layer0 = {.struct_size =
sizeof(FlutterLayer),
35 .
type = kFlutterLayerContentTypeBackingStore,
36 .backing_store = &backing_store,
37 .size = {.width = 1024, .height = 1024}};
38 const FlutterLayer* layers[] = {&layer0};
40 GdkRGBA background_color = {
41 .red = 0.2, .green = 0.3, .blue = 0.4, .alpha = 0.5};
45 TEST(FlRendererTest, RestoresGLState) {
46 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
48 constexpr
int kWidth = 100;
49 constexpr
int kHeight = 100;
51 flutter::testing::fl_ensure_gtk_init();
54 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
55 g_autoptr(FlFramebuffer) framebuffer =
61 FlutterBackingStore backing_store;
62 backing_store.type = kFlutterBackingStoreTypeOpenGL;
63 backing_store.open_gl.framebuffer.user_data = framebuffer;
66 layer.type = kFlutterLayerContentTypeBackingStore;
67 layer.backing_store = &backing_store;
68 layer.offset = {0, 0};
69 layer.size = {kWidth, kHeight};
71 std::array<const FlutterLayer*, 1> layers = {&layer};
73 constexpr GLuint kFakeTextureName = 123;
74 glBindTexture(GL_TEXTURE_2D, kFakeTextureName);
78 GdkRGBA background_color = {
79 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
83 GLuint texture_2d_binding;
84 glGetIntegerv(GL_TEXTURE_BINDING_2D,
85 reinterpret_cast<GLint*
>(&texture_2d_binding));
86 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
88 g_object_ref_sink(
view);
96 TEST(FlRendererTest, RefreshRate) {
97 flutter::testing::fl_ensure_gtk_init();
99 g_autoptr(FlMockRenderer) renderer =
102 gdouble result_refresh_rate =
107 TEST(FlRendererTest, BlitFramebuffer) {
108 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
111 ON_CALL(epoxy, glGetString(GL_VENDOR))
113 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
114 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(
true));
115 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
117 EXPECT_CALL(epoxy, glBlitFramebuffer);
119 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
122 FlutterBackingStoreConfig config = {
123 .struct_size =
sizeof(FlutterBackingStoreConfig),
124 .size = {.width = 1024, .height = 1024}};
125 FlutterBackingStore backing_store;
128 const FlutterLayer layer0 = {.struct_size =
sizeof(FlutterLayer),
129 .
type = kFlutterLayerContentTypeBackingStore,
130 .backing_store = &backing_store,
131 .size = {.width = 1024, .height = 1024}};
132 const FlutterLayer* layers[] = {&layer0};
134 GdkRGBA background_color = {
135 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
139 TEST(FlRendererTest, BlitFramebufferExtension) {
140 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
143 ON_CALL(epoxy, glGetString(GL_VENDOR))
145 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
146 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(
true));
147 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(20));
148 EXPECT_CALL(epoxy, epoxy_has_gl_extension(::testing::_))
149 .WillRepeatedly(::testing::Return(
false));
150 EXPECT_CALL(epoxy, epoxy_has_gl_extension(
151 ::testing::StrEq(
"GL_EXT_framebuffer_blit")))
152 .WillRepeatedly(::testing::Return(
true));
154 EXPECT_CALL(epoxy, glBlitFramebuffer);
156 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
159 FlutterBackingStoreConfig config = {
160 .struct_size =
sizeof(FlutterBackingStoreConfig),
161 .size = {.width = 1024, .height = 1024}};
162 FlutterBackingStore backing_store;
165 const FlutterLayer layer0 = {.struct_size =
sizeof(FlutterLayer),
166 .
type = kFlutterLayerContentTypeBackingStore,
167 .backing_store = &backing_store,
168 .size = {.width = 1024, .height = 1024}};
169 const FlutterLayer* layers[] = {&layer0};
171 GdkRGBA background_color = {
172 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
176 TEST(FlRendererTest, NoBlitFramebuffer) {
177 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
180 ON_CALL(epoxy, glGetString(GL_VENDOR))
182 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
183 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(
true));
184 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(20));
186 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
189 FlutterBackingStoreConfig config = {
190 .struct_size =
sizeof(FlutterBackingStoreConfig),
191 .size = {.width = 1024, .height = 1024}};
192 FlutterBackingStore backing_store;
195 const FlutterLayer layer0 = {.struct_size =
sizeof(FlutterLayer),
196 .
type = kFlutterLayerContentTypeBackingStore,
197 .backing_store = &backing_store,
198 .size = {.width = 1024, .height = 1024}};
199 const FlutterLayer* layers[] = {&layer0};
201 GdkRGBA background_color = {
202 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
206 TEST(FlRendererTest, BlitFramebufferNvidia) {
207 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
211 ON_CALL(epoxy, glGetString(GL_VENDOR))
213 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"NVIDIA")));
214 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(
true));
215 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
217 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
220 FlutterBackingStoreConfig config = {
221 .struct_size =
sizeof(FlutterBackingStoreConfig),
222 .size = {.width = 1024, .height = 1024}};
223 FlutterBackingStore backing_store;
226 const FlutterLayer layer0 = {.struct_size =
sizeof(FlutterLayer),
227 .
type = kFlutterLayerContentTypeBackingStore,
228 .backing_store = &backing_store,
229 .size = {.width = 1024, .height = 1024}};
230 const FlutterLayer* layers[] = {&layer0};
232 GdkRGBA background_color = {
233 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};