| Flutter Impeller |

surface_mtl.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #pragma once
6
7 #include <QuartzCore/CAMetalLayer.h>
8 #include <memory>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/geometry/rect.h"
12 #include "impeller/renderer/context.h"
13 #include "impeller/renderer/surface.h"
14
15 namespace impeller {
16
17 class SurfaceMTL final : public Surface {
18 public:
19 #pragma GCC diagnostic push
20 // Disable the diagnostic for iOS Simulators. Metal without emulation isn't
21 // available prior to iOS 13 and that's what the simulator headers say when
22 // support for CAMetalLayer begins. CAMetalLayer is available on iOS 8.0 and
23 // above which is well below Flutters support level.
24 #pragma GCC diagnostic ignored "-Wunguarded-availability-new"
25 //----------------------------------------------------------------------------
26 /// @brief Wraps the current drawable of the given Metal layer to create
27 /// a surface Impeller can render to. The surface must be created
28 /// as late as possible and discarded immediately after rendering
29 /// to it.
30 ///
31 /// @param[in] context The context
32 /// @param[in] layer The layer whose current drawable to wrap to create a
33 /// surface.
34 ///
35 /// @return A pointer to the wrapped surface or null.
36 ///
37 static id<CAMetalDrawable> GetMetalDrawableAndValidate(
38 const std::shared_ptr<Context>& context,
39 CAMetalLayer* layer);
40
41 static std::unique_ptr<SurfaceMTL> MakeFromMetalLayerDrawable(
42 const std::shared_ptr<Context>& context,
43 id<CAMetalDrawable> drawable,
44 std::optional<IRect> clip_rect = std::nullopt);
45
46 static std::unique_ptr<SurfaceMTL> MakeFromTexture(
47 const std::shared_ptr<Context>& context,
48 id<MTLTexture> texture,
49 std::optional<IRect> clip_rect,
50 id<CAMetalDrawable> drawable = nil);
51 #pragma GCC diagnostic pop
52
53 // |Surface|
54 ~SurfaceMTL() override;
55
56 id<MTLDrawable> drawable() const { return drawable_; }
57
58 // Returns a Rect defining the area of the surface in device pixels
59 IRect coverage() const;
60
61 // |Surface|
62 bool Present() const override;
63
64 private:
65 std::weak_ptr<Context> context_;
66 std::shared_ptr<Texture> resolve_texture_;
67 id<CAMetalDrawable> drawable_ = nil;
68 std::shared_ptr<Texture> source_texture_;
69 std::shared_ptr<Texture> destination_texture_;
70 bool requires_blit_ = false;
71 std::optional<IRect> clip_rect_;
72
73 static bool ShouldPerformPartialRepaint(std::optional<IRect> damage_rect);
74
75 SurfaceMTL(const std::weak_ptr<Context>& context,
76 const RenderTarget& target,
77 std::shared_ptr<Texture> resolve_texture,
78 id<CAMetalDrawable> drawable,
79 std::shared_ptr<Texture> source_texture,
80 std::shared_ptr<Texture> destination_texture,
81 bool requires_blit,
82 std::optional<IRect> clip_rect);
83
84 FML_DISALLOW_COPY_AND_ASSIGN(SurfaceMTL);
85 };
86
87 } // namespace impeller
impeller::SurfaceMTL
Definition: surface_mtl.h:17
impeller::SurfaceMTL::coverage
IRect coverage() const
Definition: surface_mtl.mm:217
impeller::Surface
Definition: surface.h:17
surface.h
impeller::SurfaceMTL::~SurfaceMTL
~SurfaceMTL() override
impeller::SurfaceMTL::MakeFromMetalLayerDrawable
static std::unique_ptr< SurfaceMTL > MakeFromMetalLayerDrawable(const std::shared_ptr< Context > &context, id< CAMetalDrawable > drawable, std::optional< IRect > clip_rect=std::nullopt)
Definition: surface_mtl.mm:119
impeller::RenderTarget
Definition: render_target.h:48
impeller::SurfaceMTL::MakeFromTexture
static std::unique_ptr< SurfaceMTL > MakeFromTexture(const std::shared_ptr< Context > &context, id< MTLTexture > texture, std::optional< IRect > clip_rect, id< CAMetalDrawable > drawable=nil)
Definition: surface_mtl.mm:127
impeller::SurfaceMTL::drawable
id< MTLDrawable > drawable() const
Definition: surface_mtl.h:56
rect.h
impeller::SurfaceMTL::GetMetalDrawableAndValidate
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....
Definition: surface_mtl.mm:21
context.h
impeller
Definition: aiks_context.cc:10
impeller::TRect< int64_t >
impeller::SurfaceMTL::Present
bool Present() const override
Definition: surface_mtl.mm:222