• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/macros.h"
11 #include "flutter/shell/platform/embedder/embedder.h"
12 #include "third_party/skia/include/gpu/GrContext.h"
13 
14 namespace flutter {
15 namespace testing {
16 
17 class EmbedderTestCompositor {
18  public:
19   enum class RenderTargetType {
20     kOpenGLFramebuffer,
21     kOpenGLTexture,
22     kSoftwareBuffer,
23   };
24 
25   EmbedderTestCompositor(sk_sp<GrContext> context);
26 
27   ~EmbedderTestCompositor();
28 
29   void SetRenderTargetType(RenderTargetType type);
30 
31   bool CreateBackingStore(const FlutterBackingStoreConfig* config,
32                           FlutterBackingStore* backing_store_out);
33 
34   bool CollectBackingStore(const FlutterBackingStore* backing_store);
35 
36   bool Present(const FlutterLayer** layers, size_t layers_count);
37 
38   using PlatformViewRendererCallback =
39       std::function<sk_sp<SkImage>(const FlutterLayer& layer,
40                                    GrContext* context)>;
41   void SetPlatformViewRendererCallback(PlatformViewRendererCallback callback);
42 
43   using PresentCallback =
44       std::function<void(const FlutterLayer** layers, size_t layers_count)>;
45   //----------------------------------------------------------------------------
46   /// @brief      Allows tests to install a callback to notify them when the
47   ///             entire render tree has been finalized so they can run their
48   ///             assertions.
49   ///
50   /// @param[in]  next_present_callback  The next present callback
51   ///
52   void SetNextPresentCallback(PresentCallback next_present_callback);
53 
54   using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
55   void SetNextSceneCallback(NextSceneCallback next_scene_callback);
56 
57   sk_sp<SkImage> GetLastComposition();
58 
59  private:
60   sk_sp<GrContext> context_;
61   RenderTargetType type_ = RenderTargetType::kOpenGLFramebuffer;
62   PlatformViewRendererCallback platform_view_renderer_callback_;
63   PresentCallback next_present_callback_;
64   NextSceneCallback next_scene_callback_;
65   sk_sp<SkImage> last_composition_;
66 
67   bool UpdateOffscrenComposition(const FlutterLayer** layers,
68                                  size_t layers_count);
69 
70   bool CreateFramebufferRenderSurface(const FlutterBackingStoreConfig* config,
71                                       FlutterBackingStore* renderer_out);
72 
73   bool CreateTextureRenderSurface(const FlutterBackingStoreConfig* config,
74                                   FlutterBackingStore* renderer_out);
75 
76   bool CreateSoftwareRenderSurface(const FlutterBackingStoreConfig* config,
77                                    FlutterBackingStore* renderer_out);
78 
79   FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestCompositor);
80 };
81 
82 }  // namespace testing
83 }  // namespace flutter
84 
85 #endif  // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_H_
86