Flutter Engine
The Flutter Engine
embedder_test_compositor.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.h"
6
7#include <utility>
8
9#include "flutter/fml/logging.h"
10#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
12
13namespace flutter {
14namespace testing {
15
18 : surface_size_(surface_size), context_(std::move(context)) {
19 FML_CHECK(!surface_size_.isEmpty()) << "Surface size must not be empty";
20}
21
23
24static void InvokeAllCallbacks(const std::vector<fml::closure>& callbacks) {
25 for (const auto& callback : callbacks) {
26 if (callback) {
27 callback();
28 }
29 }
30}
31
33 const FlutterBackingStoreConfig* config,
34 FlutterBackingStore* backing_store_out) {
35 bool success = backingstore_producer_->Create(config, backing_store_out);
36 if (success) {
39 }
40 return success;
41}
42
44 const FlutterBackingStore* backing_store) {
45 // We have already set the destruction callback for the various backing
46 // stores. Our user_data is just the canvas from that backing store and does
47 // not need to be explicitly collected. Embedders might have some other state
48 // they want to collect though.
51 return true;
52}
53
55 std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer) {
56 backingstore_producer_ = std::move(backingstore_producer);
57}
58
60 return last_composition_;
61}
62
64 const FlutterLayer** layers,
65 size_t layers_count) {
66 if (!UpdateOffscrenComposition(layers, layers_count)) {
68 << "Could not update the off-screen composition in the test compositor";
69 return false;
70 }
71
72 // If the test has asked to access the layers and renderers being presented.
73 // Access the same and present it to the test for its test assertions.
77 present_callback_ = nullptr;
78 }
79 callback(view_id, layers, layers_count);
80 }
81
83 return true;
84}
85
87 const PresentCallback& next_present_callback) {
88 SetPresentCallback(next_present_callback, true);
89}
90
92 const PresentCallback& present_callback,
93 bool one_shot) {
95 present_callback_ = present_callback;
97}
98
100 const NextSceneCallback& next_scene_callback) {
102 next_scene_callback_ = next_scene_callback;
103}
104
108}
109
113}
114
117}
118
121}
122
124 const fml::closure& callback) {
126}
127
129 const fml::closure& callback) {
131}
132
134 const fml::closure& callback) {
136}
137
139 return context_;
140}
141
142} // namespace testing
143} // namespace flutter
void AddOnCreateRenderTargetCallback(const fml::closure &callback)
void AddOnPresentCallback(const fml::closure &callback)
void SetNextSceneCallback(const NextSceneCallback &next_scene_callback)
void AddOnCollectRenderTargetCallback(const fml::closure &callback)
std::vector< fml::closure > on_create_render_target_callbacks_
EmbedderTestCompositor(SkISize surface_size, sk_sp< GrDirectContext > context)
std::function< void(FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)> PresentCallback
bool CollectBackingStore(const FlutterBackingStore *backing_store)
std::function< void(sk_sp< SkImage > image)> NextSceneCallback
std::vector< fml::closure > on_collect_render_target_callbacks_
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
void SetNextPresentCallback(const PresentCallback &next_present_callback)
Allows tests to install a callback to notify them when the entire render tree has been finalized so t...
void SetBackingStoreProducer(std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer)
bool Present(FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
virtual bool UpdateOffscrenComposition(const FlutterLayer **layers, size_t layers_count)=0
void SetPresentCallback(const PresentCallback &present_callback, bool one_shot)
std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer_
std::function< sk_sp< SkImage >(const FlutterLayer &layer, GrDirectContext *context)> PlatformViewRendererCallback
PlatformViewRendererCallback platform_view_renderer_callback_
void SetPlatformViewRendererCallback(const PlatformViewRendererCallback &callback)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_CHECK(condition)
Definition: logging.h:85
static void InvokeAllCallbacks(const std::vector< fml::closure > &callbacks)
int64_t FlutterViewId
Definition: flutter_view.h:13
std::function< void()> closure
Definition: closure.h:14
Definition: ref_ptr.h:256
Definition: SkSize.h:16
bool isEmpty() const
Definition: SkSize.h:31
#define ERROR(message)
Definition: elf_loader.cc:260