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 17 matching lines...) Expand all Loading... |
28 // Flag to indicate whether we should try and detect that | 28 // Flag to indicate whether we should try and detect that |
29 // a tile is of solid color. | 29 // a tile is of solid color. |
30 const bool kUseColorEstimator = true; | 30 const bool kUseColorEstimator = true; |
31 | 31 |
32 class RasterTaskImpl : public RasterTask { | 32 class RasterTaskImpl : public RasterTask { |
33 public: | 33 public: |
34 RasterTaskImpl( | 34 RasterTaskImpl( |
35 const Resource* resource, | 35 const Resource* resource, |
36 RasterSource* raster_source, | 36 RasterSource* raster_source, |
37 const gfx::Rect& content_rect, | 37 const gfx::Rect& content_rect, |
| 38 const gfx::Rect& invalid_content_rect, |
38 float contents_scale, | 39 float contents_scale, |
39 TileResolution tile_resolution, | 40 TileResolution tile_resolution, |
40 int layer_id, | 41 int layer_id, |
41 const void* tile_id, | 42 const void* tile, |
| 43 uint64_t new_content_id, |
| 44 uint64_t previous_content_id, |
42 int source_frame_number, | 45 int source_frame_number, |
43 bool analyze_picture, | 46 bool analyze_picture, |
44 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& | 47 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)>& |
45 reply, | 48 reply, |
46 ImageDecodeTask::Vector* dependencies) | 49 ImageDecodeTask::Vector* dependencies) |
47 : RasterTask(resource, dependencies), | 50 : RasterTask(resource, dependencies), |
48 raster_source_(raster_source), | 51 raster_source_(raster_source), |
49 content_rect_(content_rect), | 52 content_rect_(content_rect), |
| 53 invalid_content_rect_(invalid_content_rect), |
50 contents_scale_(contents_scale), | 54 contents_scale_(contents_scale), |
51 tile_resolution_(tile_resolution), | 55 tile_resolution_(tile_resolution), |
52 layer_id_(layer_id), | 56 layer_id_(layer_id), |
53 tile_id_(tile_id), | 57 tile_(tile), |
| 58 new_content_id_(new_content_id), |
| 59 previous_content_id_(previous_content_id), |
54 source_frame_number_(source_frame_number), | 60 source_frame_number_(source_frame_number), |
55 analyze_picture_(analyze_picture), | 61 analyze_picture_(analyze_picture), |
56 reply_(reply) {} | 62 reply_(reply) {} |
57 | 63 |
58 // Overridden from Task: | 64 // Overridden from Task: |
59 void RunOnWorkerThread() override { | 65 void RunOnWorkerThread() override { |
60 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); | 66 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); |
61 | 67 |
62 DCHECK(raster_source_.get()); | 68 DCHECK(raster_source_.get()); |
63 DCHECK(raster_buffer_); | 69 DCHECK(raster_buffer_); |
64 | 70 |
65 if (analyze_picture_) { | 71 if (analyze_picture_) { |
66 Analyze(raster_source_.get()); | 72 Analyze(raster_source_.get()); |
67 if (analysis_.is_solid_color) | 73 if (analysis_.is_solid_color) |
68 return; | 74 return; |
69 } | 75 } |
70 | 76 |
71 Raster(raster_source_.get()); | 77 Raster(raster_source_.get()); |
72 } | 78 } |
73 | 79 |
74 // Overridden from TileTask: | 80 // Overridden from TileTask: |
75 void ScheduleOnOriginThread(TileTaskClient* client) override { | 81 void ScheduleOnOriginThread(TileTaskClient* client) override { |
76 DCHECK(!raster_buffer_); | 82 DCHECK(!raster_buffer_); |
77 raster_buffer_ = client->AcquireBufferForRaster(resource()); | 83 TileTaskData data(resource(), new_content_id_, previous_content_id_); |
| 84 raster_buffer_ = client->AcquireBufferForRaster(data); |
78 } | 85 } |
79 void CompleteOnOriginThread(TileTaskClient* client) override { | 86 void CompleteOnOriginThread(TileTaskClient* client) override { |
80 client->ReleaseBufferForRaster(raster_buffer_.Pass()); | 87 client->ReleaseBufferForRaster(raster_buffer_.Pass()); |
81 } | 88 } |
82 void RunReplyOnOriginThread() override { | 89 void RunReplyOnOriginThread() override { |
83 DCHECK(!raster_buffer_); | 90 DCHECK(!raster_buffer_); |
84 reply_.Run(analysis_, !HasFinishedRunning()); | 91 reply_.Run(analysis_, !HasFinishedRunning()); |
85 } | 92 } |
86 | 93 |
87 protected: | 94 protected: |
88 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 95 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
89 | 96 |
90 private: | 97 private: |
91 void Analyze(const RasterSource* raster_source) { | 98 void Analyze(const RasterSource* raster_source) { |
92 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | 99 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
93 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 100 tile_, tile_resolution_, source_frame_number_, layer_id_); |
94 | 101 |
95 DCHECK(raster_source); | 102 DCHECK(raster_source); |
96 | 103 |
97 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, | 104 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, |
98 &analysis_); | 105 &analysis_); |
99 // Clear the flag if we're not using the estimator. | 106 // Clear the flag if we're not using the estimator. |
100 analysis_.is_solid_color &= kUseColorEstimator; | 107 analysis_.is_solid_color &= kUseColorEstimator; |
101 } | 108 } |
102 | 109 |
103 void Raster(const RasterSource* raster_source) { | 110 void Raster(const RasterSource* raster_source) { |
104 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 111 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
105 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 112 tile_, tile_resolution_, source_frame_number_, layer_id_); |
106 | 113 |
107 DCHECK(raster_source); | 114 DCHECK(raster_source); |
108 | 115 |
109 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 116 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
110 contents_scale_); | 117 invalid_content_rect_, contents_scale_); |
111 } | 118 } |
112 | 119 |
113 RasterSource::SolidColorAnalysis analysis_; | 120 RasterSource::SolidColorAnalysis analysis_; |
114 scoped_refptr<RasterSource> raster_source_; | 121 scoped_refptr<RasterSource> raster_source_; |
115 gfx::Rect content_rect_; | 122 gfx::Rect content_rect_; |
| 123 gfx::Rect invalid_content_rect_; |
116 float contents_scale_; | 124 float contents_scale_; |
117 TileResolution tile_resolution_; | 125 TileResolution tile_resolution_; |
118 int layer_id_; | 126 int layer_id_; |
119 const void* tile_id_; | 127 const void* tile_; |
| 128 uint64_t new_content_id_; |
| 129 uint64_t previous_content_id_; |
120 int source_frame_number_; | 130 int source_frame_number_; |
121 bool analyze_picture_; | 131 bool analyze_picture_; |
122 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> | 132 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> |
123 reply_; | 133 reply_; |
124 scoped_ptr<RasterBuffer> raster_buffer_; | 134 scoped_ptr<RasterBuffer> raster_buffer_; |
125 | 135 |
126 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 136 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
127 }; | 137 }; |
128 | 138 |
129 class ImageDecodeTaskImpl : public ImageDecodeTask { | 139 class ImageDecodeTaskImpl : public ImageDecodeTask { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 580 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
571 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 581 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
572 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 582 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
573 "had_enough_memory_to_schedule_tiles_needed_now", | 583 "had_enough_memory_to_schedule_tiles_needed_now", |
574 had_enough_memory_to_schedule_tiles_needed_now); | 584 had_enough_memory_to_schedule_tiles_needed_now); |
575 } | 585 } |
576 | 586 |
577 void TileManager::FreeResourcesForTile(Tile* tile) { | 587 void TileManager::FreeResourcesForTile(Tile* tile) { |
578 TileDrawInfo& draw_info = tile->draw_info(); | 588 TileDrawInfo& draw_info = tile->draw_info(); |
579 if (draw_info.resource_) | 589 if (draw_info.resource_) |
580 resource_pool_->ReleaseResource(draw_info.resource_.Pass()); | 590 resource_pool_->ReleaseResource(draw_info.resource_.Pass(), tile->id()); |
581 } | 591 } |
582 | 592 |
583 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 593 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
584 Tile* tile) { | 594 Tile* tile) { |
585 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); | 595 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); |
586 FreeResourcesForTile(tile); | 596 FreeResourcesForTile(tile); |
587 if (was_ready_to_draw) | 597 if (was_ready_to_draw) |
588 client_->NotifyTileStateChanged(tile); | 598 client_->NotifyTileStateChanged(tile); |
589 } | 599 } |
590 | 600 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 | 684 |
675 // Create and append new image decode task for this pixel ref. | 685 // Create and append new image decode task for this pixel ref. |
676 scoped_refptr<ImageDecodeTask> decode_task = | 686 scoped_refptr<ImageDecodeTask> decode_task = |
677 CreateImageDecodeTask(tile, pixel_ref); | 687 CreateImageDecodeTask(tile, pixel_ref); |
678 decode_tasks.push_back(decode_task); | 688 decode_tasks.push_back(decode_task); |
679 existing_pixel_refs[id] = decode_task; | 689 existing_pixel_refs[id] = decode_task; |
680 } | 690 } |
681 | 691 |
682 return make_scoped_refptr(new RasterTaskImpl( | 692 return make_scoped_refptr(new RasterTaskImpl( |
683 const_resource, prioritized_tile.raster_source(), tile->content_rect(), | 693 const_resource, prioritized_tile.raster_source(), tile->content_rect(), |
684 tile->contents_scale(), prioritized_tile.priority().resolution, | 694 tile->invalidated_content_rect(), tile->contents_scale(), |
685 tile->layer_id(), static_cast<const void*>(tile), | 695 prioritized_tile.priority().resolution, tile->layer_id(), |
| 696 static_cast<const void*>(tile), tile->id(), tile->invalidated_id(), |
686 tile->source_frame_number(), tile->use_picture_analysis(), | 697 tile->source_frame_number(), tile->use_picture_analysis(), |
687 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 698 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
688 tile->id(), base::Passed(&resource)), | 699 tile->id(), base::Passed(&resource)), |
689 &decode_tasks)); | 700 &decode_tasks)); |
690 } | 701 } |
691 | 702 |
692 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 703 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
693 SkPixelRef* pixel_ref, | 704 SkPixelRef* pixel_ref, |
694 bool was_canceled) { | 705 bool was_canceled) { |
695 // If the task was canceled, we need to clean it up | 706 // If the task was canceled, we need to clean it up |
(...skipping 20 matching lines...) Expand all Loading... |
716 bool was_canceled) { | 727 bool was_canceled) { |
717 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 728 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
718 | 729 |
719 Tile* tile = tiles_[tile_id]; | 730 Tile* tile = tiles_[tile_id]; |
720 DCHECK(tile->raster_task_.get()); | 731 DCHECK(tile->raster_task_.get()); |
721 orphan_raster_tasks_.push_back(tile->raster_task_); | 732 orphan_raster_tasks_.push_back(tile->raster_task_); |
722 tile->raster_task_ = nullptr; | 733 tile->raster_task_ = nullptr; |
723 | 734 |
724 if (was_canceled) { | 735 if (was_canceled) { |
725 ++update_visible_tiles_stats_.canceled_count; | 736 ++update_visible_tiles_stats_.canceled_count; |
726 resource_pool_->ReleaseResource(resource.Pass()); | 737 resource_pool_->ReleaseResource(resource.Pass(), Tile::Id(0)); |
727 return; | 738 return; |
728 } | 739 } |
729 | 740 |
730 UpdateTileDrawInfo(tile, resource.Pass(), analysis); | 741 UpdateTileDrawInfo(tile, resource.Pass(), analysis); |
731 } | 742 } |
732 | 743 |
733 void TileManager::UpdateTileDrawInfo( | 744 void TileManager::UpdateTileDrawInfo( |
734 Tile* tile, | 745 Tile* tile, |
735 scoped_ptr<ScopedResource> resource, | 746 scoped_ptr<ScopedResource> resource, |
736 const RasterSource::SolidColorAnalysis& analysis) { | 747 const RasterSource::SolidColorAnalysis& analysis) { |
737 TileDrawInfo& draw_info = tile->draw_info(); | 748 TileDrawInfo& draw_info = tile->draw_info(); |
738 | 749 |
739 ++update_visible_tiles_stats_.completed_count; | 750 ++update_visible_tiles_stats_.completed_count; |
740 | 751 |
741 if (analysis.is_solid_color) { | 752 if (analysis.is_solid_color) { |
742 draw_info.set_solid_color(analysis.solid_color); | 753 draw_info.set_solid_color(analysis.solid_color); |
743 if (resource) | 754 if (resource) { |
744 resource_pool_->ReleaseResource(resource.Pass()); | 755 // Pass no tile id here because the tile is solid color so we did not |
| 756 // raster anything into the tile resource. |
| 757 resource_pool_->ReleaseResource(resource.Pass(), Tile::Id(0)); |
| 758 } |
745 } else { | 759 } else { |
746 DCHECK(resource); | 760 DCHECK(resource); |
747 draw_info.set_use_resource(); | 761 draw_info.set_use_resource(); |
748 draw_info.resource_ = resource.Pass(); | 762 draw_info.resource_ = resource.Pass(); |
749 } | 763 } |
750 | 764 |
751 client_->NotifyTileStateChanged(tile); | 765 client_->NotifyTileStateChanged(tile); |
752 } | 766 } |
753 | 767 |
754 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, | 768 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 result -= other; | 980 result -= other; |
967 return result; | 981 return result; |
968 } | 982 } |
969 | 983 |
970 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 984 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
971 return memory_bytes_ > limit.memory_bytes_ || | 985 return memory_bytes_ > limit.memory_bytes_ || |
972 resource_count_ > limit.resource_count_; | 986 resource_count_ > limit.resource_count_; |
973 } | 987 } |
974 | 988 |
975 } // namespace cc | 989 } // namespace cc |
OLD | NEW |