Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_compositor_software_test.cc File Reference

Go to the source code of this file.

Functions

 TEST (FlCompositorSoftwareTest, Render)
 
 TEST (FlCompositorSoftwareTest, Resize)
 

Function Documentation

◆ TEST() [1/2]

TEST ( FlCompositorSoftwareTest  ,
Render   
)

Definition at line 16 of file fl_compositor_software_test.cc.

16 {
17 g_autoptr(FlDartProject) project = fl_dart_project_new();
18 g_autoptr(FlEngine) engine = fl_engine_new(project);
19 g_autoptr(FlTaskRunner) task_runner = fl_task_runner_new(engine);
20
21 g_autoptr(FlCompositorSoftware) compositor =
22 fl_compositor_software_new(task_runner);
23
24 // Present layer from a thread.
25 constexpr size_t width = 100;
26 constexpr size_t height = 100;
27 size_t row_bytes = width * 4;
28 g_autofree unsigned char* layer_data =
29 static_cast<unsigned char*>(malloc(height * row_bytes));
30 FlutterBackingStore backing_store = {
32 .software = {
33 .allocation = layer_data, .row_bytes = row_bytes, .height = height}};
35 .backing_store = &backing_store,
36 .offset = {0, 0},
37 .size = {width, height}};
38 const FlutterLayer* layers[1] = {&layer};
39 std::thread([&]() {
40 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers, 1);
41 }).join();
42
43 size_t frame_width, frame_height;
44 fl_compositor_get_frame_size(FL_COMPOSITOR(compositor), &frame_width,
45 &frame_height);
46 EXPECT_EQ(frame_width, width);
47 EXPECT_EQ(frame_height, height);
48
49 // Render presented layer.
50 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
51 g_autofree unsigned char* image_data =
52 static_cast<unsigned char*>(malloc(height * stride));
53 cairo_surface_t* surface = cairo_image_surface_create_for_data(
54 image_data, CAIRO_FORMAT_ARGB32, width, height, stride);
55 cairo_t* cr = cairo_create(surface);
56 fl_compositor_render(FL_COMPOSITOR(compositor), cr, nullptr, TRUE);
57 cairo_surface_destroy(surface);
58 cairo_destroy(cr);
59}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2140
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2091
FlutterEngine engine
Definition main.cc:84
VkSurfaceKHR surface
Definition main.cc:65
g_autoptr(FlEngine) engine
gboolean fl_compositor_render(FlCompositor *self, cairo_t *cr, GdkWindow *window, gboolean wait_for_frame)
void fl_compositor_get_frame_size(FlCompositor *self, size_t *width, size_t *height)
gboolean fl_compositor_present_layers(FlCompositor *self, const FlutterLayer **layers, size_t layers_count)
const FlutterLayer ** layers
FlCompositorSoftware * fl_compositor_software_new(FlTaskRunner *task_runner)
return TRUE
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition fl_engine.cc:730
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
int32_t height
int32_t width
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2109
FlutterLayerContentType type
Definition embedder.h:2172

References engine, fl_compositor_get_frame_size(), fl_compositor_present_layers(), fl_compositor_render(), fl_compositor_software_new(), fl_dart_project_new(), fl_engine_new(), fl_task_runner_new(), g_autoptr(), height, kFlutterBackingStoreTypeSoftware, kFlutterLayerContentTypeBackingStore, layers, surface, TRUE, FlutterBackingStore::type, FlutterLayer::type, and width.

◆ TEST() [2/2]

TEST ( FlCompositorSoftwareTest  ,
Resize   
)

Definition at line 61 of file fl_compositor_software_test.cc.

61 {
62 g_autoptr(FlDartProject) project = fl_dart_project_new();
63 g_autoptr(FlEngine) engine = fl_engine_new(project);
64 g_autoptr(FlTaskRunner) task_runner = fl_task_runner_new(engine);
65
66 g_autoptr(FlCompositorSoftware) compositor =
67 fl_compositor_software_new(task_runner);
68
69 // Present a layer that is the old size.
70 constexpr size_t width1 = 90;
71 constexpr size_t height1 = 90;
72 size_t row_bytes = width1 * 4;
73 g_autofree unsigned char* layer1_data =
74 static_cast<unsigned char*>(malloc(height1 * row_bytes));
75 FlutterBackingStore backing_store1 = {
77 .software = {.allocation = layer1_data,
78 .row_bytes = row_bytes,
79 .height = height1}};
81 .backing_store = &backing_store1,
82 .offset = {0, 0},
83 .size = {width1, height1}};
84 const FlutterLayer* layers1[1] = {&layer1};
85 std::thread([&]() {
86 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers1, 1);
87 }).join();
88
89 // Present layer in current size.
90 constexpr size_t width2 = 100;
91 constexpr size_t height2 = 100;
92 row_bytes = width2 * 4;
93 g_autofree unsigned char* layer2_data =
94 static_cast<unsigned char*>(malloc(height2 * row_bytes));
95 FlutterBackingStore backing_store2 = {
97 .software = {.allocation = layer2_data,
98 .row_bytes = row_bytes,
99 .height = height2}};
101 .backing_store = &backing_store2,
102 .offset = {0, 0},
103 .size = {width2, height2}};
104 const FlutterLayer* layers2[1] = {&layer2};
106 std::thread([&]() {
107 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers2, 1);
108 latch.Signal();
109 }).detach();
110
111 // Render, will wait for the second layer if necessary.
112 int stride2 = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width2);
113 g_autofree unsigned char* image_data =
114 static_cast<unsigned char*>(malloc(height2 * stride2));
115 cairo_surface_t* surface = cairo_image_surface_create_for_data(
116 image_data, CAIRO_FORMAT_ARGB32, width2, height2, stride2);
117 cairo_t* cr = cairo_create(surface);
118 fl_compositor_render(FL_COMPOSITOR(compositor), cr, nullptr, TRUE);
119 cairo_surface_destroy(surface);
120 cairo_destroy(cr);
121
122 latch.Wait();
123}

References engine, fl_compositor_present_layers(), fl_compositor_render(), fl_compositor_software_new(), fl_dart_project_new(), fl_engine_new(), fl_task_runner_new(), g_autoptr(), kFlutterBackingStoreTypeSoftware, kFlutterLayerContentTypeBackingStore, fml::AutoResetWaitableEvent::Signal(), surface, TRUE, FlutterBackingStore::type, FlutterLayer::type, and fml::AutoResetWaitableEvent::Wait().