OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/playback/display_item_list.h" | 5 #include "cc/playback/display_item_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 DCHECK_EQ(0, proto->items_size()); | 113 DCHECK_EQ(0, proto->items_size()); |
114 for (const auto& item : items_) | 114 for (const auto& item : items_) |
115 item.ToProtobuf(proto->add_items(), image_serialization_processor); | 115 item.ToProtobuf(proto->add_items(), image_serialization_processor); |
116 } | 116 } |
117 | 117 |
118 void DisplayItemList::Raster(SkCanvas* canvas, | 118 void DisplayItemList::Raster(SkCanvas* canvas, |
119 SkPicture::AbortCallback* callback, | 119 SkPicture::AbortCallback* callback, |
120 const gfx::Rect& canvas_target_playback_rect, | 120 const gfx::Rect& canvas_target_playback_rect, |
121 float contents_scale) const { | 121 float contents_scale) const { |
| 122 canvas->save(); |
| 123 |
| 124 if (!canvas_target_playback_rect.IsEmpty()) { |
| 125 // canvas_target_playback_rect is specified in device space. We can't |
| 126 // use clipRect because canvas CTM will be applied on it. Use clipRegion |
| 127 // instead because it ignores canvas CTM. |
| 128 SkRegion device_clip; |
| 129 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); |
| 130 canvas->clipRegion(device_clip); |
| 131 } |
| 132 |
| 133 canvas->scale(contents_scale, contents_scale); |
| 134 Raster(canvas, callback); |
| 135 canvas->restore(); |
| 136 } |
| 137 |
| 138 void DisplayItemList::Raster(SkCanvas* canvas, |
| 139 SkPicture::AbortCallback* callback) const { |
122 if (!settings_.use_cached_picture) { | 140 if (!settings_.use_cached_picture) { |
123 canvas->save(); | |
124 canvas->scale(contents_scale, contents_scale); | |
125 for (const auto& item : items_) | 141 for (const auto& item : items_) |
126 item.Raster(canvas, canvas_target_playback_rect, callback); | 142 item.Raster(canvas, callback); |
127 canvas->restore(); | |
128 } else { | 143 } else { |
129 DCHECK(picture_); | 144 DCHECK(picture_); |
130 | 145 |
131 canvas->save(); | 146 canvas->save(); |
132 canvas->scale(contents_scale, contents_scale); | |
133 canvas->translate(layer_rect_.x(), layer_rect_.y()); | 147 canvas->translate(layer_rect_.x(), layer_rect_.y()); |
134 if (callback) { | 148 if (callback) { |
135 // If we have a callback, we need to call |draw()|, |drawPicture()| | 149 // If we have a callback, we need to call |draw()|, |drawPicture()| |
136 // doesn't take a callback. This is used by |AnalysisCanvas| to early | 150 // doesn't take a callback. This is used by |AnalysisCanvas| to early |
137 // out. | 151 // out. |
138 picture_->playback(canvas, callback); | 152 picture_->playback(canvas, callback); |
139 } else { | 153 } else { |
140 // Prefer to call |drawPicture()| on the canvas since it could place the | 154 // Prefer to call |drawPicture()| on the canvas since it could place the |
141 // entire picture on the canvas instead of parsing the skia operations. | 155 // entire picture on the canvas instead of parsing the skia operations. |
142 canvas->drawPicture(picture_.get()); | 156 canvas->drawPicture(picture_.get()); |
143 } | 157 } |
144 canvas->restore(); | 158 canvas->restore(); |
145 } | 159 } |
146 } | 160 } |
147 | 161 |
148 void DisplayItemList::ProcessAppendedItem(const DisplayItem* item) { | 162 void DisplayItemList::ProcessAppendedItem(const DisplayItem* item) { |
149 if (settings_.use_cached_picture) { | 163 if (settings_.use_cached_picture) { |
150 DCHECK(recorder_); | 164 DCHECK(recorder_); |
151 item->Raster(recorder_->getRecordingCanvas(), gfx::Rect(), nullptr); | 165 item->Raster(recorder_->getRecordingCanvas(), nullptr); |
152 } | 166 } |
153 if (!retain_individual_display_items_) { | 167 if (!retain_individual_display_items_) { |
154 items_.Clear(); | 168 items_.Clear(); |
155 } | 169 } |
156 } | 170 } |
157 | 171 |
158 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { | 172 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { |
159 DCHECK(recorder_); | 173 DCHECK(recorder_); |
160 DCHECK(!retain_individual_display_items_); | 174 DCHECK(!retain_individual_display_items_); |
161 | 175 |
162 item.Raster(recorder_->getRecordingCanvas(), gfx::Rect(), nullptr); | 176 item.Raster(recorder_->getRecordingCanvas(), nullptr); |
163 } | 177 } |
164 | 178 |
165 bool DisplayItemList::RetainsIndividualDisplayItems() const { | 179 bool DisplayItemList::RetainsIndividualDisplayItems() const { |
166 return retain_individual_display_items_; | 180 return retain_individual_display_items_; |
167 } | 181 } |
168 | 182 |
169 void DisplayItemList::Finalize() { | 183 void DisplayItemList::Finalize() { |
170 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); | 184 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); |
171 // TODO(dtrainor): Need to deal with serializing visual_rects_. | 185 // TODO(dtrainor): Need to deal with serializing visual_rects_. |
172 // http://crbug.com/568757. | 186 // http://crbug.com/568757. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 317 } |
304 | 318 |
305 void DisplayItemList::GetDiscardableImagesInRect( | 319 void DisplayItemList::GetDiscardableImagesInRect( |
306 const gfx::Rect& rect, | 320 const gfx::Rect& rect, |
307 float raster_scale, | 321 float raster_scale, |
308 std::vector<DrawImage>* images) { | 322 std::vector<DrawImage>* images) { |
309 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); | 323 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); |
310 } | 324 } |
311 | 325 |
312 } // namespace cc | 326 } // namespace cc |
OLD | NEW |