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 #include "flutter/fml/logging.h"
7 
8 namespace flutter {
9 
10 SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
11  bool supports_readback,
12  const SubmitCallback& submit_callback)
13  : surface_(surface),
14  supports_readback_(supports_readback),
15  submit_callback_(submit_callback) {
16  FML_DCHECK(submit_callback_);
17 }
18 
19 SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
20  bool supports_readback,
21  const SubmitCallback& submit_callback,
22  std::unique_ptr<GLContextResult> context_result)
23  : submitted_(false),
24  surface_(surface),
25  supports_readback_(supports_readback),
26  submit_callback_(submit_callback),
27  context_result_(std::move(context_result)) {
28  FML_DCHECK(submit_callback_);
29 }
30 
32  if (submit_callback_ && !submitted_) {
33  // Dropping without a Submit.
34  submit_callback_(*this, nullptr);
35  }
36 }
37 
39  if (submitted_) {
40  return false;
41  }
42 
43  submitted_ = PerformSubmit();
44 
45  return submitted_;
46 }
47 
49  return submitted_;
50 }
51 
53  return surface_ != nullptr ? surface_->getCanvas() : nullptr;
54 }
55 
56 sk_sp<SkSurface> SurfaceFrame::SkiaSurface() const {
57  return surface_;
58 }
59 
60 bool SurfaceFrame::PerformSubmit() {
61  if (submit_callback_ == nullptr) {
62  return false;
63  }
64 
65  if (submit_callback_(*this, SkiaCanvas())) {
66  return true;
67  }
68 
69  return false;
70 }
71 
72 } // namespace flutter
std::function< bool(const SurfaceFrame &surface_frame, SkCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:22
#define FML_DCHECK(condition)
Definition: logging.h:86
SkCanvas * SkiaCanvas()
Definition: ref_ptr.h:252
sk_sp< SkSurface > SkiaSurface() const
bool IsSubmitted() const
SurfaceFrame(sk_sp< SkSurface > surface, bool supports_readback, const SubmitCallback &submit_callback)