OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/compositor/paint_recorder.h" |
| 6 |
| 7 #include "cc/resources/display_item_list.h" |
| 8 #include "cc/resources/drawing_display_item.h" |
| 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/skia_util.h" |
| 12 |
| 13 namespace ui { |
| 14 |
| 15 PaintRecorder::PaintRecorder(const gfx::Rect& recording_bounds, |
| 16 float device_scale_factor) |
| 17 : device_scale_factor_(device_scale_factor) { |
| 18 SkRTreeFactory* no_factory = nullptr; |
| 19 skcanvas_ = skia::SharePtr(recorder_.beginRecording( |
| 20 gfx::RectToSkRect(recording_bounds), no_factory, |
| 21 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); |
| 22 skcanvas_->clipRect(gfx::RectToSkRect(recording_bounds)); |
| 23 canvas_ = make_scoped_ptr(gfx::Canvas::CreateCanvasWithoutScaling( |
| 24 skcanvas(), device_scale_factor_)); |
| 25 } |
| 26 |
| 27 PaintRecorder::~PaintRecorder() { |
| 28 } |
| 29 |
| 30 scoped_ptr<cc::DrawingDisplayItem> PaintRecorder::TakeDisplayItem() { |
| 31 DCHECK(skcanvas_); |
| 32 scoped_ptr<cc::DrawingDisplayItem> item = |
| 33 cc::DrawingDisplayItem::Create(skia::AdoptRef(recorder_.endRecording())); |
| 34 skcanvas_.clear(); // Prevent this method from being called again. |
| 35 return item; |
| 36 } |
| 37 |
| 38 void PaintRecorder::AppendDisplayItem(cc::DisplayItemList* list) { |
| 39 DCHECK(skcanvas_); |
| 40 list->AppendItem(TakeDisplayItem()); |
| 41 } |
| 42 |
| 43 } // namespace ui |
OLD | NEW |