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

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: add ContextProvider::ScopedContextGL class 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 1058 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. 1241 tile_task_worker_pool_->ReleaseFreeMemory();
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 1242
1255 DidModifyTilePriorities(); 1243 DidModifyTilePriorities();
1256 } 1244 }
1257 1245
1258 void LayerTreeHostImpl::DidModifyTilePriorities() { 1246 void LayerTreeHostImpl::DidModifyTilePriorities() {
1259 // Mark priorities as dirty and schedule a PrepareTiles(). 1247 // Mark priorities as dirty and schedule a PrepareTiles().
1260 tile_priorities_dirty_ = true; 1248 tile_priorities_dirty_ = true;
1261 client_->SetNeedsPrepareTilesOnImplThread(); 1249 client_->SetNeedsPrepareTilesOnImplThread();
1262 } 1250 }
1263 1251
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 1446
1459 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { 1447 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) {
1460 // TODO(piman): We may need to do some validation on this ack before 1448 // TODO(piman): We may need to do some validation on this ack before
1461 // processing it. 1449 // processing it.
1462 if (renderer_) 1450 if (renderer_)
1463 renderer_->ReceiveSwapBuffersAck(*ack); 1451 renderer_->ReceiveSwapBuffersAck(*ack);
1464 1452
1465 // In OOM, we now might be able to release more resources that were held 1453 // In OOM, we now might be able to release more resources that were held
1466 // because they were exported. 1454 // because they were exported.
1467 if (resource_pool_) { 1455 if (resource_pool_) {
1468 resource_pool_->CheckBusyResources(false); 1456 resource_pool_->CheckBusyResources();
1469 resource_pool_->ReduceResourceUsage(); 1457 resource_pool_->ReduceResourceUsage();
1470 } 1458 }
1471 // If we're not visible, we likely released resources, so we want to 1459 // 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 1460 // aggressively flush here to make sure those DeleteTextures make it to the
1473 // GPU process to free up the memory. 1461 // GPU process to free up the memory.
1474 if (output_surface_->context_provider() && !visible_) { 1462 if (output_surface_->context_provider() && !visible_) {
1475 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); 1463 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1476 } 1464 }
1477 } 1465 }
1478 1466
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be 2060 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be
2073 // initialized to get max texture size. Also, after releasing resources, 2061 // initialized to get max texture size. Also, after releasing resources,
2074 // trees need another update to generate new ones. 2062 // trees need another update to generate new ones.
2075 active_tree_->set_needs_update_draw_properties(); 2063 active_tree_->set_needs_update_draw_properties();
2076 if (pending_tree_) 2064 if (pending_tree_)
2077 pending_tree_->set_needs_update_draw_properties(); 2065 pending_tree_->set_needs_update_draw_properties();
2078 client_->UpdateRendererCapabilitiesOnImplThread(); 2066 client_->UpdateRendererCapabilitiesOnImplThread();
2079 } 2067 }
2080 2068
2081 void LayerTreeHostImpl::CreateTileManagerResources() { 2069 void LayerTreeHostImpl::CreateTileManagerResources() {
2082 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_, 2070 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_);
2083 &staging_resource_pool_);
2084 // TODO(vmpstr): Initialize tile task limit at ctor time. 2071 // TODO(vmpstr): Initialize tile task limit at ctor time.
2085 tile_manager_->SetResources( 2072 tile_manager_->SetResources(
2086 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), 2073 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(),
2087 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() 2074 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max()
2088 : settings_.scheduled_raster_task_limit); 2075 : settings_.scheduled_raster_task_limit);
2089 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); 2076 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
2090 } 2077 }
2091 2078
2092 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( 2079 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
2093 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, 2080 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
2094 scoped_ptr<ResourcePool>* resource_pool, 2081 scoped_ptr<ResourcePool>* resource_pool) {
2095 scoped_ptr<ResourcePool>* staging_resource_pool) {
2096 DCHECK(GetTaskRunner()); 2082 DCHECK(GetTaskRunner());
2097 2083
2098 // Pass the single-threaded synchronous task graph runner to the worker pool 2084 // Pass the single-threaded synchronous task graph runner to the worker pool
2099 // if we're in synchronous single-threaded mode. 2085 // if we're in synchronous single-threaded mode.
2100 TaskGraphRunner* task_graph_runner = task_graph_runner_; 2086 TaskGraphRunner* task_graph_runner = task_graph_runner_;
2101 if (is_synchronous_single_threaded_) { 2087 if (is_synchronous_single_threaded_) {
2102 DCHECK(!single_thread_synchronous_task_graph_runner_); 2088 DCHECK(!single_thread_synchronous_task_graph_runner_);
2103 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); 2089 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner);
2104 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); 2090 task_graph_runner = single_thread_synchronous_task_graph_runner_.get();
2105 } 2091 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 if (settings_.use_zero_copy) { 2125 if (settings_.use_zero_copy) {
2140 *resource_pool = 2126 *resource_pool =
2141 ResourcePool::Create(resource_provider_.get(), image_target); 2127 ResourcePool::Create(resource_provider_.get(), image_target);
2142 2128
2143 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( 2129 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
2144 GetTaskRunner(), task_graph_runner, resource_provider_.get()); 2130 GetTaskRunner(), task_graph_runner, resource_provider_.get());
2145 return; 2131 return;
2146 } 2132 }
2147 2133
2148 if (settings_.use_one_copy) { 2134 if (settings_.use_one_copy) {
2149 // Synchronous single-threaded mode depends on tiles being ready to
2150 // draw when raster is complete. Therefore, it must use one of zero
2151 // copy, software raster, or GPU raster.
2152 DCHECK(!is_synchronous_single_threaded_);
2153
2154 // We need to create a staging resource pool when using copy rasterizer.
2155 *staging_resource_pool =
2156 ResourcePool::Create(resource_provider_.get(), image_target);
2157 *resource_pool = 2135 *resource_pool =
2158 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); 2136 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
2159 2137
2160 int max_copy_texture_chromium_size = 2138 int max_copy_texture_chromium_size =
2161 context_provider->ContextCapabilities() 2139 context_provider->ContextCapabilities()
2162 .gpu.max_copy_texture_chromium_size; 2140 .gpu.max_copy_texture_chromium_size;
2163 2141
2164 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( 2142 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
2165 GetTaskRunner(), task_graph_runner, context_provider, 2143 GetTaskRunner(), task_graph_runner, context_provider,
2166 resource_provider_.get(), staging_resource_pool_.get(), 2144 resource_provider_.get(), max_copy_texture_chromium_size,
2167 max_copy_texture_chromium_size, 2145 settings_.use_persistent_map_for_gpu_memory_buffers, image_target);
2168 settings_.use_persistent_map_for_gpu_memory_buffers);
2169 return; 2146 return;
2170 } 2147 }
2171 2148
2172 // Synchronous single-threaded mode depends on tiles being ready to 2149 // Synchronous single-threaded mode depends on tiles being ready to
2173 // draw when raster is complete. Therefore, it must use one of zero 2150 // draw when raster is complete. Therefore, it must use one of zero
2174 // copy, software raster, or GPU raster (in the branches above). 2151 // copy, software raster, or GPU raster (in the branches above).
2175 DCHECK(!is_synchronous_single_threaded_); 2152 DCHECK(!is_synchronous_single_threaded_);
2176 2153
2177 *resource_pool = ResourcePool::Create( 2154 *resource_pool = ResourcePool::Create(
2178 resource_provider_.get(), GL_TEXTURE_2D); 2155 resource_provider_.get(), GL_TEXTURE_2D);
(...skipping 22 matching lines...) Expand all
2201 void LayerTreeHostImpl::PostFrameTimingEvents( 2178 void LayerTreeHostImpl::PostFrameTimingEvents(
2202 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 2179 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
2203 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { 2180 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
2204 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), 2181 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(),
2205 main_frame_events.Pass()); 2182 main_frame_events.Pass());
2206 } 2183 }
2207 2184
2208 void LayerTreeHostImpl::CleanUpTileManager() { 2185 void LayerTreeHostImpl::CleanUpTileManager() {
2209 tile_manager_->FinishTasksAndCleanUp(); 2186 tile_manager_->FinishTasksAndCleanUp();
2210 resource_pool_ = nullptr; 2187 resource_pool_ = nullptr;
2211 staging_resource_pool_ = nullptr;
2212 tile_task_worker_pool_ = nullptr; 2188 tile_task_worker_pool_ = nullptr;
2213 single_thread_synchronous_task_graph_runner_ = nullptr; 2189 single_thread_synchronous_task_graph_runner_ = nullptr;
2214 } 2190 }
2215 2191
2216 bool LayerTreeHostImpl::InitializeRenderer( 2192 bool LayerTreeHostImpl::InitializeRenderer(
2217 scoped_ptr<OutputSurface> output_surface) { 2193 scoped_ptr<OutputSurface> output_surface) {
2218 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); 2194 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer");
2219 2195
2220 // Since we will create a new resource provider, we cannot continue to use 2196 // Since we will create a new resource provider, we cannot continue to use
2221 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2197 // the old resources (i.e. render_surfaces and texture IDs). Clear them
(...skipping 12 matching lines...) Expand all
2234 // point). 2210 // point).
2235 return false; 2211 return false;
2236 } 2212 }
2237 2213
2238 output_surface_ = output_surface.Pass(); 2214 output_surface_ = output_surface.Pass();
2239 resource_provider_ = ResourceProvider::Create( 2215 resource_provider_ = ResourceProvider::Create(
2240 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, 2216 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_,
2241 proxy_->blocking_main_thread_task_runner(), 2217 proxy_->blocking_main_thread_task_runner(),
2242 settings_.renderer_settings.highp_threshold_min, 2218 settings_.renderer_settings.highp_threshold_min,
2243 settings_.renderer_settings.use_rgba_4444_textures, 2219 settings_.renderer_settings.use_rgba_4444_textures,
2244 settings_.renderer_settings.texture_id_allocation_chunk_size, 2220 settings_.renderer_settings.texture_id_allocation_chunk_size);
2245 settings_.use_persistent_map_for_gpu_memory_buffers);
2246 2221
2247 CreateAndSetRenderer(); 2222 CreateAndSetRenderer();
2248 2223
2249 // Since the new renderer may be capable of MSAA, update status here. 2224 // Since the new renderer may be capable of MSAA, update status here.
2250 UpdateGpuRasterizationStatus(); 2225 UpdateGpuRasterizationStatus();
2251 2226
2252 CreateTileManagerResources(); 2227 CreateTileManagerResources();
2253 RecreateTreeResources(); 2228 RecreateTreeResources();
2254 2229
2255 // Initialize vsync parameters to sane values. 2230 // Initialize vsync parameters to sane values.
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 if (active_tree()) { 3582 if (active_tree()) {
3608 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); 3583 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id);
3609 if (layer) 3584 if (layer)
3610 return layer->ScrollOffsetForAnimation(); 3585 return layer->ScrollOffsetForAnimation();
3611 } 3586 }
3612 3587
3613 return gfx::ScrollOffset(); 3588 return gfx::ScrollOffset();
3614 } 3589 }
3615 3590
3616 } // namespace cc 3591 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698