1 // Copyright 2015 The Chromium 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.
5 #include "ui/compositor/paint_recorder.h"
7 #include "cc/resources/display_item_list.h"
8 #include "cc/resources/drawing_display_item.h"
9 #include "third_party/skia/include/core/SkPictureRecorder.h"
10 #include "ui/compositor/paint_context.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/skia_util.h"
16 PaintRecorder::PaintRecorder(const PaintContext
& context
)
17 : context_(context
), canvas_(context
.canvas_
) {
19 DCHECK(!context
.inside_paint_recorder_
);
20 context
.inside_paint_recorder_
= true;
24 SkRTreeFactory
* no_factory
= nullptr;
25 // This SkCancas is shared with the recorder_ so no need to store a RefPtr
26 // to it on this class.
27 skia::RefPtr
<SkCanvas
> skcanvas
=
28 skia::SharePtr(context
.recorder_
->beginRecording(
29 gfx::RectToSkRect(context
.bounds_
), no_factory
,
30 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag
));
31 owned_canvas_
= make_scoped_ptr(gfx::Canvas::CreateCanvasWithoutScaling(
32 skcanvas
.get(), context
.device_scale_factor_
));
33 canvas_
= owned_canvas_
.get();
37 PaintRecorder::~PaintRecorder() {
39 context_
.inside_paint_recorder_
= false;
43 context_
.list_
->AppendItem(cc::DrawingDisplayItem::Create(
44 skia::AdoptRef(context_
.recorder_
->endRecordingAsPicture())));