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);
164 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
165 g_autofree
unsigned char* image_data =
166 static_cast<unsigned char*
>(malloc(
height * stride));
167 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
168 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
169 cairo_t* cr = cairo_create(
surface);
171 cairo_surface_destroy(
surface);
174 GLuint texture_2d_binding;
175 glGetIntegerv(GL_TEXTURE_BINDING_2D,
176 reinterpret_cast<GLint*
>(&texture_2d_binding));
177 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
180TEST(FlCompositorOpenGLTest, BlitFramebuffer) {
181 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
187 constexpr size_t width = 100;
188 constexpr size_t height = 100;
191 ON_CALL(epoxy, glGetString(GL_VENDOR))
193 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
197 EXPECT_CALL(epoxy, glBlitFramebuffer);
199 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
200 g_autoptr(FlCompositorOpenGL) compositor =
208 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
210 .backing_store = &backing_store,
219 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
220 g_autofree
unsigned char* image_data =
221 static_cast<unsigned char*
>(malloc(
height * stride));
222 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
223 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
224 cairo_t* cr = cairo_create(
surface);
226 cairo_surface_destroy(
surface);
230TEST(FlCompositorOpenGLTest, BlitFramebufferExtension) {
231 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
237 constexpr size_t width = 100;
238 constexpr size_t height = 100;
241 ON_CALL(epoxy, glGetString(GL_VENDOR))
243 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
247 .WillRepeatedly(::testing::Return(
false));
249 ::testing::StrEq(
"GL_EXT_framebuffer_blit")))
250 .WillRepeatedly(::testing::Return(
true));
252 EXPECT_CALL(epoxy, glBlitFramebuffer);
254 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
255 g_autoptr(FlCompositorOpenGL) compositor =
263 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
265 .backing_store = &backing_store,
274 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
275 g_autofree
unsigned char* image_data =
276 static_cast<unsigned char*
>(malloc(
height * stride));
277 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
278 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
279 cairo_t* cr = cairo_create(
surface);
281 cairo_surface_destroy(
surface);
285TEST(FlCompositorOpenGLTest, NoBlitFramebuffer) {
286 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
292 constexpr size_t width = 100;
293 constexpr size_t height = 100;
296 ON_CALL(epoxy, glGetString(GL_VENDOR))
298 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"Intel")));
302 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
303 g_autoptr(FlCompositorOpenGL) compositor =
311 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
313 .backing_store = &backing_store,
322 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
323 g_autofree
unsigned char* image_data =
324 static_cast<unsigned char*
>(malloc(
height * stride));
325 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
326 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
327 cairo_t* cr = cairo_create(
surface);
329 cairo_surface_destroy(
surface);
333TEST(FlCompositorOpenGLTest, BlitFramebufferNvidia) {
334 ::testing::NiceMock<flutter::testing::MockEpoxy> epoxy;
340 constexpr size_t width = 100;
341 constexpr size_t height = 100;
345 ON_CALL(epoxy, glGetString(GL_VENDOR))
347 ::testing::Return(
reinterpret_cast<const GLubyte*
>(
"NVIDIA")));
351 g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
352 g_autoptr(FlCompositorOpenGL) compositor =
360 .open_gl = {.framebuffer = {.user_data = framebuffer}}};
362 .backing_store = &backing_store,
371 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
372 g_autofree
unsigned char* image_data =
373 static_cast<unsigned char*
>(malloc(
height * stride));
374 cairo_surface_t*
surface = cairo_image_surface_create_for_data(
375 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
376 cairo_t* cr = cairo_create(
surface);
378 cairo_surface_destroy(
surface);