| 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 }
g_autoptr
g_autoptr(FlEngine) engine
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:182
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(), fl_texture_registrar_register_texture(), and g_autoptr().

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 187 of file fl_texture_registrar_test.cc.

188 {
189 g_autoptr(FlDartProject) project = fl_dart_project_new();
190 g_autoptr(FlEngine) engine = fl_engine_new(project);
191
192 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
193 MOCK_ENGINE_PROC(
194 RegisterExternalTexture,
195 ([](auto engine, int64_t texture_id) { return kSuccess; }));
196 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
197 MOCK_ENGINE_PROC(
198 UnregisterExternalTexture,
199 ([](auto engine, int64_t texture_id) { return kSuccess; }));
200
201 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
202 pthread_t threads[kThreadCount];
203 int64_t ids[kThreadCount];
204
205 for (uint64_t t = 0; t < kThreadCount; t++) {
206 EXPECT_EQ(pthread_create(&threads[t], NULL, add_mock_texture_to_registrar,
207 (void*)registrar),
208 0);
209 }
210 for (uint64_t t = 0; t < kThreadCount; t++) {
211 void* id;
212 pthread_join(threads[t], &id);
213 ids[t] = static_cast<int64_t*>(id)[0];
214 free(id);
215 };
216 // Check all the textures were created.
217 for (uint64_t t = 0; t < kThreadCount; t++) {
218 EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
219 };
220 }
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:868
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:697
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(), g_autoptr(), id, kThreadCount, and texture_id.

## ◆ TEST() [2/5]

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

Definition at line 158 of file fl_texture_registrar_test.cc.

158 {
159 g_autoptr(FlDartProject) project = fl_dart_project_new();
160 g_autoptr(FlEngine) engine = fl_engine_new(project);
161 fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
162 MOCK_ENGINE_PROC(
163 RegisterExternalTexture,
164 ([](auto engine, int64_t texture_id) { return kSuccess; }));
165 fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
166 MOCK_ENGINE_PROC(
167 UnregisterExternalTexture,
168 ([](auto engine, int64_t texture_id) { return kSuccess; }));
169 fl_engine_get_embedder_api(engine)->MarkExternalTextureFrameAvailable =
170 MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
171 ([](auto engine, int64_t texture_id) {
172 return kInternalInconsistency;
173 }));
174
175 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
176 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
177
178 EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
179 EXPECT_FALSE(
180 fl_texture_registrar_mark_texture_frame_available(registrar, texture));
181 }
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:198

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(), g_autoptr(), 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(
145 MarkExternalTextureFrameAvailable,
146 ([](auto engine, int64_t texture_id) { return kSuccess; }));
147
148 g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
149 g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
150
151 EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
152 EXPECT_TRUE(register_called);
153 EXPECT_TRUE(
154 fl_texture_registrar_mark_texture_frame_available(registrar, texture));
155 }

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(), g_autoptr(), 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:207

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

## ◆ 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(), g_autoptr(), 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.