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