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 local_list_(cache ? base::MakeRefCounted<cc::DisplayItemList>( | 27 local_list_(cache ? base::MakeRefCounted<cc::DisplayItemList>( |
27 cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer) | 28 cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer) |
28 : nullptr), | 29 : nullptr), |
29 record_canvas_(cache ? local_list_.get() : context_.list_, | 30 record_canvas_(cache ? local_list_.get() : context_.list_, |
30 gfx::RectToSkRect(gfx::Rect(recording_size))), | 31 gfx::RectToSkRect(gfx::Rect(recording_size))), |
31 canvas_(&record_canvas_, context.device_scale_factor_), | 32 canvas_(&record_canvas_, context.device_scale_factor_), |
32 cache_(cache), | 33 cache_(cache), |
33 recording_size_(recording_size) { | 34 recording_size_(recording_size) { |
34 if (cache) { | 35 if (cache) { |
35 local_list_->StartPaint(); | 36 local_list_->StartPaint(); |
36 } else { | 37 } else { |
37 context_.list_->StartPaint(); | 38 context_.list_->StartPaint(); |
38 } | 39 } |
39 | 40 |
40 #if DCHECK_IS_ON() | 41 #if DCHECK_IS_ON() |
41 DCHECK(!context.inside_paint_recorder_); | 42 DCHECK(!context_.inside_paint_recorder_); |
42 context.inside_paint_recorder_ = true; | 43 context_.inside_paint_recorder_ = true; |
43 #endif | 44 #endif |
| 45 if (context_.is_pixel_canvas()) { |
| 46 canvas()->Save(); |
| 47 canvas()->Scale(recording_scale.x(), recording_scale.y()); |
| 48 } |
44 } | 49 } |
45 | 50 |
| 51 // TODO(malaykeshav): The scaling of recording size needs to be handled case |
| 52 // by case and the decision to perform the scale should be moved to the caller. |
46 PaintRecorder::PaintRecorder(const PaintContext& context, | 53 PaintRecorder::PaintRecorder(const PaintContext& context, |
47 const gfx::Size& recording_size) | 54 const gfx::Size& recording_size) |
48 : PaintRecorder(context, recording_size, nullptr) {} | 55 : PaintRecorder( |
| 56 context, |
| 57 gfx::ScaleToRoundedSize( |
| 58 recording_size, |
| 59 context.is_pixel_canvas() ? context.device_scale_factor_ : 1.f), |
| 60 gfx::PointF(context.device_scale_factor_, |
| 61 context.device_scale_factor_), |
| 62 nullptr) {} |
49 | 63 |
50 PaintRecorder::~PaintRecorder() { | 64 PaintRecorder::~PaintRecorder() { |
51 #if DCHECK_IS_ON() | 65 #if DCHECK_IS_ON() |
52 context_.inside_paint_recorder_ = false; | 66 context_.inside_paint_recorder_ = false; |
53 #endif | 67 #endif |
| 68 if (context_.is_pixel_canvas()) |
| 69 canvas()->Restore(); |
54 // If using cache, append what we've saved there to the PaintContext. | 70 // 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 | 71 // Otherwise, the content is already stored in the PaintContext, and we can |
56 // just close it. | 72 // just close it. |
57 if (cache_) { | 73 if (cache_) { |
58 local_list_->EndPaintOfUnpaired(gfx::Rect()); | 74 local_list_->EndPaintOfUnpaired(gfx::Rect()); |
59 local_list_->Finalize(); | 75 local_list_->Finalize(); |
60 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); | 76 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); |
61 cache_->UseCache(context_, recording_size_); | 77 cache_->UseCache(context_, recording_size_); |
62 } else { | 78 } else { |
63 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 79 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
64 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 80 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
65 } | 81 } |
66 } | 82 } |
67 | 83 |
68 } // namespace ui | 84 } // namespace ui |
OLD | NEW |