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
13
14#if !SLIMPELLER
15#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
16#else
17#include "third_party/skia/include/core/SkRefCnt.h"
18class GrDirectContext;
19#endif // !SLIMPELLER
20
21namespace flutter {
22
23//------------------------------------------------------------------------------
24/// @brief Holds state that is shared across Android surfaces.
25///
27 public:
28 explicit AndroidContext(AndroidRenderingAPI rendering_api);
29
30 virtual ~AndroidContext();
31
39
40 virtual AndroidRenderingAPI RenderingApi() const;
41
42 virtual bool IsDynamicSelection() const;
43
44 virtual bool IsValid() const;
45
46 //----------------------------------------------------------------------------
47 /// @brief Setter for the Skia context to be used by subsequent
48 /// AndroidSurfaces.
49 /// @details This is useful to reduce memory consumption when creating
50 /// multiple AndroidSurfaces for the same AndroidContext.
51 ///
52 /// The first AndroidSurface should set this for the
53 /// AndroidContext if the AndroidContext does not yet have a
54 /// Skia context to share via GetMainSkiaContext.
55 ///
56 void SetMainSkiaContext(const sk_sp<GrDirectContext>& main_context);
57
58 //----------------------------------------------------------------------------
59 /// @brief Accessor for the Skia context associated with AndroidSurfaces
60 /// and the raster thread.
61 /// @details This context is created lazily by the AndroidSurface based
62 /// on their respective rendering backend and set on this
63 /// AndroidContext to share via SetMainSkiaContext.
64 /// @returns `nullptr` when no Skia context has been set yet by its
65 /// AndroidSurface via SetMainSkiaContext.
66 /// @attention The software context doesn't have a Skia context, so this
67 /// value will be nullptr.
68 ///
69 sk_sp<GrDirectContext> GetMainSkiaContext() const;
70
71 //----------------------------------------------------------------------------
72 /// @brief Accessor for the Impeller context associated with
73 /// AndroidSurfaces and the raster thread.
74 ///
75 virtual std::shared_ptr<impeller::Context> GetImpellerContext() const;
76
77 //----------------------------------------------------------------------------
78 /// @brief Perform deferred setup for the impeller Context.
79 ///
80 virtual void SetupImpellerContext() {}
81
82 protected:
84 const std::shared_ptr<impeller::Context>& impeller_context);
85
86 private:
87 const AndroidRenderingAPI rendering_api_;
88
89 // This is the Skia context used for on-screen rendering.
90 NOT_SLIMPELLER(sk_sp<GrDirectContext> main_context_);
91 std::shared_ptr<impeller::Context> impeller_context_;
92
94};
95
96} // namespace flutter
97
98#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.
virtual 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 > &impeller_context)
virtual std::shared_ptr< impeller::Context > GetImpellerContext() const
Accessor for the Impeller context associated with AndroidSurfaces and the raster thread.
virtual bool IsDynamicSelection() const
virtual void SetupImpellerContext()
Perform deferred setup for the impeller Context.
#define NOT_SLIMPELLER(code)
Definition macros.h:16
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27