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 gboolean fl_compositor_software_present_layers(FlCompositor *compositor
 
 g_autoptr (GMutexLocker) locker
 
 if (layers_count==0)
 
 fl_task_runner_stop_wait (self->task_runner)
 
static void fl_compositor_software_get_frame_size (FlCompositor *compositor, size_t *width, size_t *height)
 
static gboolean fl_compositor_software_render (FlCompositor *compositor, cairo_t *cr, GdkWindow *window, gboolean wait_for_frame)
 
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 (FlTaskRunner *task_runner)
 

Variables

const FlutterLayer ** layers
 
const FlutterLayer size_t layers_count
 
self width = layers[0]->size.width
 
self height = layers[0]->size.height
 
return TRUE
 

Function Documentation

◆ fl_compositor_software_class_init()

static void fl_compositor_software_class_init ( FlCompositorSoftwareClass *  klass)
static

Definition at line 144 of file fl_compositor_software.cc.

145  {
146  FL_COMPOSITOR_CLASS(klass)->present_layers =
147  fl_compositor_software_present_layers;
148  FL_COMPOSITOR_CLASS(klass)->get_frame_size =
150  FL_COMPOSITOR_CLASS(klass)->render = fl_compositor_software_render;
151 
152  G_OBJECT_CLASS(klass)->dispose = fl_compositor_software_dispose;
153 }
static void fl_compositor_software_get_frame_size(FlCompositor *compositor, size_t *width, size_t *height)
static void fl_compositor_software_dispose(GObject *object)
static gboolean fl_compositor_software_render(FlCompositor *compositor, cairo_t *cr, GdkWindow *window, gboolean wait_for_frame)

References fl_compositor_software_dispose(), fl_compositor_software_get_frame_size(), and fl_compositor_software_render().

◆ fl_compositor_software_dispose()

static void fl_compositor_software_dispose ( GObject *  object)
static

Definition at line 131 of file fl_compositor_software.cc.

131  {
132  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(object);
133 
134  g_clear_object(&self->task_runner);
135  if (self->surface != nullptr) {
136  free(cairo_image_surface_get_data(self->surface));
137  }
138  g_clear_pointer(&self->surface, cairo_surface_destroy);
139  g_mutex_clear(&self->frame_mutex);
140 
141  G_OBJECT_CLASS(fl_compositor_software_parent_class)->dispose(object);
142 }

Referenced by fl_compositor_software_class_init().

◆ fl_compositor_software_get_frame_size()

static void fl_compositor_software_get_frame_size ( FlCompositor *  compositor,
size_t *  width,
size_t *  height 
)
static

Definition at line 71 of file fl_compositor_software.cc.

73  {
74  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(compositor);
75 
76  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
77 
78  if (width != nullptr) {
79  *width = self->width;
80  }
81  if (height != nullptr) {
82  *height = self->height;
83  }
84 }
self height
g_autoptr(GMutexLocker) locker
self width

References g_autoptr(), height, and width.

Referenced by fl_compositor_software_class_init().

◆ fl_compositor_software_init()

static void fl_compositor_software_init ( FlCompositorSoftware *  self)
static

Definition at line 155 of file fl_compositor_software.cc.

155  {
156  g_mutex_init(&self->frame_mutex);
157 }

◆ fl_compositor_software_new()

FlCompositorSoftware* fl_compositor_software_new ( FlTaskRunner *  task_runner)

Definition at line 159 of file fl_compositor_software.cc.

159  {
160  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(
161  g_object_new(fl_compositor_software_get_type(), nullptr));
162  self->task_runner = FL_TASK_RUNNER(g_object_ref(task_runner));
163  return self;
164 }

Referenced by setup_software(), and TEST().

◆ fl_compositor_software_render()

static gboolean fl_compositor_software_render ( FlCompositor *  compositor,
cairo_t *  cr,
GdkWindow *  window,
gboolean  wait_for_frame 
)
static

Definition at line 86 of file fl_compositor_software.cc.

89  {
90  FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(compositor);
91 
92  g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->frame_mutex);
93 
94  if (self->surface == nullptr) {
95  return FALSE;
96  }
97 
98  // If frame not ready, then wait for it.
99  gint scale_factor = gdk_window_get_scale_factor(window);
100  if (wait_for_frame) {
101  gint64 expiry_time =
102  g_get_monotonic_time() + kCompositorRenderTimeoutMicroseconds;
103  while (true) {
104  size_t width = gdk_window_get_width(window) * scale_factor;
105  size_t height = gdk_window_get_height(window) * scale_factor;
106  if (self->width == width && self->height == height) {
107  break;
108  }
109 
110  if (g_get_monotonic_time() > expiry_time) {
111  g_warning(
112  "Timed out waiting for software frame of size %zdx%zd (have "
113  "%zdx%zd)",
114  width, height, self->width, self->height);
115  break;
116  }
117 
118  g_mutex_unlock(&self->frame_mutex);
119  fl_task_runner_wait(self->task_runner, expiry_time);
120  g_mutex_lock(&self->frame_mutex);
121  }
122  }
123 
124  cairo_surface_set_device_scale(self->surface, scale_factor, scale_factor);
125  cairo_set_source_surface(cr, self->surface, 0.0, 0.0);
126  cairo_paint(cr);
127 
128  return TRUE;
129 }
constexpr G_BEGIN_DECLS gint64 kCompositorRenderTimeoutMicroseconds
Definition: fl_compositor.h:16
return TRUE
void fl_task_runner_wait(FlTaskRunner *self, gint64 expiry_time)

References fl_task_runner_wait(), g_autoptr(), height, kCompositorRenderTimeoutMicroseconds, TRUE, and width.

Referenced by fl_compositor_software_class_init().

◆ fl_task_runner_stop_wait()

fl_task_runner_stop_wait ( self->  task_runner)

◆ g_autoptr()

g_autoptr ( GMutexLocker  )

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlCompositorSoftware  ,
fl_compositor_software  ,
fl_compositor_get_type()   
)

◆ if()

if ( layers_count  = = 0)

Definition at line 38 of file fl_compositor_software.cc.

38  {
39  return TRUE;
40  }

References TRUE.

Variable Documentation

◆ height

◆ layers

◆ layers_count

const FlutterLayer size_t layers_count
Initial value:
{
FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(compositor)

Definition at line 33 of file fl_compositor_software.cc.

Referenced by fl_compositor_opengl_present_layers(), fl_compositor_present_layers(), fl_renderable_present_layers(), and fl_view_present_layers().

◆ TRUE

return TRUE

Definition at line 68 of file fl_compositor_software.cc.

Referenced by announcement_cb(), channel_closed_cb(), check_size(), complete_handle_event(), create_settings(), delete_event_cb(), ensure_pointer_added(), event_is_redispatched(), fl_accessible_node_do_action(), fl_accessible_text_field_add_selection(), fl_accessible_text_field_remove_selection(), fl_accessible_text_field_set_caret_offset(), fl_accessible_text_field_set_selection(), fl_application_create_window(), fl_application_local_command_line(), fl_binary_messenger_handle_message(), fl_compositor_opengl_present_layers(), fl_compositor_opengl_render(), fl_compositor_software_render(), fl_engine_send_key_event_finish(), fl_engine_send_platform_message_response(), fl_engine_start(), fl_event_channel_send(), fl_event_channel_send_end_of_stream(), fl_event_channel_send_error(), fl_gnome_settings_get_enable_animations(), fl_json_method_codec_decode_method_call(), fl_key_channel_responder_handle_event_finish(), fl_key_embedder_responder_handle_event_finish(), fl_key_embedder_responder_handle_event_impl(), fl_key_event_channel_send_finish(), fl_keyboard_manager_handle_event(), fl_method_call_respond(), fl_pixel_buffer_texture_populate(), fl_platform_channel_system_request_app_exit_finish(), fl_pointer_manager_handle_button_press(), fl_pointer_manager_handle_button_release(), fl_pointer_manager_handle_enter(), fl_pointer_manager_handle_leave(), fl_pointer_manager_handle_motion(), fl_scrolling_manager_handle_rotation_begin(), fl_scrolling_manager_handle_scroll_event(), fl_scrolling_manager_handle_zoom_begin(), fl_standard_message_codec_read_size(), fl_standard_message_codec_read_value_of_type(), fl_standard_message_codec_real_write_value(), fl_standard_method_codec_decode_method_call(), fl_test_application_activate(), fl_test_codec_decode_method_call(), fl_test_texture_populate(), fl_text_input_handler_filter_keypress(), fl_texture_gl_populate(), fl_view_accessible_handle_update_semantics(), fl_view_init(), fl_view_new_sized_to_content(), G_DEFINE_TYPE(), G_DEFINE_TYPE_WITH_CODE(), get_mouse_button(), has_child(), if(), im_delete_surrounding_cb(), im_retrieve_surrounding_cb(), notification_assertive_cb(), notification_polite_cb(), read_align(), read_uint16(), read_uint32(), read_uint8(), register_texture(), responder_handle_channel_event_cb(), responder_handle_embedder_event_cb(), scroll_event_cb(), send_response(), set_client(), set_editing_state(), settings_portal_read(), system_initialization_complete(), TEST(), TEST_F(), test_lock_event(), touch_event_cb(), view_added_cb(), view_removed_cb(), and window_delete_event_cb().

◆ width