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/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/fl_test.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, 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 69 of file fl_texture_registrar_test.cc.

69  {
70  g_return_val_if_fail(FL_TEXTURE_REGISTRAR(pointer), ((void*)NULL));
71  FlTextureRegistrar* registrar = FL_TEXTURE_REGISTRAR(pointer);
72  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
73  fl_texture_registrar_register_texture(registrar, texture);
74  int64_t* id = static_cast<int64_t*>(malloc(sizeof(int64_t)));
75  id[0] = fl_texture_get_id(texture);
76  pthread_exit(id);
77 }

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

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

◆ fl_test_registrar_texture_init()

static void fl_test_registrar_texture_init ( FlTestRegistrarTexture *  self)
static

Definition at line 62 of file fl_texture_registrar_test.cc.

62 {}

◆ fl_test_registrar_texture_new()

static FlTestRegistrarTexture* fl_test_registrar_texture_new ( )
static

Definition at line 64 of file fl_texture_registrar_test.cc.

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

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

31  {
32  FlTextureGL parent_instance;
33 };

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlTestRegistrarTexture  ,
fl_test_registrar_texture  ,
fl_texture_gl_get_type()   
)

◆ TEST() [1/4]

TEST ( FlTextureRegistrarTest  ,
DISABLED_RegistrarRegisterTextureInMultipleThreads   
)

Definition at line 124 of file fl_texture_registrar_test.cc.

125  {
126  g_autoptr(FlEngine) engine = make_mock_engine();
127  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
128  pthread_t threads[kThreadCount];
129  int64_t ids[kThreadCount];
130 
131  for (uint64_t t = 0; t < kThreadCount; t++) {
132  EXPECT_EQ(pthread_create(&threads[t], NULL, add_mock_texture_to_registrar,
133  (void*)registrar),
134  0);
135  }
136  for (uint64_t t = 0; t < kThreadCount; t++) {
137  void* id;
138  pthread_join(threads[t], &id);
139  ids[t] = static_cast<int64_t*>(id)[0];
140  free(id);
141  };
142  // Check all the textures were created.
143  for (uint64_t t = 0; t < kThreadCount; t++) {
144  EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
145  };
146 }

References add_mock_texture_to_registrar(), fl_texture_registrar_lookup_texture(), fl_texture_registrar_new(), id, kThreadCount, and make_mock_engine().

◆ TEST() [2/4]

TEST ( FlTextureRegistrarTest  ,
MarkTextureFrameAvailable   
)

Definition at line 108 of file fl_texture_registrar_test.cc.

108  {
109  g_autoptr(FlEngine) engine = make_mock_engine();
110  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
111  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
112 
113  EXPECT_FALSE(
115  EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
116  EXPECT_TRUE(
118 }

References fl_test_registrar_texture_new(), fl_texture_registrar_mark_texture_frame_available(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), and make_mock_engine().

◆ TEST() [3/4]

TEST ( FlTextureRegistrarTest  ,
MockRegistrar   
)

Definition at line 80 of file fl_texture_registrar_test.cc.

80  {
81  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
82  g_autoptr(FlMockTextureRegistrar) registrar = fl_mock_texture_registrar_new();
83  EXPECT_TRUE(FL_IS_MOCK_TEXTURE_REGISTRAR(registrar));
84 
86  FL_TEXTURE_REGISTRAR(registrar), texture));
87  EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), texture);
89  FL_TEXTURE_REGISTRAR(registrar), texture));
90  EXPECT_TRUE(fl_mock_texture_registrar_get_frame_available(registrar));
92  FL_TEXTURE_REGISTRAR(registrar), texture));
93  EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), nullptr);
94 }

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

TEST ( FlTextureRegistrarTest  ,
RegisterTexture   
)

Definition at line 97 of file fl_texture_registrar_test.cc.

97  {
98  g_autoptr(FlEngine) engine = make_mock_engine();
99  g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
100  g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
101 
102  EXPECT_FALSE(fl_texture_registrar_unregister_texture(registrar, texture));
103  EXPECT_TRUE(fl_texture_registrar_register_texture(registrar, texture));
104  EXPECT_TRUE(fl_texture_registrar_unregister_texture(registrar, texture));
105 }

References fl_test_registrar_texture_new(), fl_texture_registrar_new(), fl_texture_registrar_register_texture(), fl_texture_registrar_unregister_texture(), and make_mock_engine().

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

◆ format

* format = GL_R8

Definition at line 41 of file fl_texture_registrar_test.cc.

Referenced by clipboard_get_data_async(), and fl_framebuffer_new().

◆ height

* height = kRealBufferHeight

Definition at line 43 of file fl_texture_registrar_test.cc.

◆ kBufferHeight

constexpr uint32_t kBufferHeight = 4u
staticconstexpr

Definition at line 19 of file fl_texture_registrar_test.cc.

◆ kBufferWidth

constexpr uint32_t kBufferWidth = 4u
staticconstexpr

Definition at line 18 of file fl_texture_registrar_test.cc.

◆ kRealBufferHeight

constexpr uint32_t kRealBufferHeight = 2u
staticconstexpr

Definition at line 21 of file fl_texture_registrar_test.cc.

◆ kRealBufferWidth

constexpr uint32_t kRealBufferWidth = 2u
staticconstexpr

Definition at line 20 of file fl_texture_registrar_test.cc.

◆ kThreadCount

constexpr uint64_t kThreadCount = 16u
staticconstexpr

Definition at line 22 of file fl_texture_registrar_test.cc.

Referenced by TEST().

◆ target

◆ TRUE

return TRUE

Definition at line 54 of file fl_texture_registrar_test.cc.

◆ width

* width = kRealBufferWidth

Definition at line 42 of file fl_texture_registrar_test.cc.

add_mock_texture_to_registrar
static void * add_mock_texture_to_registrar(void *pointer)
Definition: fl_texture_registrar_test.cc:69
fl_texture_registrar_lookup_texture
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
Definition: fl_texture_registrar.cc:190
fl_test_registrar_texture_new
static FlTestRegistrarTexture * fl_test_registrar_texture_new()
Definition: fl_texture_registrar_test.cc:64
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_unregister_texture
G_MODULE_EXPORT gboolean fl_texture_registrar_unregister_texture(FlTextureRegistrar *self, FlTexture *texture)
Definition: fl_texture_registrar.cc:206
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
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_texture_get_id
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
Definition: fl_texture.cc:20
kThreadCount
static constexpr uint64_t kThreadCount
Definition: fl_texture_registrar_test.cc:22
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