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