Flutter Linux Embedder
fl_compositor_software_test.cc File Reference
#include <thread>
#include "flutter/shell/platform/linux/testing/linux_test.h"
#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.

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 = {
41  .type = kFlutterBackingStoreTypeSoftware,
42  .software = {
43  .allocation = layer_data, .row_bytes = row_bytes, .height = height}};
44  FlutterLayer layer = {.type = kFlutterLayerContentTypeBackingStore,
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 }
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)
FlFramebuffer double double int int height
FlFramebuffer double double int width
const FlutterLayer ** layers
return TRUE

References fl_compositor_get_frame_size(), fl_compositor_present_layers(), fl_compositor_render(), height, layers, TRUE, 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 = {
79  .type = kFlutterBackingStoreTypeSoftware,
80  .software = {.allocation = layer1_data,
81  .row_bytes = row_bytes,
82  .height = height1}};
83  FlutterLayer layer1 = {.type = kFlutterLayerContentTypeBackingStore,
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 = {
99  .type = kFlutterBackingStoreTypeSoftware,
100  .software = {.allocation = layer2_data,
101  .row_bytes = row_bytes,
102  .height = height2}};
103  FlutterLayer layer2 = {.type = kFlutterLayerContentTypeBackingStore,
104  .backing_store = &backing_store2,
105  .offset = {0, 0},
106  .size = {width2, height2}};
107  const FlutterLayer* layers2[1] = {&layer2};
108  fml::AutoResetWaitableEvent latch;
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(), and TRUE.