| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/tiles/tile_manager.h" | 5 #include "cc/tiles/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ScopedRasterTaskTimer, | 34 ScopedRasterTaskTimer, |
| 35 "Compositing.RasterTask.RasterUs", | 35 "Compositing.RasterTask.RasterUs", |
| 36 "Compositing.RasterTask.RasterPixelsPerMs"); | 36 "Compositing.RasterTask.RasterPixelsPerMs"); |
| 37 | 37 |
| 38 class RasterTaskImpl : public RasterTask { | 38 class RasterTaskImpl : public RasterTask { |
| 39 public: | 39 public: |
| 40 RasterTaskImpl( | 40 RasterTaskImpl( |
| 41 const Resource* resource, | 41 const Resource* resource, |
| 42 RasterSource* raster_source, | 42 RasterSource* raster_source, |
| 43 const gfx::Rect& content_rect, | 43 const gfx::Rect& content_rect, |
| 44 const gfx::Rect& invalid_content_rect, |
| 44 float contents_scale, | 45 float contents_scale, |
| 45 TileResolution tile_resolution, | 46 TileResolution tile_resolution, |
| 46 int layer_id, | 47 int layer_id, |
| 47 const void* tile_id, | 48 const void* tile, |
| 49 uint64_t new_content_id, |
| 50 uint64_t previous_content_id, |
| 48 int source_frame_number, | 51 int source_frame_number, |
| 49 bool analyze_picture, | 52 bool analyze_picture, |
| 50 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& | 53 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& |
| 51 reply, | 54 reply, |
| 52 ImageDecodeTask::Vector* dependencies) | 55 ImageDecodeTask::Vector* dependencies) |
| 53 : RasterTask(resource, dependencies), | 56 : RasterTask(resource, dependencies), |
| 54 raster_source_(raster_source), | 57 raster_source_(raster_source), |
| 55 content_rect_(content_rect), | 58 content_rect_(content_rect), |
| 59 invalid_content_rect_(invalid_content_rect), |
| 56 contents_scale_(contents_scale), | 60 contents_scale_(contents_scale), |
| 57 tile_resolution_(tile_resolution), | 61 tile_resolution_(tile_resolution), |
| 58 layer_id_(layer_id), | 62 layer_id_(layer_id), |
| 59 tile_id_(tile_id), | 63 tile_(tile), |
| 64 new_content_id_(new_content_id), |
| 65 previous_content_id_(previous_content_id), |
| 60 source_frame_number_(source_frame_number), | 66 source_frame_number_(source_frame_number), |
| 61 analyze_picture_(analyze_picture), | 67 analyze_picture_(analyze_picture), |
| 62 reply_(reply) {} | 68 reply_(reply) {} |
| 63 | 69 |
| 64 // Overridden from Task: | 70 // Overridden from Task: |
| 65 void RunOnWorkerThread() override { | 71 void RunOnWorkerThread() override { |
| 66 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); | 72 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); |
| 67 | 73 |
| 68 DCHECK(raster_source_.get()); | 74 DCHECK(raster_source_.get()); |
| 69 DCHECK(raster_buffer_); | 75 DCHECK(raster_buffer_); |
| 70 | 76 |
| 71 if (analyze_picture_) { | 77 if (analyze_picture_) { |
| 72 Analyze(raster_source_.get()); | 78 Analyze(raster_source_.get()); |
| 73 if (analysis_.is_solid_color) | 79 if (analysis_.is_solid_color) |
| 74 return; | 80 return; |
| 75 } | 81 } |
| 76 | 82 |
| 77 Raster(raster_source_.get()); | 83 Raster(raster_source_.get()); |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Overridden from TileTask: | 86 // Overridden from TileTask: |
| 81 void ScheduleOnOriginThread(TileTaskClient* client) override { | 87 void ScheduleOnOriginThread(TileTaskClient* client) override { |
| 82 DCHECK(!raster_buffer_); | 88 DCHECK(!raster_buffer_); |
| 83 raster_buffer_ = client->AcquireBufferForRaster(resource()); | 89 raster_buffer_ = client->AcquireBufferForRaster(resource(), new_content_id_, |
| 90 previous_content_id_); |
| 84 } | 91 } |
| 85 void CompleteOnOriginThread(TileTaskClient* client) override { | 92 void CompleteOnOriginThread(TileTaskClient* client) override { |
| 86 client->ReleaseBufferForRaster(raster_buffer_.Pass()); | 93 client->ReleaseBufferForRaster(raster_buffer_.Pass()); |
| 87 } | 94 } |
| 88 void RunReplyOnOriginThread() override { | 95 void RunReplyOnOriginThread() override { |
| 89 DCHECK(!raster_buffer_); | 96 DCHECK(!raster_buffer_); |
| 90 reply_.Run(analysis_, !HasFinishedRunning()); | 97 reply_.Run(analysis_, !HasFinishedRunning()); |
| 91 } | 98 } |
| 92 | 99 |
| 93 protected: | 100 protected: |
| 94 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 101 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
| 95 | 102 |
| 96 private: | 103 private: |
| 97 void Analyze(const RasterSource* raster_source) { | 104 void Analyze(const RasterSource* raster_source) { |
| 98 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | 105 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
| 99 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 106 tile_, tile_resolution_, source_frame_number_, layer_id_); |
| 100 | 107 |
| 101 DCHECK(raster_source); | 108 DCHECK(raster_source); |
| 102 | 109 |
| 103 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, | 110 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, |
| 104 &analysis_); | 111 &analysis_); |
| 105 // Clear the flag if we're not using the estimator. | 112 // Clear the flag if we're not using the estimator. |
| 106 analysis_.is_solid_color &= kUseColorEstimator; | 113 analysis_.is_solid_color &= kUseColorEstimator; |
| 107 } | 114 } |
| 108 | 115 |
| 109 void Raster(const RasterSource* raster_source) { | 116 void Raster(const RasterSource* raster_source) { |
| 110 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 117 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
| 111 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 118 tile_, tile_resolution_, source_frame_number_, layer_id_); |
| 112 ScopedRasterTaskTimer timer; | 119 ScopedRasterTaskTimer timer; |
| 113 timer.SetArea(content_rect_.size().GetArea()); | 120 timer.SetArea(content_rect_.size().GetArea()); |
| 114 | 121 |
| 115 DCHECK(raster_source); | 122 DCHECK(raster_source); |
| 116 | 123 |
| 117 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 124 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
| 118 contents_scale_); | 125 invalid_content_rect_, contents_scale_); |
| 119 } | 126 } |
| 120 | 127 |
| 121 RasterSource::SolidColorAnalysis analysis_; | 128 RasterSource::SolidColorAnalysis analysis_; |
| 122 scoped_refptr<RasterSource> raster_source_; | 129 scoped_refptr<RasterSource> raster_source_; |
| 123 gfx::Rect content_rect_; | 130 gfx::Rect content_rect_; |
| 131 gfx::Rect invalid_content_rect_; |
| 124 float contents_scale_; | 132 float contents_scale_; |
| 125 TileResolution tile_resolution_; | 133 TileResolution tile_resolution_; |
| 126 int layer_id_; | 134 int layer_id_; |
| 127 const void* tile_id_; | 135 const void* tile_; |
| 136 uint64_t new_content_id_; |
| 137 uint64_t previous_content_id_; |
| 128 int source_frame_number_; | 138 int source_frame_number_; |
| 129 bool analyze_picture_; | 139 bool analyze_picture_; |
| 130 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> | 140 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> |
| 131 reply_; | 141 reply_; |
| 132 scoped_ptr<RasterBuffer> raster_buffer_; | 142 scoped_ptr<RasterBuffer> raster_buffer_; |
| 133 | 143 |
| 134 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 144 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
| 135 }; | 145 }; |
| 136 | 146 |
| 137 class ImageDecodeTaskImpl : public ImageDecodeTask { | 147 class ImageDecodeTaskImpl : public ImageDecodeTask { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 588 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
| 579 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 589 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
| 580 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 590 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
| 581 "had_enough_memory_to_schedule_tiles_needed_now", | 591 "had_enough_memory_to_schedule_tiles_needed_now", |
| 582 had_enough_memory_to_schedule_tiles_needed_now); | 592 had_enough_memory_to_schedule_tiles_needed_now); |
| 583 } | 593 } |
| 584 | 594 |
| 585 void TileManager::FreeResourcesForTile(Tile* tile) { | 595 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 586 TileDrawInfo& draw_info = tile->draw_info(); | 596 TileDrawInfo& draw_info = tile->draw_info(); |
| 587 if (draw_info.resource_) | 597 if (draw_info.resource_) |
| 588 resource_pool_->ReleaseResource(draw_info.resource_.Pass()); | 598 resource_pool_->ReleaseResource(draw_info.resource_.Pass(), tile->id()); |
| 589 } | 599 } |
| 590 | 600 |
| 591 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 601 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
| 592 Tile* tile) { | 602 Tile* tile) { |
| 593 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); | 603 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); |
| 594 FreeResourcesForTile(tile); | 604 FreeResourcesForTile(tile); |
| 595 if (was_ready_to_draw) | 605 if (was_ready_to_draw) |
| 596 client_->NotifyTileStateChanged(tile); | 606 client_->NotifyTileStateChanged(tile); |
| 597 } | 607 } |
| 598 | 608 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 | 692 |
| 683 // Create and append new image decode task for this pixel ref. | 693 // Create and append new image decode task for this pixel ref. |
| 684 scoped_refptr<ImageDecodeTask> decode_task = | 694 scoped_refptr<ImageDecodeTask> decode_task = |
| 685 CreateImageDecodeTask(tile, pixel_ref); | 695 CreateImageDecodeTask(tile, pixel_ref); |
| 686 decode_tasks.push_back(decode_task); | 696 decode_tasks.push_back(decode_task); |
| 687 existing_pixel_refs[id] = decode_task; | 697 existing_pixel_refs[id] = decode_task; |
| 688 } | 698 } |
| 689 | 699 |
| 690 return make_scoped_refptr(new RasterTaskImpl( | 700 return make_scoped_refptr(new RasterTaskImpl( |
| 691 const_resource, prioritized_tile.raster_source(), tile->content_rect(), | 701 const_resource, prioritized_tile.raster_source(), tile->content_rect(), |
| 692 tile->contents_scale(), prioritized_tile.priority().resolution, | 702 tile->invalidated_content_rect(), tile->contents_scale(), |
| 693 tile->layer_id(), static_cast<const void*>(tile), | 703 prioritized_tile.priority().resolution, tile->layer_id(), |
| 704 static_cast<const void*>(tile), tile->id(), tile->invalidated_id(), |
| 694 tile->source_frame_number(), tile->use_picture_analysis(), | 705 tile->source_frame_number(), tile->use_picture_analysis(), |
| 695 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 706 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
| 696 tile->id(), base::Passed(&resource)), | 707 tile->id(), base::Passed(&resource)), |
| 697 &decode_tasks)); | 708 &decode_tasks)); |
| 698 } | 709 } |
| 699 | 710 |
| 700 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 711 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
| 701 SkPixelRef* pixel_ref, | 712 SkPixelRef* pixel_ref, |
| 702 bool was_canceled) { | 713 bool was_canceled) { |
| 703 // If the task was canceled, we need to clean it up | 714 // If the task was canceled, we need to clean it up |
| (...skipping 20 matching lines...) Expand all Loading... |
| 724 bool was_canceled) { | 735 bool was_canceled) { |
| 725 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 736 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
| 726 | 737 |
| 727 Tile* tile = tiles_[tile_id]; | 738 Tile* tile = tiles_[tile_id]; |
| 728 DCHECK(tile->raster_task_.get()); | 739 DCHECK(tile->raster_task_.get()); |
| 729 orphan_raster_tasks_.push_back(tile->raster_task_); | 740 orphan_raster_tasks_.push_back(tile->raster_task_); |
| 730 tile->raster_task_ = nullptr; | 741 tile->raster_task_ = nullptr; |
| 731 | 742 |
| 732 if (was_canceled) { | 743 if (was_canceled) { |
| 733 ++update_visible_tiles_stats_.canceled_count; | 744 ++update_visible_tiles_stats_.canceled_count; |
| 734 resource_pool_->ReleaseResource(resource.Pass()); | 745 resource_pool_->ReleaseResource(resource.Pass(), Tile::Id(0)); |
| 735 return; | 746 return; |
| 736 } | 747 } |
| 737 | 748 |
| 738 UpdateTileDrawInfo(tile, resource.Pass(), analysis); | 749 UpdateTileDrawInfo(tile, resource.Pass(), analysis); |
| 739 } | 750 } |
| 740 | 751 |
| 741 void TileManager::UpdateTileDrawInfo( | 752 void TileManager::UpdateTileDrawInfo( |
| 742 Tile* tile, | 753 Tile* tile, |
| 743 scoped_ptr<ScopedResource> resource, | 754 scoped_ptr<ScopedResource> resource, |
| 744 const RasterSource::SolidColorAnalysis& analysis) { | 755 const RasterSource::SolidColorAnalysis& analysis) { |
| 745 TileDrawInfo& draw_info = tile->draw_info(); | 756 TileDrawInfo& draw_info = tile->draw_info(); |
| 746 | 757 |
| 747 ++update_visible_tiles_stats_.completed_count; | 758 ++update_visible_tiles_stats_.completed_count; |
| 748 | 759 |
| 749 if (analysis.is_solid_color) { | 760 if (analysis.is_solid_color) { |
| 750 draw_info.set_solid_color(analysis.solid_color); | 761 draw_info.set_solid_color(analysis.solid_color); |
| 751 if (resource) | 762 if (resource) { |
| 752 resource_pool_->ReleaseResource(resource.Pass()); | 763 // Pass no tile id here because the tile is solid color so we did not |
| 764 // raster anything into the tile resource. |
| 765 resource_pool_->ReleaseResource(resource.Pass(), Tile::Id(0)); |
| 766 } |
| 753 } else { | 767 } else { |
| 754 DCHECK(resource); | 768 DCHECK(resource); |
| 755 draw_info.set_use_resource(); | 769 draw_info.set_use_resource(); |
| 756 draw_info.resource_ = resource.Pass(); | 770 draw_info.resource_ = resource.Pass(); |
| 757 } | 771 } |
| 758 | 772 |
| 759 client_->NotifyTileStateChanged(tile); | 773 client_->NotifyTileStateChanged(tile); |
| 760 } | 774 } |
| 761 | 775 |
| 762 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, | 776 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 result -= other; | 988 result -= other; |
| 975 return result; | 989 return result; |
| 976 } | 990 } |
| 977 | 991 |
| 978 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 992 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 979 return memory_bytes_ > limit.memory_bytes_ || | 993 return memory_bytes_ > limit.memory_bytes_ || |
| 980 resource_count_ > limit.resource_count_; | 994 resource_count_ > limit.resource_count_; |
| 981 } | 995 } |
| 982 | 996 |
| 983 } // namespace cc | 997 } // namespace cc |
| OLD | NEW |