6 #include "flutter/shell/platform/linux/testing/linux_test.h"
7 #include "gtest/gtest.h"
21 constexpr
size_t width = 100;
22 constexpr
size_t height = 100;
23 size_t row_bytes =
width * 4;
24 g_autofree
unsigned char* layer_data =
25 static_cast<unsigned char*
>(malloc(
height * row_bytes));
27 memset(layer_data, 0xFF,
height * row_bytes);
28 FlutterBackingStore backing_store = {
29 .type = kFlutterBackingStoreTypeSoftware,
31 .allocation = layer_data, .row_bytes = row_bytes, .height =
height}};
32 FlutterLayer layer = {.type = kFlutterLayerContentTypeBackingStore,
33 .backing_store = &backing_store,
36 const FlutterLayer*
layers[1] = {&layer};
39 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
40 g_autofree
unsigned char* image_data =
41 static_cast<unsigned char*
>(malloc(
height * stride));
42 memset(image_data, 0,
height * stride);
43 cairo_surface_t* surface = cairo_image_surface_create_for_data(
44 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
45 cairo_t* cr = cairo_create(surface);
48 cairo_surface_flush(surface);
51 uint32_t* pixels =
reinterpret_cast<uint32_t*
>(image_data);
52 EXPECT_EQ(pixels[50 * (stride / 4) + 50], 0xFFFFFFFFu);
55 cairo_surface_destroy(surface);
61 constexpr
size_t width = 100;
62 constexpr
size_t height = 100;
64 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
65 g_autofree
unsigned char* image_data =
66 static_cast<unsigned char*
>(malloc(
height * stride));
69 memset(image_data, 0xFF,
height * stride);
70 cairo_surface_t* surface = cairo_image_surface_create_for_data(
71 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
72 cairo_t* cr = cairo_create(surface);
75 cairo_surface_flush(surface);
78 uint32_t* pixels =
reinterpret_cast<uint32_t*
>(image_data);
79 EXPECT_EQ(pixels[50 * (stride / 4) + 50], 0x00000000u);
82 cairo_surface_destroy(surface);
86 constexpr
size_t width = 100;
87 constexpr
size_t height = 100;
91 size_t layer0_row_bytes =
width * 4;
92 g_autofree
unsigned char* layer0_data =
93 static_cast<unsigned char*
>(malloc(
height * layer0_row_bytes));
95 memset(layer0_data, 0xFF,
height * layer0_row_bytes);
96 FlutterBackingStore backing_store0 = {
97 .type = kFlutterBackingStoreTypeSoftware,
98 .software = {.allocation = layer0_data,
99 .row_bytes = layer0_row_bytes,
101 FlutterLayer layer0 = {.type = kFlutterLayerContentTypeBackingStore,
102 .backing_store = &backing_store0,
106 constexpr
size_t layer1_width = 10;
107 constexpr
size_t layer1_height = 10;
108 size_t layer1_row_bytes = layer1_width * 4;
109 g_autofree
unsigned char* layer1_data =
110 static_cast<unsigned char*
>(malloc(layer1_height * layer1_row_bytes));
112 uint32_t* layer1_pixels =
reinterpret_cast<uint32_t*
>(layer1_data);
113 for (
size_t i = 0;
i < layer1_width * layer1_height;
i++) {
114 layer1_pixels[
i] = 0xFFFF0000;
116 FlutterBackingStore backing_store1 = {
117 .type = kFlutterBackingStoreTypeSoftware,
118 .software = {.allocation = layer1_data,
119 .row_bytes = layer1_row_bytes,
120 .height = layer1_height}};
121 FlutterLayer layer1 = {.type = kFlutterLayerContentTypeBackingStore,
122 .backing_store = &backing_store1,
124 .size = {layer1_width, layer1_height}};
126 const FlutterLayer*
layers[2] = {&layer0, &layer1};
128 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
129 g_autofree
unsigned char* image_data =
130 static_cast<unsigned char*
>(malloc(
height * stride));
131 memset(image_data, 0,
height * stride);
132 cairo_surface_t* surface = cairo_image_surface_create_for_data(
133 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
134 cairo_t* cr = cairo_create(surface);
137 cairo_surface_flush(surface);
139 uint32_t* pixels =
reinterpret_cast<uint32_t*
>(image_data);
141 EXPECT_EQ(pixels[25 * (stride / 4) + 25], 0xFFFF0000u);
143 EXPECT_EQ(pixels[50 * (stride / 4) + 50], 0xFFFFFFFFu);
144 EXPECT_EQ(pixels[25 * (stride / 4) + 15], 0xFFFFFFFFu);
145 EXPECT_EQ(pixels[15 * (stride / 4) + 25], 0xFFFFFFFFu);
148 cairo_surface_destroy(surface);
154 constexpr
size_t width = 100;
155 constexpr
size_t height = 100;
156 size_t row_bytes =
width * 4;
157 g_autofree
unsigned char* layer_data =
158 static_cast<unsigned char*
>(malloc(
height * row_bytes));
160 memset(layer_data, 0xFF,
height * row_bytes);
161 FlutterPlatformView platform_view = {.identifier = 1};
162 FlutterLayer platform_view_layer = {
163 .type = kFlutterLayerContentTypePlatformView,
164 .platform_view = &platform_view,
167 FlutterBackingStore backing_store = {
168 .type = kFlutterBackingStoreTypeSoftware,
170 .allocation = layer_data, .row_bytes = row_bytes, .height =
height}};
171 FlutterLayer layer = {.type = kFlutterLayerContentTypeBackingStore,
172 .backing_store = &backing_store,
175 const FlutterLayer*
layers[2] = {&platform_view_layer, &layer};
177 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
width);
178 g_autofree
unsigned char* image_data =
179 static_cast<unsigned char*
>(malloc(
height * stride));
180 memset(image_data, 0,
height * stride);
181 cairo_surface_t* surface = cairo_image_surface_create_for_data(
182 image_data, CAIRO_FORMAT_ARGB32,
width,
height, stride);
183 cairo_t* cr = cairo_create(surface);
186 cairo_surface_flush(surface);
188 uint32_t* pixels =
reinterpret_cast<uint32_t*
>(image_data);
189 EXPECT_EQ(pixels[50 * (stride / 4) + 50], 0xFFFFFFFFu);
192 cairo_surface_destroy(surface);
~FlCompositorSoftwareTest()
FlCompositorSoftware * compositor
FlCompositorSoftware * fl_compositor_software_new()
gboolean fl_compositor_software_composite_layers(FlCompositorSoftware *self, cairo_t *cr, const FlutterLayer **layers, size_t layers_count)
TEST_F(FlCompositorSoftwareTest, Render)
const uint8_t uint32_t uint32_t * height
const uint8_t uint32_t * width
const FlutterLayer ** layers