5#include <Foundation/Foundation.h>
6#include <QuartzCore/QuartzCore.h>
9#include "gtest/gtest.h"
11#include "impeller/entity/mtl/entity_shaders.h"
12#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
13#include "impeller/entity/mtl/modern_shaders.h"
23 layer_ = [[CAMetalLayer alloc] init];
29 layer_.drawableSize = CGSizeMake(frame_info.
width, frame_info.
height);
41 void SetDevice() { layer_.device = ::MTLCreateSystemDefaultDevice(); }
44 CAMetalLayer* layer_ = nil;
48 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
49 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
50 impeller_entity_shaders_length),
51 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
52 impeller_modern_shaders_length),
53 std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
54 impeller_framebuffer_blend_shaders_length),
56 auto sync_switch = std::make_shared<fml::SyncSwitch>(
false);
62 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
63 auto surface = std::make_shared<GPUSurfaceMetalImpeller>(delegate.get(),
nullptr);
65 ASSERT_FALSE(
surface->IsValid());
69 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
70 auto surface = std::make_shared<GPUSurfaceMetalImpeller>(
73 ASSERT_TRUE(
surface->IsValid());
77 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
78 std::shared_ptr<Surface>
surface = std::make_shared<GPUSurfaceMetalImpeller>(
81 ASSERT_TRUE(
surface->IsValid());
84 ASSERT_EQ(frame,
nullptr);
88 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
89 delegate->SetDevice();
90 std::unique_ptr<Surface>
surface = std::make_unique<GPUSurfaceMetalImpeller>(
93 ASSERT_TRUE(
surface->IsValid());
101 ASSERT_TRUE(frame->Submit());
105 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
106 delegate->SetDevice();
109 std::unique_ptr<Surface>
surface = std::make_unique<GPUSurfaceMetalImpeller>(
110 delegate.get(), std::make_shared<impeller::AiksContext>(context,
nullptr));
112 ASSERT_TRUE(
surface->IsValid());
114 auto& data_host_buffer =
surface->GetAiksContext()->GetContentContext().GetTransientsDataBuffer();
116 EXPECT_EQ(data_host_buffer.GetStateForTest().current_frame, 0u);
119 frame->set_submit_info({.frame_boundary =
false});
121 ASSERT_TRUE(frame->Submit());
122 EXPECT_EQ(data_host_buffer.GetStateForTest().current_frame, 0u);
125 frame->set_submit_info({.frame_boundary =
true});
127 ASSERT_TRUE(frame->Submit());
128 EXPECT_EQ(data_host_buffer.GetStateForTest().current_frame, 1u);
133 auto delegate = std::make_shared<TestGPUSurfaceMetalDelegate>();
134 delegate->SetDevice();
137 auto aiks_context = std::make_shared<impeller::AiksContext>(context,
nullptr);
139 EXPECT_FALSE(context->GetCaptureManager()->CaptureScopeActive());
141 std::unique_ptr<Surface>
surface =
142 std::make_unique<GPUSurfaceMetalImpeller>(delegate.get(), aiks_context);
144 frame_1->set_submit_info({.frame_boundary =
false});
146 EXPECT_TRUE(context->GetCaptureManager()->CaptureScopeActive());
148 std::unique_ptr<Surface> surface_2 =
149 std::make_unique<GPUSurfaceMetalImpeller>(delegate.get(), aiks_context);
151 frame_2->set_submit_info({.frame_boundary =
true});
153 EXPECT_TRUE(context->GetCaptureManager()->CaptureScopeActive());
155 ASSERT_TRUE(frame_1->Submit());
156 EXPECT_TRUE(context->GetCaptureManager()->CaptureScopeActive());
157 ASSERT_TRUE(frame_2->Submit());
158 EXPECT_FALSE(context->GetCaptureManager()->CaptureScopeActive());
static std::shared_ptr< ContextMTL > Create(const Flags &flags, const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::ISize32 DlISize
void * GPUCAMetalLayerHandle