| 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/fml/concurrent_message_loop.h"
13 #include "flutter/fml/macros.h"
14 #include "flutter/fml/platform/darwin/scoped_nsobject.h"
15 #include "flutter/fml/synchronization/sync_switch.h"
16 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
17 #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
18 #include "impeller/display_list/aiks_context.h"
19 #include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
20
21 namespace impeller {
22 class Context;
23 } // namespace impeller
24
25 namespace flutter {
26
27 //------------------------------------------------------------------------------
28 /// @brief Manages the lifetime of the on-screen and off-screen rendering
29 /// contexts on iOS. On-screen contexts are used by Flutter for
30 /// rendering into the surface. The lifecycle of this context may be
31 /// tied to the lifecycle of the surface. On the other hand, the
32 /// lifecycle of the off-screen context it tied to that of the
33 /// platform view. This one object used to manage both context
34 /// because GPU handles may need to be shared between the two
35 /// context. To achieve this, context may need references to one
36 /// another at creation time. This one object manages the creation,
37 /// use and collection of both contexts in a client rendering API
38 /// agnostic manner.
39 ///
40 class IOSContext {
41 public:
42 //----------------------------------------------------------------------------
43 /// @brief Create an iOS context object capable of creating the on-screen
44 /// and off-screen GPU context for use by Skia.
45 ///
46 /// In case the engine does not support the specified client
47 /// rendering API, this a `nullptr` may be returned.
48 ///
49 /// @param[in] api A client rendering API supported by the
50 /// engine/platform.
51 /// @param[in] backend A client rendering backend supported by the
52 /// engine/platform.
53 ///
54 /// @return A valid context on success. `nullptr` on failure.
55 ///
56 static std::unique_ptr<IOSContext> Create(
57 IOSRenderingAPI api,
58 IOSRenderingBackend backend,
59 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch);
60
61 //----------------------------------------------------------------------------
62 /// @brief Collects the context object. This must happen on the thread on
63 /// which this object was created.
64 ///
65 virtual ~IOSContext();
66
67 //----------------------------------------------------------------------------
68 /// @brief Get the rendering backend used by this context.
69 ///
70 /// @return The rendering backend.
71 ///
72 virtual IOSRenderingBackend GetBackend() const;
73
74 //----------------------------------------------------------------------------
75 /// @brief Create a resource context for use on the IO task runner. This
76 /// resource context is used by Skia to upload texture to
77 /// asynchronously and collect resources that are no longer needed
78 /// on the render task runner.
79 ///
80 /// @attention Client rendering APIs for which a GrDirectContext cannot be realized
81 /// (software rendering), this method will always return null.
82 ///
83 /// @return A non-null Skia context on success. `nullptr` on failure.
84 ///
85 virtual sk_sp<GrDirectContext> CreateResourceContext() = 0;
86
87 //----------------------------------------------------------------------------
88 /// @brief When using client rendering APIs whose contexts need to be
89 /// bound to a specific thread, the engine will call this method
90 /// to give the on-screen context a chance to bind to the current
91 /// thread.
92 ///
93 /// @attention Client rendering APIs that have no-concept of thread local
94 /// bindings (anything that is not OpenGL) will always return
95 /// `true`.
96 ///
97 /// @attention Client rendering APIs for which a GrDirectContext cannot be created
98 /// (software rendering) will always return `false`.
99 ///
100 /// @attention This binds the on-screen context to the current thread. To
101 /// bind the off-screen context to the thread, use the
102 /// `ResoruceMakeCurrent` method instead.
103 ///
104 /// @attention Only one context may be bound to a thread at any given time.
105 /// Making a binding on a thread, clears the old binding.
106 ///
107 /// @return A GLContextResult that represents the result of the method.
108 /// The GetResult() returns a bool that indicates If the on-screen context could be
109 /// bound to the current
110 /// thread.
111 ///
112 virtual std::unique_ptr<GLContextResult> MakeCurrent() = 0;
113
114 //----------------------------------------------------------------------------
115 /// @brief Creates an external texture proxy of the appropriate client
116 /// rendering API.
117 ///
118 /// @param[in] texture_id The texture identifier
119 /// @param[in] texture The texture
120 ///
121 /// @return The texture proxy if the rendering backend supports embedder
122 /// provided external textures.
123 ///
124 virtual std::unique_ptr<Texture> CreateExternalTexture(
125 int64_t texture_id,
126 fml::scoped_nsobject<NSObject<FlutterTexture>> texture) = 0;
127
128 //----------------------------------------------------------------------------
129 /// @brief Accessor for the Skia context associated with IOSSurfaces and
130 /// the raster thread.
131 /// @details There can be any number of resource contexts but this is the
132 /// one context that will be used by surfaces to draw to the
133 /// screen from the raster thread.
134 /// @returns `nullptr` on failure.
135 /// @attention The software context doesn't have a Skia context, so this
136 /// value will be nullptr.
137 /// @see For contexts which are used for offscreen work like loading
138 /// textures see IOSContext::CreateResourceContext.
139 ///
140 virtual sk_sp<GrDirectContext> GetMainContext() const = 0;
141
142 virtual std::shared_ptr<impeller::Context> GetImpellerContext() const;
143
144 virtual std::shared_ptr<impeller::AiksContext> GetAiksContext() const;
145
146 protected:
147 explicit IOSContext();
148
149 private:
150 FML_DISALLOW_COPY_AND_ASSIGN(IOSContext);
151 };
152
153 } // namespace flutter
154
155 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_H_
flutter::IOSContext::~IOSContext
virtual ~IOSContext()
Collects the context object. This must happen on the thread on which this object was created.
FlutterTexture.h
flutter::IOSContext
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition: ios_context.h:40
flutter::IOSRenderingBackend
IOSRenderingBackend
Definition: rendering_api_selection.h:19
flutter::IOSContext::GetAiksContext
virtual std::shared_ptr< impeller::AiksContext > GetAiksContext() const
Definition: ios_context.mm:66
flutter
Definition: accessibility_bridge.h:28
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition: rendering_api_selection.h:14
flutter::IOSContext::MakeCurrent
virtual std::unique_ptr< GLContextResult > MakeCurrent()=0
When using client rendering APIs whose contexts need to be bound to a specific thread,...
flutter::IOSContext::GetBackend
virtual IOSRenderingBackend GetBackend() const
Get the rendering backend used by this context.
Definition: ios_context.mm:58
flutter::IOSContext::GetMainContext
virtual sk_sp< GrDirectContext > GetMainContext() const =0
Accessor for the Skia context associated with IOSSurfaces and the raster thread.
rendering_api_selection.h
flutter::IOSContext::CreateResourceContext
virtual sk_sp< GrDirectContext > CreateResourceContext()=0
Create a resource context for use on the IO task runner. This resource context is used by Skia to upl...
flutter::IOSContext::IOSContext
IOSContext()
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
impeller
Definition: ios_context.h:21
flutter::IOSContext::Create
static std::unique_ptr< IOSContext > Create(IOSRenderingAPI api, IOSRenderingBackend backend, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by ...
Definition: ios_context.mm:23
flutter::IOSContext::CreateExternalTexture
virtual std::unique_ptr< Texture > CreateExternalTexture(int64_t texture_id, fml::scoped_nsobject< NSObject< FlutterTexture >> texture)=0
Creates an external texture proxy of the appropriate client rendering API.
flutter::IOSContext::GetImpellerContext
virtual std::shared_ptr< impeller::Context > GetImpellerContext() const
Definition: ios_context.mm:62