Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_compositor_software_test.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
5#include <thread>
7#include "gtest/gtest.h"
8
10
12 protected:
14
15 ~FlCompositorSoftwareTest() { g_clear_object(&compositor); }
16
17 FlCompositorSoftware* compositor = nullptr;
18};
19
21 // Present layer from a thread.
22 constexpr size_t width = 100;
23 constexpr size_t height = 100;
24 size_t row_bytes = width * 4;
25 g_autofree unsigned char* layer_data =
26 static_cast<unsigned char*>(malloc(height * row_bytes));
27 FlutterBackingStore backing_store = {
29 .software = {
30 .allocation = layer_data, .row_bytes = row_bytes, .height = height}};
32 .backing_store = &backing_store,
33 .offset = {0, 0},
34 .size = {width, height}};
35 const FlutterLayer* layers[1] = {&layer};
37
38 size_t frame_width, frame_height;
39 fl_compositor_software_get_frame_size(compositor, &frame_width,
40 &frame_height);
41 EXPECT_EQ(frame_width, width);
42 EXPECT_EQ(frame_height, height);
43
44 // Render presented layer.
45 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
46 g_autofree unsigned char* image_data =
47 static_cast<unsigned char*>(malloc(height * stride));
48 cairo_surface_t* surface = cairo_image_surface_create_for_data(
49 image_data, CAIRO_FORMAT_ARGB32, width, height, stride);
50 cairo_t* cr = cairo_create(surface);
51 EXPECT_TRUE(fl_compositor_software_render(compositor, cr, 1));
52 cairo_surface_destroy(surface);
53 cairo_destroy(cr);
54}
55
57 // Present a layer that is the old size.
58 constexpr size_t width1 = 90;
59 constexpr size_t height1 = 90;
60 size_t row_bytes = width1 * 4;
61 g_autofree unsigned char* layer1_data =
62 static_cast<unsigned char*>(malloc(height1 * row_bytes));
63 FlutterBackingStore backing_store1 = {
65 .software = {.allocation = layer1_data,
66 .row_bytes = row_bytes,
67 .height = height1}};
69 .backing_store = &backing_store1,
70 .offset = {0, 0},
71 .size = {width1, height1}};
72 const FlutterLayer* layers1[1] = {&layer1};
73 fl_compositor_software_composite_layers(compositor, layers1, 1);
74
75 // Present a layer in the new size.
76 constexpr size_t width2 = 100;
77 constexpr size_t height2 = 100;
78 row_bytes = width2 * 4;
79 g_autofree unsigned char* layer2_data =
80 static_cast<unsigned char*>(malloc(height2 * row_bytes));
81 FlutterBackingStore backing_store2 = {
83 .software = {.allocation = layer2_data,
84 .row_bytes = row_bytes,
85 .height = height2}};
87 .backing_store = &backing_store2,
88 .offset = {0, 0},
89 .size = {width2, height2}};
90 const FlutterLayer* layers2[1] = {&layer2};
91 fl_compositor_software_composite_layers(compositor, layers2, 1);
92
93 // The stored frame is now the new size.
94 size_t frame_width, frame_height;
95 fl_compositor_software_get_frame_size(compositor, &frame_width,
96 &frame_height);
97 EXPECT_EQ(frame_width, width2);
98 EXPECT_EQ(frame_height, height2);
99
100 // Render the presented layer.
101 int stride2 = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width2);
102 g_autofree unsigned char* image_data =
103 static_cast<unsigned char*>(malloc(height2 * stride2));
104 cairo_surface_t* surface = cairo_image_surface_create_for_data(
105 image_data, CAIRO_FORMAT_ARGB32, width2, height2, stride2);
106 cairo_t* cr = cairo_create(surface);
107 EXPECT_TRUE(fl_compositor_software_render(compositor, cr, 1));
108 cairo_surface_destroy(surface);
109 cairo_destroy(cr);
110}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2157
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2108
VkSurfaceKHR surface
Definition main.cc:65
gboolean fl_compositor_software_render(FlCompositorSoftware *self, cairo_t *cr, gint scale_factor)
FlCompositorSoftware * fl_compositor_software_new()
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)
TEST_F(FlCompositorSoftwareTest, Render)
const FlutterLayer ** layers
int32_t height
int32_t width
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2126
FlutterLayerContentType type
Definition embedder.h:2189