| Flutter Linux Embedder |

Functions
fl_compositor_software_test.cc File Reference
`#include <thread>`
`#include "gtest/gtest.h"`
`#include "flutter/common/constants.h"`
`#include "flutter/fml/synchronization/waitable_event.h"`
`#include "flutter/shell/platform/linux/fl_compositor_software.h"`
`#include "flutter/shell/platform/linux/fl_task_runner.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"`
`#include <gdk/gdkwayland.h>`

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 = {
31 .type = kFlutterBackingStoreTypeSoftware,
32 .software = {
33 .allocation = layer_data, .row_bytes = row_bytes, .height = height}};
34 FlutterLayer layer = {.type = kFlutterLayerContentTypeBackingStore,
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 // Render presented layer.
44 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
45 g_autofree unsigned char* image_data =
46 static_cast<unsigned char*>(malloc(height * stride));
47 cairo_surface_t* surface = cairo_image_surface_create_for_data(
48 image_data, CAIRO_FORMAT_ARGB32, width, height, stride);
49 cairo_t* cr = cairo_create(surface);
50 fl_compositor_render(FL_COMPOSITOR(compositor), cr, nullptr);
51 cairo_surface_destroy(surface);
52 cairo_destroy(cr);
53 }
fl_compositor_render
gboolean fl_compositor_render(FlCompositor *self, cairo_t *cr, GdkWindow *window)
Definition: fl_compositor.cc:23
fl_compositor_present_layers
gboolean fl_compositor_present_layers(FlCompositor *self, const FlutterLayer **layers, size_t layers_count)
Definition: fl_compositor.cc:15
layers
const FlutterLayer ** layers
Definition: fl_compositor_software.cc:32
height
self height
Definition: fl_compositor_software.cc:43
g_autoptr
g_autoptr(GMutexLocker) locker
width
self width
Definition: fl_compositor_software.cc:42
fl_compositor_software_new
FlCompositorSoftware * fl_compositor_software_new(FlTaskRunner *task_runner)
Definition: fl_compositor_software.cc:125
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:697
fl_task_runner_new
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
Definition: fl_task_runner.cc:147

References 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, layers, and width.

## ◆ TEST() [2/2]

TEST | ( | FlCompositorSoftwareTest | ,
|  | Resize |
| ) |  |

Definition at line 55 of file fl_compositor_software_test.cc.

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

References fl_compositor_present_layers(), fl_compositor_render(), fl_compositor_software_new(), fl_dart_project_new(), fl_engine_new(), fl_task_runner_new(), and g_autoptr().