| Flutter Linux Embedder |

fl_renderer_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gtest/gtest.h"
6
7 #include <epoxy/egl.h>
8
9 #include "flutter/fml/logging.h"
10 #include "flutter/shell/platform/linux/fl_backing_store_provider.h"
11 #include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
12 #include "flutter/shell/platform/linux/testing/mock_renderer.h"
13
14 TEST(FlRendererTest, RestoresGLState) {
15 constexpr int kWidth = 100;
16 constexpr int kHeight = 100;
17
18 flutter::testing::fl_ensure_gtk_init();
19 g_autoptr(FlDartProject) project = fl_dart_project_new();
20 g_autoptr(FlView) view = fl_view_new(project);
21 g_autoptr(FlMockRenderer) renderer = fl_mock_renderer_new();
22 g_autoptr(FlBackingStoreProvider) backing_store_provider =
23 fl_backing_store_provider_new(kWidth, kHeight);
24
25 fl_renderer_start(FL_RENDERER(renderer), view);
26 fl_renderer_wait_for_frame(FL_RENDERER(renderer), kWidth, kHeight);
27
28 FlutterBackingStore backing_store;
29 backing_store.type = kFlutterBackingStoreTypeOpenGL;
30 backing_store.open_gl.framebuffer.user_data = backing_store_provider;
31
32 FlutterLayer layer;
33 layer.type = kFlutterLayerContentTypeBackingStore;
34 layer.backing_store = &backing_store;
35 layer.offset = {0, 0};
36 layer.size = {kWidth, kHeight};
37
38 std::array<const FlutterLayer*, 1> layers = {&layer};
39
40 constexpr GLuint kFakeTextureName = 123;
41 glBindTexture(GL_TEXTURE_2D, kFakeTextureName);
42
43 fl_renderer_present_layers(FL_RENDERER(renderer), layers.data(),
44 layers.size());
45 fl_renderer_render(FL_RENDERER(renderer), kWidth, kHeight);
46
47 GLuint texture_2d_binding;
48 glGetIntegerv(GL_TEXTURE_BINDING_2D,
49 reinterpret_cast<GLint*>(&texture_2d_binding));
50 EXPECT_EQ(texture_2d_binding, kFakeTextureName);
51
52 g_object_ref_sink(view);
53 }
54
55 static constexpr double kExpectedRefreshRate = 120.0;
56 static gdouble renderer_get_refresh_rate(FlRenderer* renderer) {
57 return kExpectedRefreshRate;
58 }
59
60 TEST(FlRendererTest, RefreshRate) {
61 flutter::testing::fl_ensure_gtk_init();
62 g_autoptr(FlDartProject) project = fl_dart_project_new();
63 g_autoptr(FlMockRenderer) renderer =
64 fl_mock_renderer_new(&renderer_get_refresh_rate);
65
66 gdouble result_refresh_rate =
67 fl_renderer_get_refresh_rate(FL_RENDERER(renderer));
68 EXPECT_DOUBLE_EQ(result_refresh_rate, kExpectedRefreshRate);
69 }
fl_renderer_wait_for_frame
void fl_renderer_wait_for_frame(FlRenderer *self, int target_width, int target_height)
Definition: fl_renderer.cc:211
fl_renderer_get_refresh_rate
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:160
renderer_get_refresh_rate
static gdouble renderer_get_refresh_rate(FlRenderer *renderer)
Definition: fl_renderer_test.cc:56
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_backing_store_provider_new
FlBackingStoreProvider * fl_backing_store_provider_new(int width, int height)
Definition: fl_backing_store_provider.cc:35
fl_view_new
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition: fl_view.cc:837
fl_renderer_start
gboolean fl_renderer_start(FlRenderer *self, FlView *view)
Definition: fl_renderer.cc:129
TEST
TEST(FlRendererTest, RestoresGLState)
Definition: fl_renderer_test.cc:14
fl_renderer_present_layers
gboolean fl_renderer_present_layers(FlRenderer *self, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:230
kExpectedRefreshRate
static constexpr double kExpectedRefreshRate
Definition: fl_renderer_test.cc:55
fl_renderer_render
void fl_renderer_render(FlRenderer *self, int width, int height)
Definition: fl_renderer.cc:320
fl_backing_store_provider.h