| 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/strings/stringprintf.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 14 #include "cc/debug/picture_debug_util.h" | 14 #include "cc/debug/picture_debug_util.h" |
| 15 #include "cc/debug/traced_display_item_list.h" | 15 #include "cc/debug/traced_display_item_list.h" |
| 16 #include "cc/debug/traced_value.h" | 16 #include "cc/debug/traced_value.h" |
| 17 #include "cc/playback/display_item_list_settings.h" | 17 #include "cc/playback/display_item_list_settings.h" |
| 18 #include "cc/playback/display_item_proto_factory.h" | 18 #include "cc/playback/display_item_proto_factory.h" |
| 19 #include "cc/playback/largest_display_item.h" | 19 #include "cc/playback/largest_display_item.h" |
| 20 #include "cc/proto/display_item.pb.h" | 20 #include "cc/proto/display_item.pb.h" |
| 21 #include "cc/proto/gfx_conversions.h" | 21 #include "cc/proto/gfx_conversions.h" |
| 22 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 23 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 24 #include "third_party/skia/include/utils/SkPictureUtils.h" | 24 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 25 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 26 #include "ui/gfx/geometry/rect_conversions.h" |
| 26 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // We don't perform per-layer solid color analysis when there are too many skia | 33 // We don't perform per-layer solid color analysis when there are too many skia |
| 33 // operations. | 34 // operations. |
| 34 const int kOpCountThatIsOkToAnalyze = 10; | 35 const int kOpCountThatIsOkToAnalyze = 10; |
| 35 | 36 |
| 36 bool DisplayItemsTracingEnabled() { | 37 bool DisplayItemsTracingEnabled() { |
| 37 bool tracing_enabled; | 38 bool tracing_enabled; |
| 38 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 39 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
| 39 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); | 40 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); |
| 40 return tracing_enabled; | 41 return tracing_enabled; |
| 41 } | 42 } |
| 42 | 43 |
| 43 const int kDefaultNumDisplayItemsToReserve = 100; | 44 const int kDefaultNumDisplayItemsToReserve = 100; |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 scoped_refptr<DisplayItemList> DisplayItemList::Create( | 48 scoped_refptr<DisplayItemList> DisplayItemList::Create( |
| 48 const gfx::Rect& layer_rect, | |
| 49 const DisplayItemListSettings& settings) { | 49 const DisplayItemListSettings& settings) { |
| 50 return make_scoped_refptr(new DisplayItemList( | 50 return make_scoped_refptr(new DisplayItemList(settings)); |
| 51 layer_rect, settings, | |
| 52 !settings.use_cached_picture || DisplayItemsTracingEnabled())); | |
| 53 } | 51 } |
| 54 | 52 |
| 55 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( | 53 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( |
| 56 const proto::DisplayItemList& proto) { | 54 const proto::DisplayItemList& proto) { |
| 57 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); | 55 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); |
| 58 scoped_refptr<DisplayItemList> list = | 56 scoped_refptr<DisplayItemList> list = |
| 59 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), | 57 DisplayItemList::Create(DisplayItemListSettings(proto.settings())); |
| 60 DisplayItemListSettings(proto.settings())); | |
| 61 | 58 |
| 62 for (int i = 0; i < proto.items_size(); i++) { | 59 for (int i = 0; i < proto.items_size(); i++) { |
| 63 const proto::DisplayItem& item_proto = proto.items(i); | 60 const proto::DisplayItem& item_proto = proto.items(i); |
| 64 DisplayItem* item = DisplayItemProtoFactory::AllocateAndConstruct( | 61 DisplayItem* item = DisplayItemProtoFactory::AllocateAndConstruct( |
| 65 layer_rect, list.get(), item_proto); | 62 layer_rect, list.get(), item_proto); |
| 66 if (item) | 63 if (item) |
| 67 item->FromProtobuf(item_proto); | 64 item->FromProtobuf(item_proto); |
| 68 } | 65 } |
| 69 | 66 |
| 70 return list; | 67 return list; |
| 71 } | 68 } |
| 72 | 69 |
| 73 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, | 70 DisplayItemList::DisplayItemList(const DisplayItemListSettings& settings) |
| 74 const DisplayItemListSettings& settings, | |
| 75 bool retain_individual_display_items) | |
| 76 : items_(LargestDisplayItemSize(), | 71 : items_(LargestDisplayItemSize(), |
| 77 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), | 72 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), |
| 78 settings_(settings), | 73 settings_(settings), |
| 79 retain_individual_display_items_(retain_individual_display_items), | 74 all_items_are_suitable_for_gpu_rasterization_(true), |
| 80 layer_rect_(layer_rect), | |
| 81 is_suitable_for_gpu_rasterization_(true), | |
| 82 approximate_op_count_(0), | 75 approximate_op_count_(0), |
| 83 picture_memory_usage_(0), | |
| 84 external_memory_usage_(0) { | 76 external_memory_usage_(0) { |
| 85 #if DCHECK_IS_ON() | 77 #if DCHECK_IS_ON() |
| 86 needs_process_ = false; | 78 needs_finalize_ = false; |
| 87 #endif | 79 #endif |
| 88 if (settings_.use_cached_picture) { | |
| 89 SkRTreeFactory factory; | |
| 90 recorder_.reset(new SkPictureRecorder()); | |
| 91 canvas_ = skia::SharePtr(recorder_->beginRecording( | |
| 92 layer_rect_.width(), layer_rect_.height(), &factory)); | |
| 93 canvas_->translate(-layer_rect_.x(), -layer_rect_.y()); | |
| 94 canvas_->clipRect(gfx::RectToSkRect(layer_rect_)); | |
| 95 } | |
| 96 } | 80 } |
| 97 | 81 |
| 98 DisplayItemList::~DisplayItemList() { | 82 DisplayItemList::~DisplayItemList() { |
| 99 } | 83 } |
| 100 | 84 |
| 101 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { | 85 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { |
| 102 // The flattened SkPicture approach is going away, and the proto | 86 // The flattened SkPicture approach is going away, and the proto |
| 103 // doesn't currently support serializing that flattened picture. | 87 // doesn't currently support serializing that flattened picture. |
| 104 DCHECK(retain_individual_display_items_); | 88 // DCHECK(retain_individual_display_items_); |
| 105 | 89 |
| 106 RectToProto(layer_rect_, proto->mutable_layer_rect()); | 90 // RectToProto(layer_rect_, proto->mutable_layer_rect()); |
| 107 settings_.ToProtobuf(proto->mutable_settings()); | 91 // settings_.ToProtobuf(proto->mutable_settings()); |
| 108 | 92 |
| 109 DCHECK_EQ(0, proto->items_size()); | 93 DCHECK_EQ(0, proto->items_size()); |
| 110 for (const auto& item : items_) | 94 for (const auto& item : items_) |
| 111 item.ToProtobuf(proto->add_items()); | 95 item.ToProtobuf(proto->add_items()); |
| 112 } | 96 } |
| 113 | 97 |
| 114 void DisplayItemList::Raster(SkCanvas* canvas, | 98 void DisplayItemList::Raster(SkCanvas* canvas, |
| 115 SkPicture::AbortCallback* callback, | 99 SkPicture::AbortCallback* callback, |
| 116 const gfx::Rect& canvas_target_playback_rect, | 100 const gfx::Rect& canvas_playback_rect, |
| 117 float contents_scale) const { | 101 float contents_scale) const { |
| 118 DCHECK(ProcessAppendedItemsCalled()); | 102 DCHECK(FinalizeCalled()); |
| 119 if (!settings_.use_cached_picture) { | 103 canvas->save(); |
| 120 canvas->save(); | 104 canvas->scale(contents_scale, contents_scale); |
| 121 canvas->scale(contents_scale, contents_scale); | |
| 122 for (const auto& item : items_) | |
| 123 item.Raster(canvas, canvas_target_playback_rect, callback); | |
| 124 canvas->restore(); | |
| 125 } else { | |
| 126 DCHECK(picture_); | |
| 127 | 105 |
| 128 canvas->save(); | 106 gfx::Rect query_rect = GetQueryRect(canvas_playback_rect, contents_scale); |
| 129 canvas->scale(contents_scale, contents_scale); | 107 std::vector<size_t> indices; |
| 130 canvas->translate(layer_rect_.x(), layer_rect_.y()); | 108 rtree_.Search(query_rect, &indices); |
| 131 if (callback) { | 109 for (size_t index : indices) |
| 132 // If we have a callback, we need to call |draw()|, |drawPicture()| | 110 items_[index].Raster(canvas, callback); |
| 133 // doesn't take a callback. This is used by |AnalysisCanvas| to early | 111 canvas->restore(); |
| 134 // out. | |
| 135 picture_->playback(canvas, callback); | |
| 136 } else { | |
| 137 // Prefer to call |drawPicture()| on the canvas since it could place the | |
| 138 // entire picture on the canvas instead of parsing the skia operations. | |
| 139 canvas->drawPicture(picture_.get()); | |
| 140 } | |
| 141 canvas->restore(); | |
| 142 } | |
| 143 } | 112 } |
| 144 | 113 |
| 145 void DisplayItemList::ProcessAppendedItemsOnTheFly() { | 114 gfx::Rect DisplayItemList::GetQueryRect(const gfx::Rect& rect, float scale) cons
t { |
| 146 if (retain_individual_display_items_) | 115 // If the playback rect is empty, assume that we need to play back everything. |
| 147 return; | 116 // TODO(wkorman): Double-check scaling the rectangle. |
| 148 if (items_.size() >= kDefaultNumDisplayItemsToReserve) { | 117 return rect.IsEmpty() ? rtree_.GetBounds() |
| 149 ProcessAppendedItems(); | 118 : ScaleToEnclosingRect(rect, 1.f / scale); |
| 150 // This function exists to keep the |items_| from growing indefinitely if | |
| 151 // we're not going to store them anyway. So the items better be deleted | |
| 152 // after |items_| grows too large and we process it. | |
| 153 DCHECK(items_.empty()); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 void DisplayItemList::ProcessAppendedItems() { | |
| 158 #if DCHECK_IS_ON() | |
| 159 needs_process_ = false; | |
| 160 #endif | |
| 161 for (const DisplayItem& item : items_) { | |
| 162 if (settings_.use_cached_picture) { | |
| 163 // When using a cached picture we will calculate gpu suitability on the | |
| 164 // entire cached picture instead of the items. This is more permissive | |
| 165 // since none of the items might individually trigger a veto even though | |
| 166 // they collectively have enough "bad" operations that a corresponding | |
| 167 // Picture would get vetoed. See crbug.com/513016. | |
| 168 DCHECK(canvas_); | |
| 169 approximate_op_count_ += item.approximate_op_count(); | |
| 170 item.Raster(canvas_.get(), gfx::Rect(), nullptr); | |
| 171 } else { | |
| 172 is_suitable_for_gpu_rasterization_ &= | |
| 173 item.is_suitable_for_gpu_rasterization(); | |
| 174 approximate_op_count_ += item.approximate_op_count(); | |
| 175 } | |
| 176 | |
| 177 if (retain_individual_display_items_) { | |
| 178 // Warning: this double-counts SkPicture data if use_cached_picture is | |
| 179 // also true. | |
| 180 external_memory_usage_ += item.external_memory_usage(); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 if (!retain_individual_display_items_) | |
| 185 items_.Clear(); | |
| 186 } | |
| 187 | |
| 188 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { | |
| 189 DCHECK(canvas_); | |
| 190 DCHECK(!retain_individual_display_items_); | |
| 191 approximate_op_count_ += item.approximate_op_count(); | |
| 192 | |
| 193 item.Raster(canvas_.get(), gfx::Rect(), nullptr); | |
| 194 } | |
| 195 | |
| 196 bool DisplayItemList::RetainsIndividualDisplayItems() const { | |
| 197 return retain_individual_display_items_; | |
| 198 } | |
| 199 | |
| 200 void DisplayItemList::RemoveLast() { | |
| 201 // We cannot remove the last item if it has been squashed into a picture. | |
| 202 // The last item should not have been handled by ProcessAppendedItems, so we | |
| 203 // don't need to remove it from approximate_op_count_, etc. | |
| 204 DCHECK(retain_individual_display_items_); | |
| 205 DCHECK(!settings_.use_cached_picture); | |
| 206 items_.RemoveLast(); | |
| 207 } | 119 } |
| 208 | 120 |
| 209 void DisplayItemList::Finalize() { | 121 void DisplayItemList::Finalize() { |
| 122 #if DCHECK_IS_ON() |
| 123 needs_finalize_ = false; |
| 124 #endif |
| 125 // LOG(ERROR) << AsValue(true)->ToString().c_str() << "\n"; |
| 126 |
| 127 int i = 0; |
| 128 for (const auto& item : items_) { |
| 129 all_items_are_suitable_for_gpu_rasterization_ &= |
| 130 item.is_suitable_for_gpu_rasterization(); |
| 131 approximate_op_count_ += item.approximate_op_count(); |
| 132 external_memory_usage_ += item.external_memory_usage(); |
| 133 // LOG(ERROR) << base::StringPrintf("item visual rect: (%0.2f, %0.2f, %0.2f, |
| 134 // %0.2f)", |
| 135 // visual_rects_[i].x(), |
| 136 // visual_rects_[i].y(), |
| 137 // visual_rects_[i].width(), |
| 138 // visual_rects_[i].height()); |
| 139 i++; |
| 140 } |
| 141 |
| 142 // LOG(ERROR) << "item count: " << i; |
| 143 |
| 210 // TODO(wkorman): Uncomment the assert below once we've investigated | 144 // TODO(wkorman): Uncomment the assert below once we've investigated |
| 211 // and resolved issues. http://crbug.com/557905 | 145 // and resolved issues. http://crbug.com/557905 |
| 212 // DCHECK_EQ(items_.size(), visual_rects_.size()); | 146 DCHECK_EQ(items_.size(), visual_rects_.size()); |
| 213 | 147 |
| 214 // TODO(vmpstr): Build and make use of an RTree from the visual | 148 // TODO(wkorman): These are RectF rather than Rect in |
| 215 // rects. For now we just clear them out since we won't ever need | 149 // http://crrev.com/1459003003 does it matter? |
| 216 // them to stick around post-Finalize. http://crbug.com/527245 | 150 rtree_.Build(visual_rects_); |
| 151 |
| 217 visual_rects_.clear(); | 152 visual_rects_.clear(); |
| 218 | |
| 219 ProcessAppendedItems(); | |
| 220 | |
| 221 if (settings_.use_cached_picture) { | |
| 222 // Convert to an SkPicture for faster rasterization. | |
| 223 DCHECK(settings_.use_cached_picture); | |
| 224 DCHECK(!picture_); | |
| 225 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); | |
| 226 DCHECK(picture_); | |
| 227 picture_memory_usage_ = | |
| 228 SkPictureUtils::ApproximateBytesUsed(picture_.get()); | |
| 229 recorder_.reset(); | |
| 230 canvas_.clear(); | |
| 231 is_suitable_for_gpu_rasterization_ = | |
| 232 picture_->suitableForGpuRasterization(nullptr); | |
| 233 } | |
| 234 } | 153 } |
| 235 | 154 |
| 236 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 155 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
| 237 DCHECK(ProcessAppendedItemsCalled()); | 156 DCHECK(FinalizeCalled()); |
| 238 return is_suitable_for_gpu_rasterization_; | 157 // This is more permissive than Picture's implementation, since none of the |
| 158 // items might individually trigger a veto even though they collectively have |
| 159 // enough "bad" operations that a corresponding Picture would get vetoed. See |
| 160 // crbug.com/513016. |
| 161 return all_items_are_suitable_for_gpu_rasterization_; |
| 239 } | 162 } |
| 240 | 163 |
| 241 int DisplayItemList::ApproximateOpCount() const { | 164 int DisplayItemList::ApproximateOpCount() const { |
| 242 DCHECK(ProcessAppendedItemsCalled()); | 165 DCHECK(FinalizeCalled()); |
| 243 return approximate_op_count_; | 166 return approximate_op_count_; |
| 244 } | 167 } |
| 245 | 168 |
| 246 size_t DisplayItemList::ApproximateMemoryUsage() const { | 169 size_t DisplayItemList::ApproximateMemoryUsage() const { |
| 247 DCHECK(ProcessAppendedItemsCalled()); | 170 DCHECK(FinalizeCalled()); |
| 248 // We double-count in this case. Produce zero to avoid being misleading. | |
| 249 if (settings_.use_cached_picture && retain_individual_display_items_) | |
| 250 return 0; | |
| 251 | |
| 252 DCHECK(!settings_.use_cached_picture || picture_); | |
| 253 | |
| 254 size_t memory_usage = sizeof(*this); | 171 size_t memory_usage = sizeof(*this); |
| 255 | 172 |
| 256 // Memory outside this class due to |items_|. | 173 // Memory outside this class due to |items_|. |
| 257 memory_usage += items_.GetCapacityInBytes() + external_memory_usage_; | 174 memory_usage += items_.GetCapacityInBytes() + external_memory_usage_; |
| 258 | 175 |
| 259 // Memory outside this class due to |picture|. | |
| 260 memory_usage += picture_memory_usage_; | |
| 261 | |
| 262 // TODO(jbroman): Does anything else owned by this class substantially | 176 // TODO(jbroman): Does anything else owned by this class substantially |
| 263 // contribute to memory usage? | 177 // contribute to memory usage? |
| 178 // TODO(vmpstr): Probably DiscardableImageMap is worth counting here. |
| 264 | 179 |
| 265 return memory_usage; | 180 return memory_usage; |
| 266 } | 181 } |
| 267 | 182 |
| 268 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { | 183 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { |
| 269 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; | 184 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; |
| 270 } | 185 } |
| 271 | 186 |
| 272 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 187 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 273 DisplayItemList::AsValue(bool include_items) const { | 188 DisplayItemList::AsValue(bool include_items) const { |
| 274 DCHECK(ProcessAppendedItemsCalled()); | 189 DCHECK(FinalizeCalled()); |
| 275 scoped_refptr<base::trace_event::TracedValue> state = | 190 scoped_refptr<base::trace_event::TracedValue> state = |
| 276 new base::trace_event::TracedValue(); | 191 new base::trace_event::TracedValue(); |
| 277 | 192 |
| 278 state->BeginDictionary("params"); | 193 state->BeginDictionary("params"); |
| 279 if (include_items) { | 194 if (include_items) { |
| 280 state->BeginArray("items"); | 195 state->BeginArray("items"); |
| 281 size_t item_index = 0; | 196 size_t item_index = 0; |
| 282 for (const DisplayItem& item : items_) { | 197 for (const auto& item : items_) { |
| 283 item.AsValueInto(visual_rects_.size() >= item_index | 198 item.AsValueInto(visual_rects_.size() >= item_index |
| 284 ? visual_rects_[item_index] | 199 ? visual_rects_[item_index] |
| 285 : gfx::Rect(), | 200 : gfx::Rect(), |
| 286 state.get()); | 201 state.get()); |
| 287 item_index++; | 202 item_index++; |
| 288 } | 203 } |
| 289 state->EndArray(); // "items". | 204 state->EndArray(); // "items". |
| 290 } | 205 } |
| 291 state->SetValue("layer_rect", MathUtil::AsValue(layer_rect_)); | |
| 292 state->EndDictionary(); // "params". | 206 state->EndDictionary(); // "params". |
| 293 | 207 |
| 294 if (!layer_rect_.IsEmpty()) { | 208 if (!items_.empty()) { |
| 295 SkPictureRecorder recorder; | 209 SkPictureRecorder recorder; |
| 296 SkCanvas* canvas = | 210 gfx::Rect bounds = rtree_.GetBounds(); |
| 297 recorder.beginRecording(layer_rect_.width(), layer_rect_.height()); | 211 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); |
| 298 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); | 212 canvas->translate(-bounds.x(), -bounds.y()); |
| 299 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); | 213 canvas->clipRect(gfx::RectToSkRect(bounds)); |
| 300 Raster(canvas, NULL, gfx::Rect(), 1.f); | 214 Raster(canvas, nullptr, gfx::Rect(), 1.f); |
| 301 skia::RefPtr<SkPicture> picture = | 215 skia::RefPtr<SkPicture> picture = |
| 302 skia::AdoptRef(recorder.endRecordingAsPicture()); | 216 skia::AdoptRef(recorder.endRecordingAsPicture()); |
| 303 | 217 |
| 304 std::string b64_picture; | 218 std::string b64_picture; |
| 305 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); | 219 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); |
| 306 state->SetString("skp64", b64_picture); | 220 state->SetString("skp64", b64_picture); |
| 307 } | 221 } |
| 308 | 222 |
| 309 return state; | 223 return state; |
| 310 } | 224 } |
| 311 | 225 |
| 312 void DisplayItemList::EmitTraceSnapshot() const { | 226 void DisplayItemList::EmitTraceSnapshot() const { |
| 313 DCHECK(ProcessAppendedItemsCalled()); | 227 DCHECK(FinalizeCalled()); |
| 314 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 228 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 315 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items") "," | 229 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items") "," |
| 316 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," | 230 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," |
| 317 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), | 231 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), |
| 318 "cc::DisplayItemList", this, | 232 "cc::DisplayItemList", this, |
| 319 TracedDisplayItemList::AsTraceableDisplayItemList(this, | 233 TracedDisplayItemList::AsTraceableDisplayItemList(this, |
| 320 DisplayItemsTracingEnabled())); | 234 DisplayItemsTracingEnabled())); |
| 321 } | 235 } |
| 322 | 236 |
| 323 void DisplayItemList::GenerateDiscardableImagesMetadata() { | 237 void DisplayItemList::GenerateDiscardableImagesMetadata() { |
| 324 DCHECK(ProcessAppendedItemsCalled()); | 238 DCHECK(FinalizeCalled()); |
| 325 // This should be only called once, and only after CreateAndCacheSkPicture. | |
| 326 DCHECK(image_map_.empty()); | 239 DCHECK(image_map_.empty()); |
| 327 DCHECK(!settings_.use_cached_picture || picture_); | |
| 328 if (settings_.use_cached_picture && !picture_->willPlayBackBitmaps()) | |
| 329 return; | |
| 330 | 240 |
| 331 // The cached picture is translated by -layer_rect_.origin during record, | 241 gfx::Rect bounds = rtree_.GetBounds(); |
| 332 // so we need to offset that back in order to get right positioning for | |
| 333 // images. | |
| 334 DiscardableImageMap::ScopedMetadataGenerator generator( | 242 DiscardableImageMap::ScopedMetadataGenerator generator( |
| 335 &image_map_, gfx::Size(layer_rect_.right(), layer_rect_.bottom())); | 243 &image_map_, gfx::Size(bounds.right(), bounds.bottom())); |
| 336 Raster(generator.canvas(), nullptr, | 244 Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); |
| 337 gfx::Rect(layer_rect_.right(), layer_rect_.bottom()), 1.f); | |
| 338 } | 245 } |
| 339 | 246 |
| 340 void DisplayItemList::GetDiscardableImagesInRect( | 247 void DisplayItemList::GetDiscardableImagesInRect( |
| 341 const gfx::Rect& rect, | 248 const gfx::Rect& rect, |
| 342 float raster_scale, | 249 float raster_scale, |
| 343 std::vector<DrawImage>* images) { | 250 std::vector<DrawImage>* images) { |
| 344 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); | 251 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); |
| 345 } | 252 } |
| 346 | 253 |
| 347 } // namespace cc | 254 } // namespace cc |
| OLD | NEW |