Flutter Linux Embedder
fl_compositor_software.cc File Reference

Go to the source code of this file.

Classes

struct  _FlCompositorSoftware
 

Functions

 G_DEFINE_TYPE (FlCompositorSoftware, fl_compositor_software, fl_compositor_get_type()) static FlutterRendererType fl_compositor_software_get_renderer_type(FlCompositor *compositor)
 
static void fl_compositor_software_wait_for_frame (FlCompositor *compositor, int target_width, int target_height)
 
static gboolean fl_compositor_software_present_layers (FlCompositor *compositor, const FlutterLayer **layers, size_t layers_count)
 
static void fl_compositor_software_dispose (GObject *object)
 
static void fl_compositor_software_class_init (FlCompositorSoftwareClass *klass)
 
static void fl_compositor_software_init (FlCompositorSoftware *self)
 
FlCompositorSoftware * fl_compositor_software_new ()
 
gboolean fl_compositor_software_render (FlCompositorSoftware *self, cairo_t *cr, gint scale_factor)
 

Function Documentation

◆ fl_compositor_software_class_init()

static void fl_compositor_software_class_init ( FlCompositorSoftwareClass *  klass)
static

Definition at line 73 of file fl_compositor_software.cc.

74  {
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 =
81 
82  G_OBJECT_CLASS(klass)->dispose = fl_compositor_software_dispose;
83 }
static gboolean fl_compositor_software_present_layers(FlCompositor *compositor, const FlutterLayer **layers, size_t layers_count)
static void fl_compositor_software_wait_for_frame(FlCompositor *compositor, int target_width, int target_height)
static void fl_compositor_software_dispose(GObject *object)

References fl_compositor_software_dispose(), fl_compositor_software_present_layers(), and fl_compositor_software_wait_for_frame().

◆ fl_compositor_software_dispose()

static void fl_compositor_software_dispose ( GObject *  object)
static

Definition at line 62 of file fl_compositor_software.cc.

62  {
63  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(object);
64 
65  if (self->surface != nullptr) {
66  free(cairo_image_surface_get_data(self->surface));
67  }
68  g_clear_pointer(&self->surface, cairo_surface_destroy);
69 
70  G_OBJECT_CLASS(fl_compositor_software_parent_class)->dispose(object);
71 }

Referenced by fl_compositor_software_class_init().

◆ fl_compositor_software_init()

static void fl_compositor_software_init ( FlCompositorSoftware *  self)
static

Definition at line 85 of file fl_compositor_software.cc.

85 {}

◆ fl_compositor_software_new()

FlCompositorSoftware* fl_compositor_software_new ( )

Definition at line 87 of file fl_compositor_software.cc.

87  {
88  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(
89  g_object_new(fl_compositor_software_get_type(), nullptr));
90  return self;
91 }

Referenced by realize_cb(), and TEST().

◆ fl_compositor_software_present_layers()

static gboolean fl_compositor_software_present_layers ( FlCompositor *  compositor,
const FlutterLayer **  layers,
size_t  layers_count 
)
static

Definition at line 30 of file fl_compositor_software.cc.

33  {
34  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(compositor);
35 
36  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
37 
38  // TODO(robert-ancell): Support multiple layers
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;
44 
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)
49  : nullptr;
50  unsigned char* data =
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);
57  }
58 
59  return TRUE;
60 }

References TRUE.

Referenced by fl_compositor_software_class_init().

◆ fl_compositor_software_render()

gboolean fl_compositor_software_render ( FlCompositorSoftware *  compositor,
cairo_t *  cr,
gint  scale_factor 
)

fl_compositor_software_render: @compositor: an #FlCompositorSoftware. @cr: the cairo context to draw to. @scale_factor: pixel scale factor.

Render the current frame.

Returns: TRUE if rendered.

Definition at line 93 of file fl_compositor_software.cc.

95  {
96  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
97 
98  if (self->surface == nullptr) {
99  return FALSE;
100  }
101 
102  cairo_surface_set_device_scale(self->surface, scale_factor, scale_factor);
103  cairo_set_source_surface(cr, self->surface, 0.0, 0.0);
104  cairo_paint(cr);
105 
106  return TRUE;
107 }

References TRUE.

Referenced by software_draw_cb(), and TEST().

◆ fl_compositor_software_wait_for_frame()

static void fl_compositor_software_wait_for_frame ( FlCompositor *  compositor,
int  target_width,
int  target_height 
)
static

Definition at line 26 of file fl_compositor_software.cc.

28  {}

Referenced by fl_compositor_software_class_init().

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlCompositorSoftware  ,
fl_compositor_software  ,
fl_compositor_get_type()   
)

Definition at line 17 of file fl_compositor_software.cc.

22  {
23  return kSoftware;
24 }