Flutter Engine
 
Loading...
Searching...
No Matches
embedder_test_compositor_metal.mm
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 sk_sp<GrDirectContext> context)
20 : EmbedderTestCompositor(surface_size, std::move(context)) {}
21
23
42
43bool EmbedderTestCompositorMetal::UpdateOffscrenComposition(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::RenderTarget(context_.get(), // context
50 skgpu::Budgeted::kNo, // budgeted
51 image_info, // image info
52 1, // sample count
53 kTopLeft_GrSurfaceOrigin, // surface origin
54 nullptr, // surface properties
55 false // create mipmaps
56 );
57
58 if (!surface) {
59 FML_LOG(ERROR) << "Could not update the off-screen composition.";
60 return false;
61 }
62
63 auto canvas = surface->getCanvas();
64
65 // This has to be transparent because we are going to be compositing this
66 // sub-hierarchy onto the on-screen surface.
67 canvas->clear(SK_ColorTRANSPARENT);
68
69 for (size_t i = 0; i < layers_count; ++i) {
70 const auto* layer = layers[i];
71
72 sk_sp<SkImage> platform_rendered_contents;
73
74 sk_sp<SkImage> layer_image;
75 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
76
77 switch (layer->type) {
79 layer_image =
80 reinterpret_cast<SkSurface*>(layer->backing_store->user_data)->makeImageSnapshot();
81 break;
85 : nullptr;
86 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
87 break;
88 };
89
90 // If the layer is not a platform view but the engine did not specify an
91 // image for the backing store, it is an error.
92 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
93 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: " << *layer;
94 return false;
95 }
96
97 // The test could have just specified no contents to be rendered in place of
98 // a platform view. This is not an error.
99 if (layer_image) {
100 // The image rendered by Flutter already has the correct offset and
101 // transformation applied. The layers offset is meant for the platform.
102 canvas->drawImage(layer_image.get(), canvas_offset.x(), canvas_offset.y());
103 }
104 }
105
106 last_composition_ = surface->makeImageSnapshot();
107
108 if (!last_composition_) {
109 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
110 return false;
111 }
112
114 auto last_composition_snapshot = last_composition_->makeRasterImage(nullptr);
115 FML_CHECK(last_composition_snapshot);
117 next_scene_callback_ = nullptr;
118 callback(std::move(last_composition_snapshot));
119 }
120
121 return true;
122}
123
124} // namespace testing
125} // namespace flutter
GLenum type
std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer_
PlatformViewRendererCallback platform_view_renderer_callback_
EmbedderTestCompositorMetal(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