Flutter Linux Embedder
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/linux_test.h"
#include "flutter/shell/platform/linux/testing/mock_texture_registrar.h"
#include "gtest/gtest.h"
#include <epoxy/gl.h>
#include <gmodule.h>

Go to the source code of this file.

Classes

class  FlTextureRegistrarTest
 

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 gpointer add_mock_texture_to_registrar (gpointer pointer)
 
 TEST_F (FlTextureRegistrarTest, MockRegistrar)
 
 TEST_F (FlTextureRegistrarTest, RegisterTexture)
 
 TEST_F (FlTextureRegistrarTest, MarkTextureFrameAvailable)
 
 TEST_F (FlTextureRegistrarTest, MarkInvalidTextureFrameAvailable)
 
 TEST_F (FlTextureRegistrarTest, 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 gpointer add_mock_texture_to_registrar ( gpointer  pointer)
static

Definition at line 70 of file fl_texture_registrar_test.cc.

70  {
71  g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(pointer), nullptr);
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 = g_new0(int64_t, 1);
76  id[0] = fl_texture_get_id(texture);
77  return id;
78 }
g_autoptr(FlEngine) engine
int64_t id
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition: fl_texture.cc:20
G_MODULE_EXPORT gboolean fl_texture_registrar_register_texture(FlTextureRegistrar *self, FlTexture *texture)
static FlTestRegistrarTexture * fl_test_registrar_texture_new()

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

Referenced by TEST_F().

◆ 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_F().

◆ 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_F() [1/5]

TEST_F ( FlTextureRegistrarTest  ,
MarkInvalidTextureFrameAvailable   
)

Definition at line 156 of file fl_texture_registrar_test.cc.

156  {
157  fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
158  MOCK_ENGINE_PROC(
159  RegisterExternalTexture,
160  ([](auto engine, int64_t texture_id) { return kSuccess; }));
161  fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
162  MOCK_ENGINE_PROC(
163  UnregisterExternalTexture,
164  ([](auto engine, int64_t texture_id) { return kSuccess; }));
165  fl_engine_get_embedder_api(engine)->MarkExternalTextureFrameAvailable =
166  MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable,
167  ([](auto engine, int64_t texture_id) {
168  return kInternalInconsistency;
169  }));
170 
171  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
172  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
173 
174  EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
175  EXPECT_FALSE(
177 }
GLuint texture_id
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:940
G_MODULE_EXPORT gboolean fl_texture_registrar_mark_texture_frame_available(FlTextureRegistrar *self, FlTexture *texture)
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)

References fl_engine_get_embedder_api(), 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_F() [2/5]

TEST_F ( FlTextureRegistrarTest  ,
MarkTextureFrameAvailable   
)

Definition at line 129 of file fl_texture_registrar_test.cc.

129  {
130  bool register_called = false;
131  fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
132  MOCK_ENGINE_PROC(RegisterExternalTexture,
133  ([&register_called](auto engine, int64_t texture_id) {
134  register_called = true;
135  return kSuccess;
136  }));
137  fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
138  MOCK_ENGINE_PROC(
139  UnregisterExternalTexture,
140  ([](auto engine, int64_t texture_id) { return kSuccess; }));
141  fl_engine_get_embedder_api(engine)->MarkExternalTextureFrameAvailable =
142  MOCK_ENGINE_PROC(
143  MarkExternalTextureFrameAvailable,
144  ([](auto engine, int64_t texture_id) { return kSuccess; }));
145 
146  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
147  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
148 
149  EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
150  EXPECT_TRUE(register_called);
151  EXPECT_TRUE(
153 }

References fl_engine_get_embedder_api(), 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_F() [3/5]

TEST_F ( FlTextureRegistrarTest  ,
MockRegistrar   
)

Definition at line 83 of file fl_texture_registrar_test.cc.

83  {
84  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
85  g_autoptr(FlMockTextureRegistrar) registrar = fl_mock_texture_registrar_new();
86  EXPECT_TRUE(FL_IS_MOCK_TEXTURE_REGISTRAR(registrar));
87 
89  FL_TEXTURE_REGISTRAR(registrar), texture));
90  EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), texture);
92  FL_TEXTURE_REGISTRAR(registrar), texture));
93  EXPECT_TRUE(fl_mock_texture_registrar_get_frame_available(registrar));
95  FL_TEXTURE_REGISTRAR(registrar), texture));
96  EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), nullptr);
97 }
G_MODULE_EXPORT gboolean fl_texture_registrar_unregister_texture(FlTextureRegistrar *self, FlTexture *texture)

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_F() [4/5]

TEST_F ( FlTextureRegistrarTest  ,
RegisterTexture   
)

Definition at line 100 of file fl_texture_registrar_test.cc.

100  {
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_engine_get_embedder_api(), fl_test_registrar_texture_new(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), fl_texture_registrar_unregister_texture(), g_autoptr(), and texture_id.

◆ TEST_F() [5/5]

TEST_F ( FlTextureRegistrarTest  ,
RegistrarRegisterTextureInMultipleThreads   
)

Definition at line 181 of file fl_texture_registrar_test.cc.

181  {
182  fl_engine_get_embedder_api(engine)->RegisterExternalTexture =
183  MOCK_ENGINE_PROC(
184  RegisterExternalTexture,
185  ([](auto engine, int64_t texture_id) { return kSuccess; }));
186  fl_engine_get_embedder_api(engine)->UnregisterExternalTexture =
187  MOCK_ENGINE_PROC(
188  UnregisterExternalTexture,
189  ([](auto engine, int64_t texture_id) { return kSuccess; }));
190 
191  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
192  GThread* threads[kThreadCount];
193  int64_t ids[kThreadCount];
194 
195  for (uint64_t t = 0; t < kThreadCount; t++) {
196  threads[t] =
197  g_thread_new(nullptr, add_mock_texture_to_registrar, registrar);
198  ASSERT_NE(threads[t], nullptr);
199  }
200  for (uint64_t t = 0; t < kThreadCount; t++) {
201  g_autofree int64_t* id = static_cast<int64_t*>(g_thread_join(threads[t]));
202  ASSERT_NE(id, nullptr);
203  ids[t] = *id;
204  }
205  // Check all the textures were created.
206  for (uint64_t t = 0; t < kThreadCount; t++) {
207  EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
208  }
209 }
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
static gpointer add_mock_texture_to_registrar(gpointer pointer)
static constexpr uint64_t kThreadCount

References add_mock_texture_to_registrar(), fl_engine_get_embedder_api(), fl_texture_registrar_lookup_texture(), fl_texture_registrar_new(), g_autoptr(), id, kThreadCount, 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
staticconstexpr

Definition at line 20 of file fl_texture_registrar_test.cc.

◆ kBufferWidth

constexpr uint32_t kBufferWidth = 4u
staticconstexpr

Definition at line 19 of file fl_texture_registrar_test.cc.

◆ kRealBufferHeight

constexpr uint32_t kRealBufferHeight = 2u
staticconstexpr

Definition at line 22 of file fl_texture_registrar_test.cc.

◆ kRealBufferWidth

constexpr uint32_t kRealBufferWidth = 2u
staticconstexpr

Definition at line 21 of file fl_texture_registrar_test.cc.

◆ kThreadCount

constexpr uint64_t kThreadCount = 16u
staticconstexpr

Definition at line 23 of file fl_texture_registrar_test.cc.

Referenced by TEST_F().

◆ target

◆ 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.