| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/strings/stringprintf.h" |
| 10 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 13 #include "cc/debug/picture_debug_util.h" | 14 #include "cc/debug/picture_debug_util.h" |
| 14 #include "cc/debug/traced_display_item_list.h" | 15 #include "cc/debug/traced_display_item_list.h" |
| 15 #include "cc/debug/traced_value.h" | 16 #include "cc/debug/traced_value.h" |
| 16 #include "cc/playback/display_item_list_settings.h" | 17 #include "cc/playback/display_item_list_settings.h" |
| 17 #include "cc/playback/display_item_proto_factory.h" | 18 #include "cc/playback/display_item_proto_factory.h" |
| 18 #include "cc/playback/largest_display_item.h" | 19 #include "cc/playback/largest_display_item.h" |
| 19 #include "cc/proto/display_item.pb.h" | 20 #include "cc/proto/display_item.pb.h" |
| 20 #include "cc/proto/gfx_conversions.h" | 21 #include "cc/proto/gfx_conversions.h" |
| 21 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 22 #include "third_party/skia/include/core/SkPictureRecorder.h" | 23 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 23 #include "third_party/skia/include/utils/SkPictureUtils.h" | 24 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 25 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
| 25 | 27 |
| 26 namespace cc { | 28 namespace cc { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 // We don't perform per-layer solid color analysis when there are too many skia | 32 // We don't perform per-layer solid color analysis when there are too many skia |
| 31 // operations. | 33 // operations. |
| 32 const int kOpCountThatIsOkToAnalyze = 10; | 34 const int kOpCountThatIsOkToAnalyze = 10; |
| 33 | 35 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( | 55 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( |
| 54 const proto::DisplayItemList& proto) { | 56 const proto::DisplayItemList& proto) { |
| 55 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); | 57 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); |
| 56 scoped_refptr<DisplayItemList> list = | 58 scoped_refptr<DisplayItemList> list = |
| 57 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), | 59 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), |
| 58 DisplayItemListSettings(proto.settings())); | 60 DisplayItemListSettings(proto.settings())); |
| 59 | 61 |
| 60 for (int i = 0; i < proto.items_size(); i++) { | 62 for (int i = 0; i < proto.items_size(); i++) { |
| 61 const proto::DisplayItem& item_proto = proto.items(i); | 63 const proto::DisplayItem& item_proto = proto.items(i); |
| 62 DisplayItem* item = | 64 DisplayItem* item = DisplayItemProtoFactory::AllocateAndConstruct( |
| 63 DisplayItemProtoFactory::AllocateAndConstruct(list.get(), item_proto); | 65 layer_rect, list.get(), item_proto); |
| 64 if (item) | 66 if (item) |
| 65 item->FromProtobuf(item_proto); | 67 item->FromProtobuf(item_proto); |
| 66 } | 68 } |
| 67 | 69 |
| 68 return list; | 70 return list; |
| 69 } | 71 } |
| 70 | 72 |
| 71 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, | 73 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, |
| 72 const DisplayItemListSettings& settings, | 74 const DisplayItemListSettings& settings, |
| 73 bool retain_individual_display_items) | 75 bool retain_individual_display_items) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 void DisplayItemList::RemoveLast() { | 195 void DisplayItemList::RemoveLast() { |
| 194 // We cannot remove the last item if it has been squashed into a picture. | 196 // We cannot remove the last item if it has been squashed into a picture. |
| 195 // The last item should not have been handled by ProcessAppendedItems, so we | 197 // The last item should not have been handled by ProcessAppendedItems, so we |
| 196 // don't need to remove it from approximate_op_count_, etc. | 198 // don't need to remove it from approximate_op_count_, etc. |
| 197 DCHECK(retain_individual_display_items_); | 199 DCHECK(retain_individual_display_items_); |
| 198 DCHECK(!settings_.use_cached_picture); | 200 DCHECK(!settings_.use_cached_picture); |
| 199 items_.RemoveLast(); | 201 items_.RemoveLast(); |
| 200 } | 202 } |
| 201 | 203 |
| 202 void DisplayItemList::Finalize() { | 204 void DisplayItemList::Finalize() { |
| 205 // TODO(wkorman): Uncomment the assert below once we've investigated |
| 206 // and resolved issues. http://crbug.com/557905 |
| 207 // DCHECK_EQ(items_.size(), visual_rects_.size()); |
| 208 |
| 209 // TODO(vmpstr): Build and make use of an RTree from the visual |
| 210 // rects. For now we just clear them out since we won't ever need |
| 211 // them to stick around post-Finalize. http://crbug.com/527245 |
| 212 visual_rects_.clear(); |
| 213 |
| 203 ProcessAppendedItems(); | 214 ProcessAppendedItems(); |
| 204 | 215 |
| 205 if (settings_.use_cached_picture) { | 216 if (settings_.use_cached_picture) { |
| 206 // Convert to an SkPicture for faster rasterization. | 217 // Convert to an SkPicture for faster rasterization. |
| 207 DCHECK(settings_.use_cached_picture); | 218 DCHECK(settings_.use_cached_picture); |
| 208 DCHECK(!picture_); | 219 DCHECK(!picture_); |
| 209 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); | 220 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); |
| 210 DCHECK(picture_); | 221 DCHECK(picture_); |
| 211 picture_memory_usage_ = | 222 picture_memory_usage_ = |
| 212 SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 223 SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 266 |
| 256 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 267 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 257 DisplayItemList::AsValue(bool include_items) const { | 268 DisplayItemList::AsValue(bool include_items) const { |
| 258 DCHECK(ProcessAppendedItemsCalled()); | 269 DCHECK(ProcessAppendedItemsCalled()); |
| 259 scoped_refptr<base::trace_event::TracedValue> state = | 270 scoped_refptr<base::trace_event::TracedValue> state = |
| 260 new base::trace_event::TracedValue(); | 271 new base::trace_event::TracedValue(); |
| 261 | 272 |
| 262 state->BeginDictionary("params"); | 273 state->BeginDictionary("params"); |
| 263 if (include_items) { | 274 if (include_items) { |
| 264 state->BeginArray("items"); | 275 state->BeginArray("items"); |
| 276 size_t item_index = 0; |
| 265 for (const DisplayItem* item : items_) { | 277 for (const DisplayItem* item : items_) { |
| 266 item->AsValueInto(state.get()); | 278 item->AsValueInto(visual_rects_.size() >= item_index |
| 279 ? visual_rects_[item_index] |
| 280 : gfx::Rect(), |
| 281 state.get()); |
| 282 item_index++; |
| 267 } | 283 } |
| 268 state->EndArray(); // "items". | 284 state->EndArray(); // "items". |
| 269 } | 285 } |
| 270 state->SetValue("layer_rect", MathUtil::AsValue(layer_rect_)); | 286 state->SetValue("layer_rect", MathUtil::AsValue(layer_rect_)); |
| 271 state->EndDictionary(); // "params". | 287 state->EndDictionary(); // "params". |
| 272 | 288 |
| 273 if (!layer_rect_.IsEmpty()) { | 289 if (!layer_rect_.IsEmpty()) { |
| 274 SkPictureRecorder recorder; | 290 SkPictureRecorder recorder; |
| 275 SkCanvas* canvas = | 291 SkCanvas* canvas = |
| 276 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); | 292 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 333 } |
| 318 | 334 |
| 319 void DisplayItemList::GetDiscardableImagesInRect( | 335 void DisplayItemList::GetDiscardableImagesInRect( |
| 320 const gfx::Rect& rect, | 336 const gfx::Rect& rect, |
| 321 float raster_scale, | 337 float raster_scale, |
| 322 std::vector<DrawImage>* images) { | 338 std::vector<DrawImage>* images) { |
| 323 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); | 339 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); |
| 324 } | 340 } |
| 325 | 341 |
| 326 } // namespace cc | 342 } // namespace cc |
| OLD | NEW |