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/resources/tile_manager.h" | 5 #include "cc/resources/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 tile_id, | |
44 uint64_t previous_frame_tile_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), |
57 tile_(tile), | |
53 tile_id_(tile_id), | 58 tile_id_(tile_id), |
59 previous_frame_tile_id_(previous_frame_tile_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(), tile_id_, previous_frame_tile_id_, |
84 invalid_content_rect_); | |
85 raster_buffer_ = client->AcquireBufferForRaster(data); | |
78 } | 86 } |
79 void CompleteOnOriginThread(TileTaskClient* client) override { | 87 void CompleteOnOriginThread(TileTaskClient* client) override { |
80 client->ReleaseBufferForRaster(raster_buffer_.Pass()); | 88 client->ReleaseBufferForRaster(raster_buffer_.Pass()); |
81 } | 89 } |
82 void RunReplyOnOriginThread() override { | 90 void RunReplyOnOriginThread() override { |
83 DCHECK(!raster_buffer_); | 91 DCHECK(!raster_buffer_); |
84 reply_.Run(analysis_, !HasFinishedRunning()); | 92 reply_.Run(analysis_, !HasFinishedRunning()); |
85 } | 93 } |
86 | 94 |
87 protected: | 95 protected: |
88 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 96 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
89 | 97 |
90 private: | 98 private: |
91 void Analyze(const RasterSource* raster_source) { | 99 void Analyze(const RasterSource* raster_source) { |
92 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | 100 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( |
93 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 101 tile_, tile_resolution_, source_frame_number_, layer_id_); |
94 | 102 |
95 DCHECK(raster_source); | 103 DCHECK(raster_source); |
96 | 104 |
97 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, | 105 raster_source->PerformSolidColorAnalysis(content_rect_, contents_scale_, |
98 &analysis_); | 106 &analysis_); |
99 // Clear the flag if we're not using the estimator. | 107 // Clear the flag if we're not using the estimator. |
100 analysis_.is_solid_color &= kUseColorEstimator; | 108 analysis_.is_solid_color &= kUseColorEstimator; |
101 } | 109 } |
102 | 110 |
103 void Raster(const RasterSource* raster_source) { | 111 void Raster(const RasterSource* raster_source) { |
104 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 112 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
105 tile_id_, tile_resolution_, source_frame_number_, layer_id_); | 113 tile_, tile_resolution_, source_frame_number_, layer_id_); |
106 | 114 |
107 DCHECK(raster_source); | 115 DCHECK(raster_source); |
108 | 116 |
109 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 117 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
110 contents_scale_); | 118 contents_scale_); |
111 } | 119 } |
112 | 120 |
113 RasterSource::SolidColorAnalysis analysis_; | 121 RasterSource::SolidColorAnalysis analysis_; |
114 scoped_refptr<RasterSource> raster_source_; | 122 scoped_refptr<RasterSource> raster_source_; |
115 gfx::Rect content_rect_; | 123 gfx::Rect content_rect_; |
124 gfx::Rect invalid_content_rect_; | |
116 float contents_scale_; | 125 float contents_scale_; |
117 TileResolution tile_resolution_; | 126 TileResolution tile_resolution_; |
118 int layer_id_; | 127 int layer_id_; |
119 const void* tile_id_; | 128 const void* tile_; |
129 uint64_t tile_id_; | |
130 uint64_t previous_frame_tile_id_; | |
120 int source_frame_number_; | 131 int source_frame_number_; |
121 bool analyze_picture_; | 132 bool analyze_picture_; |
122 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> | 133 const base::Callback<void(const RasterSource::SolidColorAnalysis&, bool)> |
123 reply_; | 134 reply_; |
124 scoped_ptr<RasterBuffer> raster_buffer_; | 135 scoped_ptr<RasterBuffer> raster_buffer_; |
125 | 136 |
126 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 137 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
127 }; | 138 }; |
128 | 139 |
129 class ImageDecodeTaskImpl : public ImageDecodeTask { | 140 class ImageDecodeTaskImpl : public ImageDecodeTask { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", | 581 TRACE_EVENT_END2("cc", "TileManager::AssignGpuMemoryToTiles", |
571 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 582 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
572 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 583 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
573 "had_enough_memory_to_schedule_tiles_needed_now", | 584 "had_enough_memory_to_schedule_tiles_needed_now", |
574 had_enough_memory_to_schedule_tiles_needed_now); | 585 had_enough_memory_to_schedule_tiles_needed_now); |
575 } | 586 } |
576 | 587 |
577 void TileManager::FreeResourcesForTile(Tile* tile) { | 588 void TileManager::FreeResourcesForTile(Tile* tile) { |
578 TileDrawInfo& draw_info = tile->draw_info(); | 589 TileDrawInfo& draw_info = tile->draw_info(); |
579 if (draw_info.resource_) | 590 if (draw_info.resource_) |
580 resource_pool_->ReleaseResource(draw_info.resource_.Pass()); | 591 resource_pool_->ReleaseResource(draw_info.resource_.Pass(), tile->id()); |
581 } | 592 } |
582 | 593 |
583 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 594 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
584 Tile* tile) { | 595 Tile* tile) { |
585 bool was_ready_to_draw = tile->IsReadyToDraw(); | 596 bool was_ready_to_draw = tile->IsReadyToDraw(); |
586 FreeResourcesForTile(tile); | 597 FreeResourcesForTile(tile); |
587 if (was_ready_to_draw) | 598 if (was_ready_to_draw) |
588 client_->NotifyTileStateChanged(tile); | 599 client_->NotifyTileStateChanged(tile); |
589 } | 600 } |
590 | 601 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 | 685 |
675 // Create and append new image decode task for this pixel ref. | 686 // Create and append new image decode task for this pixel ref. |
676 scoped_refptr<ImageDecodeTask> decode_task = | 687 scoped_refptr<ImageDecodeTask> decode_task = |
677 CreateImageDecodeTask(tile, pixel_ref); | 688 CreateImageDecodeTask(tile, pixel_ref); |
678 decode_tasks.push_back(decode_task); | 689 decode_tasks.push_back(decode_task); |
679 existing_pixel_refs[id] = decode_task; | 690 existing_pixel_refs[id] = decode_task; |
680 } | 691 } |
681 | 692 |
682 return make_scoped_refptr(new RasterTaskImpl( | 693 return make_scoped_refptr(new RasterTaskImpl( |
683 const_resource, tile->raster_source(), tile->content_rect(), | 694 const_resource, tile->raster_source(), tile->content_rect(), |
684 tile->contents_scale(), prioritized_tile.priority().resolution, | 695 tile->invalidated_content_rect(), tile->contents_scale(), |
685 tile->layer_id(), static_cast<const void*>(tile), | 696 prioritized_tile.priority().resolution, tile->layer_id(), tile, |
686 tile->source_frame_number(), tile->use_picture_analysis(), | 697 tile->id(), tile->invalidated_id(), tile->source_frame_number(), |
698 tile->use_picture_analysis(), | |
687 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 699 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
688 tile->id(), base::Passed(&resource)), | 700 tile->id(), base::Passed(&resource)), |
689 &decode_tasks)); | 701 &decode_tasks)); |
690 } | 702 } |
691 | 703 |
692 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 704 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
693 SkPixelRef* pixel_ref, | 705 SkPixelRef* pixel_ref, |
694 bool was_canceled) { | 706 bool was_canceled) { |
695 // If the task was canceled, we need to clean it up | 707 // If the task was canceled, we need to clean it up |
696 // from |image_decode_tasks_|. | 708 // from |image_decode_tasks_|. |
(...skipping 19 matching lines...) Expand all Loading... | |
716 bool was_canceled) { | 728 bool was_canceled) { |
717 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 729 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
718 | 730 |
719 Tile* tile = tiles_[tile_id]; | 731 Tile* tile = tiles_[tile_id]; |
720 DCHECK(tile->raster_task_.get()); | 732 DCHECK(tile->raster_task_.get()); |
721 orphan_raster_tasks_.push_back(tile->raster_task_); | 733 orphan_raster_tasks_.push_back(tile->raster_task_); |
722 tile->raster_task_ = nullptr; | 734 tile->raster_task_ = nullptr; |
723 | 735 |
724 if (was_canceled) { | 736 if (was_canceled) { |
725 ++update_visible_tiles_stats_.canceled_count; | 737 ++update_visible_tiles_stats_.canceled_count; |
726 resource_pool_->ReleaseResource(resource.Pass()); | 738 resource_pool_->ReleaseResource(resource.Pass(), 0); |
727 return; | 739 return; |
728 } | 740 } |
729 | 741 |
730 UpdateTileDrawInfo(tile, resource.Pass(), analysis); | 742 UpdateTileDrawInfo(tile, resource.Pass(), analysis); |
731 } | 743 } |
732 | 744 |
733 void TileManager::UpdateTileDrawInfo( | 745 void TileManager::UpdateTileDrawInfo( |
734 Tile* tile, | 746 Tile* tile, |
735 scoped_ptr<ScopedResource> resource, | 747 scoped_ptr<ScopedResource> resource, |
736 const RasterSource::SolidColorAnalysis& analysis) { | 748 const RasterSource::SolidColorAnalysis& analysis) { |
737 TileDrawInfo& draw_info = tile->draw_info(); | 749 TileDrawInfo& draw_info = tile->draw_info(); |
738 | 750 |
739 ++update_visible_tiles_stats_.completed_count; | 751 ++update_visible_tiles_stats_.completed_count; |
740 | 752 |
741 if (analysis.is_solid_color) { | 753 if (analysis.is_solid_color) { |
742 draw_info.set_solid_color(analysis.solid_color); | 754 draw_info.set_solid_color(analysis.solid_color); |
743 if (resource) | 755 if (resource) |
744 resource_pool_->ReleaseResource(resource.Pass()); | 756 resource_pool_->ReleaseResource(resource.Pass(), tile->id()); |
vmpstr
2015/05/14 23:11:46
This should be 0, because it's solid color: we mig
danakj
2015/05/14 23:22:42
Thanks, added comment too.
| |
745 } else { | 757 } else { |
746 DCHECK(resource); | 758 DCHECK(resource); |
747 draw_info.set_use_resource(); | 759 draw_info.set_use_resource(); |
748 draw_info.resource_ = resource.Pass(); | 760 draw_info.resource_ = resource.Pass(); |
749 } | 761 } |
750 | 762 |
751 client_->NotifyTileStateChanged(tile); | 763 client_->NotifyTileStateChanged(tile); |
752 } | 764 } |
753 | 765 |
754 ScopedTilePtr TileManager::CreateTile(RasterSource* raster_source, | 766 ScopedTilePtr TileManager::CreateTile(RasterSource* raster_source, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 result -= other; | 978 result -= other; |
967 return result; | 979 return result; |
968 } | 980 } |
969 | 981 |
970 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 982 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
971 return memory_bytes_ > limit.memory_bytes_ || | 983 return memory_bytes_ > limit.memory_bytes_ || |
972 resource_count_ > limit.resource_count_; | 984 resource_count_ > limit.resource_count_; |
973 } | 985 } |
974 | 986 |
975 } // namespace cc | 987 } // namespace cc |
OLD | NEW |