Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
android_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_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
7
8#include "common/settings.h"
9#include "flutter/fml/macros.h"
10#include "flutter/fml/task_runner.h"
11#include "flutter/impeller/renderer/context.h"
13
14namespace flutter {
15
16//------------------------------------------------------------------------------
17/// @brief Holds state that is shared across Android surfaces.
18///
20 public:
21 explicit AndroidContext(AndroidRenderingAPI rendering_api);
22
23 virtual ~AndroidContext();
24
26
27 virtual bool IsValid() const;
28
29 //----------------------------------------------------------------------------
30 /// @brief Setter for the Skia context to be used by subsequent
31 /// AndroidSurfaces.
32 /// @details This is useful to reduce memory consumption when creating
33 /// multiple AndroidSurfaces for the same AndroidContext.
34 ///
35 /// The first AndroidSurface should set this for the
36 /// AndroidContext if the AndroidContext does not yet have a
37 /// Skia context to share via GetMainSkiaContext.
38 ///
39 void SetMainSkiaContext(const sk_sp<GrDirectContext>& main_context);
40
41 //----------------------------------------------------------------------------
42 /// @brief Accessor for the Skia context associated with AndroidSurfaces
43 /// and the raster thread.
44 /// @details This context is created lazily by the AndroidSurface based
45 /// on their respective rendering backend and set on this
46 /// AndroidContext to share via SetMainSkiaContext.
47 /// @returns `nullptr` when no Skia context has been set yet by its
48 /// AndroidSurface via SetMainSkiaContext.
49 /// @attention The software context doesn't have a Skia context, so this
50 /// value will be nullptr.
51 ///
53
54 //----------------------------------------------------------------------------
55 /// @brief Accessor for the Impeller context associated with
56 /// AndroidSurfaces and the raster thread.
57 ///
58 std::shared_ptr<impeller::Context> GetImpellerContext() const;
59
60 protected:
61 /// Intended to be called from a subclass constructor after setup work for the
62 /// context has completed.
63 void SetImpellerContext(const std::shared_ptr<impeller::Context>& context);
64
65 private:
66 const AndroidRenderingAPI rendering_api_;
67
68 // This is the Skia context used for on-screen rendering.
69 sk_sp<GrDirectContext> main_context_;
70
71 std::shared_ptr<impeller::Context> impeller_context_;
72
74};
75
76} // namespace flutter
77
78#endif // FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
Holds state that is shared across Android surfaces.
void SetMainSkiaContext(const sk_sp< GrDirectContext > &main_context)
Setter for the Skia context to be used by subsequent AndroidSurfaces.
AndroidRenderingAPI RenderingApi() const
sk_sp< GrDirectContext > GetMainSkiaContext() const
Accessor for the Skia context associated with AndroidSurfaces and the raster thread.
virtual bool IsValid() const
void SetImpellerContext(const std::shared_ptr< impeller::Context > &context)
std::shared_ptr< impeller::Context > GetImpellerContext() const
Accessor for the Impeller context associated with AndroidSurfaces and the raster thread.
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
AndroidRenderingAPI
Definition settings.h:26