OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // that time interval, and then uploads should have a chance to be processed. | 145 // that time interval, and then uploads should have a chance to be processed. |
146 size_t ms_per_frame = std::floor(1000.0 / refresh_rate); | 146 size_t ms_per_frame = std::floor(1000.0 / refresh_rate); |
147 size_t max_transfer_buffer_usage_bytes = | 147 size_t max_transfer_buffer_usage_bytes = |
148 ms_per_frame * kMaxBytesUploadedPerMs; | 148 ms_per_frame * kMaxBytesUploadedPerMs; |
149 | 149 |
150 // The context may request a lower limit based on the device capabilities. | 150 // The context may request a lower limit based on the device capabilities. |
151 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, | 151 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, |
152 max_transfer_buffer_usage_bytes); | 152 max_transfer_buffer_usage_bytes); |
153 } | 153 } |
154 | 154 |
155 size_t GetMaxStagingResourceCount() { | |
156 // Upper bound for number of staging resource to allow. | |
157 return 32; | |
158 } | |
159 | |
160 size_t GetDefaultMemoryAllocationLimit() { | 155 size_t GetDefaultMemoryAllocationLimit() { |
161 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler | 156 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler |
162 // from the old texture manager and is just to give us a default memory | 157 // from the old texture manager and is just to give us a default memory |
163 // allocation before we get a callback from the GPU memory manager. We | 158 // allocation before we get a callback from the GPU memory manager. We |
164 // should probaby either: | 159 // should probaby either: |
165 // - wait for the callback before rendering anything instead | 160 // - wait for the callback before rendering anything instead |
166 // - push this into the GPU memory manager somehow. | 161 // - push this into the GPU memory manager somehow. |
167 return 64 * 1024 * 1024; | 162 return 64 * 1024 * 1024; |
168 } | 163 } |
169 | 164 |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 // TODO(reveman): We should avoid keeping around unused resources if | 1222 // TODO(reveman): We should avoid keeping around unused resources if |
1228 // possible. crbug.com/224475 | 1223 // possible. crbug.com/224475 |
1229 // Unused limit is calculated from soft-limit, as hard-limit may | 1224 // Unused limit is calculated from soft-limit, as hard-limit may |
1230 // be very high and shouldn't typically be exceeded. | 1225 // be very high and shouldn't typically be exceeded. |
1231 size_t unused_memory_limit_in_bytes = static_cast<size_t>( | 1226 size_t unused_memory_limit_in_bytes = static_cast<size_t>( |
1232 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * | 1227 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * |
1233 settings_.max_unused_resource_memory_percentage) / | 1228 settings_.max_unused_resource_memory_percentage) / |
1234 100); | 1229 100); |
1235 | 1230 |
1236 DCHECK(resource_pool_); | 1231 DCHECK(resource_pool_); |
1237 resource_pool_->CheckBusyResources(false); | 1232 resource_pool_->CheckBusyResources(); |
1238 // Soft limit is used for resource pool such that memory returns to soft | 1233 // Soft limit is used for resource pool such that memory returns to soft |
1239 // limit after going over. | 1234 // limit after going over. |
1240 resource_pool_->SetResourceUsageLimits( | 1235 resource_pool_->SetResourceUsageLimits( |
1241 global_tile_state_.soft_memory_limit_in_bytes, | 1236 global_tile_state_.soft_memory_limit_in_bytes, |
1242 unused_memory_limit_in_bytes, | 1237 unused_memory_limit_in_bytes, |
1243 global_tile_state_.num_resources_limit); | 1238 global_tile_state_.num_resources_limit); |
1244 | 1239 |
1245 // Release all staging resources when invisible. | |
1246 if (staging_resource_pool_) { | |
1247 staging_resource_pool_->CheckBusyResources(false); | |
1248 staging_resource_pool_->SetResourceUsageLimits( | |
1249 std::numeric_limits<size_t>::max(), | |
1250 std::numeric_limits<size_t>::max(), | |
1251 visible_ ? GetMaxStagingResourceCount() : 0); | |
1252 } | |
1253 | |
1254 DidModifyTilePriorities(); | 1240 DidModifyTilePriorities(); |
1255 } | 1241 } |
1256 | 1242 |
1257 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1243 void LayerTreeHostImpl::DidModifyTilePriorities() { |
1258 // Mark priorities as dirty and schedule a PrepareTiles(). | 1244 // Mark priorities as dirty and schedule a PrepareTiles(). |
1259 tile_priorities_dirty_ = true; | 1245 tile_priorities_dirty_ = true; |
1260 client_->SetNeedsPrepareTilesOnImplThread(); | 1246 client_->SetNeedsPrepareTilesOnImplThread(); |
1261 } | 1247 } |
1262 | 1248 |
1263 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( | 1249 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from | 1288 // don't need to schedule a draw here. Just stop WillBeginImplFrame() from |
1303 // causing optimistic requests to draw a frame. | 1289 // causing optimistic requests to draw a frame. |
1304 is_likely_to_require_a_draw_ = false; | 1290 is_likely_to_require_a_draw_ = false; |
1305 | 1291 |
1306 client_->NotifyReadyToDraw(); | 1292 client_->NotifyReadyToDraw(); |
1307 } | 1293 } |
1308 | 1294 |
1309 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { | 1295 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { |
1310 // The tile tasks started by the most recent call to PrepareTiles have | 1296 // The tile tasks started by the most recent call to PrepareTiles have |
1311 // completed. Now is a good time to free resources if necessary. | 1297 // completed. Now is a good time to free resources if necessary. |
1312 if (output_surface_ && global_tile_state_.hard_memory_limit_in_bytes == 0) { | 1298 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { |
1313 output_surface_->SetWorkerContextShouldAggressivelyFreeResources( | 1299 if (output_surface_) { |
1314 true /* aggressively_free_resources */); | 1300 output_surface_->SetWorkerContextShouldAggressivelyFreeResources( |
| 1301 true /* aggressively_free_resources */); |
| 1302 } |
1315 } | 1303 } |
1316 } | 1304 } |
1317 | 1305 |
1318 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { | 1306 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { |
1319 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); | 1307 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); |
1320 | 1308 |
1321 if (active_tree_) { | 1309 if (active_tree_) { |
1322 LayerImpl* layer_impl = | 1310 LayerImpl* layer_impl = |
1323 active_tree_->FindActiveTreeLayerById(tile->layer_id()); | 1311 active_tree_->FindActiveTreeLayerById(tile->layer_id()); |
1324 if (layer_impl) | 1312 if (layer_impl) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1445 |
1458 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { | 1446 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { |
1459 // TODO(piman): We may need to do some validation on this ack before | 1447 // TODO(piman): We may need to do some validation on this ack before |
1460 // processing it. | 1448 // processing it. |
1461 if (renderer_) | 1449 if (renderer_) |
1462 renderer_->ReceiveSwapBuffersAck(*ack); | 1450 renderer_->ReceiveSwapBuffersAck(*ack); |
1463 | 1451 |
1464 // In OOM, we now might be able to release more resources that were held | 1452 // In OOM, we now might be able to release more resources that were held |
1465 // because they were exported. | 1453 // because they were exported. |
1466 if (resource_pool_) { | 1454 if (resource_pool_) { |
1467 resource_pool_->CheckBusyResources(false); | 1455 resource_pool_->CheckBusyResources(); |
1468 resource_pool_->ReduceResourceUsage(); | 1456 resource_pool_->ReduceResourceUsage(); |
1469 } | 1457 } |
1470 // If we're not visible, we likely released resources, so we want to | 1458 // If we're not visible, we likely released resources, so we want to |
1471 // aggressively flush here to make sure those DeleteTextures make it to the | 1459 // aggressively flush here to make sure those DeleteTextures make it to the |
1472 // GPU process to free up the memory. | 1460 // GPU process to free up the memory. |
1473 if (output_surface_->context_provider() && !visible_) { | 1461 if (output_surface_->context_provider() && !visible_) { |
1474 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); | 1462 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); |
1475 } | 1463 } |
1476 } | 1464 } |
1477 | 1465 |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2057 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
2070 // initialized to get max texture size. Also, after releasing resources, | 2058 // initialized to get max texture size. Also, after releasing resources, |
2071 // trees need another update to generate new ones. | 2059 // trees need another update to generate new ones. |
2072 active_tree_->set_needs_update_draw_properties(); | 2060 active_tree_->set_needs_update_draw_properties(); |
2073 if (pending_tree_) | 2061 if (pending_tree_) |
2074 pending_tree_->set_needs_update_draw_properties(); | 2062 pending_tree_->set_needs_update_draw_properties(); |
2075 client_->UpdateRendererCapabilitiesOnImplThread(); | 2063 client_->UpdateRendererCapabilitiesOnImplThread(); |
2076 } | 2064 } |
2077 | 2065 |
2078 void LayerTreeHostImpl::CreateTileManagerResources() { | 2066 void LayerTreeHostImpl::CreateTileManagerResources() { |
2079 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_, | 2067 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_); |
2080 &staging_resource_pool_); | |
2081 // TODO(vmpstr): Initialize tile task limit at ctor time. | 2068 // TODO(vmpstr): Initialize tile task limit at ctor time. |
2082 tile_manager_->SetResources( | 2069 tile_manager_->SetResources( |
2083 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), | 2070 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), |
2084 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() | 2071 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() |
2085 : settings_.scheduled_raster_task_limit); | 2072 : settings_.scheduled_raster_task_limit); |
2086 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2073 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
2087 } | 2074 } |
2088 | 2075 |
2089 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( | 2076 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( |
2090 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, | 2077 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, |
2091 scoped_ptr<ResourcePool>* resource_pool, | 2078 scoped_ptr<ResourcePool>* resource_pool) { |
2092 scoped_ptr<ResourcePool>* staging_resource_pool) { | |
2093 DCHECK(GetTaskRunner()); | 2079 DCHECK(GetTaskRunner()); |
2094 | 2080 |
2095 // Pass the single-threaded synchronous task graph runner to the worker pool | 2081 // Pass the single-threaded synchronous task graph runner to the worker pool |
2096 // if we're in synchronous single-threaded mode. | 2082 // if we're in synchronous single-threaded mode. |
2097 TaskGraphRunner* task_graph_runner = task_graph_runner_; | 2083 TaskGraphRunner* task_graph_runner = task_graph_runner_; |
2098 if (is_synchronous_single_threaded_) { | 2084 if (is_synchronous_single_threaded_) { |
2099 DCHECK(!single_thread_synchronous_task_graph_runner_); | 2085 DCHECK(!single_thread_synchronous_task_graph_runner_); |
2100 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); | 2086 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); |
2101 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); | 2087 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); |
2102 } | 2088 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 if (settings_.use_zero_copy) { | 2122 if (settings_.use_zero_copy) { |
2137 *resource_pool = | 2123 *resource_pool = |
2138 ResourcePool::Create(resource_provider_.get(), image_target); | 2124 ResourcePool::Create(resource_provider_.get(), image_target); |
2139 | 2125 |
2140 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( | 2126 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( |
2141 GetTaskRunner(), task_graph_runner, resource_provider_.get()); | 2127 GetTaskRunner(), task_graph_runner, resource_provider_.get()); |
2142 return; | 2128 return; |
2143 } | 2129 } |
2144 | 2130 |
2145 if (settings_.use_one_copy) { | 2131 if (settings_.use_one_copy) { |
2146 // Synchronous single-threaded mode depends on tiles being ready to | |
2147 // draw when raster is complete. Therefore, it must use one of zero | |
2148 // copy, software raster, or GPU raster. | |
2149 DCHECK(!is_synchronous_single_threaded_); | |
2150 | |
2151 // We need to create a staging resource pool when using copy rasterizer. | |
2152 *staging_resource_pool = | |
2153 ResourcePool::Create(resource_provider_.get(), image_target); | |
2154 *resource_pool = | 2132 *resource_pool = |
2155 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); | 2133 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); |
2156 | 2134 |
2157 int max_copy_texture_chromium_size = | 2135 int max_copy_texture_chromium_size = |
2158 context_provider->ContextCapabilities() | 2136 context_provider->ContextCapabilities() |
2159 .gpu.max_copy_texture_chromium_size; | 2137 .gpu.max_copy_texture_chromium_size; |
2160 | 2138 |
2161 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( | 2139 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( |
2162 GetTaskRunner(), task_graph_runner, context_provider, | 2140 GetTaskRunner(), task_graph_runner, context_provider, |
2163 resource_provider_.get(), staging_resource_pool_.get(), | 2141 resource_provider_.get(), max_copy_texture_chromium_size, |
2164 max_copy_texture_chromium_size, | 2142 settings_.use_persistent_map_for_gpu_memory_buffers, image_target); |
2165 settings_.use_persistent_map_for_gpu_memory_buffers); | |
2166 return; | 2143 return; |
2167 } | 2144 } |
2168 | 2145 |
2169 // Synchronous single-threaded mode depends on tiles being ready to | 2146 // Synchronous single-threaded mode depends on tiles being ready to |
2170 // draw when raster is complete. Therefore, it must use one of zero | 2147 // draw when raster is complete. Therefore, it must use one of zero |
2171 // copy, software raster, or GPU raster (in the branches above). | 2148 // copy, software raster, or GPU raster (in the branches above). |
2172 DCHECK(!is_synchronous_single_threaded_); | 2149 DCHECK(!is_synchronous_single_threaded_); |
2173 | 2150 |
2174 *resource_pool = ResourcePool::Create( | 2151 *resource_pool = ResourcePool::Create( |
2175 resource_provider_.get(), GL_TEXTURE_2D); | 2152 resource_provider_.get(), GL_TEXTURE_2D); |
(...skipping 22 matching lines...) Expand all Loading... |
2198 void LayerTreeHostImpl::PostFrameTimingEvents( | 2175 void LayerTreeHostImpl::PostFrameTimingEvents( |
2199 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 2176 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
2200 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 2177 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
2201 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), | 2178 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), |
2202 main_frame_events.Pass()); | 2179 main_frame_events.Pass()); |
2203 } | 2180 } |
2204 | 2181 |
2205 void LayerTreeHostImpl::CleanUpTileManager() { | 2182 void LayerTreeHostImpl::CleanUpTileManager() { |
2206 tile_manager_->FinishTasksAndCleanUp(); | 2183 tile_manager_->FinishTasksAndCleanUp(); |
2207 resource_pool_ = nullptr; | 2184 resource_pool_ = nullptr; |
2208 staging_resource_pool_ = nullptr; | |
2209 tile_task_worker_pool_ = nullptr; | 2185 tile_task_worker_pool_ = nullptr; |
2210 single_thread_synchronous_task_graph_runner_ = nullptr; | 2186 single_thread_synchronous_task_graph_runner_ = nullptr; |
2211 } | 2187 } |
2212 | 2188 |
2213 bool LayerTreeHostImpl::InitializeRenderer( | 2189 bool LayerTreeHostImpl::InitializeRenderer( |
2214 scoped_ptr<OutputSurface> output_surface) { | 2190 scoped_ptr<OutputSurface> output_surface) { |
2215 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2191 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
2216 | 2192 |
2217 // Since we will create a new resource provider, we cannot continue to use | 2193 // Since we will create a new resource provider, we cannot continue to use |
2218 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2194 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
(...skipping 12 matching lines...) Expand all Loading... |
2231 // point). | 2207 // point). |
2232 return false; | 2208 return false; |
2233 } | 2209 } |
2234 | 2210 |
2235 output_surface_ = output_surface.Pass(); | 2211 output_surface_ = output_surface.Pass(); |
2236 resource_provider_ = ResourceProvider::Create( | 2212 resource_provider_ = ResourceProvider::Create( |
2237 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, | 2213 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, |
2238 proxy_->blocking_main_thread_task_runner(), | 2214 proxy_->blocking_main_thread_task_runner(), |
2239 settings_.renderer_settings.highp_threshold_min, | 2215 settings_.renderer_settings.highp_threshold_min, |
2240 settings_.renderer_settings.use_rgba_4444_textures, | 2216 settings_.renderer_settings.use_rgba_4444_textures, |
2241 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2217 settings_.renderer_settings.texture_id_allocation_chunk_size); |
2242 settings_.use_persistent_map_for_gpu_memory_buffers); | |
2243 | 2218 |
2244 CreateAndSetRenderer(); | 2219 CreateAndSetRenderer(); |
2245 | 2220 |
2246 // Since the new renderer may be capable of MSAA, update status here. | 2221 // Since the new renderer may be capable of MSAA, update status here. |
2247 UpdateGpuRasterizationStatus(); | 2222 UpdateGpuRasterizationStatus(); |
2248 | 2223 |
2249 CreateTileManagerResources(); | 2224 CreateTileManagerResources(); |
2250 RecreateTreeResources(); | 2225 RecreateTreeResources(); |
2251 | 2226 |
2252 // Initialize vsync parameters to sane values. | 2227 // Initialize vsync parameters to sane values. |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3607 if (active_tree()) { | 3582 if (active_tree()) { |
3608 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3583 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3609 if (layer) | 3584 if (layer) |
3610 return layer->ScrollOffsetForAnimation(); | 3585 return layer->ScrollOffsetForAnimation(); |
3611 } | 3586 } |
3612 | 3587 |
3613 return gfx::ScrollOffset(); | 3588 return gfx::ScrollOffset(); |
3614 } | 3589 } |
3615 | 3590 |
3616 } // namespace cc | 3591 } // namespace cc |
OLD | NEW |