Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
surface_pool.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_EXTERNAL_VIEW_EMBEDDER_SURFACE_POOL_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_VIEW_EMBEDDER_SURFACE_POOL_H_
7
8#include <mutex>
9
10#include "flutter/flow/surface.h"
11#include "flutter/shell/platform/android/context/android_context.h"
12#include "flutter/shell/platform/android/surface/android_surface.h"
13
14namespace flutter {
15
16//------------------------------------------------------------------------------
17/// An Overlay layer represents an `android.view.View` in the C side.
18///
19/// The `id` is used to uniquely identify the layer and recycle it between
20/// frames.
21///
23 OverlayLayer(int id,
24 std::unique_ptr<AndroidSurface> android_surface,
25 std::unique_ptr<Surface> surface);
26
28
29 // A unique id to identify the overlay when it gets recycled.
30 const int id;
31
32 // A GPU surface.
33 const std::unique_ptr<AndroidSurface> android_surface;
34
35 // A GPU surface. This may change when the overlay is recycled.
36 std::unique_ptr<Surface> surface;
37
38 // The `GrContext` that is currently used by the overlay surfaces.
39 // We track this to know when the GrContext for the Flutter app has changed
40 // so we can update the overlay with the new context.
41 //
42 // This may change when the overlay is recycled.
44};
45
47 public:
49
51
52 // Gets a layer from the pool if available, or allocates a new one.
53 // Finally, it marks the layer as used. That is, it increments
54 // `available_layer_index_`.
55 std::shared_ptr<OverlayLayer> GetLayer(
56 GrDirectContext* gr_context,
57 const AndroidContext& android_context,
58 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
59 const std::shared_ptr<AndroidSurfaceFactory>& surface_factory);
60
61 // Gets the layers in the pool that aren't currently used.
62 // This method doesn't mark the layers as unused.
63 std::vector<std::shared_ptr<OverlayLayer>> GetUnusedLayers();
64
65 // Marks the layers in the pool as available for reuse.
66 void RecycleLayers();
67
68 // Destroys all the layers in the pool.
69 void DestroyLayers(const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
70
71 // Sets the frame size used by the layers in the pool.
72 // If the current layers in the pool have a different frame size,
73 // then they are deallocated as soon as |GetLayer| is called.
74 void SetFrameSize(SkISize frame_size);
75
76 // Returns true if the current pool has layers in use.
77 bool HasLayers();
78
79 private:
80 // The index of the entry in the layers_ vector that determines the beginning
81 // of the unused layers. For example, consider the following vector:
82 // _____
83 // | 0 |
84 // |---|
85 // | 1 | <-- `available_layer_index_`
86 // |---|
87 // | 2 |
88 // |---|
89 //
90 // This indicates that entries starting from 1 can be reused meanwhile the
91 // entry at position 0 cannot be reused.
92 size_t available_layer_index_ = 0;
93
94 // The layers in the pool.
95 std::vector<std::shared_ptr<OverlayLayer>> layers_;
96
97 // The frame size of the layers in the pool.
98 SkISize current_frame_size_;
99
100 // The frame size to be used by future layers.
101 SkISize requested_frame_size_;
102
103 // Used to guard public methods.
104 std::mutex mutex_;
105
106 void DestroyLayersLocked(
107 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade);
108};
109
110} // namespace flutter
111
112#endif // FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_VIEW_EMBEDDER_SURFACE_POOL_H_
Holds state that is shared across Android surfaces.
void DestroyLayers(const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
void SetFrameSize(SkISize frame_size)
std::vector< std::shared_ptr< OverlayLayer > > GetUnusedLayers()
std::shared_ptr< OverlayLayer > GetLayer(GrDirectContext *gr_context, const AndroidContext &android_context, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, const std::shared_ptr< AndroidSurfaceFactory > &surface_factory)
const std::unique_ptr< AndroidSurface > android_surface
std::unique_ptr< Surface > surface