5#define FML_USED_ON_EMBEDDER
10#import <Metal/Metal.h>
13#include "flutter/display_list/skia/dl_sk_canvas.h"
14#include "flutter/fml/synchronization/count_down_latch.h"
15#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
16#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
17#include "flutter/shell/platform/embedder/tests/embedder_test.h"
18#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
19#include "flutter/shell/platform/embedder/tests/embedder_unittests_util.h"
20#include "flutter/testing/assertions_skia.h"
21#include "flutter/testing/testing.h"
43 builder.SetDartEntrypoint(
"render_gradient");
46 auto rendered_scene = context.GetNextSceneImage();
49 ASSERT_TRUE(
engine.is_valid());
56 event.pixel_ratio = 1.0;
67 GrMtlTextureInfo
info;
68 info.fTexture.reset([(id<MTLTexture>)
texture retain]);
89 auto canvas =
surface->getCanvas();
93 std::vector<FlutterMetalTextureHandle> textures{texture_info.
texture};
104 output->textures = textures.data();
110 builder.SetDartEntrypoint(
"render_texture");
111 builder.SetMetalRendererConfig(texture_size);
114 ASSERT_TRUE(
engine.is_valid());
123 event.width = texture_size.width();
124 event.height = texture_size.height();
125 event.pixel_ratio = 1.0;
137 builder.SetDartEntrypoint(
"can_composite_platform_views");
142 context.GetCompositor().SetNextPresentCallback(
144 ASSERT_EQ(layers_count, 3u);
158 .rects = paint_region_rects,
162 .paint_region = &paint_region,
173 ASSERT_EQ(*layers[0], layer);
188 ASSERT_EQ(*layers[1], layer);
203 .rects = paint_region_rects,
207 .paint_region = &paint_region,
218 ASSERT_EQ(*layers[2], layer);
224 context.AddNativeCallback(
235 event.pixel_ratio = 1.0;
237 ASSERT_TRUE(
engine.is_valid());
247 builder.SetDartEntrypoint(
"can_render_scene_without_custom_compositor");
250 auto rendered_scene = context.GetNextSceneImage();
253 ASSERT_TRUE(
engine.is_valid());
260 event.pixel_ratio = 1.0;
271 builder.SetDartEntrypoint(
"texture_destruction_callback_called_without_custom_compositor");
273 struct CollectContext {
274 int present_count = 0;
275 int collect_count = 0;
279 auto collect_context = std::make_unique<CollectContext>();
285 texture.texture_id = texture_info.texture_id;
287 texture.user_data = collect_context.get();
289 CollectContext* callback_collect_context =
reinterpret_cast<CollectContext*
>(
user_data);
290 ASSERT_TRUE(callback_collect_context->present_count > 0);
291 callback_collect_context->collect_count++;
292 callback_collect_context->latch.Signal();
297 collect_context->present_count++;
308 event.pixel_ratio = 1.0;
310 ASSERT_TRUE(
engine.is_valid());
312 collect_context->latch.Wait();
313 EXPECT_EQ(collect_context->collect_count, 1);
322 builder.SetDartEntrypoint(
"can_composite_platform_views_with_known_scene");
328 auto scene_image = context.GetNextSceneImage();
330 context.GetCompositor().SetNextPresentCallback(
332 ASSERT_EQ(layers_count, 5u);
346 .rects = paint_region_rects,
350 .paint_region = &paint_region,
361 ASSERT_EQ(*layers[0], layer);
377 ASSERT_EQ(*layers[1], layer);
392 .rects = paint_region_rects,
396 .paint_region = &paint_region,
407 ASSERT_EQ(*layers[2], layer);
423 ASSERT_EQ(*layers[3], layer);
438 .rects = paint_region_rects,
442 .paint_region = &paint_region,
453 ASSERT_EQ(*layers[4], layer);
459 context.GetCompositor().SetPlatformViewRendererCallback(
462 auto canvas =
surface->getCanvas();
486 FML_CHECK(
false) <<
"Test was asked to composite an unknown platform view.";
489 return surface->makeImageSnapshot();
492 context.AddNativeCallback(
504 event.pixel_ratio = 1.0;
506 ASSERT_TRUE(
engine.is_valid());
519 builder.SetDartEntrypoint(
"invalid_backingstore");
521 class TestCollectOnce {
525 ASSERT_FALSE(collected_);
530 bool collected_ =
false;
534 builder.GetCompositor().create_backing_store_callback =
541 backing_store_out->user_data =
nullptr;
542 backing_store_out->metal.texture.texture = 0;
544 backing_store_out->metal.texture.user_data =
new TestCollectOnce();
545 backing_store_out->metal.texture.destruction_callback = [](
void*
user_data) {
546 reinterpret_cast<TestCollectOnce*
>(
user_data)->Collect();
551 context.AddNativeCallback(
562 event.pixel_ratio = 1.0;
564 ASSERT_TRUE(
engine.is_valid());
575 std::vector<FlutterMetalTextureHandle> textures{metal_texture.
texture};
577 bool resolve_called =
false;
580 resolve_called =
true;
581 auto res = std::make_unique<FlutterMetalExternalTexture>();
583 res->width = res->height = 100;
585 res->textures = textures.data();
586 res->num_textures = 1;
592 auto skia_surface =
surface->GetSurface();
599 .gr_context =
surface->GetGrContext().get(),
604 resolve_called =
false;
608 EXPECT_FALSE(resolve_called);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kTopLeft_GrSurfaceOrigin
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
constexpr SkColor SK_ColorMAGENTA
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorGREEN
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
Backend implementation of |DlCanvas| for |SkCanvas|.
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
sk_sp< GrDirectContext > GetSkiaContext() const
TextureInfo CreateMetalTexture(const SkISize &size)
Returns texture_id = -1 when texture creation fails.
bool Present(int64_t texture_id)
virtual void MarkNewFrameAvailable()=0
virtual void Paint(PaintContext &context, const SkRect &bounds, bool freeze, const DlImageSampling sampling)=0
TestMetalSurface * GetTestMetalSurface()
void SetNextDrawableCallback(NextDrawableCallback next_drawable_callback)
void SetPresentCallback(PresentCallback present_callback)
TestMetalContext * GetTestMetalContext()
void SetExternalTextureCallback(TestExternalTextureCallback external_texture_frame_callback)
std::future< sk_sp< SkImage > > GetNextSceneImage()
struct _Dart_NativeArguments * Dart_NativeArguments
FlutterEngineResult FlutterEngineRegisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Register an external texture with a unique (per engine) identifier. Only rendering backends that supp...
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
@ kFlutterLayerContentTypeBackingStore
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
const void * FlutterMetalTextureHandle
Alias for id<MTLTexture>.
FlutterSize FlutterSizeMake(double width, double height)
FlutterRect FlutterRectMakeLTRB(double l, double t, double r, double b)
FlutterPoint FlutterPointMake(double x, double y)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
SK_API GrBackendTexture MakeMtl(int width, int height, skgpu::Mipmapped, const GrMtlTextureInfo &mtlInfo, std::string_view label={})
sk_sp< SkBlender > blender SkRect rect
SkSamplingOptions sampling
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
TEST_F(DisplayListTest, Defaults)
sk_sp< SkSurface > CreateRenderSurface(const FlutterLayer &layer, GrDirectContext *context)
testing::EmbedderTest EmbedderTest
bool ImageMatchesFixture(const std::string &fixture_file_name, const sk_sp< SkImage > &scene_image)
static sk_sp< SkSurface > GetSurfaceFromTexture(const sk_sp< GrDirectContext > &skia_context, SkISize texture_size, void *texture)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
FlutterBackingStoreType type
Specifies the type of backing store.
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
FlutterLayerContentType type
const FlutterBackingStore * backing_store
FlutterBackingStorePresentInfo * backing_store_present_info
const FlutterPlatformView * platform_view
size_t struct_size
This size of this struct. Must be sizeof(FlutterLayer).
FlutterSize size
The size of the layer (in physical pixels).
A structure to represent a rectangle.
A region represented by a collection of non-overlapping rectangles.
size_t struct_size
The size of this struct. Must be sizeof(FlutterRegion).
size_t struct_size
The size of this struct. Must be sizeof(FlutterWindowMetricsEvent).
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)
#define CREATE_NATIVE_ENTRY(native_entry)
#define EXPECT_TRUE(handle)