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

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

Issue 1336703002: Revert of Re-land: cc: Use worker context for one-copy tile initialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_pixeltest_tiles.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
156 size_t GetDefaultMemoryAllocationLimit() { 161 size_t GetDefaultMemoryAllocationLimit() {
157 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler 162 // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler
158 // from the old texture manager and is just to give us a default memory 163 // from the old texture manager and is just to give us a default memory
159 // allocation before we get a callback from the GPU memory manager. We 164 // allocation before we get a callback from the GPU memory manager. We
160 // should probaby either: 165 // should probaby either:
161 // - wait for the callback before rendering anything instead 166 // - wait for the callback before rendering anything instead
162 // - push this into the GPU memory manager somehow. 167 // - push this into the GPU memory manager somehow.
163 return 64 * 1024 * 1024; 168 return 64 * 1024 * 1024;
164 } 169 }
165 170
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // TODO(reveman): We should avoid keeping around unused resources if 1229 // TODO(reveman): We should avoid keeping around unused resources if
1225 // possible. crbug.com/224475 1230 // possible. crbug.com/224475
1226 // Unused limit is calculated from soft-limit, as hard-limit may 1231 // Unused limit is calculated from soft-limit, as hard-limit may
1227 // be very high and shouldn't typically be exceeded. 1232 // be very high and shouldn't typically be exceeded.
1228 size_t unused_memory_limit_in_bytes = static_cast<size_t>( 1233 size_t unused_memory_limit_in_bytes = static_cast<size_t>(
1229 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) * 1234 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) *
1230 settings_.max_unused_resource_memory_percentage) / 1235 settings_.max_unused_resource_memory_percentage) /
1231 100); 1236 100);
1232 1237
1233 DCHECK(resource_pool_); 1238 DCHECK(resource_pool_);
1234 resource_pool_->CheckBusyResources(); 1239 resource_pool_->CheckBusyResources(false);
1235 // Soft limit is used for resource pool such that memory returns to soft 1240 // Soft limit is used for resource pool such that memory returns to soft
1236 // limit after going over. 1241 // limit after going over.
1237 resource_pool_->SetResourceUsageLimits( 1242 resource_pool_->SetResourceUsageLimits(
1238 global_tile_state_.soft_memory_limit_in_bytes, 1243 global_tile_state_.soft_memory_limit_in_bytes,
1239 unused_memory_limit_in_bytes, 1244 unused_memory_limit_in_bytes,
1240 global_tile_state_.num_resources_limit); 1245 global_tile_state_.num_resources_limit);
1241 1246
1247 // Release all staging resources when invisible.
1248 if (staging_resource_pool_) {
1249 staging_resource_pool_->CheckBusyResources(false);
1250 staging_resource_pool_->SetResourceUsageLimits(
1251 std::numeric_limits<size_t>::max(),
1252 std::numeric_limits<size_t>::max(),
1253 visible_ ? GetMaxStagingResourceCount() : 0);
1254 }
1255
1242 DidModifyTilePriorities(); 1256 DidModifyTilePriorities();
1243 } 1257 }
1244 1258
1245 void LayerTreeHostImpl::DidModifyTilePriorities() { 1259 void LayerTreeHostImpl::DidModifyTilePriorities() {
1246 // Mark priorities as dirty and schedule a PrepareTiles(). 1260 // Mark priorities as dirty and schedule a PrepareTiles().
1247 tile_priorities_dirty_ = true; 1261 tile_priorities_dirty_ = true;
1248 client_->SetNeedsPrepareTilesOnImplThread(); 1262 client_->SetNeedsPrepareTilesOnImplThread();
1249 } 1263 }
1250 1264
1251 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( 1265 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 1459
1446 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) { 1460 void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) {
1447 // TODO(piman): We may need to do some validation on this ack before 1461 // TODO(piman): We may need to do some validation on this ack before
1448 // processing it. 1462 // processing it.
1449 if (renderer_) 1463 if (renderer_)
1450 renderer_->ReceiveSwapBuffersAck(*ack); 1464 renderer_->ReceiveSwapBuffersAck(*ack);
1451 1465
1452 // In OOM, we now might be able to release more resources that were held 1466 // In OOM, we now might be able to release more resources that were held
1453 // because they were exported. 1467 // because they were exported.
1454 if (resource_pool_) { 1468 if (resource_pool_) {
1455 resource_pool_->CheckBusyResources(); 1469 resource_pool_->CheckBusyResources(false);
1456 resource_pool_->ReduceResourceUsage(); 1470 resource_pool_->ReduceResourceUsage();
1457 } 1471 }
1458 // If we're not visible, we likely released resources, so we want to 1472 // If we're not visible, we likely released resources, so we want to
1459 // aggressively flush here to make sure those DeleteTextures make it to the 1473 // aggressively flush here to make sure those DeleteTextures make it to the
1460 // GPU process to free up the memory. 1474 // GPU process to free up the memory.
1461 if (output_surface_->context_provider() && !visible_) { 1475 if (output_surface_->context_provider() && !visible_) {
1462 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); 1476 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1463 } 1477 }
1464 } 1478 }
1465 1479
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be 2070 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be
2057 // initialized to get max texture size. Also, after releasing resources, 2071 // initialized to get max texture size. Also, after releasing resources,
2058 // trees need another update to generate new ones. 2072 // trees need another update to generate new ones.
2059 active_tree_->set_needs_update_draw_properties(); 2073 active_tree_->set_needs_update_draw_properties();
2060 if (pending_tree_) 2074 if (pending_tree_)
2061 pending_tree_->set_needs_update_draw_properties(); 2075 pending_tree_->set_needs_update_draw_properties();
2062 client_->UpdateRendererCapabilitiesOnImplThread(); 2076 client_->UpdateRendererCapabilitiesOnImplThread();
2063 } 2077 }
2064 2078
2065 void LayerTreeHostImpl::CreateTileManagerResources() { 2079 void LayerTreeHostImpl::CreateTileManagerResources() {
2066 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_); 2080 CreateResourceAndTileTaskWorkerPool(&tile_task_worker_pool_, &resource_pool_,
2081 &staging_resource_pool_);
2067 // TODO(vmpstr): Initialize tile task limit at ctor time. 2082 // TODO(vmpstr): Initialize tile task limit at ctor time.
2068 tile_manager_->SetResources( 2083 tile_manager_->SetResources(
2069 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(), 2084 resource_pool_.get(), tile_task_worker_pool_->AsTileTaskRunner(),
2070 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() 2085 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max()
2071 : settings_.scheduled_raster_task_limit); 2086 : settings_.scheduled_raster_task_limit);
2072 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); 2087 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
2073 } 2088 }
2074 2089
2075 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( 2090 void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool(
2076 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool, 2091 scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
2077 scoped_ptr<ResourcePool>* resource_pool) { 2092 scoped_ptr<ResourcePool>* resource_pool,
2093 scoped_ptr<ResourcePool>* staging_resource_pool) {
2078 DCHECK(GetTaskRunner()); 2094 DCHECK(GetTaskRunner());
2079 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is 2095 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is
2080 // resolved. 2096 // resolved.
2081 CHECK(resource_provider_); 2097 CHECK(resource_provider_);
2082 2098
2083 // Pass the single-threaded synchronous task graph runner to the worker pool 2099 // Pass the single-threaded synchronous task graph runner to the worker pool
2084 // if we're in synchronous single-threaded mode. 2100 // if we're in synchronous single-threaded mode.
2085 TaskGraphRunner* task_graph_runner = task_graph_runner_; 2101 TaskGraphRunner* task_graph_runner = task_graph_runner_;
2086 if (is_synchronous_single_threaded_) { 2102 if (is_synchronous_single_threaded_) {
2087 DCHECK(!single_thread_synchronous_task_graph_runner_); 2103 DCHECK(!single_thread_synchronous_task_graph_runner_);
2088 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); 2104 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner);
2089 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); 2105 task_graph_runner = single_thread_synchronous_task_graph_runner_.get();
2090 } 2106 }
2091 2107
2092 ContextProvider* context_provider = output_surface_->context_provider(); 2108 ContextProvider* context_provider = output_surface_->context_provider();
2093 if (!context_provider) { 2109 if (!context_provider) {
2094 *resource_pool = 2110 *resource_pool =
2095 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); 2111 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
2096 2112
2097 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create( 2113 *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
2098 GetTaskRunner(), task_graph_runner, resource_provider_.get()); 2114 GetTaskRunner(), task_graph_runner, resource_provider_.get());
2099 return; 2115 return;
2100 } 2116 }
2101 2117
2102 if (use_gpu_rasterization_) { 2118 if (use_gpu_rasterization_) {
2103 DCHECK(resource_provider_->output_surface()->worker_context_provider());
2104
2105 *resource_pool = 2119 *resource_pool =
2106 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); 2120 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
2107 2121
2108 int msaa_sample_count = use_msaa_ ? RequestedMSAASampleCount() : 0; 2122 int msaa_sample_count = use_msaa_ ? RequestedMSAASampleCount() : 0;
2109 2123
2110 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create( 2124 *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
2111 GetTaskRunner(), task_graph_runner, context_provider, 2125 GetTaskRunner(), task_graph_runner, context_provider,
2112 resource_provider_.get(), settings_.use_distance_field_text, 2126 resource_provider_.get(), settings_.use_distance_field_text,
2113 msaa_sample_count); 2127 msaa_sample_count);
2114 return; 2128 return;
2115 } 2129 }
2116 2130
2117 DCHECK(GetRendererCapabilities().using_image); 2131 DCHECK(GetRendererCapabilities().using_image);
2118 2132
2119 bool use_zero_copy = settings_.use_zero_copy; 2133 if (settings_.use_zero_copy) {
2120 // TODO(reveman): Remove this when mojo supports worker contexts.
2121 // crbug.com/522440
2122 if (!resource_provider_->output_surface()->worker_context_provider()) {
2123 LOG(ERROR)
2124 << "Forcing zero-copy tile initialization as worker context is missing";
2125 use_zero_copy = true;
2126 }
2127
2128 if (use_zero_copy) {
2129 *resource_pool = ResourcePool::Create(resource_provider_.get()); 2134 *resource_pool = ResourcePool::Create(resource_provider_.get());
2130 2135
2131 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( 2136 *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
2132 GetTaskRunner(), task_graph_runner, resource_provider_.get()); 2137 GetTaskRunner(), task_graph_runner, resource_provider_.get());
2133 return; 2138 return;
2134 } 2139 }
2135 2140
2136 if (settings_.use_one_copy) { 2141 if (settings_.use_one_copy) {
2142 // Synchronous single-threaded mode depends on tiles being ready to
2143 // draw when raster is complete. Therefore, it must use one of zero
2144 // copy, software raster, or GPU raster.
2145 DCHECK(!is_synchronous_single_threaded_);
2146
2147 // We need to create a staging resource pool when using copy rasterizer.
2148 *staging_resource_pool = ResourcePool::Create(resource_provider_.get());
2137 *resource_pool = 2149 *resource_pool =
2138 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D); 2150 ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
2139 2151
2140 int max_copy_texture_chromium_size = 2152 int max_copy_texture_chromium_size =
2141 context_provider->ContextCapabilities() 2153 context_provider->ContextCapabilities()
2142 .gpu.max_copy_texture_chromium_size; 2154 .gpu.max_copy_texture_chromium_size;
2143 2155
2144 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( 2156 *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
2145 GetTaskRunner(), task_graph_runner, context_provider, 2157 GetTaskRunner(), task_graph_runner, context_provider,
2146 resource_provider_.get(), max_copy_texture_chromium_size, 2158 resource_provider_.get(), staging_resource_pool_.get(),
2147 settings_.use_persistent_map_for_gpu_memory_buffers, 2159 max_copy_texture_chromium_size,
2148 settings_.max_staging_buffers); 2160 settings_.use_persistent_map_for_gpu_memory_buffers);
2149 return; 2161 return;
2150 } 2162 }
2151 2163
2152 // Synchronous single-threaded mode depends on tiles being ready to 2164 // Synchronous single-threaded mode depends on tiles being ready to
2153 // draw when raster is complete. Therefore, it must use one of zero 2165 // draw when raster is complete. Therefore, it must use one of zero
2154 // copy, software raster, or GPU raster (in the branches above). 2166 // copy, software raster, or GPU raster (in the branches above).
2155 DCHECK(!is_synchronous_single_threaded_); 2167 DCHECK(!is_synchronous_single_threaded_);
2156 2168
2157 *resource_pool = ResourcePool::Create( 2169 *resource_pool = ResourcePool::Create(
2158 resource_provider_.get(), GL_TEXTURE_2D); 2170 resource_provider_.get(), GL_TEXTURE_2D);
(...skipping 22 matching lines...) Expand all
2181 void LayerTreeHostImpl::PostFrameTimingEvents( 2193 void LayerTreeHostImpl::PostFrameTimingEvents(
2182 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, 2194 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
2183 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) { 2195 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
2184 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(), 2196 client_->PostFrameTimingEventsOnImplThread(composite_events.Pass(),
2185 main_frame_events.Pass()); 2197 main_frame_events.Pass());
2186 } 2198 }
2187 2199
2188 void LayerTreeHostImpl::CleanUpTileManager() { 2200 void LayerTreeHostImpl::CleanUpTileManager() {
2189 tile_manager_->FinishTasksAndCleanUp(); 2201 tile_manager_->FinishTasksAndCleanUp();
2190 resource_pool_ = nullptr; 2202 resource_pool_ = nullptr;
2203 staging_resource_pool_ = nullptr;
2191 tile_task_worker_pool_ = nullptr; 2204 tile_task_worker_pool_ = nullptr;
2192 single_thread_synchronous_task_graph_runner_ = nullptr; 2205 single_thread_synchronous_task_graph_runner_ = nullptr;
2193 } 2206 }
2194 2207
2195 bool LayerTreeHostImpl::InitializeRenderer( 2208 bool LayerTreeHostImpl::InitializeRenderer(
2196 scoped_ptr<OutputSurface> output_surface) { 2209 scoped_ptr<OutputSurface> output_surface) {
2197 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); 2210 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer");
2198 2211
2199 // Since we will create a new resource provider, we cannot continue to use 2212 // Since we will create a new resource provider, we cannot continue to use
2200 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2213 // the old resources (i.e. render_surfaces and texture IDs). Clear them
(...skipping 13 matching lines...) Expand all
2214 return false; 2227 return false;
2215 } 2228 }
2216 2229
2217 output_surface_ = output_surface.Pass(); 2230 output_surface_ = output_surface.Pass();
2218 resource_provider_ = ResourceProvider::Create( 2231 resource_provider_ = ResourceProvider::Create(
2219 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, 2232 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_,
2220 proxy_->blocking_main_thread_task_runner(), 2233 proxy_->blocking_main_thread_task_runner(),
2221 settings_.renderer_settings.highp_threshold_min, 2234 settings_.renderer_settings.highp_threshold_min,
2222 settings_.renderer_settings.use_rgba_4444_textures, 2235 settings_.renderer_settings.use_rgba_4444_textures,
2223 settings_.renderer_settings.texture_id_allocation_chunk_size, 2236 settings_.renderer_settings.texture_id_allocation_chunk_size,
2237 settings_.use_persistent_map_for_gpu_memory_buffers,
2224 settings_.use_image_texture_targets); 2238 settings_.use_image_texture_targets);
2225 2239
2226 CreateAndSetRenderer(); 2240 CreateAndSetRenderer();
2227 2241
2228 // Since the new renderer may be capable of MSAA, update status here. 2242 // Since the new renderer may be capable of MSAA, update status here.
2229 UpdateGpuRasterizationStatus(); 2243 UpdateGpuRasterizationStatus();
2230 2244
2231 CreateTileManagerResources(); 2245 CreateTileManagerResources();
2232 RecreateTreeResources(); 2246 RecreateTreeResources();
2233 2247
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 if (active_tree()) { 3645 if (active_tree()) {
3632 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); 3646 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id);
3633 if (layer) 3647 if (layer)
3634 return layer->ScrollOffsetForAnimation(); 3648 return layer->ScrollOffsetForAnimation();
3635 } 3649 }
3636 3650
3637 return gfx::ScrollOffset(); 3651 return gfx::ScrollOffset();
3638 } 3652 }
3639 3653
3640 } // namespace cc 3654 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_pixeltest_tiles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698