forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint_recorder.cc
50 lines (40 loc) · 1.65 KB
/
paint_recorder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/paint/paint_recorder.h"
#include "cc/paint/display_item_list.h"
#include "ui/gfx/skia_util.h"
namespace cc {
PaintRecorder::PaintRecorder() {
display_item_list_ = base::MakeRefCounted<DisplayItemList>(
DisplayItemList::kToBeReleasedAsPaintOpBuffer);
}
PaintRecorder::~PaintRecorder() = default;
PaintCanvas* PaintRecorder::beginRecording(const SkRect& bounds) {
display_item_list_->StartPaint();
canvas_ = CreateCanvas(display_item_list_.get(), bounds);
return getRecordingCanvas();
}
sk_sp<PaintRecord> PaintRecorder::finishRecordingAsPicture() {
// SkPictureRecorder users expect that their saves are automatically
// closed for them.
//
// NOTE: Blink paint in general doesn't appear to need this, but the
// RecordingImageBufferSurface::fallBackToRasterCanvas finishing off the
// current frame depends on this. Maybe we could remove this assumption and
// just have callers do it.
canvas_->restoreToCount(1);
// Some users (e.g. printing) use the existence of the recording canvas
// to know if recording is finished, so reset it here.
canvas_.reset();
// The rect doesn't matter, since we just release the record.
display_item_list_->EndPaintOfUnpaired(gfx::Rect());
display_item_list_->Finalize();
return display_item_list_->ReleaseAsRecord();
}
std::unique_ptr<RecordPaintCanvas> PaintRecorder::CreateCanvas(
DisplayItemList* list,
const SkRect& bounds) {
return std::make_unique<RecordPaintCanvas>(list, bounds);
}
} // namespace cc