21TEST(FlCompositorOpenGLTest, Render) {
22 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
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,
50 size_t frame_width, frame_height;
53 EXPECT_EQ(frame_width,
width);
54 EXPECT_EQ(frame_height,
height);
57 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
58 g_autofree
unsigned char* image_data =
59 static_cast<unsigned char*
>(malloc(
height * stride));
60 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
61 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
62 cairo_t* cr = cairo_create(
surface);
68TEST(FlCompositorOpenGLTest, Resize) {
69 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
76 g_autoptr(FlCompositorOpenGL) compositor =
81 constexpr size_t width1 = 90;
82 constexpr size_t height1 = 90;
87 .open_gl = {.framebuffer = {.user_data = framebuffer1}}};
89 .backing_store = &backing_store1,
91 .size = {width1, height1}};
98 constexpr size_t width2 = 100;
99 constexpr size_t height2 = 100;
104 .open_gl = {.framebuffer = {.user_data = framebuffer2}}};
106 .backing_store = &backing_store2,
108 .size = {width2, height2}};
117 int stride2 = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width2);
118 g_autofree
unsigned char* image_data =
119 static_cast<unsigned char*
>(malloc(height2 * stride2));
120 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
121 image_data, CAIRO_FORMAT_ARGB32, width2, height2, stride2);
122 cairo_t* cr = cairo_create(
surface);
124 cairo_surface_destroy(
surface);
130TEST(FlCompositorOpenGLTest, RestoresGLState) {
131 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
137 constexpr size_t width = 100;
138 constexpr size_t height = 100;
141 ON_CALL(epoxy, glGetString(GL_VENDOR))
143 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
148 g_autoptr(FlCompositorOpenGL) compositor =
156 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
158 .backing_store = &backing_store,
163 constexpr GLuint kFakeTextureName = 123;
164 glBindTexture(GL_TEXTURE_2D, kFakeTextureName);
166 glEnable(GL_SCISSOR_TEST);
172 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
173 g_autofree
unsigned char* image_data =
174 static_cast<unsigned char*
>(malloc(
height * stride));
175 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
176 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
177 cairo_t* cr = cairo_create(
surface);
179 cairo_surface_destroy(
surface);
182 GLuint texture_2d_binding;
183 glGetIntegerv(GL_TEXTURE_BINDING_2D,
184 reinterpret_cast<GLint*
>(&texture_2d_binding));
185 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
186 EXPECT_EQ(glIsEnabled(GL_BLEND), GL_FALSE);
187 EXPECT_EQ(glIsEnabled(GL_SCISSOR_TEST), GL_TRUE);
190TEST(FlCompositorOpenGLTest, BlitFramebuffer) {
191 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
197 constexpr size_t width = 100;
198 constexpr size_t height = 100;
201 ON_CALL(epoxy, glGetString(GL_VENDOR))
203 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
207 EXPECT_CALL(epoxy, glBlitFramebuffer);
210 g_autoptr(FlCompositorOpenGL) compositor =
218 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
220 .backing_store = &backing_store,
229 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
230 g_autofree
unsigned char* image_data =
231 static_cast<unsigned char*
>(malloc(
height * stride));
232 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
233 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
234 cairo_t* cr = cairo_create(
surface);
236 cairo_surface_destroy(
surface);
240TEST(FlCompositorOpenGLTest, BlitFramebufferExtension) {
241 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
247 constexpr size_t width = 100;
248 constexpr size_t height = 100;
251 ON_CALL(epoxy, glGetString(GL_VENDOR))
253 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
257 .WillRepeatedly(::testing::Return(
false));
259 ::testing::StrEq(
"GL_EXT_framebuffer_blit")))
260 .WillRepeatedly(::testing::Return(
true));
262 EXPECT_CALL(epoxy, glBlitFramebuffer);
265 g_autoptr(FlCompositorOpenGL) compositor =
273 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
275 .backing_store = &backing_store,
284 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
285 g_autofree
unsigned char* image_data =
286 static_cast<unsigned char*
>(malloc(
height * stride));
287 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
288 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
289 cairo_t* cr = cairo_create(
surface);
291 cairo_surface_destroy(
surface);
295TEST(FlCompositorOpenGLTest, NoBlitFramebuffer) {
296 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
302 constexpr size_t width = 100;
303 constexpr size_t height = 100;
306 ON_CALL(epoxy, glGetString(GL_VENDOR))
308 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
313 g_autoptr(FlCompositorOpenGL) compositor =
321 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
323 .backing_store = &backing_store,
332 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
333 g_autofree
unsigned char* image_data =
334 static_cast<unsigned char*
>(malloc(
height * stride));
335 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
336 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
337 cairo_t* cr = cairo_create(
surface);
339 cairo_surface_destroy(
surface);
343TEST(FlCompositorOpenGLTest, BlitFramebufferNvidia) {
344 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
350 constexpr size_t width = 100;
351 constexpr size_t height = 100;
355 ON_CALL(epoxy, glGetString(GL_VENDOR))
357 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"NVIDIA")));
362 g_autoptr(FlCompositorOpenGL) compositor =
370 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
372 .backing_store = &backing_store,
381 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
382 g_autofree
unsigned char* image_data =
383 static_cast<unsigned char*
>(malloc(
height * stride));
384 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
385 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
386 cairo_t* cr = cairo_create(
surface);
388 cairo_surface_destroy(
surface);