Chromium Code Reviews| 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/resources/display_item_list.h" | 7 #include "cc/resources/display_item_list.h" |
| 8 #include "cc/resources/drawing_display_item.h" | 8 #include "cc/resources/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/canvas.h" | |
| 13 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
| 14 | 13 |
| 15 namespace ui { | 14 namespace ui { |
| 16 | 15 |
| 17 PaintRecorder::PaintRecorder(const PaintContext& context, PaintCache* cache) | 16 PaintRecorder::PaintRecorder(const PaintContext& context, PaintCache* cache) |
| 18 : context_(context), canvas_(context.canvas_), cache_(cache) { | 17 : context_(context), |
| 18 owned_canvas_( | |
| 19 // If the |context| has a canvas, we'll just point to it in |canvas_| | |
| 20 // so use anything here to initialize the gfx::Canvas without any | |
| 21 // allocations. | |
| 22 // The SkCanvas reference returned by beginRecording is shared with | |
| 23 // the recorder_ so no need to store a RefPtr to it on this class. | |
| 24 (context.canvas_ | |
| 25 ? context.canvas_->sk_canvas() | |
|
danakj
2015/05/11 23:10:16
This is all a little bit crazy, but will go away/g
| |
| 26 : skia::SharePtr( | |
| 27 context.recorder_->beginRecording( | |
| 28 gfx::RectToSkRect(context.bounds_), | |
| 29 nullptr /* no SkRTreeFactory */, | |
| 30 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)) | |
| 31 .get()), | |
| 32 context.device_scale_factor_), | |
| 33 canvas_(context.canvas_ ? context.canvas_ : &owned_canvas_), | |
| 34 cache_(cache) { | |
| 19 #if DCHECK_IS_ON() | 35 #if DCHECK_IS_ON() |
| 20 DCHECK(!context.inside_paint_recorder_); | 36 DCHECK(!context.inside_paint_recorder_); |
| 21 context.inside_paint_recorder_ = true; | 37 context.inside_paint_recorder_ = true; |
| 22 #endif | 38 #endif |
| 23 | |
| 24 if (context.list_) { | |
| 25 SkRTreeFactory* no_factory = nullptr; | |
| 26 // This SkCancas is shared with the recorder_ so no need to store a RefPtr | |
| 27 // to it on this class. | |
| 28 skia::RefPtr<SkCanvas> skcanvas = | |
| 29 skia::SharePtr(context.recorder_->beginRecording( | |
| 30 gfx::RectToSkRect(context.bounds_), no_factory, | |
| 31 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); | |
| 32 owned_canvas_ = make_scoped_ptr(gfx::Canvas::CreateCanvasWithoutScaling( | |
| 33 skcanvas.get(), context.device_scale_factor_)); | |
| 34 canvas_ = owned_canvas_.get(); | |
| 35 } | |
| 36 } | 39 } |
| 37 | 40 |
| 38 PaintRecorder::PaintRecorder(const PaintContext& context) | 41 PaintRecorder::PaintRecorder(const PaintContext& context) |
| 39 : PaintRecorder(context, nullptr) { | 42 : PaintRecorder(context, nullptr) { |
| 40 } | 43 } |
| 41 | 44 |
| 42 PaintRecorder::~PaintRecorder() { | 45 PaintRecorder::~PaintRecorder() { |
| 43 #if DCHECK_IS_ON() | 46 #if DCHECK_IS_ON() |
| 44 context_.inside_paint_recorder_ = false; | 47 context_.inside_paint_recorder_ = false; |
| 45 #endif | 48 #endif |
| 46 | 49 |
| 47 if (!context_.list_) | 50 if (!context_.list_) |
| 48 return; | 51 return; |
| 49 | 52 |
| 50 auto* item = context_.list_->CreateAndAppendItem<cc::DrawingDisplayItem>(); | 53 auto* item = context_.list_->CreateAndAppendItem<cc::DrawingDisplayItem>(); |
| 51 item->SetNew(skia::AdoptRef(context_.recorder_->endRecordingAsPicture())); | 54 item->SetNew(skia::AdoptRef(context_.recorder_->endRecordingAsPicture())); |
| 52 if (cache_) | 55 if (cache_) |
| 53 cache_->SetCache(item); | 56 cache_->SetCache(item); |
| 54 } | 57 } |
| 55 | 58 |
| 56 } // namespace ui | 59 } // namespace ui |
| OLD | NEW |