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 "flutter/fml/logging.h"
8 #include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
9 #include "third_party/skia/include/core/SkSurface.h"
10 
11 namespace flutter {
12 namespace testing {
13 
15  sk_sp<GrDirectContext> context)
16  : surface_size_(surface_size), context_(context) {
17  FML_CHECK(!surface_size_.isEmpty()) << "Surface size must not be empty";
18 }
19 
21 
22 static void InvokeAllCallbacks(const std::vector<fml::closure>& callbacks) {
23  for (const auto& callback : callbacks) {
24  if (callback) {
25  callback();
26  }
27  }
28 }
29 
31  const FlutterBackingStoreConfig* config,
32  FlutterBackingStore* backing_store_out) {
33  bool success = backingstore_producer_->Create(config, backing_store_out);
34  if (success) {
37  }
38  return success;
39 }
40 
42  const FlutterBackingStore* backing_store) {
43  // We have already set the destruction callback for the various backing
44  // stores. Our user_data is just the canvas from that backing store and does
45  // not need to be explicitly collected. Embedders might have some other state
46  // they want to collect though.
49  return true;
50 }
51 
53  std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer) {
54  backingstore_producer_ = std::move(backingstore_producer);
55 }
56 
58  return last_composition_;
59 }
60 
62  size_t layers_count) {
63  if (!UpdateOffscrenComposition(layers, layers_count)) {
64  FML_LOG(ERROR)
65  << "Could not update the off-screen composition in the test compositor";
66  return false;
67  }
68 
69  // If the test has asked to access the layers and renderers being presented.
70  // Access the same and present it to the test for its test assertions.
71  if (present_callback_) {
72  auto callback = present_callback_;
74  present_callback_ = nullptr;
75  }
76  callback(layers, layers_count);
77  }
78 
80  return true;
81 }
82 
84  const PresentCallback& next_present_callback) {
85  SetPresentCallback(next_present_callback, true);
86 }
87 
89  const PresentCallback& present_callback,
90  bool one_shot) {
92  present_callback_ = present_callback;
94 }
95 
97  const NextSceneCallback& next_scene_callback) {
99  next_scene_callback_ = next_scene_callback;
100 }
101 
103  const PlatformViewRendererCallback& callback) {
105 }
106 
110 }
111 
114 }
115 
118 }
119 
121  fml::closure callback) {
122  on_create_render_target_callbacks_.push_back(callback);
123 }
124 
126  fml::closure callback) {
127  on_collect_render_target_callbacks_.push_back(callback);
128 }
129 
131  on_present_callbacks_.push_back(callback);
132 }
133 
134 sk_sp<GrDirectContext> EmbedderTestCompositor::GetGrContext() {
135  return context_;
136 }
137 
138 } // namespace testing
139 } // namespace flutter
PlatformViewRendererCallback platform_view_renderer_callback_
std::function< void(sk_sp< SkImage > image)> NextSceneCallback
static void InvokeAllCallbacks(const std::vector< fml::closure > &callbacks)
std::vector< fml::closure > on_create_render_target_callbacks_
virtual bool UpdateOffscrenComposition(const FlutterLayer **layers, size_t layers_count)=0
#define FML_LOG(severity)
Definition: logging.h:65
void AddOnCollectRenderTargetCallback(fml::closure callback)
void SetPlatformViewRendererCallback(const PlatformViewRendererCallback &callback)
void SetPresentCallback(const PresentCallback &present_callback, bool one_shot)
std::function< void()> closure
Definition: closure.h:14
std::vector< fml::closure > on_collect_render_target_callbacks_
#define FML_CHECK(condition)
Definition: logging.h:68
void SetNextSceneCallback(const NextSceneCallback &next_scene_callback)
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
bool Present(const FlutterLayer **layers, size_t layers_count)
void AddOnCreateRenderTargetCallback(fml::closure callback)
void SetBackingStoreProducer(std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer)
bool CollectBackingStore(const FlutterBackingStore *backing_store)
std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer_
std::function< sk_sp< SkImage >(const FlutterLayer &layer, GrDirectContext *context)> PlatformViewRendererCallback
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...
std::function< void(const FlutterLayer **layers, size_t layers_count)> PresentCallback
EmbedderTestCompositor(SkISize surface_size, sk_sp< GrDirectContext > context)