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/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 const gfx::PointF recording_scale, | |
| 24 PaintCache* cache) | 25 PaintCache* cache) |
| 25 : context_(context), | 26 : context_(context), |
| 26 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), | 27 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), |
| 27 gfx::RectToSkRect(gfx::Rect(recording_size))), | 28 gfx::RectToSkRect(gfx::Rect(recording_size))), |
| 28 canvas_(&record_canvas_, context.device_scale_factor_), | 29 canvas_(&record_canvas_, context_.device_scale_factor_), |
|
danakj
2017/07/25 17:58:56
why these changes?
malaykeshav
2017/07/25 22:57:58
Done
| |
| 29 cache_(cache), | 30 cache_(cache), |
| 30 recording_size_(recording_size) { | 31 recording_size_(recording_size) { |
| 31 #if DCHECK_IS_ON() | 32 #if DCHECK_IS_ON() |
| 32 DCHECK(!context.inside_paint_recorder_); | 33 DCHECK(!context_.inside_paint_recorder_); |
| 33 context.inside_paint_recorder_ = true; | 34 context_.inside_paint_recorder_ = true; |
| 34 #endif | 35 #endif |
| 36 if (context_.is_pixel_canvas()) { | |
| 37 canvas()->Save(); | |
| 38 canvas()->Scale(recording_scale.x(), recording_scale.y()); | |
| 39 } | |
| 35 } | 40 } |
| 36 | 41 |
| 37 PaintRecorder::PaintRecorder(const PaintContext& context, | 42 PaintRecorder::PaintRecorder(const PaintContext& context, |
| 38 const gfx::Size& recording_size) | 43 const gfx::Size& recording_size) |
| 39 : PaintRecorder(context, recording_size, nullptr) {} | 44 : PaintRecorder( |
| 45 context, | |
| 46 gfx::ScaleToRoundedSize( | |
|
danakj
2017/07/25 17:58:56
Why is this constructor changing the recording_siz
malaykeshav
2017/07/25 22:57:58
There are 32 occurrences to this and they need to
danakj
2017/07/26 16:06:03
Can you add a TODO that explains this and points t
| |
| 47 recording_size, | |
| 48 context.is_pixel_canvas() ? context.device_scale_factor_ : 1.f), | |
| 49 gfx::PointF(context.device_scale_factor_, | |
| 50 context.device_scale_factor_), | |
| 51 nullptr) {} | |
| 40 | 52 |
| 41 PaintRecorder::~PaintRecorder() { | 53 PaintRecorder::~PaintRecorder() { |
| 42 #if DCHECK_IS_ON() | 54 #if DCHECK_IS_ON() |
| 43 context_.inside_paint_recorder_ = false; | 55 context_.inside_paint_recorder_ = false; |
| 44 #endif | 56 #endif |
| 57 if (context_.is_pixel_canvas()) | |
| 58 canvas()->Restore(); | |
| 45 // If using cache, append what we've saved there to the PaintContext. | 59 // If using cache, append what we've saved there to the PaintContext. |
| 46 // Otherwise, the content is already stored in the PaintContext, and we can | 60 // Otherwise, the content is already stored in the PaintContext, and we can |
| 47 // just close it. | 61 // just close it. |
| 48 if (cache_) { | 62 if (cache_) { |
| 49 cache_->FinalizeCache(); | 63 cache_->FinalizeCache(); |
| 50 cache_->UseCache(context_, recording_size_); | 64 cache_->UseCache(context_, recording_size_); |
| 51 } else { | 65 } else { |
| 52 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 66 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
| 53 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 67 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
| 54 } | 68 } |
| 55 } | 69 } |
| 56 | 70 |
| 57 } // namespace ui | 71 } // namespace ui |
| OLD | NEW |