| 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 |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
| 16 #include "cc/debug/picture_debug_util.h" | 16 #include "cc/debug/picture_debug_util.h" |
| 17 #include "cc/debug/traced_display_item_list.h" | 17 #include "cc/debug/traced_display_item_list.h" |
| 18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
| 19 #include "cc/playback/display_item_list_settings.h" | 19 #include "cc/playback/display_item_list_settings.h" |
| 20 #include "cc/playback/display_item_proto_factory.h" | 20 #include "cc/playback/display_item_proto_factory.h" |
| 21 #include "cc/playback/drawing_display_item.h" | 21 #include "cc/playback/drawing_display_item.h" |
| 22 #include "cc/playback/largest_display_item.h" | 22 #include "cc/playback/largest_display_item.h" |
| 23 #include "cc/proto/display_item.pb.h" | 23 #include "cc/proto/display_item.pb.h" |
| 24 #include "cc/proto/gfx_conversions.h" | 24 #include "cc/proto/gfx_conversions.h" |
| 25 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 26 #include "third_party/skia/include/core/SkPictureRecorder.h" | 26 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 27 #include "third_party/skia/include/utils/SkPictureUtils.h" | 27 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/rect_conversions.h" | |
| 30 #include "ui/gfx/skia_util.h" | 29 #include "ui/gfx/skia_util.h" |
| 31 | 30 |
| 32 namespace cc { | 31 namespace cc { |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 // We don't perform per-layer solid color analysis when there are too many skia | 35 // We don't perform per-layer solid color analysis when there are too many skia |
| 37 // operations. | 36 // operations. |
| 38 const int kOpCountThatIsOkToAnalyze = 10; | 37 const int kOpCountThatIsOkToAnalyze = 10; |
| 39 | 38 |
| 40 bool DisplayItemsTracingEnabled() { | 39 bool DisplayItemsTracingEnabled() { |
| 41 bool tracing_enabled; | 40 bool tracing_enabled; |
| 42 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 41 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
| 43 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); | 42 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); |
| 44 return tracing_enabled; | 43 return tracing_enabled; |
| 45 } | 44 } |
| 46 | 45 |
| 47 bool GetCanvasClipBounds(SkCanvas* canvas, gfx::Rect* clip_bounds) { | |
| 48 SkRect canvas_clip_bounds; | |
| 49 if (!canvas->getClipBounds(&canvas_clip_bounds)) | |
| 50 return false; | |
| 51 *clip_bounds = ToEnclosingRect(gfx::SkRectToRectF(canvas_clip_bounds)); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 const int kDefaultNumDisplayItemsToReserve = 100; | 46 const int kDefaultNumDisplayItemsToReserve = 100; |
| 56 | 47 |
| 57 } // namespace | 48 } // namespace |
| 58 | 49 |
| 59 DisplayItemList::Inputs::Inputs(const DisplayItemListSettings& settings) | 50 DisplayItemList::Inputs::Inputs(gfx::Rect layer_rect, |
| 51 const DisplayItemListSettings& settings) |
| 60 : items(LargestDisplayItemSize(), | 52 : items(LargestDisplayItemSize(), |
| 61 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), | 53 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), |
| 62 settings(settings) {} | 54 settings(settings), |
| 55 layer_rect(layer_rect), |
| 56 is_suitable_for_gpu_rasterization(true) {} |
| 63 | 57 |
| 64 DisplayItemList::Inputs::~Inputs() {} | 58 DisplayItemList::Inputs::~Inputs() {} |
| 65 | 59 |
| 66 scoped_refptr<DisplayItemList> DisplayItemList::Create( | 60 scoped_refptr<DisplayItemList> DisplayItemList::Create( |
| 61 const gfx::Rect& layer_rect, |
| 67 const DisplayItemListSettings& settings) { | 62 const DisplayItemListSettings& settings) { |
| 68 return make_scoped_refptr(new DisplayItemList(settings)); | 63 return make_scoped_refptr(new DisplayItemList( |
| 64 layer_rect, settings, |
| 65 !settings.use_cached_picture || DisplayItemsTracingEnabled())); |
| 69 } | 66 } |
| 70 | 67 |
| 71 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( | 68 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( |
| 72 const proto::DisplayItemList& proto, | 69 const proto::DisplayItemList& proto, |
| 73 ClientPictureCache* client_picture_cache, | 70 ClientPictureCache* client_picture_cache, |
| 74 std::vector<uint32_t>* used_engine_picture_ids) { | 71 std::vector<uint32_t>* used_engine_picture_ids) { |
| 72 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); |
| 75 scoped_refptr<DisplayItemList> list = | 73 scoped_refptr<DisplayItemList> list = |
| 76 DisplayItemList::Create(DisplayItemListSettings(proto.settings())); | 74 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), |
| 75 DisplayItemListSettings(proto.settings())); |
| 77 | 76 |
| 78 for (int i = 0; i < proto.items_size(); i++) { | 77 for (int i = 0; i < proto.items_size(); i++) { |
| 79 const proto::DisplayItem& item_proto = proto.items(i); | 78 const proto::DisplayItem& item_proto = proto.items(i); |
| 80 const gfx::Rect visual_rect = ProtoToRect(proto.visual_rects(i)); | |
| 81 DisplayItemProtoFactory::AllocateAndConstruct( | 79 DisplayItemProtoFactory::AllocateAndConstruct( |
| 82 visual_rect, list.get(), item_proto, client_picture_cache, | 80 layer_rect, list.get(), item_proto, client_picture_cache, |
| 83 used_engine_picture_ids); | 81 used_engine_picture_ids); |
| 84 } | 82 } |
| 85 | 83 |
| 86 list->Finalize(); | 84 list->Finalize(); |
| 87 | 85 |
| 88 return list; | 86 return list; |
| 89 } | 87 } |
| 90 | 88 |
| 91 DisplayItemList::DisplayItemList(const DisplayItemListSettings& settings) | 89 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, |
| 92 : inputs_(settings) {} | 90 const DisplayItemListSettings& settings, |
| 91 bool retain_individual_display_items) |
| 92 : retain_individual_display_items_(retain_individual_display_items), |
| 93 approximate_op_count_(0), |
| 94 picture_memory_usage_(0), |
| 95 inputs_(layer_rect, settings) { |
| 96 if (inputs_.settings.use_cached_picture) { |
| 97 SkRTreeFactory factory; |
| 98 recorder_.reset(new SkPictureRecorder()); |
| 99 |
| 100 SkCanvas* canvas = recorder_->beginRecording( |
| 101 inputs_.layer_rect.width(), inputs_.layer_rect.height(), &factory); |
| 102 canvas->translate(-inputs_.layer_rect.x(), -inputs_.layer_rect.y()); |
| 103 canvas->clipRect(gfx::RectToSkRect(inputs_.layer_rect)); |
| 104 } |
| 105 } |
| 93 | 106 |
| 94 DisplayItemList::~DisplayItemList() { | 107 DisplayItemList::~DisplayItemList() { |
| 95 } | 108 } |
| 96 | 109 |
| 97 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { | 110 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { |
| 98 // The flattened SkPicture approach is going away, and the proto | 111 // The flattened SkPicture approach is going away, and the proto |
| 99 // doesn't currently support serializing that flattened picture. | 112 // doesn't currently support serializing that flattened picture. |
| 113 DCHECK(retain_individual_display_items_); |
| 114 |
| 115 RectToProto(inputs_.layer_rect, proto->mutable_layer_rect()); |
| 100 inputs_.settings.ToProtobuf(proto->mutable_settings()); | 116 inputs_.settings.ToProtobuf(proto->mutable_settings()); |
| 101 | 117 |
| 102 DCHECK_EQ(0, proto->items_size()); | 118 DCHECK_EQ(0, proto->items_size()); |
| 103 DCHECK_EQ(0, proto->visual_rects_size()); | 119 for (const auto& item : inputs_.items) |
| 104 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) | |
| 105 << "items.size() " << inputs_.items.size() << " visual_rects.size() " | |
| 106 << inputs_.visual_rects.size(); | |
| 107 int i = 0; | |
| 108 for (const auto& item : inputs_.items) { | |
| 109 RectToProto(inputs_.visual_rects[i++], proto->add_visual_rects()); | |
| 110 item.ToProtobuf(proto->add_items()); | 120 item.ToProtobuf(proto->add_items()); |
| 111 } | |
| 112 } | 121 } |
| 113 | 122 |
| 114 void DisplayItemList::Raster(SkCanvas* canvas, | 123 void DisplayItemList::Raster(SkCanvas* canvas, |
| 115 SkPicture::AbortCallback* callback, | 124 SkPicture::AbortCallback* callback, |
| 116 const gfx::Rect& canvas_target_playback_rect, | 125 const gfx::Rect& canvas_target_playback_rect, |
| 117 float contents_scale) const { | 126 float contents_scale) const { |
| 118 canvas->save(); | 127 canvas->save(); |
| 128 |
| 119 if (!canvas_target_playback_rect.IsEmpty()) { | 129 if (!canvas_target_playback_rect.IsEmpty()) { |
| 120 // canvas_target_playback_rect is specified in device space. We can't | 130 // canvas_target_playback_rect is specified in device space. We can't |
| 121 // use clipRect because canvas CTM will be applied on it. Use clipRegion | 131 // use clipRect because canvas CTM will be applied on it. Use clipRegion |
| 122 // instead because it ignores canvas CTM. | 132 // instead because it ignores canvas CTM. |
| 123 SkRegion device_clip; | 133 SkRegion device_clip; |
| 124 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); | 134 device_clip.setRect(gfx::RectToSkIRect(canvas_target_playback_rect)); |
| 125 canvas->clipRegion(device_clip); | 135 canvas->clipRegion(device_clip); |
| 126 } | 136 } |
| 137 |
| 127 canvas->scale(contents_scale, contents_scale); | 138 canvas->scale(contents_scale, contents_scale); |
| 128 Raster(canvas, callback); | 139 Raster(canvas, callback); |
| 129 canvas->restore(); | 140 canvas->restore(); |
| 130 } | 141 } |
| 131 | 142 |
| 132 void DisplayItemList::Raster(SkCanvas* canvas, | 143 void DisplayItemList::Raster(SkCanvas* canvas, |
| 133 SkPicture::AbortCallback* callback) const { | 144 SkPicture::AbortCallback* callback) const { |
| 134 gfx::Rect canvas_playback_rect; | 145 if (!inputs_.settings.use_cached_picture) { |
| 135 if (!GetCanvasClipBounds(canvas, &canvas_playback_rect)) | 146 for (const auto& item : inputs_.items) |
| 136 return; | 147 item.Raster(canvas, callback); |
| 148 } else { |
| 149 DCHECK(picture_); |
| 137 | 150 |
| 138 std::vector<size_t> indices; | 151 canvas->save(); |
| 139 rtree_.Search(canvas_playback_rect, &indices); | 152 canvas->translate(inputs_.layer_rect.x(), inputs_.layer_rect.y()); |
| 140 for (size_t index : indices) { | 153 if (callback) { |
| 141 inputs_.items[index].Raster(canvas, callback); | 154 // If we have a callback, we need to call |draw()|, |drawPicture()| |
| 142 // We use a callback during solid color analysis on the compositor thread to | 155 // doesn't take a callback. This is used by |AnalysisCanvas| to early |
| 143 // break out early. Since we're handling a sequence of pictures via rtree | 156 // out. |
| 144 // query results ourselves, we have to respect the callback and early out. | 157 picture_->playback(canvas, callback); |
| 145 if (callback && callback->abort()) | 158 } else { |
| 146 break; | 159 // Prefer to call |drawPicture()| on the canvas since it could place the |
| 160 // entire picture on the canvas instead of parsing the skia operations. |
| 161 canvas->drawPicture(picture_.get()); |
| 162 } |
| 163 canvas->restore(); |
| 147 } | 164 } |
| 148 } | 165 } |
| 149 | 166 |
| 167 void DisplayItemList::ProcessAppendedItem(const DisplayItem* item) { |
| 168 if (inputs_.settings.use_cached_picture) { |
| 169 DCHECK(recorder_); |
| 170 item->Raster(recorder_->getRecordingCanvas(), nullptr); |
| 171 } |
| 172 if (!retain_individual_display_items_) { |
| 173 inputs_.items.Clear(); |
| 174 } |
| 175 } |
| 176 |
| 177 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { |
| 178 DCHECK(recorder_); |
| 179 DCHECK(!retain_individual_display_items_); |
| 180 |
| 181 item.Raster(recorder_->getRecordingCanvas(), nullptr); |
| 182 } |
| 183 |
| 184 bool DisplayItemList::RetainsIndividualDisplayItems() const { |
| 185 return retain_individual_display_items_; |
| 186 } |
| 187 |
| 150 void DisplayItemList::Finalize() { | 188 void DisplayItemList::Finalize() { |
| 151 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); | 189 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); |
| 152 // TODO(dtrainor): Need to deal with serializing inputs_.visual_rects. | 190 // TODO(dtrainor): Need to deal with serializing visual_rects_. |
| 153 // http://crbug.com/568757. | 191 // http://crbug.com/568757. |
| 154 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) | 192 DCHECK(!retain_individual_display_items_ || |
| 193 inputs_.items.size() == inputs_.visual_rects.size()) |
| 155 << "items.size() " << inputs_.items.size() << " visual_rects.size() " | 194 << "items.size() " << inputs_.items.size() << " visual_rects.size() " |
| 156 << inputs_.visual_rects.size(); | 195 << inputs_.visual_rects.size(); |
| 157 rtree_.Build(inputs_.visual_rects); | |
| 158 | 196 |
| 159 // TODO(wkorman): Restore the below, potentially with a switch to allow | 197 // TODO(vmpstr): Build and make use of an RTree from the visual |
| 160 // clearing visual rects except for Blimp engine. http://crbug.com/633750 | 198 // rects. For now we just clear them out since we won't ever need |
| 161 // if (!retain_visual_rects_) | 199 // them to stick around post-Finalize. http://crbug.com/527245 |
| 162 // // This clears both the vector and the vector's capacity, since | 200 // This clears both the vector and the vector's capacity, since visual_rects_ |
| 163 // // visual_rects won't be used anymore. | 201 // won't be used anymore. |
| 164 // std::vector<gfx::Rect>().swap(inputs_.visual_rects); | 202 std::vector<gfx::Rect>().swap(inputs_.visual_rects); |
| 203 |
| 204 if (inputs_.settings.use_cached_picture) { |
| 205 // Convert to an SkPicture for faster rasterization. |
| 206 DCHECK(inputs_.settings.use_cached_picture); |
| 207 DCHECK(!picture_); |
| 208 picture_ = recorder_->finishRecordingAsPicture(); |
| 209 DCHECK(picture_); |
| 210 picture_memory_usage_ = |
| 211 SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| 212 recorder_.reset(); |
| 213 } |
| 165 } | 214 } |
| 166 | 215 |
| 167 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 216 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
| 168 // TODO(wkorman): This is more permissive than Picture's implementation, since | 217 return inputs_.is_suitable_for_gpu_rasterization; |
| 169 // none of the items might individually trigger a veto even though they | |
| 170 // collectively have enough "bad" operations that a corresponding Picture | |
| 171 // would get vetoed. See crbug.com/513016. | |
| 172 return inputs_.all_items_are_suitable_for_gpu_rasterization; | |
| 173 } | 218 } |
| 174 | 219 |
| 175 int DisplayItemList::ApproximateOpCount() const { | 220 int DisplayItemList::ApproximateOpCount() const { |
| 176 return approximate_op_count_; | 221 if (retain_individual_display_items_) |
| 222 return approximate_op_count_; |
| 223 return picture_ ? picture_->approximateOpCount() : 0; |
| 177 } | 224 } |
| 178 | 225 |
| 179 size_t DisplayItemList::ApproximateMemoryUsage() const { | 226 size_t DisplayItemList::ApproximateMemoryUsage() const { |
| 227 // We double-count in this case. Produce zero to avoid being misleading. |
| 228 if (inputs_.settings.use_cached_picture && retain_individual_display_items_) |
| 229 return 0; |
| 230 |
| 231 DCHECK(!inputs_.settings.use_cached_picture || picture_); |
| 232 |
| 180 size_t memory_usage = sizeof(*this); | 233 size_t memory_usage = sizeof(*this); |
| 181 | 234 |
| 182 size_t external_memory_usage = 0; | 235 size_t external_memory_usage = 0; |
| 183 // Warning: this double-counts SkPicture data if use_cached_picture is | 236 if (retain_individual_display_items_) { |
| 184 // also true. | 237 // Warning: this double-counts SkPicture data if use_cached_picture is |
| 185 for (const auto& item : inputs_.items) { | 238 // also true. |
| 186 external_memory_usage += item.ExternalMemoryUsage(); | 239 for (const auto& item : inputs_.items) { |
| 240 external_memory_usage += item.ExternalMemoryUsage(); |
| 241 } |
| 187 } | 242 } |
| 188 | 243 |
| 189 // Memory outside this class due to |items_|. | 244 // Memory outside this class due to |items_|. |
| 190 memory_usage += inputs_.items.GetCapacityInBytes() + external_memory_usage; | 245 memory_usage += inputs_.items.GetCapacityInBytes() + external_memory_usage; |
| 191 | 246 |
| 247 // Memory outside this class due to |picture|. |
| 248 memory_usage += picture_memory_usage_; |
| 249 |
| 192 // TODO(jbroman): Does anything else owned by this class substantially | 250 // TODO(jbroman): Does anything else owned by this class substantially |
| 193 // contribute to memory usage? | 251 // contribute to memory usage? |
| 194 // TODO(vmpstr): Probably DiscardableImageMap is worth counting here. | |
| 195 | 252 |
| 196 return memory_usage; | 253 return memory_usage; |
| 197 } | 254 } |
| 198 | 255 |
| 199 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { | 256 bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const { |
| 200 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; | 257 return ApproximateOpCount() <= kOpCountThatIsOkToAnalyze; |
| 201 } | 258 } |
| 202 | 259 |
| 203 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 260 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 204 DisplayItemList::AsValue(bool include_items) const { | 261 DisplayItemList::AsValue(bool include_items) const { |
| 205 std::unique_ptr<base::trace_event::TracedValue> state( | 262 std::unique_ptr<base::trace_event::TracedValue> state( |
| 206 new base::trace_event::TracedValue()); | 263 new base::trace_event::TracedValue()); |
| 207 | 264 |
| 208 state->BeginDictionary("params"); | 265 state->BeginDictionary("params"); |
| 209 if (include_items) { | 266 if (include_items) { |
| 210 state->BeginArray("items"); | 267 state->BeginArray("items"); |
| 211 size_t item_index = 0; | 268 size_t item_index = 0; |
| 212 for (const DisplayItem& item : inputs_.items) { | 269 for (const DisplayItem& item : inputs_.items) { |
| 213 item.AsValueInto(item_index < inputs_.visual_rects.size() | 270 item.AsValueInto(item_index < inputs_.visual_rects.size() |
| 214 ? inputs_.visual_rects[item_index] | 271 ? inputs_.visual_rects[item_index] |
| 215 : gfx::Rect(), | 272 : gfx::Rect(), |
| 216 state.get()); | 273 state.get()); |
| 217 item_index++; | 274 item_index++; |
| 218 } | 275 } |
| 219 state->EndArray(); // "items". | 276 state->EndArray(); // "items". |
| 220 } | 277 } |
| 278 state->SetValue("layer_rect", MathUtil::AsValue(inputs_.layer_rect)); |
| 221 state->EndDictionary(); // "params". | 279 state->EndDictionary(); // "params". |
| 222 | 280 |
| 223 SkPictureRecorder recorder; | 281 if (!inputs_.layer_rect.IsEmpty()) { |
| 224 gfx::Rect bounds = rtree_.GetBounds(); | 282 SkPictureRecorder recorder; |
| 225 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); | 283 SkCanvas* canvas = recorder.beginRecording(inputs_.layer_rect.width(), |
| 226 canvas->translate(-bounds.x(), -bounds.y()); | 284 inputs_.layer_rect.height()); |
| 227 canvas->clipRect(gfx::RectToSkRect(bounds)); | 285 canvas->translate(-inputs_.layer_rect.x(), -inputs_.layer_rect.y()); |
| 228 Raster(canvas, nullptr, gfx::Rect(), 1.f); | 286 canvas->clipRect(gfx::RectToSkRect(inputs_.layer_rect)); |
| 229 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 287 Raster(canvas, NULL, gfx::Rect(), 1.f); |
| 288 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 230 | 289 |
| 231 std::string b64_picture; | 290 std::string b64_picture; |
| 232 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); | 291 PictureDebugUtil::SerializeAsBase64(picture.get(), &b64_picture); |
| 233 state->SetString("skp64", b64_picture); | 292 state->SetString("skp64", b64_picture); |
| 293 } |
| 234 | 294 |
| 235 return std::move(state); | 295 return std::move(state); |
| 236 } | 296 } |
| 237 | 297 |
| 238 void DisplayItemList::EmitTraceSnapshot() const { | 298 void DisplayItemList::EmitTraceSnapshot() const { |
| 239 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 299 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 240 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items") "," | 300 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items") "," |
| 241 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," | 301 TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," |
| 242 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), | 302 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), |
| 243 "cc::DisplayItemList", this, | 303 "cc::DisplayItemList", this, |
| 244 TracedDisplayItemList::AsTraceableDisplayItemList(this, | 304 TracedDisplayItemList::AsTraceableDisplayItemList(this, |
| 245 DisplayItemsTracingEnabled())); | 305 DisplayItemsTracingEnabled())); |
| 246 } | 306 } |
| 247 | 307 |
| 248 void DisplayItemList::GenerateDiscardableImagesMetadata() { | 308 void DisplayItemList::GenerateDiscardableImagesMetadata() { |
| 249 // This should be only called once, and only after CreateAndCacheSkPicture. | 309 // This should be only called once, and only after CreateAndCacheSkPicture. |
| 250 DCHECK(image_map_.empty()); | 310 DCHECK(image_map_.empty()); |
| 311 DCHECK(!inputs_.settings.use_cached_picture || picture_); |
| 312 if (inputs_.settings.use_cached_picture && !picture_->willPlayBackBitmaps()) |
| 313 return; |
| 251 | 314 |
| 252 gfx::Rect bounds = rtree_.GetBounds(); | 315 // The cached picture is translated by -layer_rect_.origin during record, |
| 316 // so we need to offset that back in order to get right positioning for |
| 317 // images. |
| 253 DiscardableImageMap::ScopedMetadataGenerator generator( | 318 DiscardableImageMap::ScopedMetadataGenerator generator( |
| 254 &image_map_, gfx::Size(bounds.right(), bounds.bottom())); | 319 &image_map_, |
| 255 Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | 320 gfx::Size(inputs_.layer_rect.right(), inputs_.layer_rect.bottom())); |
| 321 Raster(generator.canvas(), nullptr, |
| 322 gfx::Rect(inputs_.layer_rect.right(), inputs_.layer_rect.bottom()), |
| 323 1.f); |
| 256 } | 324 } |
| 257 | 325 |
| 258 void DisplayItemList::GetDiscardableImagesInRect( | 326 void DisplayItemList::GetDiscardableImagesInRect( |
| 259 const gfx::Rect& rect, | 327 const gfx::Rect& rect, |
| 260 float raster_scale, | 328 float raster_scale, |
| 261 std::vector<DrawImage>* images) { | 329 std::vector<DrawImage>* images) { |
| 262 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); | 330 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); |
| 263 } | 331 } |
| 264 | 332 |
| 265 } // namespace cc | 333 } // namespace cc |
| OLD | NEW |