Flutter Engine
picture_recorder.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/lib/ui/painting/picture_recorder.h"
6 
7 #include "flutter/lib/ui/painting/canvas.h"
8 #include "flutter/lib/ui/painting/picture.h"
13 
14 namespace flutter {
15 
16 static void PictureRecorder_constructor(Dart_NativeArguments args) {
19 }
20 
22 
23 #define FOR_EACH_BINDING(V) V(PictureRecorder, endRecording)
24 
26 
27 void PictureRecorder::RegisterNatives(tonic::DartLibraryNatives* natives) {
28  natives->Register(
29  {{"PictureRecorder_constructor", PictureRecorder_constructor, 1, true},
31 }
32 
34  return fml::MakeRefCounted<PictureRecorder>();
35 }
36 
37 PictureRecorder::PictureRecorder() {}
38 
40 
41 SkCanvas* PictureRecorder::BeginRecording(SkRect bounds) {
42  bool enable_display_list = UIDartState::Current()->enable_display_list();
43  if (enable_display_list) {
44  display_list_recorder_ = sk_make_sp<DisplayListCanvasRecorder>(bounds);
45  return display_list_recorder_.get();
46  } else {
47  return picture_recorder_.beginRecording(bounds, &rtree_factory_);
48  }
49 }
50 
52  if (!canvas_) {
53  return nullptr;
54  }
55 
56  fml::RefPtr<Picture> picture;
57 
58  if (display_list_recorder_) {
59  picture = Picture::Create(
60  dart_picture,
61  UIDartState::CreateGPUObject(display_list_recorder_->Build()));
62  display_list_recorder_ = nullptr;
63  } else {
64  picture = Picture::Create(
65  dart_picture, UIDartState::CreateGPUObject(
66  picture_recorder_.finishRecordingAsPicture()));
67  }
68 
69  canvas_->Invalidate();
70  canvas_ = nullptr;
72  return picture;
73 }
74 
75 } // namespace flutter
G_BEGIN_DECLS FlValue * args
void DartCallConstructor(Sig func, Dart_NativeArguments args)
Definition: dart_args.h:218
SkCanvas * BeginRecording(SkRect bounds)
fml::RefPtr< Picture > endRecording(Dart_Handle dart_picture)
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
#define FOR_EACH_BINDING(V)
bool enable_display_list() const
static fml::RefPtr< Picture > Create(Dart_Handle dart_handle, flutter::SkiaGPUObject< SkPicture > picture)
Definition: picture.cc:31
IMPLEMENT_WRAPPERTYPEINFO(ui, Scene)
static void ThrowIfUIOperationsProhibited()
static void PictureRecorder_constructor(Dart_NativeArguments args)
#define DART_REGISTER_NATIVE(CLASS, METHOD)
static flutter::SkiaGPUObject< T > CreateGPUObject(sk_sp< T > object)
static fml::RefPtr< PictureRecorder > Create()
static UIDartState * Current()