18 fl_compositor_software,
19 fl_compositor_get_type())
21 static FlutterRendererType fl_compositor_software_get_renderer_type(
22 FlCompositor* compositor) {
31 FlCompositor* compositor,
32 const FlutterLayer** layers,
33 size_t layers_count) {
34 FlCompositorSoftware*
self = FL_COMPOSITOR_SOFTWARE(compositor);
36 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
39 if (layers_count == 1) {
40 const FlutterLayer* layer = layers[0];
41 g_assert(layer->type == kFlutterLayerContentTypeBackingStore);
42 g_assert(layer->backing_store->type == kFlutterBackingStoreTypeSoftware);
43 const FlutterBackingStore* backing_store = layer->backing_store;
45 size_t allocation_length =
46 backing_store->software.row_bytes * backing_store->software.height;
47 unsigned char* old_data =
self->surface !=
nullptr
48 ? cairo_image_surface_get_data(self->surface)
51 static_cast<unsigned char*
>(realloc(old_data, allocation_length));
52 memcpy(data, backing_store->software.allocation, allocation_length);
53 cairo_surface_destroy(self->surface);
54 self->surface = cairo_image_surface_create_for_data(
55 data, CAIRO_FORMAT_ARGB32, backing_store->software.row_bytes / 4,
56 backing_store->software.height, backing_store->software.row_bytes);
63 FlCompositorSoftware*
self = FL_COMPOSITOR_SOFTWARE(
object);
65 if (self->surface !=
nullptr) {
66 free(cairo_image_surface_get_data(self->surface));
68 g_clear_pointer(&self->surface, cairo_surface_destroy);
70 G_OBJECT_CLASS(fl_compositor_software_parent_class)->dispose(
object);
74 FlCompositorSoftwareClass* klass) {
75 FL_COMPOSITOR_CLASS(klass)->get_renderer_type =
76 fl_compositor_software_get_renderer_type;
77 FL_COMPOSITOR_CLASS(klass)->wait_for_frame =
79 FL_COMPOSITOR_CLASS(klass)->present_layers =
88 FlCompositorSoftware*
self = FL_COMPOSITOR_SOFTWARE(
89 g_object_new(fl_compositor_software_get_type(),
nullptr));
96 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
98 if (self->surface ==
nullptr) {
102 cairo_surface_set_device_scale(self->surface, scale_factor, scale_factor);
103 cairo_set_source_surface(cr, self->surface, 0.0, 0.0);
gboolean fl_compositor_software_render(FlCompositorSoftware *self, cairo_t *cr, gint scale_factor)
G_DEFINE_TYPE(FlCompositorSoftware, fl_compositor_software, fl_compositor_get_type()) static FlutterRendererType fl_compositor_software_get_renderer_type(FlCompositor *compositor)
static gboolean fl_compositor_software_present_layers(FlCompositor *compositor, const FlutterLayer **layers, size_t layers_count)
FlCompositorSoftware * fl_compositor_software_new()
static void fl_compositor_software_class_init(FlCompositorSoftwareClass *klass)
static void fl_compositor_software_wait_for_frame(FlCompositor *compositor, int target_width, int target_height)
static void fl_compositor_software_init(FlCompositorSoftware *self)
static void fl_compositor_software_dispose(GObject *object)
FlCompositor parent_instance
cairo_surface_t * surface