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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) { | 122 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) { |
123 if (visible) { | 123 if (visible) { |
124 TRACE_EVENT_ASYNC_BEGIN1("cc", "LayerTreeHostImpl::SetVisible", id, | 124 TRACE_EVENT_ASYNC_BEGIN1("cc", "LayerTreeHostImpl::SetVisible", id, |
125 "LayerTreeHostImpl", id); | 125 "LayerTreeHostImpl", id); |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 TRACE_EVENT_ASYNC_END0("cc", "LayerTreeHostImpl::SetVisible", id); | 129 TRACE_EVENT_ASYNC_END0("cc", "LayerTreeHostImpl::SetVisible", id); |
130 } | 130 } |
131 | 131 |
132 size_t GetMaxTransferBufferUsageBytes( | |
133 const ContextProvider::Capabilities& context_capabilities, | |
134 double refresh_rate) { | |
135 // We want to make sure the default transfer buffer size is equal to the | |
136 // amount of data that can be uploaded by the compositor to avoid stalling | |
137 // the pipeline. | |
138 // For reference Chromebook Pixel can upload 1MB in about 0.5ms. | |
139 const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2; | |
140 | |
141 // We need to upload at least enough work to keep the GPU process busy until | |
142 // the next time it can handle a request to start more uploads from the | |
143 // compositor. We assume that it will pick up any sent upload requests within | |
144 // the time of a vsync, since the browser will want to swap a frame within | |
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); | |
147 size_t max_transfer_buffer_usage_bytes = | |
148 ms_per_frame * kMaxBytesUploadedPerMs; | |
149 | |
150 // The context may request a lower limit based on the device capabilities. | |
151 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, | |
152 max_transfer_buffer_usage_bytes); | |
153 } | |
154 | |
155 size_t GetMaxStagingResourceCount() { | 132 size_t GetMaxStagingResourceCount() { |
156 // Upper bound for number of staging resource to allow. | 133 // Upper bound for number of staging resource to allow. |
157 return 32; | 134 return 32; |
158 } | 135 } |
159 | 136 |
160 size_t GetDefaultMemoryAllocationLimit() { | 137 size_t GetDefaultMemoryAllocationLimit() { |
161 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler | 138 // 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 | 139 // 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 | 140 // allocation before we get a callback from the GPU memory manager. We |
164 // should probaby either: | 141 // should probaby either: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 animation_host_->SetSupportsScrollAnimations( | 231 animation_host_->SetSupportsScrollAnimations( |
255 proxy_->SupportsImplScrolling()); | 232 proxy_->SupportsImplScrolling()); |
256 } | 233 } |
257 } else { | 234 } else { |
258 animation_registrar_ = AnimationRegistrar::Create(); | 235 animation_registrar_ = AnimationRegistrar::Create(); |
259 animation_registrar_->set_supports_scroll_animations( | 236 animation_registrar_->set_supports_scroll_animations( |
260 proxy_->SupportsImplScrolling()); | 237 proxy_->SupportsImplScrolling()); |
261 } | 238 } |
262 | 239 |
263 DCHECK(proxy_->IsImplThread()); | 240 DCHECK(proxy_->IsImplThread()); |
264 DCHECK_IMPLIES(settings.use_one_copy, !settings.use_zero_copy); | |
265 DCHECK_IMPLIES(settings.use_zero_copy, !settings.use_one_copy); | |
266 DidVisibilityChange(this, visible_); | 241 DidVisibilityChange(this, visible_); |
267 | 242 |
268 SetDebugState(settings.initial_debug_state); | 243 SetDebugState(settings.initial_debug_state); |
269 | 244 |
270 // LTHI always has an active tree. | 245 // LTHI always has an active tree. |
271 active_tree_ = | 246 active_tree_ = |
272 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), | 247 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), |
273 new SyncedTopControls, new SyncedElasticOverscroll); | 248 new SyncedTopControls, new SyncedElasticOverscroll); |
274 | 249 |
275 viewport_ = Viewport::Create(this); | 250 viewport_ = Viewport::Create(this); |
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 | 2105 |
2131 if (settings_.use_zero_copy) { | 2106 if (settings_.use_zero_copy) { |
2132 *resource_pool = | 2107 *resource_pool = |
2133 ResourcePool::Create(resource_provider_.get(), image_target); | 2108 ResourcePool::Create(resource_provider_.get(), image_target); |
2134 | 2109 |
2135 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( | 2110 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( |
2136 GetTaskRunner(), task_graph_runner, resource_provider_.get()); | 2111 GetTaskRunner(), task_graph_runner, resource_provider_.get()); |
2137 return; | 2112 return; |
2138 } | 2113 } |
2139 | 2114 |
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(!IsSynchronousSingleThreaded()); | |
2145 | |
2146 // We need to create a staging resource pool when using copy rasterizer. | |
2147 *staging_resource_pool = | |
2148 ResourcePool::Create(resource_provider_.get(), image_target); | |
2149 *resource_pool = | |
2150 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); | |
2151 | |
2152 int max_copy_texture_chromium_size = | |
2153 context_provider->ContextCapabilities() | |
2154 .gpu.max_copy_texture_chromium_size; | |
2155 | |
2156 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( | |
2157 GetTaskRunner(), task_graph_runner, context_provider, | |
2158 resource_provider_.get(), staging_resource_pool_.get(), | |
2159 max_copy_texture_chromium_size, | |
2160 settings_.use_persistent_map_for_gpu_memory_buffers); | |
2161 return; | |
2162 } | |
2163 | |
2164 // Synchronous single-threaded mode depends on tiles being ready to | 2115 // Synchronous single-threaded mode depends on tiles being ready to |
2165 // draw when raster is complete. Therefore, it must use one of zero | 2116 // draw when raster is complete. Therefore, it must use one of zero |
2166 // copy, software raster, or GPU raster (in the branches above). | 2117 // copy, software raster, or GPU raster. |
2167 DCHECK(!IsSynchronousSingleThreaded()); | 2118 DCHECK(!IsSynchronousSingleThreaded()); |
2168 | 2119 |
2169 *resource_pool = ResourcePool::Create( | 2120 // We need to create a staging resource pool when using copy rasterizer. |
2170 resource_provider_.get(), GL_TEXTURE_2D); | 2121 *staging_resource_pool = |
| 2122 ResourcePool::Create(resource_provider_.get(), image_target); |
| 2123 *resource_pool = |
| 2124 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); |
2171 | 2125 |
2172 *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create( | 2126 int max_copy_texture_chromium_size = context_provider->ContextCapabilities() |
2173 GetTaskRunner(), task_graph_runner_, context_provider, | 2127 .gpu.max_copy_texture_chromium_size; |
2174 resource_provider_.get(), | 2128 |
2175 GetMaxTransferBufferUsageBytes(context_provider->ContextCapabilities(), | 2129 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( |
2176 settings_.renderer_settings.refresh_rate)); | 2130 GetTaskRunner(), task_graph_runner, context_provider, |
| 2131 resource_provider_.get(), staging_resource_pool_.get(), |
| 2132 max_copy_texture_chromium_size, |
| 2133 settings_.use_persistent_map_for_gpu_memory_buffers); |
2177 } | 2134 } |
2178 | 2135 |
2179 void LayerTreeHostImpl::RecordMainFrameTiming( | 2136 void LayerTreeHostImpl::RecordMainFrameTiming( |
2180 const BeginFrameArgs& start_of_main_frame_args, | 2137 const BeginFrameArgs& start_of_main_frame_args, |
2181 const BeginFrameArgs& expected_next_main_frame_args) { | 2138 const BeginFrameArgs& expected_next_main_frame_args) { |
2182 std::vector<int64_t> request_ids; | 2139 std::vector<int64_t> request_ids; |
2183 active_tree_->GatherFrameTimingRequestIds(&request_ids); | 2140 active_tree_->GatherFrameTimingRequestIds(&request_ids); |
2184 if (request_ids.empty()) | 2141 if (request_ids.empty()) |
2185 return; | 2142 return; |
2186 | 2143 |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3607 if (active_tree()) { | 3564 if (active_tree()) { |
3608 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3565 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3609 if (layer) | 3566 if (layer) |
3610 return layer->ScrollOffsetForAnimation(); | 3567 return layer->ScrollOffsetForAnimation(); |
3611 } | 3568 } |
3612 | 3569 |
3613 return gfx::ScrollOffset(); | 3570 return gfx::ScrollOffset(); |
3614 } | 3571 } |
3615 | 3572 |
3616 } // namespace cc | 3573 } // namespace cc |
OLD | NEW |