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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // that time interval, and then uploads should have a chance to be processed. | 146 // that time interval, and then uploads should have a chance to be processed. |
147 size_t ms_per_frame = std::floor(1000.0 / refresh_rate); | 147 size_t ms_per_frame = std::floor(1000.0 / refresh_rate); |
148 size_t max_transfer_buffer_usage_bytes = | 148 size_t max_transfer_buffer_usage_bytes = |
149 ms_per_frame * kMaxBytesUploadedPerMs; | 149 ms_per_frame * kMaxBytesUploadedPerMs; |
150 | 150 |
151 // The context may request a lower limit based on the device capabilities. | 151 // The context may request a lower limit based on the device capabilities. |
152 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, | 152 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, |
153 max_transfer_buffer_usage_bytes); | 153 max_transfer_buffer_usage_bytes); |
154 } | 154 } |
155 | 155 |
| 156 size_t GetMaxStagingResourceCount() { |
| 157 // Upper bound for number of staging resource to allow. |
| 158 return 32; |
| 159 } |
| 160 |
156 size_t GetDefaultMemoryAllocationLimit() { | 161 size_t GetDefaultMemoryAllocationLimit() { |
157 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler | 162 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler |
158 // from the old texture manager and is just to give us a default memory | 163 // from the old texture manager and is just to give us a default memory |
159 // allocation before we get a callback from the GPU memory manager. We | 164 // allocation before we get a callback from the GPU memory manager. We |
160 // should probaby either: | 165 // should probaby either: |
161 // - wait for the callback before rendering anything instead | 166 // - wait for the callback before rendering anything instead |
162 // - push this into the GPU memory manager somehow. | 167 // - push this into the GPU memory manager somehow. |
163 return 64 * 1024 * 1024; | 168 return 64 * 1024 * 1024; |
164 } | 169 } |
165 | 170 |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 // TODO(reveman): We should avoid keeping around unused resources if | 1228 // TODO(reveman): We should avoid keeping around unused resources if |
1224 // possible. crbug.com/224475 | 1229 // possible. crbug.com/224475 |
1225 // Unused limit is calculated from soft-limit, as hard-limit may | 1230 // Unused limit is calculated from soft-limit, as hard-limit may |
1226 // be very high and shouldn't typically be exceeded. | 1231 // be very high and shouldn't typically be exceeded. |
1227 size_t unused_memory_limit_in_bytes = static_cast<size_t>( | 1232 size_t unused_memory_limit_in_bytes = static_cast<size_t>( |
1228 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * | 1233 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * |
1229 settings_.max_unused_resource_memory_percentage) / | 1234 settings_.max_unused_resource_memory_percentage) / |
1230 100); | 1235 100); |
1231 | 1236 |
1232 DCHECK(resource_pool_); | 1237 DCHECK(resource_pool_); |
1233 resource_pool_->CheckBusyResources(); | 1238 resource_pool_->CheckBusyResources(false); |
1234 // Soft limit is used for resource pool such that memory returns to soft | 1239 // Soft limit is used for resource pool such that memory returns to soft |
1235 // limit after going over. | 1240 // limit after going over. |
1236 resource_pool_->SetResourceUsageLimits( | 1241 resource_pool_->SetResourceUsageLimits( |
1237 global_tile_state_.soft_memory_limit_in_bytes, | 1242 global_tile_state_.soft_memory_limit_in_bytes, |
1238 unused_memory_limit_in_bytes, | 1243 unused_memory_limit_in_bytes, |
1239 global_tile_state_.num_resources_limit); | 1244 global_tile_state_.num_resources_limit); |
1240 | 1245 |
| 1246 // Release all staging resources when invisible. |
| 1247 if (staging_resource_pool_) { |
| 1248 staging_resource_pool_->CheckBusyResources(false); |
| 1249 staging_resource_pool_->SetResourceUsageLimits( |
| 1250 std::numeric_limits<size_t>::max(), |
| 1251 std::numeric_limits<size_t>::max(), |
| 1252 visible_ ? GetMaxStagingResourceCount() : 0); |
| 1253 } |
| 1254 |
1241 DidModifyTilePriorities(); | 1255 DidModifyTilePriorities(); |
1242 } | 1256 } |
1243 | 1257 |
1244 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1258 void LayerTreeHostImpl::DidModifyTilePriorities() { |
1245 // Mark priorities as dirty and schedule a PrepareTiles(). | 1259 // Mark priorities as dirty and schedule a PrepareTiles(). |
1246 tile_priorities_dirty_ = true; | 1260 tile_priorities_dirty_ = true; |
1247 client_->SetNeedsPrepareTilesOnImplThread(); | 1261 client_->SetNeedsPrepareTilesOnImplThread(); |
1248 } | 1262 } |
1249 | 1263 |
1250 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( | 1264 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 | 1458 |
1445 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { | 1459 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { |
1446 // TODO(piman): We may need to do some validation on this ack before | 1460 // TODO(piman): We may need to do some validation on this ack before |
1447 // processing it. | 1461 // processing it. |
1448 if (renderer_) | 1462 if (renderer_) |
1449 renderer_->ReceiveSwapBuffersAck(*ack); | 1463 renderer_->ReceiveSwapBuffersAck(*ack); |
1450 | 1464 |
1451 // In OOM, we now might be able to release more resources that were held | 1465 // In OOM, we now might be able to release more resources that were held |
1452 // because they were exported. | 1466 // because they were exported. |
1453 if (resource_pool_) { | 1467 if (resource_pool_) { |
1454 resource_pool_->CheckBusyResources(); | 1468 resource_pool_->CheckBusyResources(false); |
1455 resource_pool_->ReduceResourceUsage(); | 1469 resource_pool_->ReduceResourceUsage(); |
1456 } | 1470 } |
1457 // If we're not visible, we likely released resources, so we want to | 1471 // If we're not visible, we likely released resources, so we want to |
1458 // aggressively flush here to make sure those DeleteTextures make it to the | 1472 // aggressively flush here to make sure those DeleteTextures make it to the |
1459 // GPU process to free up the memory. | 1473 // GPU process to free up the memory. |
1460 if (output_surface_->context_provider() && !visible_) { | 1474 if (output_surface_->context_provider() && !visible_) { |
1461 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); | 1475 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); |
1462 } | 1476 } |
1463 } | 1477 } |
1464 | 1478 |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2054 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
2041 // initialized to get max texture size. Also, after releasing resources, | 2055 // initialized to get max texture size. Also, after releasing resources, |
2042 // trees need another update to generate new ones. | 2056 // trees need another update to generate new ones. |
2043 active_tree_->set_needs_update_draw_properties(); | 2057 active_tree_->set_needs_update_draw_properties(); |
2044 if (pending_tree_) | 2058 if (pending_tree_) |
2045 pending_tree_->set_needs_update_draw_properties(); | 2059 pending_tree_->set_needs_update_draw_properties(); |
2046 client_->UpdateRendererCapabilitiesOnImplThread(); | 2060 client_->UpdateRendererCapabilitiesOnImplThread(); |
2047 } | 2061 } |
2048 | 2062 |
2049 void LayerTreeHostImpl::CreateTileManagerResources() { | 2063 void LayerTreeHostImpl::CreateTileManagerResources() { |
2050 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_); | 2064 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_, |
| 2065 &staging_resource_pool_); |
2051 // TODO(vmpstr): Initialize tile task limit at ctor time. | 2066 // TODO(vmpstr): Initialize tile task limit at ctor time. |
2052 tile_manager_->SetResources( | 2067 tile_manager_->SetResources( |
2053 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), | 2068 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), |
2054 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() | 2069 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() |
2055 : settings_.scheduled_raster_task_limit); | 2070 : settings_.scheduled_raster_task_limit); |
2056 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2071 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
2057 } | 2072 } |
2058 | 2073 |
2059 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( | 2074 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( |
2060 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, | 2075 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, |
2061 scoped_ptr<ResourcePool>* resource_pool) { | 2076 scoped_ptr<ResourcePool>* resource_pool, |
| 2077 scoped_ptr<ResourcePool>* staging_resource_pool) { |
2062 DCHECK(GetTaskRunner()); | 2078 DCHECK(GetTaskRunner()); |
2063 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is | 2079 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is |
2064 // resolved. | 2080 // resolved. |
2065 CHECK(resource_provider_); | 2081 CHECK(resource_provider_); |
2066 | 2082 |
2067 // Pass the single-threaded synchronous task graph runner to the worker pool | 2083 // Pass the single-threaded synchronous task graph runner to the worker pool |
2068 // if we're in synchronous single-threaded mode. | 2084 // if we're in synchronous single-threaded mode. |
2069 TaskGraphRunner* task_graph_runner = task_graph_runner_; | 2085 TaskGraphRunner* task_graph_runner = task_graph_runner_; |
2070 if (is_synchronous_single_threaded_) { | 2086 if (is_synchronous_single_threaded_) { |
2071 DCHECK(!single_thread_synchronous_task_graph_runner_); | 2087 DCHECK(!single_thread_synchronous_task_graph_runner_); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 if (settings_.use_zero_copy) { | 2124 if (settings_.use_zero_copy) { |
2109 *resource_pool = | 2125 *resource_pool = |
2110 ResourcePool::Create(resource_provider_.get(), image_target); | 2126 ResourcePool::Create(resource_provider_.get(), image_target); |
2111 | 2127 |
2112 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( | 2128 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( |
2113 GetTaskRunner(), task_graph_runner, resource_provider_.get()); | 2129 GetTaskRunner(), task_graph_runner, resource_provider_.get()); |
2114 return; | 2130 return; |
2115 } | 2131 } |
2116 | 2132 |
2117 if (settings_.use_one_copy) { | 2133 if (settings_.use_one_copy) { |
| 2134 // Synchronous single-threaded mode depends on tiles being ready to |
| 2135 // draw when raster is complete. Therefore, it must use one of zero |
| 2136 // copy, software raster, or GPU raster. |
| 2137 DCHECK(!is_synchronous_single_threaded_); |
| 2138 |
| 2139 // We need to create a staging resource pool when using copy rasterizer. |
| 2140 *staging_resource_pool = |
| 2141 ResourcePool::Create(resource_provider_.get(), image_target); |
2118 *resource_pool = | 2142 *resource_pool = |
2119 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); | 2143 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); |
2120 | 2144 |
2121 int max_copy_texture_chromium_size = | 2145 int max_copy_texture_chromium_size = |
2122 context_provider->ContextCapabilities() | 2146 context_provider->ContextCapabilities() |
2123 .gpu.max_copy_texture_chromium_size; | 2147 .gpu.max_copy_texture_chromium_size; |
2124 | 2148 |
2125 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( | 2149 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( |
2126 GetTaskRunner(), task_graph_runner, context_provider, | 2150 GetTaskRunner(), task_graph_runner, context_provider, |
2127 resource_provider_.get(), max_copy_texture_chromium_size, | 2151 resource_provider_.get(), staging_resource_pool_.get(), |
2128 settings_.use_persistent_map_for_gpu_memory_buffers, image_target, | 2152 max_copy_texture_chromium_size, |
2129 settings_.max_staging_buffers); | 2153 settings_.use_persistent_map_for_gpu_memory_buffers); |
2130 return; | 2154 return; |
2131 } | 2155 } |
2132 | 2156 |
2133 // Synchronous single-threaded mode depends on tiles being ready to | 2157 // Synchronous single-threaded mode depends on tiles being ready to |
2134 // draw when raster is complete. Therefore, it must use one of zero | 2158 // draw when raster is complete. Therefore, it must use one of zero |
2135 // copy, software raster, or GPU raster (in the branches above). | 2159 // copy, software raster, or GPU raster (in the branches above). |
2136 DCHECK(!is_synchronous_single_threaded_); | 2160 DCHECK(!is_synchronous_single_threaded_); |
2137 | 2161 |
2138 *resource_pool = ResourcePool::Create( | 2162 *resource_pool = ResourcePool::Create( |
2139 resource_provider_.get(), GL_TEXTURE_2D); | 2163 resource_provider_.get(), GL_TEXTURE_2D); |
(...skipping 22 matching lines...) Expand all Loading... |
2162 void LayerTreeHostImpl::PostFrameTimingEvents( | 2186 void LayerTreeHostImpl::PostFrameTimingEvents( |
2163 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 2187 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
2164 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 2188 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
2165 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), | 2189 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), |
2166 main_frame_events.Pass()); | 2190 main_frame_events.Pass()); |
2167 } | 2191 } |
2168 | 2192 |
2169 void LayerTreeHostImpl::CleanUpTileManager() { | 2193 void LayerTreeHostImpl::CleanUpTileManager() { |
2170 tile_manager_->FinishTasksAndCleanUp(); | 2194 tile_manager_->FinishTasksAndCleanUp(); |
2171 resource_pool_ = nullptr; | 2195 resource_pool_ = nullptr; |
| 2196 staging_resource_pool_ = nullptr; |
2172 tile_task_worker_pool_ = nullptr; | 2197 tile_task_worker_pool_ = nullptr; |
2173 single_thread_synchronous_task_graph_runner_ = nullptr; | 2198 single_thread_synchronous_task_graph_runner_ = nullptr; |
2174 } | 2199 } |
2175 | 2200 |
2176 bool LayerTreeHostImpl::InitializeRenderer( | 2201 bool LayerTreeHostImpl::InitializeRenderer( |
2177 scoped_ptr<OutputSurface> output_surface) { | 2202 scoped_ptr<OutputSurface> output_surface) { |
2178 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2203 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
2179 | 2204 |
2180 // Since we will create a new resource provider, we cannot continue to use | 2205 // Since we will create a new resource provider, we cannot continue to use |
2181 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2206 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
(...skipping 12 matching lines...) Expand all Loading... |
2194 // point). | 2219 // point). |
2195 return false; | 2220 return false; |
2196 } | 2221 } |
2197 | 2222 |
2198 output_surface_ = output_surface.Pass(); | 2223 output_surface_ = output_surface.Pass(); |
2199 resource_provider_ = ResourceProvider::Create( | 2224 resource_provider_ = ResourceProvider::Create( |
2200 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, | 2225 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, |
2201 proxy_->blocking_main_thread_task_runner(), | 2226 proxy_->blocking_main_thread_task_runner(), |
2202 settings_.renderer_settings.highp_threshold_min, | 2227 settings_.renderer_settings.highp_threshold_min, |
2203 settings_.renderer_settings.use_rgba_4444_textures, | 2228 settings_.renderer_settings.use_rgba_4444_textures, |
2204 settings_.renderer_settings.texture_id_allocation_chunk_size); | 2229 settings_.renderer_settings.texture_id_allocation_chunk_size, |
| 2230 settings_.use_persistent_map_for_gpu_memory_buffers); |
2205 | 2231 |
2206 CreateAndSetRenderer(); | 2232 CreateAndSetRenderer(); |
2207 | 2233 |
2208 // Since the new renderer may be capable of MSAA, update status here. | 2234 // Since the new renderer may be capable of MSAA, update status here. |
2209 UpdateGpuRasterizationStatus(); | 2235 UpdateGpuRasterizationStatus(); |
2210 | 2236 |
2211 CreateTileManagerResources(); | 2237 CreateTileManagerResources(); |
2212 RecreateTreeResources(); | 2238 RecreateTreeResources(); |
2213 | 2239 |
2214 // Initialize vsync parameters to sane values. | 2240 // Initialize vsync parameters to sane values. |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3609 if (active_tree()) { | 3635 if (active_tree()) { |
3610 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3636 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3611 if (layer) | 3637 if (layer) |
3612 return layer->ScrollOffsetForAnimation(); | 3638 return layer->ScrollOffsetForAnimation(); |
3613 } | 3639 } |
3614 | 3640 |
3615 return gfx::ScrollOffset(); | 3641 return gfx::ScrollOffset(); |
3616 } | 3642 } |
3617 | 3643 |
3618 } // namespace cc | 3644 } // namespace cc |
OLD | NEW |