| 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/raster_source.h" | 5 #include "cc/playback/raster_source.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "base/trace_event/memory_dump_manager.h" | |
| 12 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 13 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
| 14 #include "cc/debug/debug_colors.h" | 11 #include "cc/debug/debug_colors.h" |
| 15 #include "cc/playback/display_item_list.h" | 12 #include "cc/playback/display_item_list.h" |
| 16 #include "cc/playback/image_hijack_canvas.h" | 13 #include "cc/playback/image_hijack_canvas.h" |
| 17 #include "cc/playback/skip_image_canvas.h" | 14 #include "cc/playback/skip_image_canvas.h" |
| 18 #include "skia/ext/analysis_canvas.h" | 15 #include "skia/ext/analysis_canvas.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkPictureRecorder.h" | 17 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 21 #include "ui/gfx/geometry/rect_conversions.h" | 18 #include "ui/gfx/geometry/rect_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 can_use_lcd_text_(can_use_lcd_text), | 33 can_use_lcd_text_(can_use_lcd_text), |
| 37 is_solid_color_(other->is_solid_color_), | 34 is_solid_color_(other->is_solid_color_), |
| 38 solid_color_(other->solid_color_), | 35 solid_color_(other->solid_color_), |
| 39 recorded_viewport_(other->recorded_viewport_), | 36 recorded_viewport_(other->recorded_viewport_), |
| 40 size_(other->size_), | 37 size_(other->size_), |
| 41 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 38 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
| 42 slow_down_raster_scale_factor_for_debug_( | 39 slow_down_raster_scale_factor_for_debug_( |
| 43 other->slow_down_raster_scale_factor_for_debug_), | 40 other->slow_down_raster_scale_factor_for_debug_), |
| 44 should_attempt_to_use_distance_field_text_(false), | 41 should_attempt_to_use_distance_field_text_(false), |
| 45 image_decode_controller_(nullptr) { | 42 image_decode_controller_(nullptr) { |
| 46 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | |
| 47 // Don't register a dump provider in these cases. | |
| 48 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | |
| 49 if (base::ThreadTaskRunnerHandle::IsSet()) { | |
| 50 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 51 this, "cc::RasterSource", base::ThreadTaskRunnerHandle::Get()); | |
| 52 } | |
| 53 } | 43 } |
| 54 | 44 |
| 55 RasterSource::RasterSource(const RasterSource* other, bool can_use_lcd_text) | 45 RasterSource::RasterSource(const RasterSource* other, bool can_use_lcd_text) |
| 56 : display_list_(other->display_list_), | 46 : display_list_(other->display_list_), |
| 57 painter_reported_memory_usage_(other->painter_reported_memory_usage_), | 47 painter_reported_memory_usage_(other->painter_reported_memory_usage_), |
| 58 background_color_(other->background_color_), | 48 background_color_(other->background_color_), |
| 59 requires_clear_(other->requires_clear_), | 49 requires_clear_(other->requires_clear_), |
| 60 can_use_lcd_text_(can_use_lcd_text), | 50 can_use_lcd_text_(can_use_lcd_text), |
| 61 is_solid_color_(other->is_solid_color_), | 51 is_solid_color_(other->is_solid_color_), |
| 62 solid_color_(other->solid_color_), | 52 solid_color_(other->solid_color_), |
| 63 recorded_viewport_(other->recorded_viewport_), | 53 recorded_viewport_(other->recorded_viewport_), |
| 64 size_(other->size_), | 54 size_(other->size_), |
| 65 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | 55 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), |
| 66 slow_down_raster_scale_factor_for_debug_( | 56 slow_down_raster_scale_factor_for_debug_( |
| 67 other->slow_down_raster_scale_factor_for_debug_), | 57 other->slow_down_raster_scale_factor_for_debug_), |
| 68 should_attempt_to_use_distance_field_text_( | 58 should_attempt_to_use_distance_field_text_( |
| 69 other->should_attempt_to_use_distance_field_text_), | 59 other->should_attempt_to_use_distance_field_text_), |
| 70 image_decode_controller_(other->image_decode_controller_) { | 60 image_decode_controller_(other->image_decode_controller_) { |
| 71 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | |
| 72 // Don't register a dump provider in these cases. | |
| 73 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | |
| 74 if (base::ThreadTaskRunnerHandle::IsSet()) { | |
| 75 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 76 this, "cc::RasterSource", base::ThreadTaskRunnerHandle::Get()); | |
| 77 } | |
| 78 } | 61 } |
| 79 | 62 |
| 80 RasterSource::~RasterSource() { | 63 RasterSource::~RasterSource() { |
| 81 // For MemoryDumpProvider deregistration to work correctly, this must happen | |
| 82 // on the same thread that the RasterSource was created on. | |
| 83 DCHECK(memory_dump_thread_checker_.CalledOnValidThread()); | |
| 84 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 85 this); | |
| 86 } | 64 } |
| 87 | 65 |
| 88 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, | 66 void RasterSource::PlaybackToCanvas(SkCanvas* raster_canvas, |
| 89 const gfx::Rect& canvas_bitmap_rect, | 67 const gfx::Rect& canvas_bitmap_rect, |
| 90 const gfx::Rect& canvas_playback_rect, | 68 const gfx::Rect& canvas_playback_rect, |
| 91 float contents_scale, | 69 float contents_scale, |
| 92 const PlaybackSettings& settings) const { | 70 const PlaybackSettings& settings) const { |
| 93 if (!settings.playback_to_shared_canvas) { | 71 if (!settings.playback_to_shared_canvas) { |
| 94 PrepareForPlaybackToCanvas(raster_canvas, canvas_bitmap_rect, | 72 PrepareForPlaybackToCanvas(raster_canvas, canvas_bitmap_rect, |
| 95 canvas_playback_rect, contents_scale); | 73 canvas_playback_rect, contents_scale); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 bool can_use_lcd_text = false; | 306 bool can_use_lcd_text = false; |
| 329 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); | 307 return scoped_refptr<RasterSource>(new RasterSource(this, can_use_lcd_text)); |
| 330 } | 308 } |
| 331 | 309 |
| 332 void RasterSource::SetImageDecodeController( | 310 void RasterSource::SetImageDecodeController( |
| 333 ImageDecodeController* image_decode_controller) { | 311 ImageDecodeController* image_decode_controller) { |
| 334 DCHECK(image_decode_controller); | 312 DCHECK(image_decode_controller); |
| 335 image_decode_controller_ = image_decode_controller; | 313 image_decode_controller_ = image_decode_controller; |
| 336 } | 314 } |
| 337 | 315 |
| 338 bool RasterSource::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
| 339 base::trace_event::ProcessMemoryDump* pmd) { | |
| 340 DCHECK(memory_dump_thread_checker_.CalledOnValidThread()); | |
| 341 | |
| 342 uint64_t memory_usage = GetPictureMemoryUsage(); | |
| 343 if (memory_usage > 0) { | |
| 344 std::string dump_name = | |
| 345 base::StringPrintf("cc/display_lists/raster_source_%p", this); | |
| 346 base::trace_event::MemoryAllocatorDump* dump = | |
| 347 pmd->CreateAllocatorDump(dump_name); | |
| 348 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 349 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 350 memory_usage); | |
| 351 } | |
| 352 return true; | |
| 353 } | |
| 354 | |
| 355 RasterSource::PlaybackSettings::PlaybackSettings() | 316 RasterSource::PlaybackSettings::PlaybackSettings() |
| 356 : playback_to_shared_canvas(false), | 317 : playback_to_shared_canvas(false), |
| 357 skip_images(false), | 318 skip_images(false), |
| 358 use_image_hijack_canvas(true) {} | 319 use_image_hijack_canvas(true) {} |
| 359 | 320 |
| 360 } // namespace cc | 321 } // namespace cc |
| OLD | NEW |