Flutter Linux Embedder
fl_compositor_software.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
8  GObject parent_instance;
9 };
10 
11 G_DEFINE_TYPE(FlCompositorSoftware, fl_compositor_software, G_TYPE_OBJECT)
12 
14  FlCompositorSoftwareClass* klass) {}
15 
16 static void fl_compositor_software_init(FlCompositorSoftware* self) {}
17 
18 FlCompositorSoftware* fl_compositor_software_new() {
19  return FL_COMPOSITOR_SOFTWARE(
20  g_object_new(fl_compositor_software_get_type(), nullptr));
21 }
22 
23 gboolean fl_compositor_software_composite_layers(FlCompositorSoftware* self,
24  cairo_t* cr,
25  const FlutterLayer** layers,
26  size_t layers_count) {
27  cairo_save(cr);
28  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
29  cairo_paint(cr);
30  cairo_restore(cr);
31 
32  for (size_t i = 0; i < layers_count; i++) {
33  const FlutterLayer* layer = layers[i];
34  switch (layer->type) {
35  case kFlutterLayerContentTypeBackingStore: {
36  const FlutterBackingStore* backing_store = layer->backing_store;
37  g_assert(backing_store->type == kFlutterBackingStoreTypeSoftware);
38 
39  cairo_surface_t* surface = cairo_image_surface_create_for_data(
40  static_cast<unsigned char*>(
41  const_cast<void*>(backing_store->software.allocation)),
42  CAIRO_FORMAT_ARGB32, backing_store->software.row_bytes / 4,
43  backing_store->software.height, backing_store->software.row_bytes);
44 
45  // Layers are placed at their offset in the frame, and only cover the
46  // area they were rendered for.
47  cairo_save(cr);
48  cairo_rectangle(cr, layer->offset.x, layer->offset.y, layer->size.width,
49  layer->size.height);
50  cairo_clip(cr);
51  cairo_set_source_surface(cr, surface, layer->offset.x, layer->offset.y);
52  cairo_paint(cr);
53  cairo_restore(cr);
54 
55  cairo_surface_destroy(surface);
56  } break;
57  case kFlutterLayerContentTypePlatformView: {
58  // TODO(robert-ancell) Not implemented -
59  // https://github.com/flutter/flutter/issues/41724
60  } break;
61  }
62  }
63 
64  return TRUE;
65 }
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
FlCompositorSoftware * fl_compositor_software_new()
gboolean fl_compositor_software_composite_layers(FlCompositorSoftware *self, cairo_t *cr, const FlutterLayer **layers, size_t layers_count)
static void fl_compositor_software_class_init(FlCompositorSoftwareClass *klass)
static void fl_compositor_software_init(FlCompositorSoftware *self)
const FlutterLayer size_t layers_count
const FlutterLayer ** layers