Flutter Engine
The Flutter Engine
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/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());
74 int64_t* id = static_cast<int64_t*>(malloc(sizeof(int64_t)));
76 pthread_exit(id);
77}
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()
FlTexture * texture
void * malloc(size_t size)
Definition: allocation.cc:19

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

◆ 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}
FlutterEngine engine
Definition: main.cc:68
static FlEngine * make_mock_engine()
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
static void * add_mock_texture_to_registrar(void *pointer)
static constexpr uint64_t kThreadCount
const uintptr_t id
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678

◆ 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(
118}
G_MODULE_EXPORT gboolean fl_texture_registrar_mark_texture_frame_available(FlTextureRegistrar *self, FlTexture *texture)

◆ 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));
89 FL_TEXTURE_REGISTRAR(registrar), texture));
92 FL_TEXTURE_REGISTRAR(registrar), texture));
93 EXPECT_EQ(fl_mock_texture_registrar_get_texture(registrar), nullptr);
94}
G_MODULE_EXPORT gboolean fl_texture_registrar_unregister_texture(FlTextureRegistrar *self, FlTexture *texture)
FlTexture * fl_mock_texture_registrar_get_texture(FlMockTextureRegistrar *self)
FlMockTextureRegistrar * fl_mock_texture_registrar_new()
gboolean fl_mock_texture_registrar_get_frame_available(FlMockTextureRegistrar *self)

◆ 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));
105}

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.

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

◆ target

* target = GL_TEXTURE_2D

Definition at line 40 of file fl_texture_registrar_test.cc.

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