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/paint/display_item_list.h" | 5 #include "cc/paint/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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 break; | 93 break; |
94 } | 94 } |
95 case DisplayItem::END_COMPOSITING: | 95 case DisplayItem::END_COMPOSITING: |
96 canvas->restore(); | 96 canvas->restore(); |
97 break; | 97 break; |
98 case DisplayItem::DRAWING: { | 98 case DisplayItem::DRAWING: { |
99 const auto& item = static_cast<const DrawingDisplayItem&>(base_item); | 99 const auto& item = static_cast<const DrawingDisplayItem&>(base_item); |
100 if (canvas->quickReject(item.picture->cullRect())) | 100 if (canvas->quickReject(item.picture->cullRect())) |
101 break; | 101 break; |
102 | 102 |
103 // SkPicture always does a wrapping save/restore on the canvas, so it is | 103 // TODO(enne): Maybe the PaintRecord itself could know whether this |
vmpstr
2017/03/28 18:27:14
I think it makes sense for the paint record to fig
enne (OOO)
2017/03/28 19:28:05
I think this just needs some investigation. I thi
| |
104 // not necessary here. | 104 // was needed? It's not clear whether these save/restore semantics |
105 // that SkPicture handles during playback are things that should be | |
106 // kept around. | |
107 canvas->save(); | |
105 item.picture->playback(canvas, callback); | 108 item.picture->playback(canvas, callback); |
109 canvas->restore(); | |
106 break; | 110 break; |
107 } | 111 } |
108 case DisplayItem::FLOAT_CLIP: { | 112 case DisplayItem::FLOAT_CLIP: { |
109 const auto& item = static_cast<const FloatClipDisplayItem&>(base_item); | 113 const auto& item = static_cast<const FloatClipDisplayItem&>(base_item); |
110 canvas->save(); | 114 canvas->save(); |
111 canvas->clipRect(gfx::RectFToSkRect(item.clip_rect)); | 115 canvas->clipRect(gfx::RectFToSkRect(item.clip_rect)); |
112 break; | 116 break; |
113 } | 117 } |
114 case DisplayItem::END_FLOAT_CLIP: | 118 case DisplayItem::END_FLOAT_CLIP: |
115 canvas->restore(); | 119 canvas->restore(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // instead because it ignores canvas CTM. | 173 // instead because it ignores canvas CTM. |
170 SkRegion device_clip; | 174 SkRegion device_clip; |
171 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); | 175 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); |
172 canvas->clipRegion(device_clip); | 176 canvas->clipRegion(device_clip); |
173 } | 177 } |
174 canvas->scale(contents_scale, contents_scale); | 178 canvas->scale(contents_scale, contents_scale); |
175 Raster(canvas, callback); | 179 Raster(canvas, callback); |
176 canvas->restore(); | 180 canvas->restore(); |
177 } | 181 } |
178 | 182 |
183 static bool MergeAndDrawIfPossible(const CompositingDisplayItem& save_item, | |
vmpstr
2017/03/28 18:27:14
nit: Can you add a comment mentioning what this do
enne (OOO)
2017/03/28 19:28:05
Done.
| |
184 const DrawingDisplayItem& draw_item, | |
185 SkCanvas* canvas) { | |
186 if (save_item.color_filter) | |
187 return false; | |
188 if (save_item.xfermode != SkBlendMode::kSrcOver) | |
189 return false; | |
190 // TODO(enne): I believe that lcd_text_requires_opaque_layer is not | |
191 // relevant here and that lcd text is preserved post merge, but I haven't | |
192 // tested that. | |
193 const PaintRecord* record = draw_item.picture.get(); | |
194 if (record->approximateOpCount() != 1) | |
vmpstr
2017/03/28 18:27:14
I'm a bit <_< at "approximate" here... Is this gua
enne (OOO)
2017/03/28 19:28:05
This is the SkPicture API. This patch changes Pai
| |
195 return false; | |
196 | |
197 const PaintOp* op = record->GetFirstOp(); | |
198 if (!op->IsDrawOp()) | |
199 return false; | |
200 | |
201 op->RasterWithAlpha(canvas, save_item.alpha); | |
vmpstr
2017/03/28 18:27:14
Hmm is there a way to guard/dcheck against future
enne (OOO)
2017/03/28 19:28:05
I think there's really no way to guard. There's n
| |
202 return true; | |
203 } | |
204 | |
179 void DisplayItemList::Raster(SkCanvas* canvas, | 205 void DisplayItemList::Raster(SkCanvas* canvas, |
180 SkPicture::AbortCallback* callback) const { | 206 SkPicture::AbortCallback* callback) const { |
181 gfx::Rect canvas_playback_rect; | 207 gfx::Rect canvas_playback_rect; |
182 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) | 208 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) |
183 return; | 209 return; |
184 | 210 |
185 std::vector<size_t> indices; | 211 std::vector<size_t> indices; |
186 rtree_.Search(canvas_playback_rect, &indices); | 212 rtree_.Search(canvas_playback_rect, &indices); |
187 for (size_t index : indices) { | 213 for (size_t i = 0; i < indices.size(); ++i) { |
188 RasterItem(items_[index], canvas, callback); | 214 const DisplayItem& item = items_[indices[i]]; |
215 // Optimize empty begin/end compositing and merge begin/draw/end compositing | |
216 // where possible. | |
217 // TODO(enne): remove empty clips here too? | |
218 // TODO(enne): does this happen recursively? Or is this good enough? | |
219 if (i < indices.size() - 2 && item.type == DisplayItem::COMPOSITING) { | |
220 const DisplayItem& second = items_[indices[i + 1]]; | |
221 if (second.type == DisplayItem::END_COMPOSITING) { | |
222 i += 2; | |
vmpstr
2017/03/28 18:27:14
I think this has to be ++i because of the ++i in t
enne (OOO)
2017/03/28 19:28:05
OOPS
| |
223 // TODO(enne): does this ever happen? Is this worth catching? | |
vmpstr
2017/03/28 18:27:14
I think this is possible in this situation:
- Com
enne (OOO)
2017/03/28 19:28:05
Yeah, I'm not saying it's not impossible. It just
| |
224 continue; | |
225 } | |
226 const DisplayItem& third = items_[indices[i + 2]]; | |
227 if (second.type == DisplayItem::DRAWING && | |
228 third.type == DisplayItem::END_COMPOSITING) { | |
229 if (MergeAndDrawIfPossible( | |
230 static_cast<const CompositingDisplayItem&>(item), | |
231 static_cast<const DrawingDisplayItem&>(second), canvas)) { | |
232 i += 3; | |
vmpstr
2017/03/28 18:27:14
+= 2?
enne (OOO)
2017/03/28 19:28:05
***<_<***
| |
233 continue; | |
234 } | |
235 } | |
236 } | |
237 | |
238 RasterItem(item, canvas, callback); | |
189 | 239 |
190 // We use a callback during solid color analysis on the compositor thread to | 240 // We use a callback during solid color analysis on the compositor thread to |
191 // break out early. Since we're handling a sequence of pictures via rtree | 241 // break out early. Since we're handling a sequence of pictures via rtree |
192 // query results ourselves, we have to respect the callback and early out. | 242 // query results ourselves, we have to respect the callback and early out. |
193 if (callback && callback->abort()) | 243 if (callback && callback->abort()) |
194 break; | 244 break; |
195 } | 245 } |
196 } | 246 } |
197 | 247 |
198 void DisplayItemList::GrowCurrentBeginItemVisualRect( | 248 void DisplayItemList::GrowCurrentBeginItemVisualRect( |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 float contents_scale, | 540 float contents_scale, |
491 std::vector<DrawImage>* images) { | 541 std::vector<DrawImage>* images) { |
492 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); | 542 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); |
493 } | 543 } |
494 | 544 |
495 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const { | 545 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const { |
496 return image_map_.GetRectForImage(image_id); | 546 return image_map_.GetRectForImage(image_id); |
497 } | 547 } |
498 | 548 |
499 } // namespace cc | 549 } // namespace cc |
OLD | NEW |