Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
9
10 // Width of frame in pixels.
11 size_t width;
12
13 // Height of frame in pixels.
14 size_t height;
15
16 // Surface to draw on view.
17 cairo_surface_t* surface;
18};
19
20G_DEFINE_TYPE(FlCompositorSoftware, fl_compositor_software, G_TYPE_OBJECT)
21
22static void fl_compositor_software_dispose(GObject* object) {
23 FlCompositorSoftware* self = FL_COMPOSITOR_SOFTWARE(object);
24
25 if (self->surface != nullptr) {
26 g_free(cairo_image_surface_get_data(self->surface));
27 }
28 g_clear_pointer(&self->surface, cairo_surface_destroy);
29
30 G_OBJECT_CLASS(fl_compositor_software_parent_class)->dispose(object);
31}
32
34 FlCompositorSoftwareClass* klass) {
35 G_OBJECT_CLASS(klass)->dispose = fl_compositor_software_dispose;
36}
37
38static void fl_compositor_software_init(FlCompositorSoftware* self) {}
39
40FlCompositorSoftware* fl_compositor_software_new() {
41 return FL_COMPOSITOR_SOFTWARE(
42 g_object_new(fl_compositor_software_get_type(), nullptr));
43}
44
45gboolean fl_compositor_software_composite_layers(FlCompositorSoftware* self,
46 const FlutterLayer** layers,
47 size_t layers_count) {
48 if (layers_count == 0) {
49 return TRUE;
50 }
51
52 self->width = layers[0]->size.width;
53 self->height = layers[0]->size.height;
54
55 // TODO(robert-ancell): Support multiple layers
56 if (layers_count == 1) {
57 const FlutterLayer* layer = layers[0];
60 const FlutterBackingStore* backing_store = layer->backing_store;
61
62 size_t allocation_length =
63 backing_store->software.row_bytes * backing_store->software.height;
64 unsigned char* old_data = self->surface != nullptr
65 ? cairo_image_surface_get_data(self->surface)
66 : nullptr;
67 unsigned char* data =
68 static_cast<unsigned char*>(g_realloc(old_data, allocation_length));
69 memcpy(data, backing_store->software.allocation, allocation_length);
70 cairo_surface_destroy(self->surface);
71 self->surface = cairo_image_surface_create_for_data(
72 data, CAIRO_FORMAT_ARGB32, backing_store->software.row_bytes / 4,
73 backing_store->software.height, backing_store->software.row_bytes);
74 }
75
76 return TRUE;
77}
78
80 size_t* width,
81 size_t* height) {
82 if (width != nullptr) {
83 *width = self->width;
84 }
85 if (height != nullptr) {
86 *height = self->height;
87 }
88}
89
90gboolean fl_compositor_software_render(FlCompositorSoftware* self,
91 cairo_t* cr,
92 gint scale_factor) {
93 if (self->surface == nullptr) {
94 return FALSE;
95 }
96
97 cairo_surface_set_device_scale(self->surface, scale_factor, scale_factor);
98 cairo_set_source_surface(cr, self->surface, 0.0, 0.0);
99 cairo_paint(cr);
100
101 return TRUE;
102}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2157
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2108
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
gboolean fl_compositor_software_render(FlCompositorSoftware *self, cairo_t *cr, gint scale_factor)
FlCompositorSoftware * fl_compositor_software_new()
static void fl_compositor_software_class_init(FlCompositorSoftwareClass *klass)
static void fl_compositor_software_init(FlCompositorSoftware *self)
void fl_compositor_software_get_frame_size(FlCompositorSoftware *self, size_t *width, size_t *height)
gboolean fl_compositor_software_composite_layers(FlCompositorSoftware *self, const FlutterLayer **layers, size_t layers_count)
static void fl_compositor_software_dispose(GObject *object)
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
int32_t height
int32_t width
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2126
FlutterSoftwareBackingStore software
The description of the software backing store.
Definition embedder.h:2134
FlutterLayerContentType type
Definition embedder.h:2189
const FlutterBackingStore * backing_store
Definition embedder.h:2193
FlutterSize size
The size of the layer (in physical pixels).
Definition embedder.h:2202
double height
Definition embedder.h:636
double width
Definition embedder.h:635
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition embedder.h:1987
size_t height
The number of rows in the allocation.
Definition embedder.h:1989