| Flutter Windows Embedder |

Public Member Functions | List of all members
flutter::CompositorSoftware Class Reference

`#include <compositor_software.h>`

Inheritance diagram for flutter::CompositorSoftware:

## Public Member Functions
| CompositorSoftware ()
bool | CreateBackingStore (const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
| |Compositor| More...
bool | CollectBackingStore (const FlutterBackingStore *store) override
| |Compositor| More...
bool | Present (FlutterWindowsView *view, const FlutterLayer **layers, size_t layers_count) override
| |Compositor| More...
Public Member Functions inherited from flutter::Compositor
virtual | ~Compositor ()=default

## Detailed Description

Definition at line 17 of file compositor_software.h.

## Constructor & Destructor Documentation

## ◆ CompositorSoftware()

flutter::CompositorSoftware::CompositorSoftware | ( |  | ) |

Definition at line 84 of file compositor_software.cc.

84 {}

## Member Function Documentation

## ◆ CollectBackingStore()

bool flutter::CompositorSoftware::CollectBackingStore | ( | const FlutterBackingStore * | store | ) |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 107 of file compositor_software.cc.

107 {
108 std::free(const_cast<void*>(store->software.allocation));
109 return true;
110 }

Referenced by flutter::testing::TEST_F().

## ◆ CreateBackingStore()

bool flutter::CompositorSoftware::CreateBackingStore | ( | const FlutterBackingStoreConfig & | config,
|  | FlutterBackingStore * | result
| ) |  |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 86 of file compositor_software.cc.

88 {
89 size_t size = config.size.width * config.size.height * 4;
90 void* allocation = std::calloc(size, sizeof(uint8_t));
91 if (!allocation) {
92 return false;
93 }
94
95 result->type = kFlutterBackingStoreTypeSoftware;
96 result->software.allocation = allocation;
97 result->software.height = config.size.height;
98 result->software.row_bytes = config.size.width * 4;
99 result->software.user_data = nullptr;
100 result->software.destruction_callback = [](void* user_data) {
101 // Backing store destroyed in `CompositorSoftware::CollectBackingStore`, set
102 // on FlutterCompositor.collect_backing_store_callback during engine start.
103 };
104 return true;
105 }

References user_data.

Referenced by flutter::testing::TEST_F().

## ◆ Present()

bool flutter::CompositorSoftware::Present | ( | FlutterWindowsView * | view,
|  | const FlutterLayer ** | layers,
|  | size_t | layers_count
| ) |  |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 112 of file compositor_software.cc.

114 {
115 FML_DCHECK(view != nullptr);
116
117 // Clear the view if there are no layers to present.
118 if (layers_count == 0) {
119 return view->ClearSoftwareBitmap();
120 }
121
122 // Bypass composition logic if there is only one layer.
123 if (layers_count == 1) {
124 const FlutterLayer* layer = layers[0];
125 FML_DCHECK(layer != nullptr);
126 if (layer->type == kFlutterLayerContentTypeBackingStore &&
127 layer->offset.x == 0 && layer->offset.y == 0) {
128 auto& backing_store = *layer->backing_store;
129 FML_DCHECK(backing_store.type == kFlutterBackingStoreTypeSoftware);
130 auto& software = backing_store.software;
131 return view->PresentSoftwareBitmap(software.allocation,
132 software.row_bytes, software.height);
133 }
134 }
135
136 // Composite many layers.
137 FlutterRect bounds = CalculateBounds(layers, layers_count);
138 // Truncate from double to integer to represent whole pixels.
139 int x_min = static_cast<int>(bounds.left);
140 int x_max = static_cast<int>(bounds.right);
141 int y_min = static_cast<int>(bounds.top);
142 int y_max = static_cast<int>(bounds.bottom);
143
144 int width = x_max - x_min;
145 int height = y_max - y_min;
146 std::vector<uint32_t> allocation(width * height, kOpaqueBlack);
147
148 for (const FlutterLayer** layer = layers; layer < layers + layers_count;
149 layer++) {
150 // TODO(schectman): handle platform view type layers.
151 // https://github.com/flutter/flutter/issues/143375
152 if ((*layer)->type == kFlutterLayerContentTypeBackingStore) {
153 BlendLayer(allocation, **layer, x_min, y_min, width, height);
154 } else {
155 FML_UNREACHABLE();
156 return false;
157 }
158 }
159
160 return view->PresentSoftwareBitmap(static_cast<void*>(allocation.data()),
161 width * sizeof(uint32_t), height);
162 }

References flutter::FlutterWindowsView::ClearSoftwareBitmap(), flutter::kOpaqueBlack, and flutter::FlutterWindowsView::PresentSoftwareBitmap().

Referenced by flutter::testing::TEST_F().

The documentation for this class was generated from the following files:

- shell/platform/windows/compositor_software.h
- shell/platform/windows/compositor_software.cc

user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
flutter::kOpaqueBlack
constexpr int kOpaqueBlack
Definition: compositor_software.cc:12