Flutter Engine
The Flutter Engine
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
14TEST(FlRendererTest, RestoresGLState) {
15 constexpr int kWidth = 100;
16 constexpr int kHeight = 100;
17
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 =
24
25 fl_renderer_start(FL_RENDERER(renderer), view);
27
28 FlutterBackingStore backing_store;
30 backing_store.open_gl.framebuffer.user_data = backing_store_provider;
31
32 FlutterLayer layer;
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());
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
55static constexpr double kExpectedRefreshRate = 120.0;
56static gdouble renderer_get_refresh_rate(FlRenderer* renderer) {
58}
59
60TEST(FlRendererTest, RefreshRate) {
62 g_autoptr(FlDartProject) project = fl_dart_project_new();
63 g_autoptr(FlMockRenderer) renderer =
65
66 gdouble result_refresh_rate =
68 EXPECT_DOUBLE_EQ(result_refresh_rate, kExpectedRefreshRate);
69}
@ kFlutterLayerContentTypeBackingStore
Definition: embedder.h:1793
@ kFlutterBackingStoreTypeOpenGL
Definition: embedder.h:1742
FlBackingStoreProvider * fl_backing_store_provider_new(int width, int height)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
gboolean fl_renderer_present_layers(FlRenderer *self, const FlutterLayer **layers, size_t layers_count)
Definition: fl_renderer.cc:226
gboolean fl_renderer_start(FlRenderer *self, FlView *view)
Definition: fl_renderer.cc:125
void fl_renderer_render(FlRenderer *self, int width, int height)
Definition: fl_renderer.cc:316
gdouble fl_renderer_get_refresh_rate(FlRenderer *self)
Definition: fl_renderer.cc:156
void fl_renderer_wait_for_frame(FlRenderer *self, int target_width, int target_height)
Definition: fl_renderer.cc:207
TEST(FlRendererTest, RestoresGLState)
static gdouble renderer_get_refresh_rate(FlRenderer *renderer)
static constexpr double kExpectedRefreshRate
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition: fl_view.cc:830
FlMockRenderer * fl_mock_renderer_new(FlMockRendererGetRefreshRate get_refresh_rate)
void fl_ensure_gtk_init(GLogWriterFunc writer)
Ensures that GTK has been initialized and starts monitoring logs.
FlutterBackingStoreType type
Specifies the type of backing store.
Definition: embedder.h:1762
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition: embedder.h:1768
FlutterPoint offset
Definition: embedder.h:1835
FlutterLayerContentType type
Definition: embedder.h:1824
const FlutterBackingStore * backing_store
Definition: embedder.h:1828
FlutterSize size
The size of the layer (in physical pixels).
Definition: embedder.h:1837
FlutterOpenGLFramebuffer framebuffer
Definition: embedder.h:1616
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition: embedder.h:399
constexpr size_t kHeight
constexpr size_t kWidth