Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
flutter::testing::EmbedderTestCompositorGL Class Reference

#include <embedder_test_compositor_gl.h>

Inheritance diagram for flutter::testing::EmbedderTestCompositorGL:
flutter::testing::EmbedderTestCompositor

Public Member Functions

 EmbedderTestCompositorGL (SkISize surface_size, sk_sp< GrDirectContext > context)
 
 ~EmbedderTestCompositorGL () override
 
- Public Member Functions inherited from flutter::testing::EmbedderTestCompositor
 EmbedderTestCompositor (SkISize surface_size, sk_sp< GrDirectContext > context)
 
virtual ~EmbedderTestCompositor ()
 
void SetBackingStoreProducer (std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer)
 
bool CreateBackingStore (const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
 
bool CollectBackingStore (const FlutterBackingStore *backing_store)
 
bool Present (FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
 
void SetPlatformViewRendererCallback (const PlatformViewRendererCallback &callback)
 
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 they can run their assertions.
 
void SetPresentCallback (const PresentCallback &present_callback, bool one_shot)
 
void SetNextSceneCallback (const NextSceneCallback &next_scene_callback)
 
sk_sp< SkImageGetLastComposition ()
 
size_t GetPendingBackingStoresCount () const
 
size_t GetBackingStoresCreatedCount () const
 
size_t GetBackingStoresCollectedCount () const
 
void AddOnCreateRenderTargetCallback (const fml::closure &callback)
 
void AddOnCollectRenderTargetCallback (const fml::closure &callback)
 
void AddOnPresentCallback (const fml::closure &callback)
 
sk_sp< GrDirectContextGetGrContext ()
 

Private Member Functions

bool UpdateOffscrenComposition (const FlutterLayer **layers, size_t layers_count) override
 

Additional Inherited Members

- Public Types inherited from flutter::testing::EmbedderTestCompositor
using PlatformViewRendererCallback = std::function< sk_sp< SkImage >(const FlutterLayer &layer, GrDirectContext *context)>
 
using PresentCallback = std::function< void(FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)>
 
using NextSceneCallback = std::function< void(sk_sp< SkImage > image)>
 
- Protected Member Functions inherited from flutter::testing::EmbedderTestCompositor
 FML_DISALLOW_COPY_AND_ASSIGN (EmbedderTestCompositor)
 
- Protected Attributes inherited from flutter::testing::EmbedderTestCompositor
std::unique_ptr< EmbedderTestBackingStoreProducerbackingstore_producer_
 
const SkISize surface_size_
 
sk_sp< GrDirectContextcontext_
 
PlatformViewRendererCallback platform_view_renderer_callback_
 
bool present_callback_is_one_shot_ = false
 
PresentCallback present_callback_
 
NextSceneCallback next_scene_callback_
 
sk_sp< SkImagelast_composition_
 
size_t backing_stores_created_ = 0
 
size_t backing_stores_collected_ = 0
 
std::vector< fml::closureon_create_render_target_callbacks_
 
std::vector< fml::closureon_collect_render_target_callbacks_
 
std::vector< fml::closureon_present_callbacks_
 

Detailed Description

Definition at line 15 of file embedder_test_compositor_gl.h.

Constructor & Destructor Documentation

◆ EmbedderTestCompositorGL()

flutter::testing::EmbedderTestCompositorGL::EmbedderTestCompositorGL ( SkISize  surface_size,
sk_sp< GrDirectContext context 
)

Definition at line 17 of file embedder_test_compositor_gl.cc.

20 : EmbedderTestCompositor(surface_size, std::move(context)) {}
EmbedderTestCompositor(SkISize surface_size, sk_sp< GrDirectContext > context)

◆ ~EmbedderTestCompositorGL()

flutter::testing::EmbedderTestCompositorGL::~EmbedderTestCompositorGL ( )
overridedefault

Member Function Documentation

◆ UpdateOffscrenComposition()

bool flutter::testing::EmbedderTestCompositorGL::UpdateOffscrenComposition ( const FlutterLayer **  layers,
size_t  layers_count 
)
overrideprivatevirtual

Implements flutter::testing::EmbedderTestCompositor.

Definition at line 24 of file embedder_test_compositor_gl.cc.

26 {
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}
@ 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
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)
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)

The documentation for this class was generated from the following files: