Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | List of all members
impeller::PlaygroundImplMTL Class Referencefinal

#include <playground_impl_mtl.h>

Inheritance diagram for impeller::PlaygroundImplMTL:
impeller::PlaygroundImpl

Classes

struct  Data
 

Public Member Functions

 PlaygroundImplMTL (PlaygroundSwitches switches)
 
 ~PlaygroundImplMTL ()
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities) override
 
- Public Member Functions inherited from impeller::PlaygroundImpl
virtual ~PlaygroundImpl ()
 
Vector2 GetContentScale () const
 

Private Member Functions

std::shared_ptr< ContextGetContext () const override
 
WindowHandle GetWindowHandle () const override
 
std::unique_ptr< SurfaceAcquireSurfaceFrame (std::shared_ptr< Context > context) override
 

Additional Inherited Members

- Public Types inherited from impeller::PlaygroundImpl
using WindowHandle = void *
 
- Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImplCreate (PlaygroundBackend backend, PlaygroundSwitches switches)
 
- Protected Member Functions inherited from impeller::PlaygroundImpl
 PlaygroundImpl (PlaygroundSwitches switches)
 
- Protected Attributes inherited from impeller::PlaygroundImpl
const PlaygroundSwitches switches_
 

Detailed Description

Definition at line 20 of file playground_impl_mtl.h.

Constructor & Destructor Documentation

◆ PlaygroundImplMTL()

impeller::PlaygroundImplMTL::PlaygroundImplMTL ( PlaygroundSwitches  switches)
explicit

Definition at line 63 of file playground_impl_mtl.mm.

64 : PlaygroundImpl(switches),
65 handle_(nullptr, &DestroyWindowHandle),
66 data_(std::make_unique<Data>()),
67 concurrent_loop_(fml::ConcurrentMessageLoop::Create()),
68 is_gpu_disabled_sync_switch_(new fml::SyncSwitch(false)) {
69 ::glfwDefaultWindowHints();
70 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
71 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
72 auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
73 if (!window) {
74 return;
75 }
76
77 auto context = ContextMTL::Create(
78 ShaderLibraryMappingsForPlayground(), is_gpu_disabled_sync_switch_,
79 "Playground Library",
80 switches.enable_wide_gamut
81 ? std::optional<PixelFormat>(PixelFormat::kB10G10R10A10XR)
82 : std::nullopt);
83 if (!context) {
84 return;
85 }
86 NSWindow* cocoa_window = ::glfwGetCocoaWindow(window);
87 if (cocoa_window == nil) {
88 return;
89 }
90 data_->metal_layer = [CAMetalLayer layer];
91 data_->metal_layer.device = ContextMTL::Cast(*context).GetMTLDevice();
92 data_->metal_layer.pixelFormat =
93 ToMTLPixelFormat(context->GetCapabilities()->GetDefaultColorFormat());
94 data_->metal_layer.framebufferOnly = NO;
95 cocoa_window.contentView.layer = data_->metal_layer;
96 cocoa_window.contentView.wantsLayer = YES;
97
98 handle_.reset(window);
99 context_ = std::move(context);
100}
static std::shared_ptr< ConcurrentMessageLoop > Create(size_t worker_count=std::thread::hardware_concurrency())
static ContextMTL & Cast(Context &base)
static std::shared_ptr< ContextMTL > Create(const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
id< MTLDevice > GetMTLDevice() const
PlaygroundImpl(PlaygroundSwitches switches)
GLFWwindow * window
Definition main.cc:45
#define GLFW_FALSE
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format)
Definition formats_mtl.h:77
Definition ref_ptr.h:256

◆ ~PlaygroundImplMTL()

impeller::PlaygroundImplMTL::~PlaygroundImplMTL ( )
default

Member Function Documentation

◆ AcquireSurfaceFrame()

std::unique_ptr< Surface > impeller::PlaygroundImplMTL::AcquireSurfaceFrame ( std::shared_ptr< Context context)
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 114 of file playground_impl_mtl.mm.

115 {
116 if (!data_->metal_layer) {
117 return nullptr;
118 }
119
120 const auto layer_size = data_->metal_layer.bounds.size;
121 const auto scale = GetContentScale();
122 data_->metal_layer.drawableSize =
123 CGSizeMake(layer_size.width * scale.x, layer_size.height * scale.y);
124
125 auto drawable =
126 SurfaceMTL::GetMetalDrawableAndValidate(context, data_->metal_layer);
127 return SurfaceMTL::MakeFromMetalLayerDrawable(context, drawable);
128}
Vector2 GetContentScale() const
static id< CAMetalDrawable > GetMetalDrawableAndValidate(const std::shared_ptr< Context > &context, CAMetalLayer *layer)
Wraps the current drawable of the given Metal layer to create a surface Impeller can render to....
static std::unique_ptr< SurfaceMTL > MakeFromMetalLayerDrawable(const std::shared_ptr< Context > &context, id< CAMetalDrawable > drawable, std::optional< IRect > clip_rect=std::nullopt)
const Scalar scale

◆ GetContext()

std::shared_ptr< Context > impeller::PlaygroundImplMTL::GetContext ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 104 of file playground_impl_mtl.mm.

104 {
105 return context_;
106}

◆ GetWindowHandle()

PlaygroundImpl::WindowHandle impeller::PlaygroundImplMTL::GetWindowHandle ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 109 of file playground_impl_mtl.mm.

109 {
110 return handle_.get();
111}

◆ SetCapabilities()

fml::Status impeller::PlaygroundImplMTL::SetCapabilities ( const std::shared_ptr< Capabilities > &  capabilities)
overridevirtual

Implements impeller::PlaygroundImpl.

Definition at line 130 of file playground_impl_mtl.mm.

131 {
132 context_->SetCapabilities(capabilities);
133 return fml::Status();
134}

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