Flutter Engine
The 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
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 adapter_.set_canvas(surface_->getCanvas());
31 canvas_ = &adapter_;
32 } else if (display_list_fallback) {
33 FML_DCHECK(!frame_size.isEmpty());
34 // The root frame of a surface will be filled by the layer_tree which
35 // performs branch culling so it will be unlikely to need an rtree for
36 // further culling during `DisplayList::Dispatch`. Further, this canvas
37 // will live underneath any platform views so we do not need to compute
38 // exact coverage to describe "pixel ownership" to the platform.
39 dl_builder_ = sk_make_sp<DisplayListBuilder>(SkRect::Make(frame_size),
40 /*prepare_rtree=*/false);
41 canvas_ = dl_builder_.get();
42 }
43}
44
46 TRACE_EVENT0("flutter", "SurfaceFrame::Submit");
47 if (submitted_) {
48 return false;
49 }
50
51 submitted_ = PerformSubmit();
52
53 return submitted_;
54}
55
57 return submitted_;
58}
59
61 return canvas_;
62}
63
65 return surface_;
66}
67
68bool SurfaceFrame::PerformSubmit() {
69 if (submit_callback_ == nullptr) {
70 return false;
71 }
72
73 if (submit_callback_(*this, Canvas())) {
74 return true;
75 }
76
77 return false;
78}
79
81 TRACE_EVENT0("impeller", "SurfaceFrame::BuildDisplayList");
82 return dl_builder_ ? dl_builder_->Build() : nullptr;
83}
84
85} // namespace flutter
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
void set_canvas(SkCanvas *canvas)
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
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
VkSurfaceKHR surface
Definition main.cc:49
#define FML_DCHECK(condition)
Definition logging.h:103
EGLSurface surface_
Definition ref_ptr.h:256
bool isEmpty() const
Definition SkSize.h:31
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
#define TRACE_EVENT0(category_group, name)