Skip to content

Commit 96c7599

Browse files
chinmaygardekjlubick
authored andcommitted
[Impeller] Document impeller::Context. (flutter#43389)
1 parent 348f3c3 commit 96c7599

File tree

1 file changed

+93
-2
lines changed

1 file changed

+93
-2
lines changed

impeller/renderer/context.h

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,122 @@ class CommandBuffer;
1919
class PipelineLibrary;
2020
class Allocator;
2121

22+
//------------------------------------------------------------------------------
23+
/// @brief To do anything rendering related with Impeller, you need a
24+
/// context.
25+
///
26+
/// Contexts are expensive to construct and typically you only need
27+
/// one in the process. The context represents a connection to a
28+
/// graphics or compute accelerator on the device.
29+
///
30+
/// If there are multiple context in a process, it would typically
31+
/// be for separation of concerns (say, use with multiple engines in
32+
/// Flutter), talking to multiple accelerators, or talking to the
33+
/// same accelerator using different client APIs (Metal, Vulkan,
34+
/// OpenGL ES, etc..).
35+
///
36+
/// Contexts are thread-safe. They may be created, used, and
37+
/// collected (though not from a thread used by an internal pool) on
38+
/// any thread. They may also be accessed simultaneously from
39+
/// multiple threads.
40+
///
41+
/// Contexts are abstract and a concrete instance must be created
42+
/// using one of the subclasses of `Context` in
43+
/// `//impeller/renderer/backend`.
2244
class Context {
2345
public:
46+
//----------------------------------------------------------------------------
47+
/// @brief Destroys an Impeller context.
48+
///
2449
virtual ~Context();
2550

51+
// TODO(129920): Refactor and move to capabilities.
2652
virtual std::string DescribeGpuModel() const = 0;
2753

54+
//----------------------------------------------------------------------------
55+
/// @brief Determines if a context is valid. If the caller ever receives
56+
/// an invalid context, they must discard it and construct a new
57+
/// context. There is no recovery mechanism to repair a bad
58+
/// context.
59+
///
60+
/// It is convention in Impeller to never return an invalid
61+
/// context from a call that returns an pointer to a context. The
62+
/// call implementation performs validity checks itself and return
63+
/// a null context instead of a pointer to an invalid context.
64+
///
65+
/// How a context goes invalid is backend specific. It could
66+
/// happen due to device loss, or any other unrecoverable error.
67+
///
68+
/// @return If the context is valid.
69+
///
2870
virtual bool IsValid() const = 0;
2971

72+
//----------------------------------------------------------------------------
73+
/// @brief Get the capabilities of Impeller context. All optionally
74+
/// supported feature of the platform, client-rendering API, and
75+
/// device can be queried using the `Capabilities`.
76+
///
77+
/// @return The capabilities. Can never be `nullptr` for a valid context.
78+
///
3079
virtual const std::shared_ptr<const Capabilities>& GetCapabilities()
3180
const = 0;
3281

82+
// TODO(129920): Refactor and move to capabilities.
3383
virtual bool UpdateOffscreenLayerPixelFormat(PixelFormat format);
3484

85+
//----------------------------------------------------------------------------
86+
/// @brief Returns the allocator used to create textures and buffers on
87+
/// the device.
88+
///
89+
/// @return The resource allocator. Can never be `nullptr` for a valid
90+
/// context.
91+
///
3592
virtual std::shared_ptr<Allocator> GetResourceAllocator() const = 0;
3693

94+
//----------------------------------------------------------------------------
95+
/// @brief Returns the library of shaders used to specify the
96+
/// programmable stages of a pipeline.
97+
///
98+
/// @return The shader library. Can never be `nullptr` for a valid
99+
/// context.
100+
///
37101
virtual std::shared_ptr<ShaderLibrary> GetShaderLibrary() const = 0;
38102

103+
//----------------------------------------------------------------------------
104+
/// @brief Returns the library of combined image samplers used in
105+
/// shaders.
106+
///
107+
/// @return The sampler library. Can never be `nullptr` for a valid
108+
/// context.
109+
///
39110
virtual std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const = 0;
40111

112+
//----------------------------------------------------------------------------
113+
/// @brief Returns the library of pipelines used by render or compute
114+
/// commands.
115+
///
116+
/// @return The pipeline library. Can never be `nullptr` for a valid
117+
/// context.
118+
///
41119
virtual std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const = 0;
42120

121+
//----------------------------------------------------------------------------
122+
/// @brief Create a new command buffer. Command buffers can be used to
123+
/// encode graphics, blit, or compute commands to be submitted to
124+
/// the device.
125+
///
126+
/// A command buffer can only be used on a single thread.
127+
/// Multi-threaded render, blit, or compute passes must create a
128+
/// new command buffer on each thread.
129+
///
130+
/// @return A new command buffer.
131+
///
43132
virtual std::shared_ptr<CommandBuffer> CreateCommandBuffer() const = 0;
44133

45-
/// @brief Force all pending async work to finish by deleting any owned
46-
/// concurrent message loops.
134+
//----------------------------------------------------------------------------
135+
/// @brief Force all pending asynchronous work to finish. This is
136+
/// achieved by deleting all owned concurrent message loops.
137+
///
47138
virtual void Shutdown() = 0;
48139

49140
protected:

0 commit comments

Comments
 (0)