Flutter Engine
The 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
5#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_software.h"
6
7#include "flutter/fml/logging.h"
8#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
10
11namespace flutter {
12namespace testing {
13
17
19
20bool EmbedderTestCompositorSoftware::UpdateOffscrenComposition(
21 const FlutterLayer** layers,
22 size_t layers_count) {
23 last_composition_ = nullptr;
24
25 const auto image_info = SkImageInfo::MakeN32Premul(surface_size_);
26
27 auto surface = SkSurfaces::Raster(image_info);
28
29 if (!surface) {
30 FML_LOG(ERROR) << "Could not update the off-screen composition.";
31 return false;
32 }
33
34 auto canvas = surface->getCanvas();
35
36 // This has to be transparent because we are going to be compositing this
37 // sub-hierarchy onto the on-screen surface.
38 canvas->clear(SK_ColorTRANSPARENT);
39
40 for (size_t i = 0; i < layers_count; ++i) {
41 const auto* layer = layers[i];
42
43 sk_sp<SkImage> platform_rendered_contents;
44
45 sk_sp<SkImage> layer_image;
46 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
47
48 switch (layer->type) {
50 layer_image =
51 reinterpret_cast<SkSurface*>(layer->backing_store->user_data)
52 ->makeImageSnapshot();
53
54 break;
57 ? platform_view_renderer_callback_(*layer, nullptr)
58 : nullptr;
59 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
60 break;
61 };
62
63 // If the layer is not a platform view but the engine did not specify an
64 // image for the backing store, it is an error.
65 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
66 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
67 << *layer;
68 return false;
69 }
70
71 // The test could have just specified no contents to be rendered in place of
72 // a platform view. This is not an error.
73 if (layer_image) {
74 // The image rendered by Flutter already has the correct offset and
75 // transformation applied. The layers offset is meant for the platform.
76 canvas->drawImage(layer_image.get(), canvas_offset.x(),
77 canvas_offset.y());
78 }
79 }
80
81 last_composition_ = surface->makeImageSnapshot();
82
83 if (!last_composition_) {
84 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
85 return false;
86 }
87
89 auto last_composition_snapshot = last_composition_->makeRasterImage();
90 FML_CHECK(last_composition_snapshot);
92 next_scene_callback_ = nullptr;
93 callback(std::move(last_composition_snapshot));
94 }
95
96 return true;
97}
98
99} // namespace testing
100} // namespace flutter
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267
PlatformViewRendererCallback platform_view_renderer_callback_
T * get() const
Definition SkRefCnt.h:303
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
Definition embedder.h:1793
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:1791
VkSurfaceKHR surface
Definition main.cc:49
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
constexpr int32_t y() const
static constexpr SkIPoint Make(int32_t x, int32_t y)
constexpr int32_t x() const
static SkImageInfo MakeN32Premul(int width, int height)
#define ERROR(message)