| 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_list_raster_source.h" | 5 #include "cc/playback/display_list_raster_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/containers/adapters.h" | 9 #include "base/containers/adapters.h" |
| 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" |
| 10 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 11 #include "cc/base/region.h" | 14 #include "cc/base/region.h" |
| 12 #include "cc/debug/debug_colors.h" | 15 #include "cc/debug/debug_colors.h" |
| 13 #include "cc/playback/discardable_image_map.h" | 16 #include "cc/playback/discardable_image_map.h" |
| 14 #include "cc/playback/display_item_list.h" | 17 #include "cc/playback/display_item_list.h" |
| 15 #include "cc/tiles/image_decode_controller.h" | 18 #include "cc/tiles/image_decode_controller.h" |
| 16 #include "skia/ext/analysis_canvas.h" | 19 #include "skia/ext/analysis_canvas.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkPictureRecorder.h" | 21 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 19 #include "third_party/skia/include/core/SkTLazy.h" | 22 #include "third_party/skia/include/core/SkTLazy.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 requires_clear_(other->requires_clear_), | 205 requires_clear_(other->requires_clear_), |
| 203 can_use_lcd_text_(can_use_lcd_text), | 206 can_use_lcd_text_(can_use_lcd_text), |
| 204 is_solid_color_(other->is_solid_color_), | 207 is_solid_color_(other->is_solid_color_), |
| 205 solid_color_(other->solid_color_), | 208 solid_color_(other->solid_color_), |
| 206 recorded_viewport_(other->recorded_viewport_), | 209 recorded_viewport_(other->recorded_viewport_), |
| 207 size_(other->size_), | 210 size_(other->size_), |
| 208 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 211 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
| 209 slow_down_raster_scale_factor_for_debug_( | 212 slow_down_raster_scale_factor_for_debug_( |
| 210 other->slow_down_raster_scale_factor_for_debug_), | 213 other->slow_down_raster_scale_factor_for_debug_), |
| 211 should_attempt_to_use_distance_field_text_(false), | 214 should_attempt_to_use_distance_field_text_(false), |
| 212 image_decode_controller_(nullptr) {} | 215 image_decode_controller_(nullptr) { |
| 216 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 217 // Don't register a dump provider in these cases. |
| 218 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
| 219 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 220 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 221 this, "cc::DisplayListRasterSource", |
| 222 base::ThreadTaskRunnerHandle::Get()); |
| 223 } |
| 224 } |
| 213 | 225 |
| 214 DisplayListRasterSource::DisplayListRasterSource( | 226 DisplayListRasterSource::DisplayListRasterSource( |
| 215 const DisplayListRasterSource* other, | 227 const DisplayListRasterSource* other, |
| 216 bool can_use_lcd_text) | 228 bool can_use_lcd_text) |
| 217 : display_list_(other->display_list_), | 229 : display_list_(other->display_list_), |
| 218 painter_reported_memory_usage_(other->painter_reported_memory_usage_), | 230 painter_reported_memory_usage_(other->painter_reported_memory_usage_), |
| 219 background_color_(other->background_color_), | 231 background_color_(other->background_color_), |
| 220 requires_clear_(other->requires_clear_), | 232 requires_clear_(other->requires_clear_), |
| 221 can_use_lcd_text_(can_use_lcd_text), | 233 can_use_lcd_text_(can_use_lcd_text), |
| 222 is_solid_color_(other->is_solid_color_), | 234 is_solid_color_(other->is_solid_color_), |
| 223 solid_color_(other->solid_color_), | 235 solid_color_(other->solid_color_), |
| 224 recorded_viewport_(other->recorded_viewport_), | 236 recorded_viewport_(other->recorded_viewport_), |
| 225 size_(other->size_), | 237 size_(other->size_), |
| 226 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 238 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
| 227 slow_down_raster_scale_factor_for_debug_( | 239 slow_down_raster_scale_factor_for_debug_( |
| 228 other->slow_down_raster_scale_factor_for_debug_), | 240 other->slow_down_raster_scale_factor_for_debug_), |
| 229 should_attempt_to_use_distance_field_text_( | 241 should_attempt_to_use_distance_field_text_( |
| 230 other->should_attempt_to_use_distance_field_text_), | 242 other->should_attempt_to_use_distance_field_text_), |
| 231 image_decode_controller_(other->image_decode_controller_) {} | 243 image_decode_controller_(other->image_decode_controller_) { |
| 244 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 245 // Don't register a dump provider in these cases. |
| 246 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
| 247 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 248 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 249 this, "cc::DisplayListRasterSource", |
| 250 base::ThreadTaskRunnerHandle::Get()); |
| 251 } |
| 252 } |
| 232 | 253 |
| 233 DisplayListRasterSource::~DisplayListRasterSource() { | 254 DisplayListRasterSource::~DisplayListRasterSource() { |
| 255 // For MemoryDumpProvider deregistration to work correctly, this must happen |
| 256 // on the same thread that the DisplayListRasterSource was created on. |
| 257 DCHECK(memory_dump_thread_checker_.CalledOnValidThread()); |
| 258 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 259 this); |
| 234 } | 260 } |
| 235 | 261 |
| 236 void DisplayListRasterSource::PlaybackToSharedCanvas( | 262 void DisplayListRasterSource::PlaybackToSharedCanvas( |
| 237 SkCanvas* raster_canvas, | 263 SkCanvas* raster_canvas, |
| 238 const gfx::Rect& canvas_rect, | 264 const gfx::Rect& canvas_rect, |
| 239 float contents_scale) const { | 265 float contents_scale) const { |
| 240 // TODO(vmpstr): This can be improved by plumbing whether the tile itself has | 266 // TODO(vmpstr): This can be improved by plumbing whether the tile itself has |
| 241 // discardable images. This way we would only pay for the hijack canvas if the | 267 // discardable images. This way we would only pay for the hijack canvas if the |
| 242 // tile actually needed it. | 268 // tile actually needed it. |
| 243 if (display_list_->MayHaveDiscardableImages()) { | 269 if (display_list_->MayHaveDiscardableImages()) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 void DisplayListRasterSource::SetImageDecodeController( | 526 void DisplayListRasterSource::SetImageDecodeController( |
| 501 ImageDecodeController* image_decode_controller) { | 527 ImageDecodeController* image_decode_controller) { |
| 502 DCHECK(image_decode_controller); | 528 DCHECK(image_decode_controller); |
| 503 // Note that although this function should only be called once, tests tend to | 529 // Note that although this function should only be called once, tests tend to |
| 504 // call it several times using the same controller. | 530 // call it several times using the same controller. |
| 505 DCHECK(!image_decode_controller_ || | 531 DCHECK(!image_decode_controller_ || |
| 506 image_decode_controller_ == image_decode_controller); | 532 image_decode_controller_ == image_decode_controller); |
| 507 image_decode_controller_ = image_decode_controller; | 533 image_decode_controller_ = image_decode_controller; |
| 508 } | 534 } |
| 509 | 535 |
| 536 bool DisplayListRasterSource::OnMemoryDump( |
| 537 const base::trace_event::MemoryDumpArgs& args, |
| 538 base::trace_event::ProcessMemoryDump* pmd) { |
| 539 DCHECK(memory_dump_thread_checker_.CalledOnValidThread()); |
| 540 |
| 541 uint64_t memory_usage = GetPictureMemoryUsage(); |
| 542 if (memory_usage > 0) { |
| 543 std::string dump_name = base::StringPrintf( |
| 544 "cc/display_lists/display_list_raster_source_%p", this); |
| 545 base::trace_event::MemoryAllocatorDump* dump = |
| 546 pmd->CreateAllocatorDump(dump_name); |
| 547 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 548 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 549 memory_usage); |
| 550 } |
| 551 return true; |
| 552 } |
| 553 |
| 510 } // namespace cc | 554 } // namespace cc |
| OLD | NEW |