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& effective_recording_size, |
|
oshima
2017/06/15 22:59:12
do you need this change?
malaykeshav
2017/06/16 20:41:57
Added it to differentiate if from the other constr
| |
| 24 PaintCache* cache) | 24 PaintCache* cache) |
| 25 : context_(context), | 25 : context_(context), |
| 26 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), | 26 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), |
| 27 gfx::RectToSkRect(gfx::Rect(recording_size))), | 27 gfx::RectToSkRect(gfx::Rect(effective_recording_size))), |
| 28 canvas_(&record_canvas_, context.device_scale_factor_), | 28 canvas_(&record_canvas_, context.device_scale_factor_), |
| 29 cache_(cache), | 29 cache_(cache), |
| 30 recording_size_(recording_size) { | 30 recording_size_(effective_recording_size) { |
| 31 #if DCHECK_IS_ON() | 31 #if DCHECK_IS_ON() |
| 32 DCHECK(!context.inside_paint_recorder_); | 32 DCHECK(!context.inside_paint_recorder_); |
| 33 context.inside_paint_recorder_ = true; | 33 context.inside_paint_recorder_ = true; |
| 34 #endif | 34 #endif |
| 35 if (context_.IsPixelCanvas()) { | |
| 36 canvas()->Save(); | |
| 37 canvas()->Scale(context.effective_scale_factor_x(), | |
| 38 context.effective_scale_factor_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(context, |
| 45 context.ScaleToEffectivePixelSize(recording_size), | |
| 46 nullptr) {} | |
| 40 | 47 |
| 41 PaintRecorder::~PaintRecorder() { | 48 PaintRecorder::~PaintRecorder() { |
| 42 #if DCHECK_IS_ON() | 49 #if DCHECK_IS_ON() |
| 43 context_.inside_paint_recorder_ = false; | 50 context_.inside_paint_recorder_ = false; |
| 44 #endif | 51 #endif |
| 52 if (context_.IsPixelCanvas()) | |
| 53 canvas()->Restore(); | |
| 45 // If using cache, append what we've saved there to the PaintContext. | 54 // 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 | 55 // Otherwise, the content is already stored in the PaintContext, and we can |
| 47 // just close it. | 56 // just close it. |
| 48 if (cache_) { | 57 if (cache_) { |
| 49 cache_->FinalizeCache(); | 58 cache_->FinalizeCache(); |
| 50 cache_->UseCache(context_, recording_size_); | 59 cache_->UseCache(context_, recording_size_); |
| 51 } else { | 60 } else { |
| 52 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 61 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
| 53 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 62 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
| 54 } | 63 } |
| 55 } | 64 } |
| 56 | 65 |
| 57 } // namespace ui | 66 } // namespace ui |
| OLD | NEW |