| Flutter Linux Embedder |

Functions | Variables
fl_texture_registrar_test.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_texture_registrar.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_pixel_buffer_texture.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_texture_gl.h"`
`#include "flutter/shell/platform/linux/testing/mock_texture_registrar.h"`
`#include "gtest/gtest.h"`
`#include <epoxy/gl.h>`
`#include <gmodule.h>`
`#include <pthread.h>`

Go to the source code of this file.

## Functions
| G_DECLARE_FINAL_TYPE (FlTestRegistrarTexture, fl_test_registrar_texture, FL, TEST_REGISTRAR_TEXTURE, FlTextureGL) struct _FlTestRegistrarTexture
| A simple texture. More...
| G_DEFINE_TYPE (FlTestRegistrarTexture, fl_test_registrar_texture, fl_texture_gl_get_type()) static gboolean fl_test_registrar_texture_populate(FlTextureGL *texture
static void | fl_test_registrar_texture_class_init (FlTestRegistrarTextureClass *klass)
static void | fl_test_registrar_texture_init (FlTestRegistrarTexture *self)
static FlTestRegistrarTexture * | fl_test_registrar_texture_new ()
static void * | add_mock_texture_to_registrar (void *pointer)
| TEST (FlTextureRegistrarTest, MockRegistrar)
| TEST (FlTextureRegistrarTest, RegisterTexture)
| TEST (FlTextureRegistrarTest, MarkTextureFrameAvailable)
| TEST (FlTextureRegistrarTest, MarkInvalidTextureFrameAvailable)
| TEST (FlTextureRegistrarTest, DISABLED_RegistrarRegisterTextureInMultipleThreads)

## Variables
static constexpr uint32_t | kBufferWidth = 4u
static constexpr uint32_t | kBufferHeight = 4u
static constexpr uint32_t | kRealBufferWidth = 2u
static constexpr uint32_t | kRealBufferHeight = 2u
static constexpr uint64_t | kThreadCount = 16u
uint32_t * | target = GL_TEXTURE_2D
uint32_t uint32_t * | format = GL_R8
uint32_t uint32_t uint32_t * | width = kRealBufferWidth
uint32_t uint32_t uint32_t uint32_t * | height = kRealBufferHeight
uint32_t uint32_t uint32_t uint32_t GError ** | error
return | TRUE

## Function Documentation

## ◆ add_mock_texture_to_registrar()

static void* add_mock_texture_to_registrar | ( | void * | pointer | ) |
| static

Definition at line 70 of file fl_texture_registrar_test.cc.

70 {
71 g_return_val_if_fail(FL_TEXTURE_REGISTRAR(pointer), ((void*)NULL));
72 FlTextureRegistrar* registrar = FL_TEXTURE_REGISTRAR(pointer);
73 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
74 fl_texture_registrar_register_texture(registrar, texture);
75 int64_t* id = static_cast<int64_t*>(malloc(sizeof(int64_t)));
76 id[0] = fl_texture_get_id(texture);
77 pthread_exit(id);
78 }
fl_texture_get_id
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition: fl_texture.cc:20
fl_texture_registrar_register_texture
G_MODULE_EXPORT gboolean fl_texture_registrar_register_texture(FlTextureRegistrar *self, FlTexture *texture)
Definition: fl_texture_registrar.cc:181
fl_test_registrar_texture_new
static FlTestRegistrarTexture * fl_test_registrar_texture_new()
Definition: fl_texture_registrar_test.cc:65

References fl_test_registrar_texture_new(), fl_texture_get_id(), and fl_texture_registrar_register_texture().

Referenced by TEST().

## ◆ fl_test_registrar_texture_class_init()

static void fl_test_registrar_texture_class_init | ( | FlTestRegistrarTextureClass * | klass | ) |
| static

Definition at line 58 of file fl_texture_registrar_test.cc.

59 {
60 FL_TEXTURE_GL_CLASS(klass)->populate = fl_test_registrar_texture_populate;
61 }

## ◆ fl_test_registrar_texture_init()

static void fl_test_registrar_texture_init | ( | FlTestRegistrarTexture * | self | ) |
| static

Definition at line 63 of file fl_texture_registrar_test.cc.

63 {}

## ◆ fl_test_registrar_texture_new()

static FlTestRegistrarTexture* fl_test_registrar_texture_new | ( |  | ) |
| static

Definition at line 65 of file fl_texture_registrar_test.cc.

65 {
66 return FL_TEST_REGISTRAR_TEXTURE(
67 g_object_new(fl_test_registrar_texture_get_type(), nullptr));
68 }

Referenced by add_mock_texture_to_registrar(), and TEST().

## ◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE | ( | FlTestRegistrarTexture | ,
|  | fl_test_registrar_texture | ,
|  | FL | ,
|  | TEST_REGISTRAR_TEXTURE | ,
|  | FlTextureGL |
| ) |  |

A simple texture.

Definition at line 25 of file fl_texture_registrar_test.cc.

32 {
33 FlTextureGL parent_instance;
34 };

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlTestRegistrarTexture | ,
|  | fl_test_registrar_texture | ,
|  | fl_texture_gl_get_type() |
| ) |  |

## ◆ TEST() [1/5]

TEST | ( | FlTextureRegistrarTest | ,
|  | DISABLED_RegistrarRegisterTextureInMultipleThreads |
| ) |  |

Definition at line 189 of file fl_texture_registrar_test.cc.

190 {
191 g_autoptr(FlDartProject) project = fl_dart_project_new();
192 g_autoptr(FlEngine) engine = fl_engine_new(project);
193
194 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
195 MOCK_ENGINE_PROC(
196 RegisterExternalTexture,
197 ([](auto engine, int64_t texture_id) { return kSuccess; }));
198 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
199 MOCK_ENGINE_PROC(
200 UnregisterExternalTexture,
201 ([](auto engine, int64_t texture_id) { return kSuccess; }));
202
203 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
204 pthread_t threads[kThreadCount];
205 int64_t ids[kThreadCount];
206
207 for (uint64_t t = 0; t < kThreadCount; t++) {
208 EXPECT_EQ(pthread_create(&threads[t], NULL, add_mock_texture_to_registrar,
209 (void*)registrar),
210 0);
211 }
212 for (uint64_t t = 0; t < kThreadCount; t++) {
213 void* id;
214 pthread_join(threads[t], &id);
215 ids[t] = static_cast<int64_t*>(id)[0];
216 free(id);
217 };
218 // Check all the textures were created.
219 for (uint64_t t = 0; t < kThreadCount; t++) {
220 EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
221 };
222 }
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:661
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:524
id
int64_t id
Definition: fl_pixel_buffer_texture.cc:28
fl_texture_registrar_new
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
Definition: fl_texture_registrar.cc:221
fl_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:190
kThreadCount
static constexpr uint64_t kThreadCount
Definition: fl_texture_registrar_test.cc:23
add_mock_texture_to_registrar
static void * add_mock_texture_to_registrar(void *pointer)
Definition: fl_texture_registrar_test.cc:70
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24

References add_mock_texture_to_registrar(), fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_new(), fl_texture_registrar_lookup_texture(), fl_texture_registrar_new(), id, kThreadCount, and texture_id.

## ◆ TEST() [2/5]

TEST | ( | FlTextureRegistrarTest | ,
|  | MarkInvalidTextureFrameAvailable |
| ) |  |

Definition at line 160 of file fl_texture_registrar_test.cc.

160 {
161 g_autoptr(FlDartProject) project = fl_dart_project_new();
162 g_autoptr(FlEngine) engine = fl_engine_new(project);
163 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
164 MOCK_ENGINE_PROC(
165 RegisterExternalTexture,
166 ([](auto engine, int64_t texture_id) { return kSuccess; }));
167 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
168 MOCK_ENGINE_PROC(
169 UnregisterExternalTexture,
170 ([](auto engine, int64_t texture_id) { return kSuccess; }));
171 fl_engine_get_embedder_api(engine)->MarkExternalTextureFrameAvailable =
172 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
173 ([](auto engine, int64_t texture_id) {
174 return kInternalInconsistency;
175 }));
176
177 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
178 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
179
180 EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
181 EXPECT_FALSE(
182 fl_texture_registrar_mark_texture_frame_available(registrar, texture));
183 }
fl_texture_registrar_mark_texture_frame_available
G_MODULE_EXPORT gboolean fl_texture_registrar_mark_texture_frame_available(FlTextureRegistrar *self, FlTexture *texture)
Definition: fl_texture_registrar.cc:197

References fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_new(), fl_test_registrar_texture_new(), fl_texture_registrar_mark_texture_frame_available(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), and texture_id.

## ◆ TEST() [3/5]

TEST | ( | FlTextureRegistrarTest | ,
|  | MarkTextureFrameAvailable |
| ) |  |

Definition at line 129 of file fl_texture_registrar_test.cc.

129 {
130 g_autoptr(FlDartProject) project = fl_dart_project_new();
131 g_autoptr(FlEngine) engine = fl_engine_new(project);
132 bool register_called = false;
133 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
134 MOCK_ENGINE_PROC(RegisterExternalTexture,
135 ([&register_called](auto engine, int64_t texture_id) {
136 register_called = true;
137 return kSuccess;
138 }));
139 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
140 MOCK_ENGINE_PROC(
141 UnregisterExternalTexture,
142 ([](auto engine, int64_t texture_id) { return kSuccess; }));
143 fl_engine_get_embedder_api(engine)->MarkExternalTextureFrameAvailable =
144 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
145 ([](auto engine, int64_t texture_id) {
146 g_printerr("!\n");
147 return kSuccess;
148 }));
149
150 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
151 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
152
153 EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
154 EXPECT_TRUE(register_called);
155 EXPECT_TRUE(
156 fl_texture_registrar_mark_texture_frame_available(registrar, texture));
157 }

References fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_new(), fl_test_registrar_texture_new(), fl_texture_registrar_mark_texture_frame_available(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), and texture_id.

## ◆ TEST() [4/5]

TEST | ( | FlTextureRegistrarTest | ,
|  | MockRegistrar |
| ) |  |

Definition at line 81 of file fl_texture_registrar_test.cc.

81 {
82 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
83 g_autoptr(FlMockTextureRegistrar) registrar = fl_mock_texture_registrar_new();
84 EXPECT_TRUE(FL_IS_MOCK_TEXTURE_REGISTRAR(registrar));
85
86 EXPECT_TRUE(fl_texture_registrar_register_texture(
87 FL_TEXTURE_REGISTRAR(registrar), texture));
88 EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), texture);
89 EXPECT_TRUE(fl_texture_registrar_mark_texture_frame_available(
90 FL_TEXTURE_REGISTRAR(registrar), texture));
91 EXPECT_TRUE(fl_mock_texture_registrar_get_frame_available(registrar));
92 EXPECT_TRUE(fl_texture_registrar_unregister_texture(
93 FL_TEXTURE_REGISTRAR(registrar), texture));
94 EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), nullptr);
95 }
fl_texture_registrar_unregister_texture
G_MODULE_EXPORT gboolean fl_texture_registrar_unregister_texture(FlTextureRegistrar *self, FlTexture *texture)
Definition: fl_texture_registrar.cc:206

References fl_test_registrar_texture_new(), fl_texture_registrar_mark_texture_frame_available(), fl_texture_registrar_register_texture(), and fl_texture_registrar_unregister_texture().

## ◆ TEST() [5/5]

TEST | ( | FlTextureRegistrarTest | ,
|  | RegisterTexture |
| ) |  |

Definition at line 98 of file fl_texture_registrar_test.cc.

98 {
99 g_autoptr(FlDartProject) project = fl_dart_project_new();
100 g_autoptr(FlEngine) engine = fl_engine_new(project);
101 bool register_called = false;
102 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
103 MOCK_ENGINE_PROC(RegisterExternalTexture,
104 ([&register_called](auto engine, int64_t texture_id) {
105 register_called = true;
106 return kSuccess;
107 }));
108 bool unregister_called = false;
109 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
110 MOCK_ENGINE_PROC(UnregisterExternalTexture,
111 ([&unregister_called](auto engine, int64_t texture_id) {
112 unregister_called = true;
113 return kSuccess;
114 }));
115
116 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
117 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
118
119 // EXPECT_FALSE(fl_texture_registrar_unregister_texture(registrar, texture));
120 EXPECT_FALSE(register_called);
121 EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
122 EXPECT_TRUE(register_called);
123 EXPECT_FALSE(unregister_called);
124 EXPECT_TRUE(fl_texture_registrar_unregister_texture(registrar, texture));
125 EXPECT_TRUE(unregister_called);
126 }

References fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_new(), fl_test_registrar_texture_new(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), fl_texture_registrar_unregister_texture(), and texture_id.

## Variable Documentation

## ◆ error

uint32_t uint32_t uint32_t uint32_t GError** error

Initial value:
{
EXPECT_TRUE(FL_IS_TEST_REGISTRAR_TEXTURE(texture))

Definition at line 45 of file fl_texture_registrar_test.cc.

## ◆ format

* format = GL_R8

Definition at line 42 of file fl_texture_registrar_test.cc.

Referenced by clipboard_get_data(), and fl_framebuffer_new().

## ◆ height

* height = kRealBufferHeight

Definition at line 44 of file fl_texture_registrar_test.cc.

## ◆ kBufferHeight

constexpr uint32_t kBufferHeight = 4u
| static constexpr

Definition at line 20 of file fl_texture_registrar_test.cc.

## ◆ kBufferWidth

constexpr uint32_t kBufferWidth = 4u
| static constexpr

Definition at line 19 of file fl_texture_registrar_test.cc.

## ◆ kRealBufferHeight

constexpr uint32_t kRealBufferHeight = 2u
| static constexpr

Definition at line 22 of file fl_texture_registrar_test.cc.

## ◆ kRealBufferWidth

constexpr uint32_t kRealBufferWidth = 2u
| static constexpr

Definition at line 21 of file fl_texture_registrar_test.cc.

## ◆ kThreadCount

constexpr uint64_t kThreadCount = 16u
| static constexpr

Definition at line 23 of file fl_texture_registrar_test.cc.

Referenced by TEST().

## ◆ target

* target = GL_TEXTURE_2D

Definition at line 41 of file fl_texture_registrar_test.cc.

Referenced by flutter::FlutterPlatformNodeDelegate::AccessibilityPerformAction(), flutter::AccessibilityBridge::CommitUpdates(), fl_test_texture_populate(), and fl_texture_gl_populate().

## ◆ TRUE

return TRUE

Definition at line 55 of file fl_texture_registrar_test.cc.

## ◆ width

* width = kRealBufferWidth

Definition at line 43 of file fl_texture_registrar_test.cc.