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/compositor/paint_info.h" | |
12 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 // This class records a reference to the context, the canvas returned | 17 // 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 | 18 // by its recorder_, and the cache. Thus all 3 of these must remain |
18 // valid for the lifetime of this object. | 19 // valid for the lifetime of this object. |
19 // If a |cache| is provided, this records into the |cache|'s PaintOpBuffer | 20 // 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 | 21 // directly, then appends that to the |context|. If not, then this records |
21 // to the |context|'s PaintOpBuffer. | 22 // to the |context|'s PaintOpBuffer. |
22 PaintRecorder::PaintRecorder(const PaintContext& context, | 23 PaintRecorder::PaintRecorder(const PaintInfo& info, PaintCache* cache) |
danakj
2017/07/21 17:29:39
Can you pass in the various things it needs here i
malaykeshav
2017/07/21 23:30:17
Done
| |
23 const gfx::Size& recording_size, | 24 : context_(info.context()), |
24 PaintCache* cache) | |
25 : context_(context), | |
26 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), | 25 record_canvas_(cache ? cache->ResetCache() : context_.list_->StartPaint(), |
27 gfx::RectToSkRect(gfx::Rect(recording_size))), | 26 gfx::RectToSkRect(gfx::Rect(info.paint_recording_size()))), |
28 canvas_(&record_canvas_, context.device_scale_factor_), | 27 canvas_(&record_canvas_, context_.device_scale_factor_), |
29 cache_(cache), | 28 cache_(cache), |
30 recording_size_(recording_size) { | 29 recording_size_(info.paint_recording_size()), |
30 is_pixel_canvas_(info.IsPixelCanvas()) { | |
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 (is_pixel_canvas_) { | |
36 canvas()->Save(); | |
37 canvas()->Scale(info.paint_recording_scale().x(), | |
38 info.paint_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(PaintInfo(context, recording_size), nullptr) {} |
40 | 45 |
41 PaintRecorder::~PaintRecorder() { | 46 PaintRecorder::~PaintRecorder() { |
42 #if DCHECK_IS_ON() | 47 #if DCHECK_IS_ON() |
43 context_.inside_paint_recorder_ = false; | 48 context_.inside_paint_recorder_ = false; |
44 #endif | 49 #endif |
50 if (is_pixel_canvas_) | |
51 canvas()->Restore(); | |
45 // If using cache, append what we've saved there to the PaintContext. | 52 // 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 | 53 // Otherwise, the content is already stored in the PaintContext, and we can |
47 // just close it. | 54 // just close it. |
48 if (cache_) { | 55 if (cache_) { |
49 cache_->FinalizeCache(); | 56 cache_->FinalizeCache(); |
50 cache_->UseCache(context_, recording_size_); | 57 cache_->UseCache(context_, recording_size_); |
51 } else { | 58 } else { |
52 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); | 59 gfx::Rect bounds_in_layer = context_.ToLayerSpaceBounds(recording_size_); |
53 context_.list_->EndPaintOfUnpaired(bounds_in_layer); | 60 context_.list_->EndPaintOfUnpaired(bounds_in_layer); |
54 } | 61 } |
55 } | 62 } |
56 | 63 |
57 } // namespace ui | 64 } // namespace ui |
OLD | NEW |