| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 break; | 150 break; |
| 151 } | 151 } |
| 152 case DisplayItem::END_TRANSFORM: | 152 case DisplayItem::END_TRANSFORM: |
| 153 canvas->restore(); | 153 canvas->restore(); |
| 154 break; | 154 break; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| 159 | 159 |
| 160 DisplayItemList::Inputs::Inputs() | 160 DisplayItemList::DisplayItemList() |
| 161 : items(LargestDisplayItemSize(), | 161 : items_(LargestDisplayItemSize(), |
| 162 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve) {} | 162 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve) {} |
| 163 | |
| 164 DisplayItemList::Inputs::~Inputs() = default; | |
| 165 | |
| 166 DisplayItemList::DisplayItemList() = default; | |
| 167 | 163 |
| 168 DisplayItemList::~DisplayItemList() = default; | 164 DisplayItemList::~DisplayItemList() = default; |
| 169 | 165 |
| 170 void DisplayItemList::Raster(SkCanvas* canvas, | 166 void DisplayItemList::Raster(SkCanvas* canvas, |
| 171 SkPicture::AbortCallback* callback, | 167 SkPicture::AbortCallback* callback, |
| 172 const gfx::Rect& canvas_target_playback_rect, | 168 const gfx::Rect& canvas_target_playback_rect, |
| 173 float contents_scale) const { | 169 float contents_scale) const { |
| 174 canvas->save(); | 170 canvas->save(); |
| 175 if (!canvas_target_playback_rect.IsEmpty()) { | 171 if (!canvas_target_playback_rect.IsEmpty()) { |
| 176 // canvas_target_playback_rect is specified in device space. We can't | 172 // canvas_target_playback_rect is specified in device space. We can't |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 | 183 |
| 188 void DisplayItemList::Raster(SkCanvas* canvas, | 184 void DisplayItemList::Raster(SkCanvas* canvas, |
| 189 SkPicture::AbortCallback* callback) const { | 185 SkPicture::AbortCallback* callback) const { |
| 190 gfx::Rect canvas_playback_rect; | 186 gfx::Rect canvas_playback_rect; |
| 191 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) | 187 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) |
| 192 return; | 188 return; |
| 193 | 189 |
| 194 std::vector<size_t> indices; | 190 std::vector<size_t> indices; |
| 195 rtree_.Search(canvas_playback_rect, &indices); | 191 rtree_.Search(canvas_playback_rect, &indices); |
| 196 for (size_t index : indices) { | 192 for (size_t index : indices) { |
| 197 RasterItem(inputs_.items[index], canvas, callback); | 193 RasterItem(items_[index], canvas, callback); |
| 198 | 194 |
| 199 // We use a callback during solid color analysis on the compositor thread to | 195 // We use a callback during solid color analysis on the compositor thread to |
| 200 // break out early. Since we're handling a sequence of pictures via rtree | 196 // break out early. Since we're handling a sequence of pictures via rtree |
| 201 // query results ourselves, we have to respect the callback and early out. | 197 // query results ourselves, we have to respect the callback and early out. |
| 202 if (callback && callback->abort()) | 198 if (callback && callback->abort()) |
| 203 break; | 199 break; |
| 204 } | 200 } |
| 205 } | 201 } |
| 206 | 202 |
| 207 void DisplayItemList::GrowCurrentBeginItemVisualRect( | 203 void DisplayItemList::GrowCurrentBeginItemVisualRect( |
| 208 const gfx::Rect& visual_rect) { | 204 const gfx::Rect& visual_rect) { |
| 209 if (!inputs_.begin_item_indices.empty()) | 205 if (!begin_item_indices_.empty()) |
| 210 inputs_.visual_rects[inputs_.begin_item_indices.back()].Union(visual_rect); | 206 visual_rects_[begin_item_indices_.back()].Union(visual_rect); |
| 211 } | 207 } |
| 212 | 208 |
| 213 void DisplayItemList::Finalize() { | 209 void DisplayItemList::Finalize() { |
| 214 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); | 210 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); |
| 215 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) | 211 DCHECK(items_.size() == visual_rects_.size()) |
| 216 << "items.size() " << inputs_.items.size() << " visual_rects.size() " | 212 << "items.size() " << items_.size() << " visual_rects.size() " |
| 217 << inputs_.visual_rects.size(); | 213 << visual_rects_.size(); |
| 218 rtree_.Build(inputs_.visual_rects); | 214 rtree_.Build(visual_rects_); |
| 219 | 215 |
| 220 if (!retain_visual_rects_) | 216 if (!retain_visual_rects_) |
| 221 // This clears both the vector and the vector's capacity, since | 217 // This clears both the vector and the vector's capacity, since |
| 222 // visual_rects won't be used anymore. | 218 // visual_rects won't be used anymore. |
| 223 std::vector<gfx::Rect>().swap(inputs_.visual_rects); | 219 std::vector<gfx::Rect>().swap(visual_rects_); |
| 224 } | 220 } |
| 225 | 221 |
| 226 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 222 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
| 227 // TODO(wkorman): This is more permissive than Picture's implementation, since | 223 // TODO(wkorman): This is more permissive than Picture's implementation, since |
| 228 // none of the items might individually trigger a veto even though they | 224 // none of the items might individually trigger a veto even though they |
| 229 // collectively have enough "bad" operations that a corresponding Picture | 225 // collectively have enough "bad" operations that a corresponding Picture |
| 230 // would get vetoed. See crbug.com/513016. | 226 // would get vetoed. See crbug.com/513016. |
| 231 return inputs_.all_items_are_suitable_for_gpu_rasterization; | 227 return all_items_are_suitable_for_gpu_rasterization_; |
| 232 } | 228 } |
| 233 | 229 |
| 234 int DisplayItemList::ApproximateOpCount() const { | 230 int DisplayItemList::ApproximateOpCount() const { |
| 235 return approximate_op_count_; | 231 return approximate_op_count_; |
| 236 } | 232 } |
| 237 | 233 |
| 238 size_t DisplayItemList::ApproximateMemoryUsage() const { | 234 size_t DisplayItemList::ApproximateMemoryUsage() const { |
| 239 size_t memory_usage = sizeof(*this); | 235 size_t memory_usage = sizeof(*this); |
| 240 | 236 |
| 241 size_t external_memory_usage = 0; | 237 size_t external_memory_usage = 0; |
| 242 for (const auto& item : inputs_.items) { | 238 for (const auto& item : items_) { |
| 243 size_t bytes = 0; | 239 size_t bytes = 0; |
| 244 switch (item.type) { | 240 switch (item.type) { |
| 245 case DisplayItem::CLIP: | 241 case DisplayItem::CLIP: |
| 246 bytes = static_cast<const ClipDisplayItem&>(item).ExternalMemoryUsage(); | 242 bytes = static_cast<const ClipDisplayItem&>(item).ExternalMemoryUsage(); |
| 247 break; | 243 break; |
| 248 case DisplayItem::CLIP_PATH: | 244 case DisplayItem::CLIP_PATH: |
| 249 bytes = | 245 bytes = |
| 250 static_cast<const ClipPathDisplayItem&>(item).ExternalMemoryUsage(); | 246 static_cast<const ClipPathDisplayItem&>(item).ExternalMemoryUsage(); |
| 251 break; | 247 break; |
| 252 case DisplayItem::COMPOSITING: | 248 case DisplayItem::COMPOSITING: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 274 case DisplayItem::END_COMPOSITING: | 270 case DisplayItem::END_COMPOSITING: |
| 275 case DisplayItem::END_FLOAT_CLIP: | 271 case DisplayItem::END_FLOAT_CLIP: |
| 276 case DisplayItem::END_FILTER: | 272 case DisplayItem::END_FILTER: |
| 277 case DisplayItem::END_TRANSFORM: | 273 case DisplayItem::END_TRANSFORM: |
| 278 break; | 274 break; |
| 279 } | 275 } |
| 280 external_memory_usage += bytes; | 276 external_memory_usage += bytes; |
| 281 } | 277 } |
| 282 | 278 |
| 283 // Memory outside this class due to |items_|. | 279 // Memory outside this class due to |items_|. |
| 284 memory_usage += inputs_.items.GetCapacityInBytes() + external_memory_usage; | 280 memory_usage += items_.GetCapacityInBytes() + external_memory_usage; |
| 285 | 281 |
| 286 // TODO(jbroman): Does anything else owned by this class substantially | 282 // TODO(jbroman): Does anything else owned by this class substantially |
| 287 // contribute to memory usage? | 283 // contribute to memory usage? |
| 288 // TODO(vmpstr): Probably DiscardableImageMap is worth counting here. | 284 // TODO(vmpstr): Probably DiscardableImageMap is worth counting here. |
| 289 | 285 |
| 290 return memory_usage; | 286 return memory_usage; |
| 291 } | 287 } |
| 292 | 288 |
| 293 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { | 289 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { |
| 294 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; | 290 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 306 } | 302 } |
| 307 | 303 |
| 308 std::unique_ptr<base::trace_event::TracedValue> | 304 std::unique_ptr<base::trace_event::TracedValue> |
| 309 DisplayItemList::CreateTracedValue(bool include_items) const { | 305 DisplayItemList::CreateTracedValue(bool include_items) const { |
| 310 auto state = base::MakeUnique<base::trace_event::TracedValue>(); | 306 auto state = base::MakeUnique<base::trace_event::TracedValue>(); |
| 311 state->BeginDictionary("params"); | 307 state->BeginDictionary("params"); |
| 312 | 308 |
| 313 if (include_items) { | 309 if (include_items) { |
| 314 state->BeginArray("items"); | 310 state->BeginArray("items"); |
| 315 | 311 |
| 316 auto visual_rects_it = inputs_.visual_rects.begin(); | 312 auto visual_rects_it = visual_rects_.begin(); |
| 317 for (const DisplayItem& base_item : inputs_.items) { | 313 for (const DisplayItem& base_item : items_) { |
| 318 gfx::Rect visual_rect; | 314 gfx::Rect visual_rect; |
| 319 if (visual_rects_it != inputs_.visual_rects.end()) { | 315 if (visual_rects_it != visual_rects_.end()) { |
| 320 visual_rect = *visual_rects_it; | 316 visual_rect = *visual_rects_it; |
| 321 ++visual_rects_it; | 317 ++visual_rects_it; |
| 322 } | 318 } |
| 323 | 319 |
| 324 switch (base_item.type) { | 320 switch (base_item.type) { |
| 325 case DisplayItem::CLIP: { | 321 case DisplayItem::CLIP: { |
| 326 const auto& item = static_cast<const ClipDisplayItem&>(base_item); | 322 const auto& item = static_cast<const ClipDisplayItem&>(base_item); |
| 327 std::string output = | 323 std::string output = |
| 328 base::StringPrintf("ClipDisplayItem rect: [%s] visualRect: [%s]", | 324 base::StringPrintf("ClipDisplayItem rect: [%s] visualRect: [%s]", |
| 329 item.clip_rect.ToString().c_str(), | 325 item.clip_rect.ToString().c_str(), |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 479 } |
| 484 | 480 |
| 485 void DisplayItemList::GenerateDiscardableImagesMetadata() { | 481 void DisplayItemList::GenerateDiscardableImagesMetadata() { |
| 486 // This should be only called once. | 482 // This should be only called once. |
| 487 DCHECK(image_map_.empty()); | 483 DCHECK(image_map_.empty()); |
| 488 | 484 |
| 489 gfx::Rect bounds = rtree_.GetBounds(); | 485 gfx::Rect bounds = rtree_.GetBounds(); |
| 490 DiscardableImageMap::ScopedMetadataGenerator generator( | 486 DiscardableImageMap::ScopedMetadataGenerator generator( |
| 491 &image_map_, gfx::Size(bounds.right(), bounds.bottom())); | 487 &image_map_, gfx::Size(bounds.right(), bounds.bottom())); |
| 492 auto* canvas = generator.canvas(); | 488 auto* canvas = generator.canvas(); |
| 493 for (const auto& item : inputs_.items) | 489 for (const auto& item : items_) |
| 494 RasterItem(item, canvas, nullptr); | 490 RasterItem(item, canvas, nullptr); |
| 495 } | 491 } |
| 496 | 492 |
| 497 void DisplayItemList::GetDiscardableImagesInRect( | 493 void DisplayItemList::GetDiscardableImagesInRect( |
| 498 const gfx::Rect& rect, | 494 const gfx::Rect& rect, |
| 499 float contents_scale, | 495 float contents_scale, |
| 500 std::vector<DrawImage>* images) { | 496 std::vector<DrawImage>* images) { |
| 501 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); | 497 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); |
| 502 } | 498 } |
| 503 | 499 |
| 504 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const { | 500 gfx::Rect DisplayItemList::GetRectForImage(ImageId image_id) const { |
| 505 return image_map_.GetRectForImage(image_id); | 501 return image_map_.GetRectForImage(image_id); |
| 506 } | 502 } |
| 507 | 503 |
| 508 } // namespace cc | 504 } // namespace cc |
| OLD | NEW |