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.

Classes

class  FlCompositorSoftwareTest
 

Functions

 TEST_F (FlCompositorSoftwareTest, Render)
 
 TEST_F (FlCompositorSoftwareTest, Resize)
 

Function Documentation

◆ TEST_F() [1/2]

TEST_F ( FlCompositorSoftwareTest  ,
Render   
)

Definition at line 33 of file fl_compositor_software_test.cc.

33 {
34 // Present layer from a thread.
35 constexpr size_t width = 100;
36 constexpr size_t height = 100;
37 size_t row_bytes = width * 4;
38 g_autofree unsigned char* layer_data =
39 static_cast<unsigned char*>(malloc(height * row_bytes));
40 FlutterBackingStore backing_store = {
42 .software = {
43 .allocation = layer_data, .row_bytes = row_bytes, .height = height}};
45 .backing_store = &backing_store,
46 .offset = {0, 0},
47 .size = {width, height}};
48 const FlutterLayer* layers[1] = {&layer};
49 std::thread([&]() {
50 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers, 1);
51 }).join();
52
53 size_t frame_width, frame_height;
54 fl_compositor_get_frame_size(FL_COMPOSITOR(compositor), &frame_width,
55 &frame_height);
56 EXPECT_EQ(frame_width, width);
57 EXPECT_EQ(frame_height, height);
58
59 // Render presented layer.
60 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
61 g_autofree unsigned char* image_data =
62 static_cast<unsigned char*>(malloc(height * stride));
63 cairo_surface_t* surface = cairo_image_surface_create_for_data(
64 image_data, CAIRO_FORMAT_ARGB32, width, height, stride);
65 cairo_t* cr = cairo_create(surface);
66 fl_compositor_render(FL_COMPOSITOR(compositor), cr, nullptr, TRUE);
67 cairo_surface_destroy(surface);
68 cairo_destroy(cr);
69}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2157
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2108
VkSurfaceKHR surface
Definition main.cc:65
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
return TRUE
int32_t height
int32_t width
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2126
FlutterLayerContentType type
Definition embedder.h:2189

References fl_compositor_get_frame_size(), fl_compositor_present_layers(), fl_compositor_render(), height, kFlutterBackingStoreTypeSoftware, kFlutterLayerContentTypeBackingStore, layers, surface, TRUE, FlutterBackingStore::type, FlutterLayer::type, and width.

◆ TEST_F() [2/2]

TEST_F ( FlCompositorSoftwareTest  ,
Resize   
)

Definition at line 71 of file fl_compositor_software_test.cc.

71 {
72 // Present a layer that is the old size.
73 constexpr size_t width1 = 90;
74 constexpr size_t height1 = 90;
75 size_t row_bytes = width1 * 4;
76 g_autofree unsigned char* layer1_data =
77 static_cast<unsigned char*>(malloc(height1 * row_bytes));
78 FlutterBackingStore backing_store1 = {
80 .software = {.allocation = layer1_data,
81 .row_bytes = row_bytes,
82 .height = height1}};
84 .backing_store = &backing_store1,
85 .offset = {0, 0},
86 .size = {width1, height1}};
87 const FlutterLayer* layers1[1] = {&layer1};
88 std::thread([&]() {
89 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers1, 1);
90 }).join();
91
92 // Present layer in current size.
93 constexpr size_t width2 = 100;
94 constexpr size_t height2 = 100;
95 row_bytes = width2 * 4;
96 g_autofree unsigned char* layer2_data =
97 static_cast<unsigned char*>(malloc(height2 * row_bytes));
98 FlutterBackingStore backing_store2 = {
100 .software = {.allocation = layer2_data,
101 .row_bytes = row_bytes,
102 .height = height2}};
104 .backing_store = &backing_store2,
105 .offset = {0, 0},
106 .size = {width2, height2}};
107 const FlutterLayer* layers2[1] = {&layer2};
109 std::thread([&]() {
110 fl_compositor_present_layers(FL_COMPOSITOR(compositor), layers2, 1);
111 latch.Signal();
112 }).detach();
113
114 // Render, will wait for the second layer if necessary.
115 int stride2 = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width2);
116 g_autofree unsigned char* image_data =
117 static_cast<unsigned char*>(malloc(height2 * stride2));
118 cairo_surface_t* surface = cairo_image_surface_create_for_data(
119 image_data, CAIRO_FORMAT_ARGB32, width2, height2, stride2);
120 cairo_t* cr = cairo_create(surface);
121 fl_compositor_render(FL_COMPOSITOR(compositor), cr, nullptr, TRUE);
122 cairo_surface_destroy(surface);
123 cairo_destroy(cr);
124
125 latch.Wait();
126}

References fl_compositor_present_layers(), fl_compositor_render(), kFlutterBackingStoreTypeSoftware, kFlutterLayerContentTypeBackingStore, fml::AutoResetWaitableEvent::Signal(), surface, TRUE, FlutterBackingStore::type, FlutterLayer::type, and fml::AutoResetWaitableEvent::Wait().