| Flutter Windows Embedder |

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
5 #include "flutter/shell/platform/windows/compositor_software.h"
6
7 #include "flutter/shell/platform/windows/flutter_windows_engine.h"
8 #include "flutter/shell/platform/windows/flutter_windows_view.h"
9
10 namespace flutter {
11
12 CompositorSoftware::CompositorSoftware(FlutterWindowsEngine* engine)
13 : engine_(engine) {}
14
15 bool CompositorSoftware::CreateBackingStore(
16 const FlutterBackingStoreConfig& config,
17 FlutterBackingStore* result) {
18 size_t size = config.size.width * config.size.height * 4;
19 void* allocation = std::calloc(size, sizeof(uint8_t));
20 if (!allocation) {
21 return false;
22 }
23
24 result->type = kFlutterBackingStoreTypeSoftware;
25 result->software.allocation = allocation;
26 result->software.height = config.size.height;
27 result->software.row_bytes = config.size.width * 4;
28 result->software.user_data = nullptr;
29 result->software.destruction_callback = [](void* user_data) {
30 // Backing store destroyed in `CompositorSoftware::CollectBackingStore`, set
31 // on FlutterCompositor.collect_backing_store_callback during engine start.
32 };
33 return true;
34 }
35
36 bool CompositorSoftware::CollectBackingStore(const FlutterBackingStore* store) {
37 std::free(const_cast<void*>(store->software.allocation));
38 return true;
39 }
40
41 bool CompositorSoftware::Present(FlutterViewId view_id,
42 const FlutterLayer** layers,
43 size_t layers_count) {
44 FlutterWindowsView* view = engine_->view(view_id);
45 if (!view) {
46 return false;
47 }
48
49 // Clear the view if there are no layers to present.
50 if (layers_count == 0) {
51 return view->ClearSoftwareBitmap();
52 }
53
54 // TODO: Support compositing layers and platform views.
55 // See: https://github.com/flutter/flutter/issues/31713
56 FML_DCHECK(layers_count == 1);
57 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
58 FML_DCHECK(layers[0]->type == kFlutterLayerContentTypeBackingStore);
59 FML_DCHECK(layers[0]->backing_store->type ==
60 kFlutterBackingStoreTypeSoftware);
61
62 const auto& backing_store = layers[0]->backing_store->software;
63
64 return view->PresentSoftwareBitmap(
65 backing_store.allocation, backing_store.row_bytes, backing_store.height);
66 }
67
68 } // namespace flutter
flutter::FlutterWindowsEngine::view
FlutterWindowsView * view(FlutterViewId view_id) const
Definition: flutter_windows_engine.cc:533
flutter::FlutterWindowsView
Definition: flutter_windows_view.h:34
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:52
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:89
flutter::CompositorSoftware::CreateBackingStore
bool CreateBackingStore(const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
|Compositor|
Definition: compositor_software.cc:15
type
enum flutter::testing::@87::KeyboardChange::Type type
flutter_windows_view.h
flutter::CompositorSoftware::CompositorSoftware
CompositorSoftware(FlutterWindowsEngine *engine)
Definition: compositor_software.cc:12
flutter::FlutterViewId
int64_t FlutterViewId
Definition: flutter_view.h:13
flutter
Definition: accessibility_bridge_windows.cc:11
compositor_software.h
flutter::FlutterWindowsView::PresentSoftwareBitmap
virtual bool PresentSoftwareBitmap(const void *allocation, size_t row_bytes, size_t height)
Definition: flutter_windows_view.cc:649
flutter_windows_engine.h
flutter::FlutterWindowsView::ClearSoftwareBitmap
virtual bool ClearSoftwareBitmap()
Definition: flutter_windows_view.cc:645
flutter::CompositorSoftware::CollectBackingStore
bool CollectBackingStore(const FlutterBackingStore *store) override
|Compositor|
Definition: compositor_software.cc:36
flutter::CompositorSoftware::Present
bool Present(FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count) override
|Compositor|
Definition: compositor_software.cc:41