21TEST(FlCompositorOpenGLTest, Render) {
22 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
28 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
29 g_autoptr(FlCompositorOpenGL) compositor =
34 constexpr size_t width = 100;
35 constexpr size_t height = 100;
40 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
42 .backing_store = &backing_store,
51 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
52 g_autofree
unsigned char* image_data =
53 static_cast<unsigned char*
>(malloc(
height * stride));
54 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
55 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
56 cairo_t* cr = cairo_create(
surface);
62TEST(FlCompositorOpenGLTest, Resize) {
63 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
69 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
70 g_autoptr(FlCompositorOpenGL) compositor =
75 constexpr size_t width1 = 90;
76 constexpr size_t height1 = 90;
81 .open_gl = {.framebuffer = {.user_data = framebuffer1}}};
83 .backing_store = &backing_store1,
85 .size = {width1, height1}};
92 constexpr size_t width2 = 100;
93 constexpr size_t height2 = 100;
98 .open_gl = {.framebuffer = {.user_data = framebuffer2}}};
100 .backing_store = &backing_store2,
102 .size = {width2, height2}};
111 int stride2 = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width2);
112 g_autofree
unsigned char* image_data =
113 static_cast<unsigned char*
>(malloc(height2 * stride2));
114 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
115 image_data, CAIRO_FORMAT_ARGB32, width2, height2, stride2);
116 cairo_t* cr = cairo_create(
surface);
118 cairo_surface_destroy(
surface);
124TEST(FlCompositorOpenGLTest, RestoresGLState) {
125 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
131 constexpr size_t width = 100;
132 constexpr size_t height = 100;
135 ON_CALL(epoxy, glGetString(GL_VENDOR))
137 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
141 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
142 g_autoptr(FlCompositorOpenGL) compositor =
150 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
152 .backing_store = &backing_store,
157 constexpr GLuint kFakeTextureName = 123;
158 glBindTexture(GL_TEXTURE_2D, kFakeTextureName);
160 glEnable(GL_SCISSOR_TEST);
166 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
167 g_autofree
unsigned char* image_data =
168 static_cast<unsigned char*
>(malloc(
height * stride));
169 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
170 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
171 cairo_t* cr = cairo_create(
surface);
173 cairo_surface_destroy(
surface);
176 GLuint texture_2d_binding;
177 glGetIntegerv(GL_TEXTURE_BINDING_2D,
178 reinterpret_cast<GLint*
>(&texture_2d_binding));
179 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
180 EXPECT_EQ(glIsEnabled(GL_BLEND), GL_FALSE);
181 EXPECT_EQ(glIsEnabled(GL_SCISSOR_TEST), GL_TRUE);
184TEST(FlCompositorOpenGLTest, BlitFramebuffer) {
185 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
191 constexpr size_t width = 100;
192 constexpr size_t height = 100;
195 ON_CALL(epoxy, glGetString(GL_VENDOR))
197 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
201 EXPECT_CALL(epoxy, glBlitFramebuffer);
203 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
204 g_autoptr(FlCompositorOpenGL) compositor =
212 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
214 .backing_store = &backing_store,
223 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
224 g_autofree
unsigned char* image_data =
225 static_cast<unsigned char*
>(malloc(
height * stride));
226 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
227 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
228 cairo_t* cr = cairo_create(
surface);
230 cairo_surface_destroy(
surface);
234TEST(FlCompositorOpenGLTest, BlitFramebufferExtension) {
235 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
241 constexpr size_t width = 100;
242 constexpr size_t height = 100;
245 ON_CALL(epoxy, glGetString(GL_VENDOR))
247 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
251 .WillRepeatedly(::testing::Return(
false));
253 ::testing::StrEq(
"GL_EXT_framebuffer_blit")))
254 .WillRepeatedly(::testing::Return(
true));
256 EXPECT_CALL(epoxy, glBlitFramebuffer);
258 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
259 g_autoptr(FlCompositorOpenGL) compositor =
267 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
269 .backing_store = &backing_store,
278 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
279 g_autofree
unsigned char* image_data =
280 static_cast<unsigned char*
>(malloc(
height * stride));
281 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
282 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
283 cairo_t* cr = cairo_create(
surface);
285 cairo_surface_destroy(
surface);
289TEST(FlCompositorOpenGLTest, NoBlitFramebuffer) {
290 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
296 constexpr size_t width = 100;
297 constexpr size_t height = 100;
300 ON_CALL(epoxy, glGetString(GL_VENDOR))
302 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
306 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
307 g_autoptr(FlCompositorOpenGL) compositor =
315 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
317 .backing_store = &backing_store,
326 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
327 g_autofree
unsigned char* image_data =
328 static_cast<unsigned char*
>(malloc(
height * stride));
329 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
330 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
331 cairo_t* cr = cairo_create(
surface);
333 cairo_surface_destroy(
surface);
337TEST(FlCompositorOpenGLTest, BlitFramebufferNvidia) {
338 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
344 constexpr size_t width = 100;
345 constexpr size_t height = 100;
349 ON_CALL(epoxy, glGetString(GL_VENDOR))
351 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"NVIDIA")));
355 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
356 g_autoptr(FlCompositorOpenGL) compositor =
364 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
366 .backing_store = &backing_store,
375 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
376 g_autofree
unsigned char* image_data =
377 static_cast<unsigned char*
>(malloc(
height * stride));
378 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
379 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
380 cairo_t* cr = cairo_create(
surface);
382 cairo_surface_destroy(
surface);