Flutter Engine
The 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
5#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_gl.h"
6
7#include <utility>
8
9#include "flutter/fml/logging.h"
10#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
13
14namespace flutter {
15namespace testing {
16
18 SkISize surface_size,
20 : EmbedderTestCompositor(surface_size, std::move(context)) {}
21
23
25 const FlutterLayer** layers,
26 size_t layers_count) {
27 last_composition_ = nullptr;
28
29 const auto image_info = SkImageInfo::MakeN32Premul(surface_size_);
30
31 auto surface =
33 skgpu::Budgeted::kNo, // budgeted
34 image_info, // image info
35 1, // sample count
36 kTopLeft_GrSurfaceOrigin, // surface origin
37 nullptr, // surface properties
38 false // create mipmaps
39 );
40
41 if (!surface) {
42 FML_LOG(ERROR) << "Could not update the off-screen composition.";
43 return false;
44 }
45
46 auto canvas = surface->getCanvas();
47
48 // This has to be transparent because we are going to be compositing this
49 // sub-hierarchy onto the on-screen surface.
50 canvas->clear(SK_ColorTRANSPARENT);
51
52 for (size_t i = 0; i < layers_count; ++i) {
53 const auto* layer = layers[i];
54
55 sk_sp<SkImage> platform_rendered_contents;
56
57 sk_sp<SkImage> layer_image;
58 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
59
60 switch (layer->type) {
62 layer_image =
63 reinterpret_cast<SkSurface*>(layer->backing_store->user_data)
64 ->makeImageSnapshot();
65
66 break;
68 layer_image =
71 : nullptr;
72 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
73 break;
74 };
75
76 // If the layer is not a platform view but the engine did not specify an
77 // image for the backing store, it is an error.
78 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
79 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
80 << *layer;
81 return false;
82 }
83
84 // The test could have just specified no contents to be rendered in place of
85 // a platform view. This is not an error.
86 if (layer_image) {
87 // The image rendered by Flutter already has the correct offset and
88 // transformation applied. The layers offset is meant for the platform.
89 canvas->drawImage(layer_image.get(), canvas_offset.x(),
90 canvas_offset.y());
91 }
92 }
93
94 last_composition_ = surface->makeImageSnapshot();
95
96 if (!last_composition_) {
97 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
98 return false;
99 }
100
102 auto last_composition_snapshot = last_composition_->makeRasterImage();
103 FML_CHECK(last_composition_snapshot);
105 next_scene_callback_ = nullptr;
106 callback(std::move(last_composition_snapshot));
107 }
108
109 return true;
110}
111
112} // namespace testing
113} // 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
EmbedderTestCompositorGL(SkISize surface_size, sk_sp< GrDirectContext > context)
bool UpdateOffscrenComposition(const FlutterLayer **layers, size_t layers_count) override
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 > 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
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)