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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2069 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
2056 // initialized to get max texture size. Also, after releasing resources, | 2070 // initialized to get max texture size. Also, after releasing resources, |
2057 // trees need another update to generate new ones. | 2071 // trees need another update to generate new ones. |
2058 active_tree_->set_needs_update_draw_properties(); | 2072 active_tree_->set_needs_update_draw_properties(); |
2059 if (pending_tree_) | 2073 if (pending_tree_) |
2060 pending_tree_->set_needs_update_draw_properties(); | 2074 pending_tree_->set_needs_update_draw_properties(); |
2061 client_->UpdateRendererCapabilitiesOnImplThread(); | 2075 client_->UpdateRendererCapabilitiesOnImplThread(); |
2062 } | 2076 } |
2063 | 2077 |
2064 void LayerTreeHostImpl::CreateTileManagerResources() { | 2078 void LayerTreeHostImpl::CreateTileManagerResources() { |
2065 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_); | 2079 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_, |
| 2080 &staging_resource_pool_); |
2066 // TODO(vmpstr): Initialize tile task limit at ctor time. | 2081 // TODO(vmpstr): Initialize tile task limit at ctor time. |
2067 tile_manager_->SetResources( | 2082 tile_manager_->SetResources( |
2068 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), | 2083 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), |
2069 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() | 2084 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() |
2070 : settings_.scheduled_raster_task_limit); | 2085 : settings_.scheduled_raster_task_limit); |
2071 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2086 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
2072 } | 2087 } |
2073 | 2088 |
2074 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( | 2089 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( |
2075 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, | 2090 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, |
2076 scoped_ptr<ResourcePool>* resource_pool) { | 2091 scoped_ptr<ResourcePool>* resource_pool, |
| 2092 scoped_ptr<ResourcePool>* staging_resource_pool) { |
2077 DCHECK(GetTaskRunner()); | 2093 DCHECK(GetTaskRunner()); |
2078 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is | 2094 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is |
2079 // resolved. | 2095 // resolved. |
2080 CHECK(resource_provider_); | 2096 CHECK(resource_provider_); |
2081 | 2097 |
2082 // Pass the single-threaded synchronous task graph runner to the worker pool | 2098 // Pass the single-threaded synchronous task graph runner to the worker pool |
2083 // if we're in synchronous single-threaded mode. | 2099 // if we're in synchronous single-threaded mode. |
2084 TaskGraphRunner* task_graph_runner = task_graph_runner_; | 2100 TaskGraphRunner* task_graph_runner = task_graph_runner_; |
2085 if (is_synchronous_single_threaded_) { | 2101 if (is_synchronous_single_threaded_) { |
2086 DCHECK(!single_thread_synchronous_task_graph_runner_); | 2102 DCHECK(!single_thread_synchronous_task_graph_runner_); |
(...skipping 28 matching lines...) Expand all Loading... |
2115 | 2131 |
2116 if (settings_.use_zero_copy) { | 2132 if (settings_.use_zero_copy) { |
2117 *resource_pool = ResourcePool::Create(resource_provider_.get()); | 2133 *resource_pool = ResourcePool::Create(resource_provider_.get()); |
2118 | 2134 |
2119 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( | 2135 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( |
2120 GetTaskRunner(), task_graph_runner, resource_provider_.get()); | 2136 GetTaskRunner(), task_graph_runner, resource_provider_.get()); |
2121 return; | 2137 return; |
2122 } | 2138 } |
2123 | 2139 |
2124 if (settings_.use_one_copy) { | 2140 if (settings_.use_one_copy) { |
| 2141 // Synchronous single-threaded mode depends on tiles being ready to |
| 2142 // draw when raster is complete. Therefore, it must use one of zero |
| 2143 // copy, software raster, or GPU raster. |
| 2144 DCHECK(!is_synchronous_single_threaded_); |
| 2145 |
| 2146 // We need to create a staging resource pool when using copy rasterizer. |
| 2147 *staging_resource_pool = ResourcePool::Create(resource_provider_.get()); |
2125 *resource_pool = | 2148 *resource_pool = |
2126 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); | 2149 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); |
2127 | 2150 |
2128 int max_copy_texture_chromium_size = | 2151 int max_copy_texture_chromium_size = |
2129 context_provider->ContextCapabilities() | 2152 context_provider->ContextCapabilities() |
2130 .gpu.max_copy_texture_chromium_size; | 2153 .gpu.max_copy_texture_chromium_size; |
2131 | 2154 |
2132 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( | 2155 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( |
2133 GetTaskRunner(), task_graph_runner, context_provider, | 2156 GetTaskRunner(), task_graph_runner, context_provider, |
2134 resource_provider_.get(), max_copy_texture_chromium_size, | 2157 resource_provider_.get(), staging_resource_pool_.get(), |
2135 settings_.use_persistent_map_for_gpu_memory_buffers, | 2158 max_copy_texture_chromium_size, |
2136 settings_.max_staging_buffers); | 2159 settings_.use_persistent_map_for_gpu_memory_buffers); |
2137 return; | 2160 return; |
2138 } | 2161 } |
2139 | 2162 |
2140 // Synchronous single-threaded mode depends on tiles being ready to | 2163 // Synchronous single-threaded mode depends on tiles being ready to |
2141 // draw when raster is complete. Therefore, it must use one of zero | 2164 // draw when raster is complete. Therefore, it must use one of zero |
2142 // copy, software raster, or GPU raster (in the branches above). | 2165 // copy, software raster, or GPU raster (in the branches above). |
2143 DCHECK(!is_synchronous_single_threaded_); | 2166 DCHECK(!is_synchronous_single_threaded_); |
2144 | 2167 |
2145 *resource_pool = ResourcePool::Create( | 2168 *resource_pool = ResourcePool::Create( |
2146 resource_provider_.get(), GL_TEXTURE_2D); | 2169 resource_provider_.get(), GL_TEXTURE_2D); |
(...skipping 22 matching lines...) Expand all Loading... |
2169 void LayerTreeHostImpl::PostFrameTimingEvents( | 2192 void LayerTreeHostImpl::PostFrameTimingEvents( |
2170 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 2193 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
2171 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { | 2194 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { |
2172 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), | 2195 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), |
2173 main_frame_events.Pass()); | 2196 main_frame_events.Pass()); |
2174 } | 2197 } |
2175 | 2198 |
2176 void LayerTreeHostImpl::CleanUpTileManager() { | 2199 void LayerTreeHostImpl::CleanUpTileManager() { |
2177 tile_manager_->FinishTasksAndCleanUp(); | 2200 tile_manager_->FinishTasksAndCleanUp(); |
2178 resource_pool_ = nullptr; | 2201 resource_pool_ = nullptr; |
| 2202 staging_resource_pool_ = nullptr; |
2179 tile_task_worker_pool_ = nullptr; | 2203 tile_task_worker_pool_ = nullptr; |
2180 single_thread_synchronous_task_graph_runner_ = nullptr; | 2204 single_thread_synchronous_task_graph_runner_ = nullptr; |
2181 } | 2205 } |
2182 | 2206 |
2183 bool LayerTreeHostImpl::InitializeRenderer( | 2207 bool LayerTreeHostImpl::InitializeRenderer( |
2184 scoped_ptr<OutputSurface> output_surface) { | 2208 scoped_ptr<OutputSurface> output_surface) { |
2185 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2209 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
2186 | 2210 |
2187 // Since we will create a new resource provider, we cannot continue to use | 2211 // Since we will create a new resource provider, we cannot continue to use |
2188 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2212 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
(...skipping 13 matching lines...) Expand all Loading... |
2202 return false; | 2226 return false; |
2203 } | 2227 } |
2204 | 2228 |
2205 output_surface_ = output_surface.Pass(); | 2229 output_surface_ = output_surface.Pass(); |
2206 resource_provider_ = ResourceProvider::Create( | 2230 resource_provider_ = ResourceProvider::Create( |
2207 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, | 2231 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, |
2208 proxy_->blocking_main_thread_task_runner(), | 2232 proxy_->blocking_main_thread_task_runner(), |
2209 settings_.renderer_settings.highp_threshold_min, | 2233 settings_.renderer_settings.highp_threshold_min, |
2210 settings_.renderer_settings.use_rgba_4444_textures, | 2234 settings_.renderer_settings.use_rgba_4444_textures, |
2211 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2235 settings_.renderer_settings.texture_id_allocation_chunk_size, |
| 2236 settings_.use_persistent_map_for_gpu_memory_buffers, |
2212 settings_.use_image_texture_targets); | 2237 settings_.use_image_texture_targets); |
2213 | 2238 |
2214 CreateAndSetRenderer(); | 2239 CreateAndSetRenderer(); |
2215 | 2240 |
2216 // Since the new renderer may be capable of MSAA, update status here. | 2241 // Since the new renderer may be capable of MSAA, update status here. |
2217 UpdateGpuRasterizationStatus(); | 2242 UpdateGpuRasterizationStatus(); |
2218 | 2243 |
2219 CreateTileManagerResources(); | 2244 CreateTileManagerResources(); |
2220 RecreateTreeResources(); | 2245 RecreateTreeResources(); |
2221 | 2246 |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3619 if (active_tree()) { | 3644 if (active_tree()) { |
3620 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3645 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3621 if (layer) | 3646 if (layer) |
3622 return layer->ScrollOffsetForAnimation(); | 3647 return layer->ScrollOffsetForAnimation(); |
3623 } | 3648 } |
3624 | 3649 |
3625 return gfx::ScrollOffset(); | 3650 return gfx::ScrollOffset(); |
3626 } | 3651 } |
3627 | 3652 |
3628 } // namespace cc | 3653 } // namespace cc |
OLD | NEW |