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/playback/display_item_list.h"
8 #include "cc/playback/drawing_display_item.h"
9 #include "third_party/skia/include/core/SkPictureRecorder.h"
10 #include "ui/compositor/paint_cache.h"
11 #include "ui/compositor/paint_context.h"
12 #include "ui/gfx/skia_util.h"
16 PaintRecorder::PaintRecorder(const PaintContext
& context
,
17 const gfx::Size
& recording_size
,
20 // The SkCanvas reference returned by beginRecording is shared with
21 // the recorder_ so no need to store a RefPtr to it on this class, we just
22 // store the gfx::Canvas.
23 canvas_(skia::SharePtr(context
.recorder_
->beginRecording(
24 gfx::RectToSkRect(gfx::Rect(recording_size
))))
26 context
.device_scale_factor_
),
29 DCHECK(!context
.inside_paint_recorder_
);
30 context
.inside_paint_recorder_
= true;
34 PaintRecorder::PaintRecorder(const PaintContext
& context
,
35 const gfx::Size
& recording_size
)
36 : PaintRecorder(context
, recording_size
, nullptr) {
39 PaintRecorder::~PaintRecorder() {
41 context_
.inside_paint_recorder_
= false;
44 auto* item
= context_
.list_
->CreateAndAppendItem
<cc::DrawingDisplayItem
>();
45 item
->SetNew(skia::AdoptRef(context_
.recorder_
->endRecordingAsPicture()));
47 cache_
->SetCache(item
);