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" 9 10 namespace flutter { 11 12 IMPLEMENT_WRAPPERTYPEINFO(ui, PictureRecorder); 13 14 #define FOR_EACH_BINDING(V) \ 15 V(PictureRecorder, isRecording) \ 16 V(PictureRecorder, endRecording) 17 FOR_EACH_BINDING(DART_NATIVE_CALLBACK)18FOR_EACH_BINDING(DART_NATIVE_CALLBACK) 19 20 void PictureRecorder::RegisterNatives(tonic::DartLibraryNatives* natives) { 21 } 22 Create()23fml::RefPtr<PictureRecorder> PictureRecorder::Create() { 24 return fml::MakeRefCounted<PictureRecorder>(); 25 } 26 PictureRecorder()27PictureRecorder::PictureRecorder() {} 28 ~PictureRecorder()29PictureRecorder::~PictureRecorder() {} 30 isRecording()31bool PictureRecorder::isRecording() { 32 return canvas_ && canvas_->IsRecording(); 33 } 34 BeginRecording(SkRect bounds)35SkCanvas* PictureRecorder::BeginRecording(SkRect bounds) { 36 return picture_recorder_.beginRecording(bounds, &rtree_factory_); 37 } 38 endRecording()39fml::RefPtr<Picture> PictureRecorder::endRecording() { 40 if (!isRecording()) 41 return nullptr; 42 43 fml::RefPtr<Picture> picture = Picture::Create(UIDartState::CreateGPUObject( 44 picture_recorder_.finishRecordingAsPicture())); 45 canvas_->Clear(); 46 canvas_->ClearDartWrapper(); 47 canvas_ = nullptr; 48 ClearDartWrapper(); 49 return picture; 50 } 51 52 } // namespace flutter 53