Flutter Engine
 
Loading...
Searching...
No Matches
surface_frame.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_FLOW_SURFACE_FRAME_H_
6#define FLUTTER_FLOW_SURFACE_FRAME_H_
7
8#include <memory>
9#include <optional>
10
14#include "flutter/fml/macros.h"
16
17#include "third_party/skia/include/core/SkSurface.h"
18
19namespace impeller {
20class Surface;
21}
22
23namespace flutter {
24
25// This class represents a frame that has been fully configured for the
26// underlying client rendering API. A frame may only be submitted once.
28 public:
30 std::function<bool(SurfaceFrame& surface_frame, DlCanvas* canvas)>;
31 using SubmitCallback = std::function<bool(SurfaceFrame& surface_frame)>;
32
33 // Information about the underlying framebuffer
35 // Indicates whether or not the surface supports pixel readback as used in
36 // circumstances such as a BackdropFilter.
37 bool supports_readback = false;
38
39 // Indicates that target device supports partial repaint. At very minimum
40 // this means that the surface will provide valid existing damage.
42
43 // For some targets it may be beneficial or even required to snap clip
44 // rect to tile grid. I.e. repainting part of a tile may cause performance
45 // degradation if the tile needs to be decompressed first.
48
49 // This is the area of framebuffer that lags behind the front buffer.
50 //
51 // Correctly providing exiting_damage is necessary for supporting double and
52 // triple buffering. Embedder is responsible for tracking this area for each
53 // of the back buffers used. When doing partial redraw, this area will be
54 // repainted alongside of dirty area determined by diffing current and
55 // last successfully rasterized layer tree;
56 //
57 // If existing damage is unspecified (nullopt), entire frame will be
58 // rasterized (no partial redraw). To signal that there is no existing
59 // damage use an empty DlIRect.
60 std::optional<DlIRect> existing_damage = std::nullopt;
61 };
62
63 SurfaceFrame(sk_sp<SkSurface> surface,
65 const EncodeCallback& encode_callback,
66 const SubmitCallback& submit_callback,
67 DlISize frame_size,
68 std::unique_ptr<GLContextResult> context_result = nullptr,
69 bool display_list_fallback = false);
70
71 struct SubmitInfo {
72 // The frame damage for frame n is the difference between frame n and
73 // frame (n-1), and represents the area that a compositor must recompose.
74 //
75 // Corresponds to EGL_KHR_swap_buffers_with_damage
76 std::optional<DlIRect> frame_damage;
77
78 // The buffer damage for a frame is the area changed since that same buffer
79 // was last used. If the buffer has not been used before, the buffer damage
80 // is the entire area of the buffer.
81 //
82 // Corresponds to EGL_KHR_partial_update
83 std::optional<DlIRect> buffer_damage;
84
85 // Time at which this frame is scheduled to be presented. This is a hint
86 // that can be passed to the platform to drop queued frames.
87 std::optional<fml::TimePoint> presentation_time;
88
89 // Whether this surface frame represents the last in a group frames that
90 // were submitted as part of a platform compositor interop step, such as
91 // during iOS platform view compositing.
92 //
93 // Defaults to true, which is generally a safe value.
94 bool frame_boundary = true;
95
96 // Whether this surface presents with a CATransaction on Apple platforms.
97 //
98 // When there are platform views in the scene, the drawable needs to be
99 // presented in the same CATransaction as the one created for platform view
100 // mutations.
101 //
102 // If the drawables are being presented from the raster thread, we cannot
103 // use a transaction as it will dirty the UIViews being presented. If there
104 // is a non-Flutter UIView active, such as in add2app or a
105 // presentViewController page transition, then this will cause CoreAnimation
106 // assertion errors and exit the app.
108 };
109
110 bool Encode();
111
112 bool Submit();
113
114 bool IsSubmitted() const;
115
116 sk_sp<SkSurface> SkiaSurface() const;
117
118 DlCanvas* Canvas();
119
120 const FramebufferInfo& framebuffer_info() const { return framebuffer_info_; }
121
123 submit_info_ = submit_info;
124 }
125 const SubmitInfo& submit_info() const { return submit_info_; }
126
127 sk_sp<DisplayList> BuildDisplayList();
128
129 void set_user_data(std::shared_ptr<impeller::Surface> data) {
130 user_data_ = std::move(data);
131 }
132
133 std::shared_ptr<impeller::Surface> take_user_data() {
134 return std::move(user_data_);
135 }
136
137 private:
138 bool submitted_ = false;
139 bool encoded_ = false;
140
141#if !SLIMPELLER
142 DlSkCanvasAdapter adapter_;
143#endif // !SLIMPELLER
144 sk_sp<DisplayListBuilder> dl_builder_;
145 sk_sp<SkSurface> surface_;
146 DlCanvas* canvas_ = nullptr;
147 FramebufferInfo framebuffer_info_;
148 SubmitInfo submit_info_;
149 EncodeCallback encode_callback_;
150 SubmitCallback submit_callback_;
151 std::shared_ptr<impeller::Surface> user_data_;
152 std::unique_ptr<GLContextResult> context_result_;
153
154 bool PerformSubmit();
155
156 bool PerformEncode();
157
159};
160
161} // namespace flutter
162
163#endif // FLUTTER_FLOW_SURFACE_FRAME_H_
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
Backend implementation of |DlCanvas| for |SkCanvas|.
void set_submit_info(const SubmitInfo &submit_info)
sk_sp< DisplayList > BuildDisplayList()
std::shared_ptr< impeller::Surface > take_user_data()
sk_sp< SkSurface > SkiaSurface() const
void set_user_data(std::shared_ptr< impeller::Surface > data)
const FramebufferInfo & framebuffer_info() const
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
const SubmitInfo & submit_info() const
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
std::optional< DlIRect > existing_damage
std::optional< DlIRect > frame_damage
std::optional< DlIRect > buffer_damage
std::optional< fml::TimePoint > presentation_time