Flutter Engine
embedder_test_compositor.h
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 #ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_H_
6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_H_
7 
8 #include <vector>
9 
10 #include "flutter/fml/closure.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/shell/platform/embedder/embedder.h"
13 #include "flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.h"
14 #include "third_party/skia/include/gpu/GrDirectContext.h"
15 
16 namespace flutter {
17 namespace testing {
18 
20  public:
22  std::function<sk_sp<SkImage>(const FlutterLayer& layer,
23  GrDirectContext* context)>;
24  using PresentCallback =
25  std::function<void(const FlutterLayer** layers, size_t layers_count)>;
26 
27  EmbedderTestCompositor(SkISize surface_size, sk_sp<GrDirectContext> context);
28 
29  virtual ~EmbedderTestCompositor();
30 
32  std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer);
33 
35  FlutterBackingStore* backing_store_out);
36 
37  bool CollectBackingStore(const FlutterBackingStore* backing_store);
38 
39  bool Present(const FlutterLayer** layers, size_t layers_count);
40 
42  const PlatformViewRendererCallback& callback);
43 
44  //----------------------------------------------------------------------------
45  /// @brief Allows tests to install a callback to notify them when the
46  /// entire render tree has been finalized so they can run their
47  /// assertions.
48  ///
49  /// @param[in] next_present_callback The next present callback
50  ///
51  void SetNextPresentCallback(const PresentCallback& next_present_callback);
52 
53  void SetPresentCallback(const PresentCallback& present_callback,
54  bool one_shot);
55 
56  using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
57  void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);
58 
59  sk_sp<SkImage> GetLastComposition();
60 
61  size_t GetPendingBackingStoresCount() const;
62 
63  size_t GetBackingStoresCreatedCount() const;
64 
65  size_t GetBackingStoresCollectedCount() const;
66 
68 
70 
71  void AddOnPresentCallback(fml::closure callback);
72 
73  sk_sp<GrDirectContext> GetGrContext();
74 
75  protected:
76  virtual bool UpdateOffscrenComposition(const FlutterLayer** layers,
77  size_t layers_count) = 0;
78 
79  // TODO(gw280): encapsulate these properly for subclasses to use
80  std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer_;
81  const SkISize surface_size_;
82  sk_sp<GrDirectContext> context_;
83 
86  PresentCallback present_callback_;
88  sk_sp<SkImage> last_composition_;
91  std::vector<fml::closure> on_create_render_target_callbacks_;
92  std::vector<fml::closure> on_collect_render_target_callbacks_;
93  std::vector<fml::closure> on_present_callbacks_;
94 
96 };
97 
98 } // namespace testing
99 } // namespace flutter
100 
101 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_GL_H_
PlatformViewRendererCallback platform_view_renderer_callback_
std::function< void(sk_sp< SkImage > image)> NextSceneCallback
std::vector< fml::closure > on_create_render_target_callbacks_
virtual bool UpdateOffscrenComposition(const FlutterLayer **layers, size_t layers_count)=0
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_
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
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestCompositor)
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)