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

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

Powered by Google App Engine
This is Rietveld 408576698