#include <surface_mtl.h>
Definition at line 18 of file surface_mtl.h.
◆ ~SurfaceMTL()
impeller::SurfaceMTL::~SurfaceMTL |
( |
| ) |
|
|
overridedefault |
◆ coverage()
IRect impeller::SurfaceMTL::coverage |
( |
| ) |
const |
◆ drawable()
id<MTLDrawable> impeller::SurfaceMTL::drawable |
( |
| ) |
const |
|
inline |
◆ GetMetalDrawableAndValidate()
id< CAMetalDrawable > impeller::SurfaceMTL::GetMetalDrawableAndValidate |
( |
const std::shared_ptr< Context > & |
context, |
|
|
CAMetalLayer * |
layer |
|
) |
| |
|
static |
Wraps the current drawable of the given Metal layer to create a surface Impeller can render to. The surface must be created as late as possible and discarded immediately after rendering to it.
- Parameters
-
[in] | context | The context |
[in] | layer | The layer whose current drawable to wrap to create a surface. |
- Returns
- A pointer to the wrapped surface or null.
Definition at line 25 of file surface_mtl.mm.
28 TRACE_EVENT0(
"impeller",
"SurfaceMTL::WrapCurrentMetalLayerDrawable");
30 if (context ==
nullptr || !context->IsValid() || layer == nil) {
34 id<CAMetalDrawable> current_drawable = nil;
36 TRACE_EVENT0(
"impeller",
"WaitForNextDrawable");
37 current_drawable = [layer nextDrawable];
40 if (!current_drawable) {
44 return current_drawable;
References VALIDATION_LOG.
◆ MakeFromMetalLayerDrawable()
std::unique_ptr< SurfaceMTL > impeller::SurfaceMTL::MakeFromMetalLayerDrawable |
( |
const std::shared_ptr< Context > & |
context, |
|
|
id< CAMetalDrawable > |
drawable, |
|
|
std::optional< IRect > |
clip_rect = std::nullopt |
|
) |
| |
|
static |
◆ MakeFromTexture()
std::unique_ptr< SurfaceMTL > impeller::SurfaceMTL::MakeFromTexture |
( |
const std::shared_ptr< Context > & |
context, |
|
|
id< MTLTexture > |
texture, |
|
|
std::optional< IRect > |
clip_rect, |
|
|
id< CAMetalDrawable > |
drawable = nil |
|
) |
| |
|
static |
Definition at line 131 of file surface_mtl.mm.
136 bool partial_repaint_blit_required = ShouldPerformPartialRepaint(clip_rect);
143 partial_repaint_blit_required, clip_rect);
144 if (!render_target) {
151 auto source_texture = partial_repaint_blit_required
152 ? render_target->GetRenderTargetTexture()
157 std::shared_ptr<Texture> destination_texture;
158 if (partial_repaint_blit_required) {
162 auto destination_descriptor =
163 render_target->GetRenderTargetTexture()->GetTextureDescriptor();
164 destination_descriptor.size = {
static_cast<ISize::Type>(texture.width),
170 destination_texture = render_target->GetRenderTargetTexture();
173 return std::unique_ptr<SurfaceMTL>(
new SurfaceMTL(
176 render_target->GetRenderTargetTexture(),
180 partial_repaint_blit_required,
References drawable(), impeller::TextureMTL::Wrapper(), and impeller::WrapTextureWithRenderTarget().
Referenced by MakeFromMetalLayerDrawable().
◆ Present()
bool impeller::SurfaceMTL::Present |
( |
| ) |
const |
|
overridevirtual |
Reimplemented from impeller::Surface.
Definition at line 226 of file surface_mtl.mm.
227 auto context = context_.lock();
232 if (requires_blit_) {
233 if (!(source_texture_ && destination_texture_)) {
237 auto blit_command_buffer = context->CreateCommandBuffer();
238 if (!blit_command_buffer) {
241 auto blit_pass = blit_command_buffer->CreateBlitPass();
242 if (!clip_rect_.has_value()) {
246 blit_pass->AddCopy(source_texture_, destination_texture_, std::nullopt,
247 clip_rect_->GetOrigin());
248 blit_pass->EncodeCommands(context->GetResourceAllocator());
249 if (!context->GetCommandQueue()->Submit({blit_command_buffer}).ok()) {
253 #ifdef IMPELLER_DEBUG
255 #endif // IMPELLER_DEBUG
258 id<MTLCommandBuffer> command_buffer =
262 id<CAMetalDrawable> metal_drawable =
263 reinterpret_cast<id<CAMetalDrawable>
>(drawable_);
265 [(id<FlutterMetalDrawable>)metal_drawable
266 flutterPrepareForPresent:command_buffer];
272 if ([[NSThread currentThread] isMainThread] ||
273 [[MTLCaptureManager sharedCaptureManager] isCapturing]) {
274 TRACE_EVENT0(
"flutter",
"waitUntilScheduled");
275 [command_buffer commit];
276 [command_buffer waitUntilScheduled];
281 id<CAMetalDrawable>
drawable = drawable_;
282 [command_buffer addScheduledHandler:^(id<MTLCommandBuffer> buffer) {
285 [command_buffer commit];
References impeller::BackendCast< ContextMTL, Context >::Cast(), impeller::ContextMTL::CreateMTLCommandBuffer(), drawable(), and VALIDATION_LOG.
The documentation for this class was generated from the following files: