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