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 |
46 PaintRecorder::PaintRecorder(const PaintContext& context, | 51 PaintRecorder::PaintRecorder(const PaintContext& context, |
47 const gfx::Size& recording_size) | 52 const gfx::Size& recording_size) |
48 : PaintRecorder(context, recording_size, nullptr) {} | 53 : PaintRecorder( |
| 54 context, |
| 55 gfx::ScaleToRoundedSize( |
| 56 recording_size, |
| 57 context.is_pixel_canvas() ? context.device_scale_factor_ : 1.f), |
| 58 gfx::PointF(context.device_scale_factor_, |
| 59 context.device_scale_factor_), |
| 60 nullptr) {} |
49 | 61 |
50 PaintRecorder::~PaintRecorder() { | 62 PaintRecorder::~PaintRecorder() { |
51 #if DCHECK_IS_ON() | 63 #if DCHECK_IS_ON() |
52 context_.inside_paint_recorder_ = false; | 64 context_.inside_paint_recorder_ = false; |
53 #endif | 65 #endif |
| 66 if (context_.is_pixel_canvas()) |
| 67 canvas()->Restore(); |
54 // If using cache, append what we've saved there to the PaintContext. | 68 // 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 | 69 // Otherwise, the content is already stored in the PaintContext, and we can |
56 // just close it. | 70 // just close it. |
57 if (cache_) { | 71 if (cache_) { |
58 local_list_->EndPaintOfUnpaired(gfx::Rect()); | 72 local_list_->EndPaintOfUnpaired(gfx::Rect()); |
59 local_list_->Finalize(); | 73 local_list_->Finalize(); |
60 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); | 74 cache_->SetPaintOpBuffer(local_list_->ReleaseAsRecord()); |
61 cache_->UseCache(context_, recording_size_); | 75 cache_->UseCache(context_, recording_size_); |
62 } else { | 76 } else { |
63 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 77 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
64 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 78 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
65 } | 79 } |
66 } | 80 } |
67 | 81 |
68 } // namespace ui | 82 } // namespace ui |
OLD | NEW |