Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7#include <utility>
8
12#include "third_party/skia/include/core/SkSurface.h"
13#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
14
15namespace flutter {
16namespace testing {
17
19 DlISize surface_size,
20 sk_sp<GrDirectContext> context)
21 : EmbedderTestCompositor(surface_size, std::move(context)) {}
22
24
45
46bool EmbedderTestCompositorVulkan::UpdateOffscrenComposition(
47 const FlutterLayer** layers,
48 size_t layers_count) {
49 last_composition_ = nullptr;
50
51 const auto image_info = SkImageInfo::MakeN32Premul(ToSkISize(surface_size_));
52
53 sk_sp<SkSurface> surface =
54 SkSurfaces::RenderTarget(context_.get(), // context
55 skgpu::Budgeted::kNo, // budgeted
56 image_info, // image info
57 1, // sample count
58 kTopLeft_GrSurfaceOrigin, // surface origin
59 nullptr, // surface properties
60 false // create mipmaps
61 );
62
63 if (!surface) {
64 FML_LOG(ERROR) << "Could not update the off-screen composition.";
65 return false;
66 }
67
68 auto canvas = surface->getCanvas();
69
70 // This has to be transparent because we are going to be compositing this
71 // sub-hierarchy onto the on-screen surface.
72 canvas->clear(SK_ColorTRANSPARENT);
73
74 for (size_t i = 0; i < layers_count; ++i) {
75 const auto* layer = layers[i];
76
77 sk_sp<SkImage> platform_rendered_contents;
78
79 sk_sp<SkImage> layer_image;
80 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
81
82 switch (layer->type) {
84 layer_image =
85 backingstore_producer_->MakeImageSnapshot(layer->backing_store);
86 break;
88 layer_image =
91 : nullptr;
92 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
93 break;
94 };
95
96 // If the layer is not a platform view but the engine did not specify an
97 // image for the backing store, it is an error.
98 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
99 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
100 << *layer;
101 return false;
102 }
103
104 // The test could have just specified no contents to be rendered in place of
105 // a platform view. This is not an error.
106 if (layer_image) {
107 // The image rendered by Flutter already has the correct offset and
108 // transformation applied. The layers offset is meant for the platform.
109 canvas->drawImage(layer_image.get(), canvas_offset.x(),
110 canvas_offset.y());
111 }
112 }
113
114 last_composition_ = surface->makeImageSnapshot();
115
116 if (!last_composition_) {
117 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
118 return false;
119 }
120
122 auto last_composition_snapshot =
123 last_composition_->makeRasterImage(nullptr);
124 FML_CHECK(last_composition_snapshot);
126 next_scene_callback_ = nullptr;
127 callback(std::move(last_composition_snapshot));
128 }
129
130 return true;
131}
132
133} // namespace testing
134} // namespace flutter
GLenum type
std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer_
PlatformViewRendererCallback platform_view_renderer_callback_
EmbedderTestCompositorVulkan(DlISize surface_size, sk_sp< GrDirectContext > context)
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)
Definition ref_ptr.h:261