Flutter iOS Embedder
ios_context.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 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_H_
7 
8 #include <memory>
9 
10 #include "flutter/common/graphics/gl_context_switch.h"
11 #include "flutter/common/graphics/texture.h"
12 #include "flutter/common/settings.h"
13 #include "flutter/fml/concurrent_message_loop.h"
14 #include "flutter/fml/macros.h"
15 #include "flutter/fml/synchronization/sync_switch.h"
17 #include "impeller/display_list/aiks_context.h"
18 
19 namespace impeller {
20 class Context;
21 } // namespace impeller
22 
23 namespace flutter {
24 
25 //------------------------------------------------------------------------------
26 /// @brief Manages the lifetime of the on-screen and off-screen rendering
27 /// contexts on iOS. On-screen contexts are used by Flutter for
28 /// rendering into the surface. The lifecycle of this context may be
29 /// tied to the lifecycle of the surface. On the other hand, the
30 /// lifecycle of the off-screen context it tied to that of the
31 /// platform view. This one object used to manage both context
32 /// because GPU handles may need to be shared between the two
33 /// context. To achieve this, context may need references to one
34 /// another at creation time. This one object manages the creation,
35 /// use and collection of both contexts in a client rendering API
36 /// agnostic manner.
37 ///
38 class IOSContext {
39  public:
40  //----------------------------------------------------------------------------
41  /// @brief Create an iOS context object capable of creating the on-screen
42  /// and off-screen GPU context for use by Impeller.
43  ///
44  /// @return A valid context on success. `nullptr` on failure.
45  ///
46  static std::unique_ptr<IOSContext> Create(
47  const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch,
48  const Settings& settings);
49 
50  //----------------------------------------------------------------------------
51  /// @brief Collects the context object. This must happen on the thread on
52  /// which this object was created.
53  ///
54  virtual ~IOSContext();
55 
56  //----------------------------------------------------------------------------
57  /// @brief Creates an external texture proxy of the appropriate client
58  /// rendering API.
59  ///
60  /// @param[in] texture_id The texture identifier
61  /// @param[in] texture The texture
62  ///
63  /// @return The texture proxy if the rendering backend supports embedder
64  /// provided external textures.
65  ///
66  virtual std::unique_ptr<Texture> CreateExternalTexture(int64_t texture_id,
67  NSObject<FlutterTexture>* texture) = 0;
68 
69  virtual std::shared_ptr<impeller::Context> GetImpellerContext() const;
70 
71  virtual std::shared_ptr<impeller::AiksContext> GetAiksContext() const;
72 
73  protected:
74  explicit IOSContext();
75 
76  private:
77  FML_DISALLOW_COPY_AND_ASSIGN(IOSContext);
78 };
79 
80 } // namespace flutter
81 
82 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_H_
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition: ios_context.h:38
virtual std::unique_ptr< Texture > CreateExternalTexture(int64_t texture_id, NSObject< FlutterTexture > *texture)=0
Creates an external texture proxy of the appropriate client rendering API.
virtual std::shared_ptr< impeller::Context > GetImpellerContext() const
Definition: ios_context.mm:27
virtual ~IOSContext()
Collects the context object. This must happen on the thread on which this object was created.
virtual std::shared_ptr< impeller::AiksContext > GetAiksContext() const
Definition: ios_context.mm:31
static std::unique_ptr< IOSContext > Create(const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch, const Settings &settings)
Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by ...
Definition: ios_context.mm:21
int64_t texture_id