| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/paint_recorder.h" | 5 #include "ui/compositor/paint_recorder.h" |
| 6 | 6 |
| 7 #include "cc/playback/display_item_list.h" | 7 #include "cc/playback/display_item_list.h" |
| 8 #include "cc/playback/drawing_display_item.h" | 8 #include "cc/playback/drawing_display_item.h" |
| 9 #include "third_party/skia/include/core/SkPictureRecorder.h" | 9 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 10 #include "ui/compositor/paint_cache.h" | 10 #include "ui/compositor/paint_cache.h" |
| 11 #include "ui/compositor/paint_context.h" | 11 #include "ui/compositor/paint_context.h" |
| 12 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 PaintRecorder::PaintRecorder(const PaintContext& context, | 16 PaintRecorder::PaintRecorder(const PaintContext& context, |
| 17 const gfx::Size& recording_size, | 17 const gfx::Size& recording_size, |
| 18 PaintCache* cache) | 18 PaintCache* cache) |
| 19 : context_(context), | 19 : context_(context), |
| 20 // The SkCanvas reference returned by beginRecording is shared with | 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 | 21 // the recorder_ so no need to store a RefPtr to it on this class, we just |
| 22 // store the gfx::Canvas. | 22 // store the gfx::Canvas. |
| 23 canvas_(skia::SharePtr(context.recorder_->beginRecording( | 23 canvas_(skia::SharePtr(context.recorder_->beginRecording( |
| 24 gfx::RectToSkRect(gfx::Rect(recording_size)))) | 24 gfx::RectToSkRect(gfx::Rect(recording_size)))) |
| 25 .get(), | 25 .get(), |
| 26 context.device_scale_factor_), | 26 context.device_scale_factor_), |
| 27 cache_(cache) { | 27 cache_(cache), |
| 28 layer_bounds_(context.ToLayerSpaceBounds(recording_size)) { |
| 28 #if DCHECK_IS_ON() | 29 #if DCHECK_IS_ON() |
| 29 DCHECK(!context.inside_paint_recorder_); | 30 DCHECK(!context.inside_paint_recorder_); |
| 30 context.inside_paint_recorder_ = true; | 31 context.inside_paint_recorder_ = true; |
| 31 #endif | 32 #endif |
| 32 } | 33 } |
| 33 | 34 |
| 34 PaintRecorder::PaintRecorder(const PaintContext& context, | 35 PaintRecorder::PaintRecorder(const PaintContext& context, |
| 35 const gfx::Size& recording_size) | 36 const gfx::Size& recording_size) |
| 36 : PaintRecorder(context, recording_size, nullptr) { | 37 : PaintRecorder(context, recording_size, nullptr) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 PaintRecorder::~PaintRecorder() { | 40 PaintRecorder::~PaintRecorder() { |
| 40 #if DCHECK_IS_ON() | 41 #if DCHECK_IS_ON() |
| 41 context_.inside_paint_recorder_ = false; | 42 context_.inside_paint_recorder_ = false; |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 auto* item = context_.list_->CreateAndAppendItem<cc::DrawingDisplayItem>(); | 45 auto* item = context_.list_->CreateAndAppendItem<cc::DrawingDisplayItem>( |
| 46 layer_bounds_); |
| 45 item->SetNew(skia::AdoptRef(context_.recorder_->endRecordingAsPicture())); | 47 item->SetNew(skia::AdoptRef(context_.recorder_->endRecordingAsPicture())); |
| 46 if (cache_) | 48 if (cache_) |
| 47 cache_->SetCache(item); | 49 cache_->SetCache(layer_bounds_, item); |
| 48 } | 50 } |
| 49 | 51 |
| 50 } // namespace ui | 52 } // namespace ui |
| OLD | NEW |