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