7 #define GLFW_INCLUDE_NONE
8 #import "third_party/glfw/include/GLFW/glfw3.h"
10 #define GLFW_EXPOSE_NATIVE_COCOA
11 #import "third_party/glfw/include/GLFW/glfw3native.h"
13 #include <Metal/Metal.h>
14 #include <QuartzCore/QuartzCore.h>
16 #include "flutter/fml/mapping.h"
17 #include "impeller/entity/mtl/entity_shaders.h"
18 #include "impeller/entity/mtl/framebuffer_blend_shaders.h"
19 #include "impeller/entity/mtl/modern_shaders.h"
20 #include "impeller/fixtures/mtl/fixtures_shaders.h"
21 #include "impeller/fixtures/mtl/modern_fixtures_shaders.h"
22 #include "impeller/playground/imgui/mtl/imgui_shaders.h"
27 #include "impeller/renderer/mtl/compute_shaders.h"
35 static std::vector<std::shared_ptr<fml::Mapping>>
37 return {std::make_shared<fml::NonOwnedMapping>(
38 impeller_entity_shaders_data, impeller_entity_shaders_length),
39 std::make_shared<fml::NonOwnedMapping>(
40 impeller_modern_shaders_data, impeller_modern_shaders_length),
41 std::make_shared<fml::NonOwnedMapping>(
42 impeller_framebuffer_blend_shaders_data,
43 impeller_framebuffer_blend_shaders_length),
44 std::make_shared<fml::NonOwnedMapping>(
45 impeller_fixtures_shaders_data, impeller_fixtures_shaders_length),
46 std::make_shared<fml::NonOwnedMapping>(
47 impeller_modern_fixtures_shaders_data,
48 impeller_modern_fixtures_shaders_length),
49 std::make_shared<fml::NonOwnedMapping>(impeller_imgui_shaders_data,
50 impeller_imgui_shaders_length),
51 std::make_shared<fml::NonOwnedMapping>(
52 impeller_compute_shaders_data, impeller_compute_shaders_length)
57 void PlaygroundImplMTL::DestroyWindowHandle(WindowHandle handle) {
61 ::glfwDestroyWindow(
reinterpret_cast<GLFWwindow*
>(handle));
66 handle_(nullptr, &DestroyWindowHandle),
67 data_(
std::make_unique<
Data>()),
68 concurrent_loop_(fml::ConcurrentMessageLoop::
Create()),
69 is_gpu_disabled_sync_switch_(new fml::SyncSwitch(false)) {
70 ::glfwDefaultWindowHints();
71 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
72 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
73 auto window = ::glfwCreateWindow(1, 1,
"Test",
nullptr,
nullptr);
87 NSWindow* cocoa_window = ::glfwGetCocoaWindow(window);
88 if (cocoa_window == nil) {
91 data_->metal_layer = [CAMetalLayer layer];
93 data_->metal_layer.pixelFormat =
95 data_->metal_layer.framebufferOnly = NO;
96 cocoa_window.contentView.layer = data_->metal_layer;
97 cocoa_window.contentView.wantsLayer = YES;
99 handle_.reset(window);
100 context_ = std::move(context);
105 std::shared_ptr<Context> PlaygroundImplMTL::GetContext()
const {
111 return handle_.get();
115 std::unique_ptr<Surface> PlaygroundImplMTL::AcquireSurfaceFrame(
116 std::shared_ptr<Context> context) {
117 if (!data_->metal_layer) {
121 const auto layer_size = data_->metal_layer.bounds.size;
123 data_->metal_layer.drawableSize =
124 CGSizeMake(layer_size.width *
scale.x, layer_size.height *
scale.y);
132 const std::shared_ptr<Capabilities>& capabilities) {
133 context_->SetCapabilities(capabilities);
134 return fml::Status();