Flutter Engine
The Flutter Engine
embedder_test_compositor_vulkan.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_vulkan.h"
6
7#include <utility>
8
9#include "flutter/fml/logging.h"
10#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
11#include "flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.h"
14
15namespace flutter {
16namespace testing {
17
19 SkISize surface_size,
21 : EmbedderTestCompositor(surface_size, std::move(context)) {}
22
24
25bool EmbedderTestCompositorVulkan::UpdateOffscrenComposition(
26 const FlutterLayer** layers,
27 size_t layers_count) {
28 last_composition_ = nullptr;
29
30 const auto image_info = SkImageInfo::MakeN32Premul(surface_size_);
31
34 skgpu::Budgeted::kNo, // budgeted
35 image_info, // image info
36 1, // sample count
37 kTopLeft_GrSurfaceOrigin, // surface origin
38 nullptr, // surface properties
39 false // create mipmaps
40 );
41
42 if (!surface) {
43 FML_LOG(ERROR) << "Could not update the off-screen composition.";
44 return false;
45 }
46
47 auto canvas = surface->getCanvas();
48
49 // This has to be transparent because we are going to be compositing this
50 // sub-hierarchy onto the on-screen surface.
51 canvas->clear(SK_ColorTRANSPARENT);
52
53 for (size_t i = 0; i < layers_count; ++i) {
54 const auto* layer = layers[i];
55
56 sk_sp<SkImage> platform_rendered_contents;
57
58 sk_sp<SkImage> layer_image;
59 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
60
61 switch (layer->type) {
63 layer_image =
64 reinterpret_cast<EmbedderTestBackingStoreProducer::UserData*>(
65 layer->backing_store->user_data)
66 ->surface->makeImageSnapshot();
67 break;
69 layer_image =
72 : nullptr;
73 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
74 break;
75 };
76
77 // If the layer is not a platform view but the engine did not specify an
78 // image for the backing store, it is an error.
79 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
80 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
81 << *layer;
82 return false;
83 }
84
85 // The test could have just specified no contents to be rendered in place of
86 // a platform view. This is not an error.
87 if (layer_image) {
88 // The image rendered by Flutter already has the correct offset and
89 // transformation applied. The layers offset is meant for the platform.
90 canvas->drawImage(layer_image.get(), canvas_offset.x(),
91 canvas_offset.y());
92 }
93 }
94
95 last_composition_ = surface->makeImageSnapshot();
96
97 if (!last_composition_) {
98 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
99 return false;
100 }
101
103 auto last_composition_snapshot = last_composition_->makeRasterImage();
104 FML_CHECK(last_composition_snapshot);
106 next_scene_callback_ = nullptr;
107 callback(std::move(last_composition_snapshot));
108 }
109
110 return true;
111}
112
113} // namespace testing
114} // namespace flutter
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition: SkImage.cpp:267
EmbedderTestCompositorVulkan(SkISize surface_size, sk_sp< GrDirectContext > context)
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:1795
@ kFlutterLayerContentTypeBackingStore
Definition: embedder.h:1793
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 > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition: ref_ptr.h:256
constexpr int32_t y() const
Definition: SkPoint_impl.h:52
static constexpr SkIPoint Make(int32_t x, int32_t y)
Definition: SkPoint_impl.h:38
constexpr int32_t x() const
Definition: SkPoint_impl.h:46
Definition: SkSize.h:16
static SkImageInfo MakeN32Premul(int width, int height)
#define ERROR(message)
Definition: elf_loader.cc:260