Flutter Engine
The Flutter Engine
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
5#include "flutter/flow/surface_frame.h"
6
7#include <limits>
8#include <utility>
9
10#include "flutter/fml/logging.h"
11#include "flutter/fml/trace_event.h"
12
15
16namespace flutter {
17
19 FramebufferInfo framebuffer_info,
20 const SubmitCallback& submit_callback,
21 SkISize frame_size,
22 std::unique_ptr<GLContextResult> context_result,
23 bool display_list_fallback)
24 : surface_(std::move(surface)),
25 framebuffer_info_(framebuffer_info),
26 submit_callback_(submit_callback),
27 context_result_(std::move(context_result)) {
28 FML_DCHECK(submit_callback_);
29 if (surface_) {
30#if !SLIMPELLER
31 adapter_.set_canvas(surface_->getCanvas());
32 canvas_ = &adapter_;
33#else // !SLIMPELLER
34 FML_LOG(FATAL) << "Impeller opt-out unavailable.";
35 return;
36#endif // !SLIMPELLER
37 } else if (display_list_fallback) {
38 FML_DCHECK(!frame_size.isEmpty());
39 // The root frame of a surface will be filled by the layer_tree which
40 // performs branch culling so it will be unlikely to need an rtree for
41 // further culling during `DisplayList::Dispatch`. Further, this canvas
42 // will live underneath any platform views so we do not need to compute
43 // exact coverage to describe "pixel ownership" to the platform.
44 dl_builder_ = sk_make_sp<DisplayListBuilder>(SkRect::Make(frame_size),
45 /*prepare_rtree=*/false);
46 canvas_ = dl_builder_.get();
47 }
48}
49
51 TRACE_EVENT0("flutter", "SurfaceFrame::Submit");
52 if (submitted_) {
53 return false;
54 }
55
56 submitted_ = PerformSubmit();
57
58 return submitted_;
59}
60
62 return submitted_;
63}
64
66 return canvas_;
67}
68
70 return surface_;
71}
72
73bool SurfaceFrame::PerformSubmit() {
74 if (submit_callback_ == nullptr) {
75 return false;
76 }
77
78 if (submit_callback_(*this, Canvas())) {
79 return true;
80 }
81
82 return false;
83}
84
86 TRACE_EVENT0("impeller", "SurfaceFrame::BuildDisplayList");
87 return dl_builder_ ? dl_builder_->Build() : nullptr;
88}
89
90} // namespace flutter
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
void set_canvas(SkCanvas *canvas)
Definition: dl_sk_canvas.cc:39
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:27
SurfaceFrame(sk_sp< SkSurface > surface, FramebufferInfo framebuffer_info, const SubmitCallback &submit_callback, SkISize frame_size, std::unique_ptr< GLContextResult > context_result=nullptr, bool display_list_fallback=false)
sk_sp< DisplayList > BuildDisplayList()
sk_sp< SkSurface > SkiaSurface() const
bool IsSubmitted() const
VkSurfaceKHR surface
Definition: main.cc:49
#define FATAL(error)
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
EGLSurface surface_
Definition: ref_ptr.h:256
Definition: SkSize.h:16
bool isEmpty() const
Definition: SkSize.h:31
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131