Flutter Engine
 
Loading...
Searching...
No Matches
embedder_test_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
10#include "third_party/skia/include/core/SkSurface.h"
11
12namespace flutter {
13namespace testing {
14
18
20
41
42bool EmbedderTestCompositorSoftware::UpdateOffscrenComposition(
43 const FlutterLayer** layers,
44 size_t layers_count) {
45 last_composition_ = nullptr;
46
47 const auto image_info = SkImageInfo::MakeN32Premul(ToSkISize(surface_size_));
48
49 auto surface = SkSurfaces::Raster(image_info);
50
51 if (!surface) {
52 FML_LOG(ERROR) << "Could not update the off-screen composition.";
53 return false;
54 }
55
56 auto canvas = surface->getCanvas();
57
58 // This has to be transparent because we are going to be compositing this
59 // sub-hierarchy onto the on-screen surface.
60 canvas->clear(SK_ColorTRANSPARENT);
61
62 for (size_t i = 0; i < layers_count; ++i) {
63 const auto* layer = layers[i];
64
65 sk_sp<SkImage> platform_rendered_contents;
66
67 sk_sp<SkImage> layer_image;
68 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
69
70 switch (layer->type) {
72 layer_image =
73 backingstore_producer_->MakeImageSnapshot(layer->backing_store);
74 break;
75 }
78 ? platform_view_renderer_callback_(*layer, nullptr)
79 : nullptr;
80 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
81 break;
82 };
83
84 // If the layer is not a platform view but the engine did not specify an
85 // image for the backing store, it is an error.
86 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
87 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
88 << *layer;
89 return false;
90 }
91
92 // The test could have just specified no contents to be rendered in place of
93 // a platform view. This is not an error.
94 if (layer_image) {
95 // The image rendered by Flutter already has the correct offset and
96 // transformation applied. The layers offset is meant for the platform.
97 canvas->drawImage(layer_image.get(), canvas_offset.x(),
98 canvas_offset.y());
99 }
100 }
101
102 last_composition_ = surface->makeImageSnapshot();
103
104 if (!last_composition_) {
105 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
106 return false;
107 }
108
110 auto last_composition_snapshot =
111 last_composition_->makeRasterImage(nullptr);
112 FML_CHECK(last_composition_snapshot);
114 next_scene_callback_ = nullptr;
115 callback(std::move(last_composition_snapshot));
116 }
117
118 return true;
119}
120
121} // namespace testing
122} // namespace flutter
GLenum type
std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer_
PlatformViewRendererCallback platform_view_renderer_callback_
void SetRenderTargetType(EmbedderTestBackingStoreProducer::RenderTargetType type, FlutterSoftwarePixelFormat software_pixfmt) override
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
Definition embedder.h:2104
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2102
FlutterSoftwarePixelFormat
Definition embedder.h:450
VkSurfaceKHR surface
Definition main.cc:65
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
const SkISize & ToSkISize(const DlISize &size)