| Flutter Linux Embedder |

Functions
fl_renderer_test.cc File Reference
`#include "gtest/gtest.h"`
`#include "flutter/common/constants.h"`
`#include "flutter/fml/logging.h"`
`#include "flutter/shell/platform/linux/fl_framebuffer.h"`
`#include "flutter/shell/platform/linux/testing/mock_epoxy.h"`
`#include "flutter/shell/platform/linux/testing/mock_renderer.h"`
`#include <epoxy/egl.h>`

Go to the source code of this file.

## Functions
| TEST (FlRendererTest, BackgroundColor)
| TEST (FlRendererTest, RestoresGLState)
| TEST (FlRendererTest, BlitFramebuffer)
| TEST (FlRendererTest, BlitFramebufferExtension)
| TEST (FlRendererTest, NoBlitFramebuffer)
| TEST (FlRendererTest, BlitFramebufferNvidia)
| TEST (FlRendererTest, MultiView)

## Function Documentation

## ◆ TEST() [1/7]

TEST | ( | FlRendererTest | ,
|  | BackgroundColor |
| ) |  |

Definition at line 15 of file fl_renderer_test.cc.

15 {
16 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
17
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))
21 .WillByDefault(
22 ::testing::Return(reinterpret_cast<const GLubyte*>("Intel")));
23 EXPECT_CALL(epoxy, glClearColor(0.2, 0.3, 0.4, 0.5));
24
25 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
26 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
27 fl_renderer_setup(FL_RENDERER(renderer));
28 fl_renderer_add_renderable(FL_RENDERER(renderer),
29 flutter::kFlutterImplicitViewId,
30 FL_RENDERABLE(renderable));
31 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
32 FlutterBackingStoreConfig config = {
33 .struct_size = sizeof(FlutterBackingStoreConfig),
34 .size = {.width = 1024, .height = 1024}};
35 FlutterBackingStore backing_store;
36 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
37 &backing_store);
38 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
39 .type = kFlutterLayerContentTypeBackingStore,
40 .backing_store = &backing_store,
41 .size = {.width = 1024, .height = 1024}};
42 const FlutterLayer* layers[] = {&layer0};
43 fl_renderer_present_layers(FL_RENDERER(renderer),
44 flutter::kFlutterImplicitViewId, layers, 1);
45 GdkRGBA background_color = {
46 .red = 0.2, .green = 0.3, .blue = 0.4, .alpha = 0.5};
47 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
48 1024, 1024, &background_color);
49 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_render(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [2/7]

TEST | ( | FlRendererTest | ,
|  | BlitFramebuffer |
| ) |  |

Definition at line 96 of file fl_renderer_test.cc.

96 {
97 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
98
99 // OpenGL 3.0
100 ON_CALL(epoxy, glGetString(GL_VENDOR))
101 .WillByDefault(
102 ::testing::Return(reinterpret_cast<const GLubyte*>("Intel")));
103 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
104 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
105
106 EXPECT_CALL(epoxy, glBlitFramebuffer);
107
108 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
109 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
110 fl_renderer_setup(FL_RENDERER(renderer));
111 fl_renderer_add_renderable(FL_RENDERER(renderer),
112 flutter::kFlutterImplicitViewId,
113 FL_RENDERABLE(renderable));
114 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
115 FlutterBackingStoreConfig config = {
116 .struct_size = sizeof(FlutterBackingStoreConfig),
117 .size = {.width = 1024, .height = 1024}};
118 FlutterBackingStore backing_store;
119 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
120 &backing_store);
121 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
122 .type = kFlutterLayerContentTypeBackingStore,
123 .backing_store = &backing_store,
124 .size = {.width = 1024, .height = 1024}};
125 const FlutterLayer* layers[] = {&layer0};
126 fl_renderer_present_layers(FL_RENDERER(renderer),
127 flutter::kFlutterImplicitViewId, layers, 1);
128 GdkRGBA background_color = {
129 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
130 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
131 1024, 1024, &background_color);
132 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_render(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [3/7]

TEST | ( | FlRendererTest | ,
|  | BlitFramebufferExtension |
| ) |  |

Definition at line 134 of file fl_renderer_test.cc.

134 {
135 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
136
137 // OpenGL 2.0 with GL_EXT_framebuffer_blit extension
138 ON_CALL(epoxy, glGetString(GL_VENDOR))
139 .WillByDefault(
140 ::testing::Return(reinterpret_cast<const GLubyte*>("Intel")));
141 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
142 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(20));
143 EXPECT_CALL(epoxy, epoxy_has_gl_extension(::testing::_))
144 .WillRepeatedly(::testing::Return(false));
145 EXPECT_CALL(epoxy, epoxy_has_gl_extension(
146 ::testing::StrEq("GL_EXT_framebuffer_blit")))
147 .WillRepeatedly(::testing::Return(true));
148
149 EXPECT_CALL(epoxy, glBlitFramebuffer);
150
151 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
152 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
153 fl_renderer_setup(FL_RENDERER(renderer));
154 fl_renderer_add_renderable(FL_RENDERER(renderer),
155 flutter::kFlutterImplicitViewId,
156 FL_RENDERABLE(renderable));
157 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
158 FlutterBackingStoreConfig config = {
159 .struct_size = sizeof(FlutterBackingStoreConfig),
160 .size = {.width = 1024, .height = 1024}};
161 FlutterBackingStore backing_store;
162 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
163 &backing_store);
164 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
165 .type = kFlutterLayerContentTypeBackingStore,
166 .backing_store = &backing_store,
167 .size = {.width = 1024, .height = 1024}};
168 const FlutterLayer* layers[] = {&layer0};
169 fl_renderer_present_layers(FL_RENDERER(renderer),
170 flutter::kFlutterImplicitViewId, layers, 1);
171 GdkRGBA background_color = {
172 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
173 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
174 1024, 1024, &background_color);
175 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_render(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [4/7]

TEST | ( | FlRendererTest | ,
|  | BlitFramebufferNvidia |
| ) |  |

Definition at line 213 of file fl_renderer_test.cc.

213 {
214 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
215
216 // OpenGL 3.0, but on NVIDIA driver so temporarily disabled due to
217 // https://github.com/flutter/flutter/issues/152099
218 ON_CALL(epoxy, glGetString(GL_VENDOR))
219 .WillByDefault(
220 ::testing::Return(reinterpret_cast<const GLubyte*>("NVIDIA")));
221 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
222 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
223
224 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
225 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
226 fl_renderer_setup(FL_RENDERER(renderer));
227 fl_renderer_add_renderable(FL_RENDERER(renderer),
228 flutter::kFlutterImplicitViewId,
229 FL_RENDERABLE(renderable));
230 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
231 FlutterBackingStoreConfig config = {
232 .struct_size = sizeof(FlutterBackingStoreConfig),
233 .size = {.width = 1024, .height = 1024}};
234 FlutterBackingStore backing_store;
235 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
236 &backing_store);
237 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
238 .type = kFlutterLayerContentTypeBackingStore,
239 .backing_store = &backing_store,
240 .size = {.width = 1024, .height = 1024}};
241 const FlutterLayer* layers[] = {&layer0};
242 fl_renderer_present_layers(FL_RENDERER(renderer),
243 flutter::kFlutterImplicitViewId, layers, 1);
244 GdkRGBA background_color = {
245 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
246 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
247 1024, 1024, &background_color);
248 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_render(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [5/7]

TEST | ( | FlRendererTest | ,
|  | MultiView |
| ) |  |

Definition at line 250 of file fl_renderer_test.cc.

250 {
251 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
252
253 // OpenGL 3.0
254 ON_CALL(epoxy, glGetString(GL_VENDOR))
255 .WillByDefault(
256 ::testing::Return(reinterpret_cast<const GLubyte*>("Intel")));
257 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
258 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(30));
259
260 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
261 g_autoptr(FlMockRenderable) secondary_renderable = fl_mock_renderable_new();
262
263 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
264 fl_renderer_setup(FL_RENDERER(renderer));
265 fl_renderer_add_renderable(FL_RENDERER(renderer),
266 flutter::kFlutterImplicitViewId,
267 FL_RENDERABLE(renderable));
268 fl_renderer_add_renderable(FL_RENDERER(renderer), 1,
269 FL_RENDERABLE(secondary_renderable));
270 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
271
272 EXPECT_EQ(fl_mock_renderable_get_redraw_count(renderable),
273 static_cast<size_t>(0));
274 EXPECT_EQ(fl_mock_renderable_get_redraw_count(secondary_renderable),
275 static_cast<size_t>(0));
276
277 FlutterBackingStoreConfig config = {
278 .struct_size = sizeof(FlutterBackingStoreConfig),
279 .size = {.width = 1024, .height = 1024}};
280 FlutterBackingStore backing_store;
281 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
282 &backing_store);
283 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
284 .type = kFlutterLayerContentTypeBackingStore,
285 .backing_store = &backing_store,
286 .size = {.width = 1024, .height = 1024}};
287 const FlutterLayer* layers[] = {&layer0};
288 fl_renderer_present_layers(FL_RENDERER(renderer), 1, layers, 1);
289
290 EXPECT_EQ(fl_mock_renderable_get_redraw_count(renderable),
291 static_cast<size_t>(0));
292 EXPECT_EQ(fl_mock_renderable_get_redraw_count(secondary_renderable),
293 static_cast<size_t>(1));
294 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [6/7]

TEST | ( | FlRendererTest | ,
|  | NoBlitFramebuffer |
| ) |  |

Definition at line 177 of file fl_renderer_test.cc.

177 {
178 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
179
180 // OpenGL 2.0
181 ON_CALL(epoxy, glGetString(GL_VENDOR))
182 .WillByDefault(
183 ::testing::Return(reinterpret_cast<const GLubyte*>("Intel")));
184 ON_CALL(epoxy, epoxy_is_desktop_gl).WillByDefault(::testing::Return(true));
185 EXPECT_CALL(epoxy, epoxy_gl_version).WillRepeatedly(::testing::Return(20));
186
187 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
188 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
189 fl_renderer_setup(FL_RENDERER(renderer));
190 fl_renderer_add_renderable(FL_RENDERER(renderer),
191 flutter::kFlutterImplicitViewId,
192 FL_RENDERABLE(renderable));
193 fl_renderer_wait_for_frame(FL_RENDERER(renderer), 1024, 1024);
194 FlutterBackingStoreConfig config = {
195 .struct_size = sizeof(FlutterBackingStoreConfig),
196 .size = {.width = 1024, .height = 1024}};
197 FlutterBackingStore backing_store;
198 fl_renderer_create_backing_store(FL_RENDERER(renderer), &config,
199 &backing_store);
200 const FlutterLayer layer0 = {.struct_size = sizeof(FlutterLayer),
201 .type = kFlutterLayerContentTypeBackingStore,
202 .backing_store = &backing_store,
203 .size = {.width = 1024, .height = 1024}};
204 const FlutterLayer* layers[] = {&layer0};
205 fl_renderer_present_layers(FL_RENDERER(renderer),
206 flutter::kFlutterImplicitViewId, layers, 1);
207 GdkRGBA background_color = {
208 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
209 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
210 1024, 1024, &background_color);
211 }

References fl_renderer_add_renderable(), fl_renderer_create_backing_store(), fl_renderer_present_layers(), fl_renderer_render(), fl_renderer_setup(), fl_renderer_wait_for_frame(), and type.

## ◆ TEST() [7/7]

TEST | ( | FlRendererTest | ,
|  | RestoresGLState |
| ) |  |

Definition at line 51 of file fl_renderer_test.cc.

51 {
52 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
53
54 constexpr int kWidth = 100;
55 constexpr int kHeight = 100;
56
57 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
58 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
59 g_autoptr(FlFramebuffer) framebuffer =
60 fl_framebuffer_new(GL_RGB, kWidth, kHeight);
61
62 fl_renderer_add_renderable(FL_RENDERER(renderer),
63 flutter::kFlutterImplicitViewId,
64 FL_RENDERABLE(renderable));
65 fl_renderer_wait_for_frame(FL_RENDERER(renderer), kWidth, kHeight);
66
67 FlutterBackingStore backing_store;
68 backing_store.type = kFlutterBackingStoreTypeOpenGL;
69 backing_store.open_gl.framebuffer.user_data = framebuffer;
70
71 FlutterLayer layer;
72 layer.type = kFlutterLayerContentTypeBackingStore;
73 layer.backing_store = &backing_store;
74 layer.offset = {0, 0};
75 layer.size = {kWidth, kHeight};
76
77 std::array<const FlutterLayer*, 1> layers = {&layer};
78
79 constexpr GLuint kFakeTextureName = 123;
80 glBindTexture(GL_TEXTURE_2D, kFakeTextureName);
81
82 fl_renderer_present_layers(FL_RENDERER(renderer),
83 flutter::kFlutterImplicitViewId, layers.data(),
84 layers.size());
85 GdkRGBA background_color = {
86 .red = 0.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
87 fl_renderer_render(FL_RENDERER(renderer), flutter::kFlutterImplicitViewId,
88 kWidth, kHeight, &background_color);
89
90 GLuint texture_2d_binding;
91 glGetIntegerv(GL_TEXTURE_BINDING_2D,
92 reinterpret_cast<GLint*>(&texture_2d_binding));
93 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
94 }

References fl_framebuffer_new(), fl_renderer_add_renderable(), fl_renderer_present_layers(), fl_renderer_render(), and fl_renderer_wait_for_frame().

fl_renderer_wait_for_frame
void fl_renderer_wait_for_frame(FlRenderer *self, int target_width, int target_height)
Definition: fl_renderer.cc:433
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *self, FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:453
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1115
fl_framebuffer_new
FlFramebuffer * fl_framebuffer_new(GLint format, size_t width, size_t height)
Definition: fl_framebuffer.cc:42
fl_renderer_render
void fl_renderer_render(FlRenderer *self, FlutterViewId view_id, int width, int height, const GdkRGBA *background_color)
Definition: fl_renderer.cc:585
fl_renderer_create_backing_store
gboolean fl_renderer_create_backing_store(FlRenderer *self, const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
Definition: fl_renderer.cc:391
fl_renderer_add_renderable
void fl_renderer_add_renderable(FlRenderer *self, FlutterViewId view_id, FlRenderable *renderable)
Definition: fl_renderer.cc:341
fl_renderer_setup
void fl_renderer_setup(FlRenderer *self)
Definition: fl_renderer.cc:567