Flutter Engine
The Flutter Engine
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"
19
20namespace impeller {
21class Context;
22} // namespace impeller
23
24namespace 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///
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(
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 ///
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(
124 int64_t texture_id,
125 fml::scoped_nsobject<NSObject<FlutterTexture>> texture) = 0;
126
127 //----------------------------------------------------------------------------
128 /// @brief Accessor for the Skia context associated with IOSSurfaces and
129 /// the raster thread.
130 /// @details There can be any number of resource contexts but this is the
131 /// one context that will be used by surfaces to draw to the
132 /// screen from the raster thread.
133 /// @returns `nullptr` on failure.
134 /// @attention The software context doesn't have a Skia context, so this
135 /// value will be nullptr.
136 /// @see For contexts which are used for offscreen work like loading
137 /// textures see IOSContext::CreateResourceContext.
138 ///
140
141 virtual std::shared_ptr<impeller::Context> GetImpellerContext() const;
142
143 protected:
144 explicit IOSContext();
145
146 private:
147 FML_DISALLOW_COPY_AND_ASSIGN(IOSContext);
148};
149
150} // namespace flutter
151
152#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_H_
const char * backend
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition: ios_context.h:39
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.
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...
virtual sk_sp< GrDirectContext > GetMainContext() const =0
Accessor for the Skia context associated with IOSSurfaces and the raster thread.
virtual std::unique_ptr< GLContextResult > MakeCurrent()=0
When using client rendering APIs whose contexts need to be bound to a specific thread,...
virtual std::shared_ptr< impeller::Context > GetImpellerContext() const
Definition: ios_context.mm:56
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:21
virtual ~IOSContext()
Collects the context object. This must happen on the thread on which this object was created.
virtual IOSRenderingBackend GetBackend() const
Get the rendering backend used by this context.
Definition: ios_context.mm:52
FlTexture * texture
int64_t texture_id