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