Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 1230203007: Re-land: cc: Use worker context for one-copy tile initialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed output surface lost worker context handling Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // that time interval, and then uploads should have a chance to be processed. 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); 146 size_t ms_per_frame = std::floor(1000.0 / refresh_rate);
147 size_t max_transfer_buffer_usage_bytes = 147 size_t max_transfer_buffer_usage_bytes =
148 ms_per_frame * kMaxBytesUploadedPerMs; 148 ms_per_frame * kMaxBytesUploadedPerMs;
149 149
150 // The context may request a lower limit based on the device capabilities. 150 // The context may request a lower limit based on the device capabilities.
151 return std::min(context_capabilities.max_transfer_buffer_usage_bytes, 151 return std::min(context_capabilities.max_transfer_buffer_usage_bytes,
152 max_transfer_buffer_usage_bytes); 152 max_transfer_buffer_usage_bytes);
153 } 153 }
154 154
155 size_t GetMaxStagingResourceCount() {
156 // Upper bound for number of staging resource to allow.
157 return 32;
158 }
159
160 size_t GetDefaultMemoryAllocationLimit() { 155 size_t GetDefaultMemoryAllocationLimit() {
161 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler 156 // 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 157 // 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 158 // allocation before we get a callback from the GPU memory manager. We
164 // should probaby either: 159 // should probaby either:
165 // - wait for the callback before rendering anything instead 160 // - wait for the callback before rendering anything instead
166 // - push this into the GPU memory manager somehow. 161 // - push this into the GPU memory manager somehow.
167 return 64 * 1024 * 1024; 162 return 64 * 1024 * 1024;
168 } 163 }
169 164
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 // TODO(reveman): We should avoid keeping around unused resources if 1222 // TODO(reveman): We should avoid keeping around unused resources if
1228 // possible. crbug.com/224475 1223 // possible. crbug.com/224475
1229 // Unused limit is calculated from soft-limit, as hard-limit may 1224 // Unused limit is calculated from soft-limit, as hard-limit may
1230 // be very high and shouldn't typically be exceeded. 1225 // be very high and shouldn't typically be exceeded.
1231 size_t unused_memory_limit_in_bytes = static_cast<size_t>( 1226 size_t unused_memory_limit_in_bytes = static_cast<size_t>(
1232 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * 1227 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) *
1233 settings_.max_unused_resource_memory_percentage) / 1228 settings_.max_unused_resource_memory_percentage) /
1234 100); 1229 100);
1235 1230
1236 DCHECK(resource_pool_); 1231 DCHECK(resource_pool_);
1237 resource_pool_->CheckBusyResources(false); 1232 resource_pool_->CheckBusyResources();
1238 // Soft limit is used for resource pool such that memory returns to soft 1233 // Soft limit is used for resource pool such that memory returns to soft
1239 // limit after going over. 1234 // limit after going over.
1240 resource_pool_->SetResourceUsageLimits( 1235 resource_pool_->SetResourceUsageLimits(
1241 global_tile_state_.soft_memory_limit_in_bytes, 1236 global_tile_state_.soft_memory_limit_in_bytes,
1242 unused_memory_limit_in_bytes, 1237 unused_memory_limit_in_bytes,
1243 global_tile_state_.num_resources_limit); 1238 global_tile_state_.num_resources_limit);
1244 1239
1245 // Release all staging resources when invisible.
1246 if (staging_resource_pool_) {
1247 staging_resource_pool_->CheckBusyResources(false);
1248 staging_resource_pool_->SetResourceUsageLimits(
1249 std::numeric_limits<size_t>::max(),
1250 std::numeric_limits<size_t>::max(),
1251 visible_ ? GetMaxStagingResourceCount() : 0);
1252 }
1253
1254 DidModifyTilePriorities(); 1240 DidModifyTilePriorities();
1255 } 1241 }
1256 1242
1257 void LayerTreeHostImpl::DidModifyTilePriorities() { 1243 void LayerTreeHostImpl::DidModifyTilePriorities() {
1258 // Mark priorities as dirty and schedule a PrepareTiles(). 1244 // Mark priorities as dirty and schedule a PrepareTiles().
1259 tile_priorities_dirty_ = true; 1245 tile_priorities_dirty_ = true;
1260 client_->SetNeedsPrepareTilesOnImplThread(); 1246 client_->SetNeedsPrepareTilesOnImplThread();
1261 } 1247 }
1262 1248
1263 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( 1249 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 1443
1458 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { 1444 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) {
1459 // TODO(piman): We may need to do some validation on this ack before 1445 // TODO(piman): We may need to do some validation on this ack before
1460 // processing it. 1446 // processing it.
1461 if (renderer_) 1447 if (renderer_)
1462 renderer_->ReceiveSwapBuffersAck(*ack); 1448 renderer_->ReceiveSwapBuffersAck(*ack);
1463 1449
1464 // In OOM, we now might be able to release more resources that were held 1450 // In OOM, we now might be able to release more resources that were held
1465 // because they were exported. 1451 // because they were exported.
1466 if (resource_pool_) { 1452 if (resource_pool_) {
1467 resource_pool_->CheckBusyResources(false); 1453 resource_pool_->CheckBusyResources();
1468 resource_pool_->ReduceResourceUsage(); 1454 resource_pool_->ReduceResourceUsage();
1469 } 1455 }
1470 // If we're not visible, we likely released resources, so we want to 1456 // If we're not visible, we likely released resources, so we want to
1471 // aggressively flush here to make sure those DeleteTextures make it to the 1457 // aggressively flush here to make sure those DeleteTextures make it to the
1472 // GPU process to free up the memory. 1458 // GPU process to free up the memory.
1473 if (output_surface_->context_provider() && !visible_) { 1459 if (output_surface_->context_provider() && !visible_) {
1474 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); 1460 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1475 } 1461 }
1476 } 1462 }
1477 1463
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be 2061 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be
2076 // initialized to get max texture size. Also, after releasing resources, 2062 // initialized to get max texture size. Also, after releasing resources,
2077 // trees need another update to generate new ones. 2063 // trees need another update to generate new ones.
2078 active_tree_->set_needs_update_draw_properties(); 2064 active_tree_->set_needs_update_draw_properties();
2079 if (pending_tree_) 2065 if (pending_tree_)
2080 pending_tree_->set_needs_update_draw_properties(); 2066 pending_tree_->set_needs_update_draw_properties();
2081 client_->UpdateRendererCapabilitiesOnImplThread(); 2067 client_->UpdateRendererCapabilitiesOnImplThread();
2082 } 2068 }
2083 2069
2084 void LayerTreeHostImpl::CreateTileManagerResources() { 2070 void LayerTreeHostImpl::CreateTileManagerResources() {
2085 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_, 2071 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_);
2086 &staging_resource_pool_);
2087 // TODO(vmpstr): Initialize tile task limit at ctor time. 2072 // TODO(vmpstr): Initialize tile task limit at ctor time.
2088 tile_manager_->SetResources( 2073 tile_manager_->SetResources(
2089 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), 2074 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(),
2090 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() 2075 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max()
2091 : settings_.scheduled_raster_task_limit); 2076 : settings_.scheduled_raster_task_limit);
2092 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); 2077 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
2093 } 2078 }
2094 2079
2095 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( 2080 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
2096 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, 2081 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
2097 scoped_ptr<ResourcePool>* resource_pool, 2082 scoped_ptr<ResourcePool>* resource_pool) {
2098 scoped_ptr<ResourcePool>* staging_resource_pool) {
2099 DCHECK(GetTaskRunner()); 2083 DCHECK(GetTaskRunner());
2100 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is 2084 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is
2101 // resolved. 2085 // resolved.
2102 CHECK(resource_provider_); 2086 CHECK(resource_provider_);
2103 2087
2104 // Pass the single-threaded synchronous task graph runner to the worker pool 2088 // Pass the single-threaded synchronous task graph runner to the worker pool
2105 // if we're in synchronous single-threaded mode. 2089 // if we're in synchronous single-threaded mode.
2106 TaskGraphRunner* task_graph_runner = task_graph_runner_; 2090 TaskGraphRunner* task_graph_runner = task_graph_runner_;
2107 if (is_synchronous_single_threaded_) { 2091 if (is_synchronous_single_threaded_) {
2108 DCHECK(!single_thread_synchronous_task_graph_runner_); 2092 DCHECK(!single_thread_synchronous_task_graph_runner_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 if (settings_.use_zero_copy) { 2129 if (settings_.use_zero_copy) {
2146 *resource_pool = 2130 *resource_pool =
2147 ResourcePool::Create(resource_provider_.get(), image_target); 2131 ResourcePool::Create(resource_provider_.get(), image_target);
2148 2132
2149 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( 2133 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
2150 GetTaskRunner(), task_graph_runner, resource_provider_.get()); 2134 GetTaskRunner(), task_graph_runner, resource_provider_.get());
2151 return; 2135 return;
2152 } 2136 }
2153 2137
2154 if (settings_.use_one_copy) { 2138 if (settings_.use_one_copy) {
2155 // Synchronous single-threaded mode depends on tiles being ready to
2156 // draw when raster is complete. Therefore, it must use one of zero
2157 // copy, software raster, or GPU raster.
2158 DCHECK(!is_synchronous_single_threaded_);
2159
2160 // We need to create a staging resource pool when using copy rasterizer.
2161 *staging_resource_pool =
2162 ResourcePool::Create(resource_provider_.get(), image_target);
2163 *resource_pool = 2139 *resource_pool =
2164 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); 2140 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
2165 2141
2166 int max_copy_texture_chromium_size = 2142 int max_copy_texture_chromium_size =
2167 context_provider->ContextCapabilities() 2143 context_provider->ContextCapabilities()
2168 .gpu.max_copy_texture_chromium_size; 2144 .gpu.max_copy_texture_chromium_size;
2169 2145
2170 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( 2146 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
2171 GetTaskRunner(), task_graph_runner, context_provider, 2147 GetTaskRunner(), task_graph_runner, context_provider,
2172 resource_provider_.get(), staging_resource_pool_.get(), 2148 resource_provider_.get(), max_copy_texture_chromium_size,
2173 max_copy_texture_chromium_size, 2149 settings_.use_persistent_map_for_gpu_memory_buffers, image_target,
2174 settings_.use_persistent_map_for_gpu_memory_buffers); 2150 settings_.max_staging_buffers);
2175 return; 2151 return;
2176 } 2152 }
2177 2153
2178 // Synchronous single-threaded mode depends on tiles being ready to 2154 // Synchronous single-threaded mode depends on tiles being ready to
2179 // draw when raster is complete. Therefore, it must use one of zero 2155 // draw when raster is complete. Therefore, it must use one of zero
2180 // copy, software raster, or GPU raster (in the branches above). 2156 // copy, software raster, or GPU raster (in the branches above).
2181 DCHECK(!is_synchronous_single_threaded_); 2157 DCHECK(!is_synchronous_single_threaded_);
2182 2158
2183 *resource_pool = ResourcePool::Create( 2159 *resource_pool = ResourcePool::Create(
2184 resource_provider_.get(), GL_TEXTURE_2D); 2160 resource_provider_.get(), GL_TEXTURE_2D);
(...skipping 22 matching lines...) Expand all
2207 void LayerTreeHostImpl::PostFrameTimingEvents( 2183 void LayerTreeHostImpl::PostFrameTimingEvents(
2208 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 2184 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
2209 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { 2185 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
2210 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), 2186 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(),
2211 main_frame_events.Pass()); 2187 main_frame_events.Pass());
2212 } 2188 }
2213 2189
2214 void LayerTreeHostImpl::CleanUpTileManager() { 2190 void LayerTreeHostImpl::CleanUpTileManager() {
2215 tile_manager_->FinishTasksAndCleanUp(); 2191 tile_manager_->FinishTasksAndCleanUp();
2216 resource_pool_ = nullptr; 2192 resource_pool_ = nullptr;
2217 staging_resource_pool_ = nullptr;
2218 tile_task_worker_pool_ = nullptr; 2193 tile_task_worker_pool_ = nullptr;
2219 single_thread_synchronous_task_graph_runner_ = nullptr; 2194 single_thread_synchronous_task_graph_runner_ = nullptr;
2220 } 2195 }
2221 2196
2222 bool LayerTreeHostImpl::InitializeRenderer( 2197 bool LayerTreeHostImpl::InitializeRenderer(
2223 scoped_ptr<OutputSurface> output_surface) { 2198 scoped_ptr<OutputSurface> output_surface) {
2224 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); 2199 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer");
2225 2200
2226 // Since we will create a new resource provider, we cannot continue to use 2201 // Since we will create a new resource provider, we cannot continue to use
2227 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2202 // the old resources (i.e. render_surfaces and texture IDs). Clear them
(...skipping 12 matching lines...) Expand all
2240 // point). 2215 // point).
2241 return false; 2216 return false;
2242 } 2217 }
2243 2218
2244 output_surface_ = output_surface.Pass(); 2219 output_surface_ = output_surface.Pass();
2245 resource_provider_ = ResourceProvider::Create( 2220 resource_provider_ = ResourceProvider::Create(
2246 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, 2221 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_,
2247 proxy_->blocking_main_thread_task_runner(), 2222 proxy_->blocking_main_thread_task_runner(),
2248 settings_.renderer_settings.highp_threshold_min, 2223 settings_.renderer_settings.highp_threshold_min,
2249 settings_.renderer_settings.use_rgba_4444_textures, 2224 settings_.renderer_settings.use_rgba_4444_textures,
2250 settings_.renderer_settings.texture_id_allocation_chunk_size, 2225 settings_.renderer_settings.texture_id_allocation_chunk_size);
2251 settings_.use_persistent_map_for_gpu_memory_buffers);
2252 2226
2253 CreateAndSetRenderer(); 2227 CreateAndSetRenderer();
2254 2228
2255 // Since the new renderer may be capable of MSAA, update status here. 2229 // Since the new renderer may be capable of MSAA, update status here.
2256 UpdateGpuRasterizationStatus(); 2230 UpdateGpuRasterizationStatus();
2257 2231
2258 CreateTileManagerResources(); 2232 CreateTileManagerResources();
2259 RecreateTreeResources(); 2233 RecreateTreeResources();
2260 2234
2261 // Initialize vsync parameters to sane values. 2235 // Initialize vsync parameters to sane values.
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
3616 if (active_tree()) { 3590 if (active_tree()) {
3617 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); 3591 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id);
3618 if (layer) 3592 if (layer)
3619 return layer->ScrollOffsetForAnimation(); 3593 return layer->ScrollOffsetForAnimation();
3620 } 3594 }
3621 3595
3622 return gfx::ScrollOffset(); 3596 return gfx::ScrollOffset();
3623 } 3597 }
3624 3598
3625 } // namespace cc 3599 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698