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

#include <embedder_test_compositor_vulkan.h>

Inheritance diagram for flutter::testing::EmbedderTestCompositorVulkan:
flutter::testing::EmbedderTestCompositor

Public Member Functions

 EmbedderTestCompositorVulkan (SkISize surface_size, sk_sp< GrDirectContext > context)
 
 ~EmbedderTestCompositorVulkan () 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_vulkan.h.

Constructor & Destructor Documentation

◆ EmbedderTestCompositorVulkan()

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

Definition at line 18 of file embedder_test_compositor_vulkan.cc.

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

◆ ~EmbedderTestCompositorVulkan()

flutter::testing::EmbedderTestCompositorVulkan::~EmbedderTestCompositorVulkan ( )
overridedefault

Member Function Documentation

◆ UpdateOffscrenComposition()

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

Implements flutter::testing::EmbedderTestCompositor.

Definition at line 25 of file embedder_test_compositor_vulkan.cc.

27 {
28 last_composition_ = nullptr;
29
30 const auto image_info = SkImageInfo::MakeN32Premul(surface_size_);
31
34 skgpu::Budgeted::kNo, // budgeted
35 image_info, // image info
36 1, // sample count
37 kTopLeft_GrSurfaceOrigin, // surface origin
38 nullptr, // surface properties
39 false // create mipmaps
40 );
41
42 if (!surface) {
43 FML_LOG(ERROR) << "Could not update the off-screen composition.";
44 return false;
45 }
46
47 auto canvas = surface->getCanvas();
48
49 // This has to be transparent because we are going to be compositing this
50 // sub-hierarchy onto the on-screen surface.
51 canvas->clear(SK_ColorTRANSPARENT);
52
53 for (size_t i = 0; i < layers_count; ++i) {
54 const auto* layer = layers[i];
55
56 sk_sp<SkImage> platform_rendered_contents;
57
58 sk_sp<SkImage> layer_image;
59 SkIPoint canvas_offset = SkIPoint::Make(0, 0);
60
61 switch (layer->type) {
63 layer_image =
64 reinterpret_cast<EmbedderTestBackingStoreProducer::UserData*>(
65 layer->backing_store->user_data)
66 ->surface->makeImageSnapshot();
67 break;
69 layer_image =
72 : nullptr;
73 canvas_offset = SkIPoint::Make(layer->offset.x, layer->offset.y);
74 break;
75 };
76
77 // If the layer is not a platform view but the engine did not specify an
78 // image for the backing store, it is an error.
79 if (!layer_image && layer->type != kFlutterLayerContentTypePlatformView) {
80 FML_LOG(ERROR) << "Could not snapshot layer in test compositor: "
81 << *layer;
82 return false;
83 }
84
85 // The test could have just specified no contents to be rendered in place of
86 // a platform view. This is not an error.
87 if (layer_image) {
88 // The image rendered by Flutter already has the correct offset and
89 // transformation applied. The layers offset is meant for the platform.
90 canvas->drawImage(layer_image.get(), canvas_offset.x(),
91 canvas_offset.y());
92 }
93 }
94
95 last_composition_ = surface->makeImageSnapshot();
96
97 if (!last_composition_) {
98 FML_LOG(ERROR) << "Could not update the contents of the sub-composition.";
99 return false;
100 }
101
103 auto last_composition_snapshot = last_composition_->makeRasterImage();
104 FML_CHECK(last_composition_snapshot);
106 next_scene_callback_ = nullptr;
107 callback(std::move(last_composition_snapshot));
108 }
109
110 return true;
111}
@ 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: