Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: cc/paint/display_item_list.cc

Issue 2820133005: Revert of Back PaintRecord with PaintOpBuffer instead of SkPicture (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/paint/BUILD.gn ('k') | cc/paint/display_item_list_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(enne): Maybe the PaintRecord itself could know whether this 103 // SkPicture always does a wrapping save/restore on the canvas, so it is
104 // was needed? It's not clear whether these save/restore semantics 104 // not necessary here.
105 // that SkPicture handles during playback are things that should be
106 // kept around.
107 canvas->save();
108 item.picture->playback(canvas, callback); 105 item.picture->playback(canvas, callback);
109 canvas->restore();
110 break; 106 break;
111 } 107 }
112 case DisplayItem::FLOAT_CLIP: { 108 case DisplayItem::FLOAT_CLIP: {
113 const auto& item = static_cast<const FloatClipDisplayItem&>(base_item); 109 const auto& item = static_cast<const FloatClipDisplayItem&>(base_item);
114 canvas->save(); 110 canvas->save();
115 canvas->clipRect(gfx::RectFToSkRect(item.clip_rect)); 111 canvas->clipRect(gfx::RectFToSkRect(item.clip_rect));
116 break; 112 break;
117 } 113 }
118 case DisplayItem::END_FLOAT_CLIP: 114 case DisplayItem::END_FLOAT_CLIP:
119 canvas->restore(); 115 canvas->restore();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // instead because it ignores canvas CTM. 169 // instead because it ignores canvas CTM.
174 SkRegion device_clip; 170 SkRegion device_clip;
175 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); 171 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect));
176 canvas->clipRegion(device_clip); 172 canvas->clipRegion(device_clip);
177 } 173 }
178 canvas->scale(contents_scale, contents_scale); 174 canvas->scale(contents_scale, contents_scale);
179 Raster(canvas, callback); 175 Raster(canvas, callback);
180 canvas->restore(); 176 canvas->restore();
181 } 177 }
182 178
183 // Atttempts to merge a CompositingDisplayItem and DrawingDisplayItem
184 // into a single "draw with alpha". This function returns true if
185 // it was successful. If false, then the caller is responsible for
186 // drawing these items. This is a DisplayItemList version of the
187 // SkRecord optimization SkRecordNoopSaveLayerDrawRestores.
188 static bool MergeAndDrawIfPossible(const CompositingDisplayItem& save_item,
189 const DrawingDisplayItem& draw_item,
190 SkCanvas* canvas) {
191 if (save_item.color_filter)
192 return false;
193 if (save_item.xfermode != SkBlendMode::kSrcOver)
194 return false;
195 // TODO(enne): I believe that lcd_text_requires_opaque_layer is not
196 // relevant here and that lcd text is preserved post merge, but I haven't
197 // tested that.
198 const PaintRecord* record = draw_item.picture.get();
199 if (record->approximateOpCount() != 1)
200 return false;
201
202 const PaintOp* op = record->GetFirstOp();
203 if (!op->IsDrawOp())
204 return false;
205
206 op->RasterWithAlpha(canvas, save_item.alpha);
207 return true;
208 }
209
210 void DisplayItemList::Raster(SkCanvas* canvas, 179 void DisplayItemList::Raster(SkCanvas* canvas,
211 SkPicture::AbortCallback* callback) const { 180 SkPicture::AbortCallback* callback) const {
212 gfx::Rect canvas_playback_rect; 181 gfx::Rect canvas_playback_rect;
213 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) 182 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect))
214 return; 183 return;
215 184
216 std::vector<size_t> indices; 185 std::vector<size_t> indices;
217 rtree_.Search(canvas_playback_rect, &indices); 186 rtree_.Search(canvas_playback_rect, &indices);
218 for (size_t i = 0; i < indices.size(); ++i) { 187 for (size_t index : indices) {
188 RasterItem(items_[index], canvas, callback);
189
219 // We use a callback during solid color analysis on the compositor thread to 190 // We use a callback during solid color analysis on the compositor thread to
220 // break out early. Since we're handling a sequence of pictures via rtree 191 // break out early. Since we're handling a sequence of pictures via rtree
221 // query results ourselves, we have to respect the callback and early out. 192 // query results ourselves, we have to respect the callback and early out.
222 if (callback && callback->abort()) 193 if (callback && callback->abort())
223 break; 194 break;
224
225 const DisplayItem& item = items_[indices[i]];
226 // Optimize empty begin/end compositing and merge begin/draw/end compositing
227 // where possible.
228 // TODO(enne): remove empty clips here too?
229 // TODO(enne): does this happen recursively? Or is this good enough?
230 if (i < indices.size() - 2 && item.type == DisplayItem::COMPOSITING) {
231 const DisplayItem& second = items_[indices[i + 1]];
232 const DisplayItem& third = items_[indices[i + 2]];
233 if (second.type == DisplayItem::DRAWING &&
234 third.type == DisplayItem::END_COMPOSITING) {
235 if (MergeAndDrawIfPossible(
236 static_cast<const CompositingDisplayItem&>(item),
237 static_cast<const DrawingDisplayItem&>(second), canvas)) {
238 i += 2;
239 continue;
240 }
241 }
242 }
243
244 RasterItem(item, canvas, callback);
245 } 195 }
246 } 196 }
247 197
248 void DisplayItemList::GrowCurrentBeginItemVisualRect( 198 void DisplayItemList::GrowCurrentBeginItemVisualRect(
249 const gfx::Rect& visual_rect) { 199 const gfx::Rect& visual_rect) {
250 if (!begin_item_indices_.empty()) 200 if (!begin_item_indices_.empty())
251 visual_rects_[begin_item_indices_.back()].Union(visual_rect); 201 visual_rects_[begin_item_indices_.back()].Union(visual_rect);
252 } 202 }
253 203
254 void DisplayItemList::Finalize() { 204 void DisplayItemList::Finalize() {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 std::vector<DrawImage>* images) { 492 std::vector<DrawImage>* images) {
543 image_map_.GetDiscardableImagesInRect(rect, contents_scale, 493 image_map_.GetDiscardableImagesInRect(rect, contents_scale,
544 target_color_space, images); 494 target_color_space, images);
545 } 495 }
546 496
547 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const { 497 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const {
548 return image_map_.GetRectForImage(image_id); 498 return image_map_.GetRectForImage(image_id);
549 } 499 }
550 500
551 } // namespace cc 501 } // namespace cc
OLDNEW
« no previous file with comments | « cc/paint/BUILD.gn ('k') | cc/paint/display_item_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698