Flutter Engine
 
Loading...
Searching...
No Matches
surface_frame.cc
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
6
7#include <limits>
8#include <utility>
9
11#include "flutter/fml/logging.h"
13
14#include "third_party/skia/include/core/SkSurface.h"
15
16namespace flutter {
17
18SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
19 FramebufferInfo framebuffer_info,
20 const EncodeCallback& encode_callback,
21 const SubmitCallback& submit_callback,
22 DlISize frame_size,
23 std::unique_ptr<GLContextResult> context_result,
24 bool display_list_fallback)
25 : surface_(std::move(surface)),
26 framebuffer_info_(framebuffer_info),
27 encode_callback_(encode_callback),
28 submit_callback_(submit_callback),
29 context_result_(std::move(context_result)) {
30 FML_DCHECK(submit_callback_);
31 if (surface_) {
32#if !SLIMPELLER
33 adapter_.set_canvas(surface_->getCanvas());
34 canvas_ = &adapter_;
35#else // !SLIMPELLER
36 FML_LOG(FATAL) << "Impeller opt-out unavailable.";
37 return;
38#endif // !SLIMPELLER
39 } else if (display_list_fallback) {
40 FML_DCHECK(!frame_size.IsEmpty());
41 // The root frame of a surface will be filled by the layer_tree which
42 // performs branch culling so it will be unlikely to need an rtree for
43 // further culling during `DisplayList::Dispatch`. Further, this canvas
44 // will live underneath any platform views so we do not need to compute
45 // exact coverage to describe "pixel ownership" to the platform.
46 dl_builder_ = sk_make_sp<DisplayListBuilder>(DlRect::MakeSize(frame_size),
47 /*prepare_rtree=*/false);
48 canvas_ = dl_builder_.get();
49 }
50}
51
53 TRACE_EVENT0("flutter", "SurfaceFrame::Encode");
54 if (encoded_) {
55 return false;
56 }
57
58 encoded_ = PerformEncode();
59
60 return encoded_;
61}
62
64 TRACE_EVENT0("flutter", "SurfaceFrame::Submit");
65 if (!encoded_ && !Encode()) {
66 return false;
67 }
68
69 if (submitted_) {
70 return false;
71 }
72
73 submitted_ = PerformSubmit();
74
75 return submitted_;
76}
77
79 return submitted_;
80}
81
83 return canvas_;
84}
85
86sk_sp<SkSurface> SurfaceFrame::SkiaSurface() const {
87 return surface_;
88}
89
90bool SurfaceFrame::PerformEncode() {
91 if (encode_callback_ == nullptr) {
92 return false;
93 }
94
95 if (encode_callback_(*this, Canvas())) {
96 return true;
97 }
98
99 return false;
100}
101
102bool SurfaceFrame::PerformSubmit() {
103 if (submit_callback_ == nullptr) {
104 return false;
105 }
106
107 if (submit_callback_(*this)) {
108 return true;
109 }
110
111 return false;
112}
113
114sk_sp<DisplayList> SurfaceFrame::BuildDisplayList() {
115 TRACE_EVENT0("impeller", "SurfaceFrame::BuildDisplayList");
116 return dl_builder_ ? dl_builder_->Build() : nullptr;
117}
118
119} // namespace flutter
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
void set_canvas(SkCanvas *canvas)
sk_sp< DisplayList > BuildDisplayList()
sk_sp< SkSurface > SkiaSurface() const
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
SurfaceFrame(sk_sp< SkSurface > surface, FramebufferInfo framebuffer_info, const EncodeCallback &encode_callback, const SubmitCallback &submit_callback, DlISize frame_size, std::unique_ptr< GLContextResult > context_result=nullptr, bool display_list_fallback=false)
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
#define FML_DCHECK(condition)
Definition logging.h:122
EGLSurface surface_
Definition ref_ptr.h:261
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition size.h:123
#define TRACE_EVENT0(category_group, name)