| 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/paint/display_item_list.h" | 7 #include "cc/paint/display_item_list.h" |
| 8 #include "cc/paint/paint_recorder.h" | 8 #include "cc/paint/paint_recorder.h" |
| 9 #include "third_party/skia/include/core/SkRefCnt.h" | 9 #include "third_party/skia/include/core/SkRefCnt.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 // This class records a reference to the context, the canvas returned | 16 // This class records a reference to the context, the canvas returned |
| 17 // by its recorder_, and the cache. Thus all 3 of these must remain | 17 // by its recorder_, and the cache. Thus all 3 of these must remain |
| 18 // valid for the lifetime of this object. | 18 // valid for the lifetime of this object. |
| 19 // If a |cache| is provided, this records into the |cache|'s PaintOpBuffer | 19 // If a |cache| is provided, this records into the |cache|'s PaintOpBuffer |
| 20 // directly, then appends that to the |context|. If not, then this records | 20 // directly, then appends that to the |context|. If not, then this records |
| 21 // to the |context|'s PaintOpBuffer. | 21 // to the |context|'s PaintOpBuffer. |
| 22 PaintRecorder::PaintRecorder(const PaintContext& context, | 22 PaintRecorder::PaintRecorder(const PaintContext& context, |
| 23 const gfx::Size& recording_size, | 23 const gfx::Size& recording_size, |
| 24 float recording_scale_x, |
| 25 float recording_scale_y, |
| 24 PaintCache* cache) | 26 PaintCache* cache) |
| 25 : context_(context), | 27 : context_(context), |
| 26 local_list_(cache ? base::MakeRefCounted<cc::DisplayItemList>( | 28 local_list_(cache ? base::MakeRefCounted<cc::DisplayItemList>( |
| 27 cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer) | 29 cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer) |
| 28 : nullptr), | 30 : nullptr), |
| 29 record_canvas_(cache ? local_list_.get() : context_.list_, | 31 record_canvas_(cache ? local_list_.get() : context_.list_, |
| 30 gfx::RectToSkRect(gfx::Rect(recording_size))), | 32 gfx::RectToSkRect(gfx::Rect(recording_size))), |
| 31 canvas_(&record_canvas_, context.device_scale_factor_), | 33 canvas_(&record_canvas_, context.device_scale_factor_), |
| 32 cache_(cache), | 34 cache_(cache), |
| 33 recording_size_(recording_size) { | 35 recording_size_(recording_size) { |
| 34 if (cache) { | 36 if (cache) { |
| 35 local_list_->StartPaint(); | 37 local_list_->StartPaint(); |
| 36 } else { | 38 } else { |
| 37 context_.list_->StartPaint(); | 39 context_.list_->StartPaint(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 #if DCHECK_IS_ON() | 42 #if DCHECK_IS_ON() |
| 41 DCHECK(!context.inside_paint_recorder_); | 43 DCHECK(!context_.inside_paint_recorder_); |
| 42 context.inside_paint_recorder_ = true; | 44 context_.inside_paint_recorder_ = true; |
| 43 #endif | 45 #endif |
| 46 if (context_.is_pixel_canvas()) { |
| 47 canvas()->Save(); |
| 48 canvas()->Scale(recording_scale_x, recording_scale_y); |
| 49 } |
| 44 } | 50 } |
| 45 | 51 |
| 52 // TODO(malaykeshav): The scaling of recording size needs to be handled case |
| 53 // by case and the decision to perform the scale should be moved to the caller. |
| 46 PaintRecorder::PaintRecorder(const PaintContext& context, | 54 PaintRecorder::PaintRecorder(const PaintContext& context, |
| 47 const gfx::Size& recording_size) | 55 const gfx::Size& recording_size) |
| 48 : PaintRecorder(context, recording_size, nullptr) {} | 56 : PaintRecorder( |
| 57 context, |
| 58 gfx::ScaleToRoundedSize( |
| 59 recording_size, |
| 60 context.is_pixel_canvas() ? context.device_scale_factor_ : 1.f), |
| 61 context.device_scale_factor_, |
| 62 context.device_scale_factor_, |
| 63 nullptr) {} |
| 49 | 64 |
| 50 PaintRecorder::~PaintRecorder() { | 65 PaintRecorder::~PaintRecorder() { |
| 51 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
| 52 context_.inside_paint_recorder_ = false; | 67 context_.inside_paint_recorder_ = false; |
| 53 #endif | 68 #endif |
| 69 if (context_.is_pixel_canvas()) |
| 70 canvas()->Restore(); |
| 54 // If using cache, append what we've saved there to the PaintContext. | 71 // If using cache, append what we've saved there to the PaintContext. |
| 55 // Otherwise, the content is already stored in the PaintContext, and we can | 72 // Otherwise, the content is already stored in the PaintContext, and we can |
| 56 // just close it. | 73 // just close it. |
| 57 if (cache_) { | 74 if (cache_) { |
| 58 local_list_->EndPaintOfUnpaired(gfx::Rect()); | 75 local_list_->EndPaintOfUnpaired(gfx::Rect()); |
| 59 local_list_->Finalize(); | 76 local_list_->Finalize(); |
| 60 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); | 77 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); |
| 61 cache_->UseCache(context_, recording_size_); | 78 cache_->UseCache(context_, recording_size_); |
| 62 } else { | 79 } else { |
| 63 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 80 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
| 64 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 81 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
| 65 } | 82 } |
| 66 } | 83 } |
| 67 | 84 |
| 68 } // namespace ui | 85 } // namespace ui |
| OLD | NEW |