| 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 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 if (pending_tree_) | 1996 if (pending_tree_) |
| 1997 pending_tree_->set_needs_update_draw_properties(); | 1997 pending_tree_->set_needs_update_draw_properties(); |
| 1998 client_->UpdateRendererCapabilitiesOnImplThread(); | 1998 client_->UpdateRendererCapabilitiesOnImplThread(); |
| 1999 } | 1999 } |
| 2000 | 2000 |
| 2001 void LayerTreeHostImpl::CreateAndSetTileManager() { | 2001 void LayerTreeHostImpl::CreateAndSetTileManager() { |
| 2002 DCHECK(!tile_manager_); | 2002 DCHECK(!tile_manager_); |
| 2003 DCHECK(settings_.impl_side_painting); | 2003 DCHECK(settings_.impl_side_painting); |
| 2004 DCHECK(output_surface_); | 2004 DCHECK(output_surface_); |
| 2005 DCHECK(resource_provider_); | 2005 DCHECK(resource_provider_); |
| 2006 |
| 2007 CreateResourceAndRasterWorkerPool( |
| 2008 &raster_worker_pool_, &resource_pool_, &staging_resource_pool_); |
| 2009 DCHECK(raster_worker_pool_); |
| 2010 DCHECK(resource_pool_); |
| 2011 |
| 2012 base::SingleThreadTaskRunner* task_runner = |
| 2013 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 2014 : proxy_->MainThreadTaskRunner(); |
| 2015 DCHECK(task_runner); |
| 2016 size_t scheduled_raster_task_limit = |
| 2017 IsSynchronousSingleThreaded() ? std::numeric_limits<size_t>::max() |
| 2018 : settings_.scheduled_raster_task_limit; |
| 2019 tile_manager_ = TileManager::Create(this, |
| 2020 task_runner, |
| 2021 resource_pool_.get(), |
| 2022 raster_worker_pool_->AsRasterizer(), |
| 2023 rendering_stats_instrumentation_, |
| 2024 scheduled_raster_task_limit); |
| 2025 |
| 2026 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
| 2027 need_to_update_visible_tiles_before_draw_ = false; |
| 2028 } |
| 2029 |
| 2030 void LayerTreeHostImpl::CreateResourceAndRasterWorkerPool( |
| 2031 scoped_ptr<RasterWorkerPool>* raster_worker_pool, |
| 2032 scoped_ptr<ResourcePool>* resource_pool, |
| 2033 scoped_ptr<ResourcePool>* staging_resource_pool) { |
| 2006 base::SingleThreadTaskRunner* task_runner = | 2034 base::SingleThreadTaskRunner* task_runner = |
| 2007 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 2035 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 2008 : proxy_->MainThreadTaskRunner(); | 2036 : proxy_->MainThreadTaskRunner(); |
| 2009 DCHECK(task_runner); | 2037 DCHECK(task_runner); |
| 2010 | 2038 |
| 2011 ContextProvider* context_provider = output_surface_->context_provider(); | 2039 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2012 bool is_synchronous_single_threaded = | |
| 2013 !proxy_->HasImplThread() && !settings_.single_thread_proxy_scheduler; | |
| 2014 bool should_use_zero_copy_rasterizer = | 2040 bool should_use_zero_copy_rasterizer = |
| 2015 settings_.use_zero_copy || is_synchronous_single_threaded; | 2041 settings_.use_zero_copy || IsSynchronousSingleThreaded(); |
| 2016 size_t scheduled_raster_task_limit = settings_.scheduled_raster_task_limit; | |
| 2017 | 2042 |
| 2018 if (!context_provider) { | 2043 if (!context_provider) { |
| 2019 resource_pool_ = | 2044 *resource_pool = |
| 2020 ResourcePool::Create(resource_provider_.get(), | 2045 ResourcePool::Create(resource_provider_.get(), |
| 2021 GL_TEXTURE_2D, | 2046 GL_TEXTURE_2D, |
| 2022 resource_provider_->best_texture_format()); | 2047 resource_provider_->best_texture_format()); |
| 2023 | 2048 |
| 2024 raster_worker_pool_ = | 2049 *raster_worker_pool = |
| 2025 BitmapRasterWorkerPool::Create(task_runner, | 2050 BitmapRasterWorkerPool::Create(task_runner, |
| 2026 RasterWorkerPool::GetTaskGraphRunner(), | 2051 RasterWorkerPool::GetTaskGraphRunner(), |
| 2027 resource_provider_.get()); | 2052 resource_provider_.get()); |
| 2028 } else if (use_gpu_rasterization_) { | 2053 } else if (use_gpu_rasterization_) { |
| 2029 resource_pool_ = | 2054 *resource_pool = |
| 2030 ResourcePool::Create(resource_provider_.get(), | 2055 ResourcePool::Create(resource_provider_.get(), |
| 2031 GL_TEXTURE_2D, | 2056 GL_TEXTURE_2D, |
| 2032 resource_provider_->best_texture_format()); | 2057 resource_provider_->best_texture_format()); |
| 2033 | 2058 |
| 2034 raster_worker_pool_ = | 2059 *raster_worker_pool = |
| 2035 GpuRasterWorkerPool::Create(task_runner, | 2060 GpuRasterWorkerPool::Create(task_runner, |
| 2036 context_provider, | 2061 context_provider, |
| 2037 resource_provider_.get(), | 2062 resource_provider_.get(), |
| 2038 settings_.use_distance_field_text); | 2063 settings_.use_distance_field_text); |
| 2039 } else if (should_use_zero_copy_rasterizer && CanUseZeroCopyRasterizer()) { | 2064 } else if (should_use_zero_copy_rasterizer && CanUseZeroCopyRasterizer()) { |
| 2040 resource_pool_ = ResourcePool::Create( | 2065 *resource_pool = ResourcePool::Create( |
| 2041 resource_provider_.get(), | 2066 resource_provider_.get(), |
| 2042 GetMapImageTextureTarget(context_provider->ContextCapabilities()), | 2067 GetMapImageTextureTarget(context_provider->ContextCapabilities()), |
| 2043 resource_provider_->best_texture_format()); | 2068 resource_provider_->best_texture_format()); |
| 2044 | 2069 |
| 2045 TaskGraphRunner* task_graph_runner; | 2070 TaskGraphRunner* task_graph_runner; |
| 2046 if (is_synchronous_single_threaded) { | 2071 if (IsSynchronousSingleThreaded()) { |
| 2047 DCHECK(!single_thread_synchronous_task_graph_runner_); | 2072 DCHECK(!single_thread_synchronous_task_graph_runner_); |
| 2048 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); | 2073 single_thread_synchronous_task_graph_runner_.reset(new TaskGraphRunner); |
| 2049 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); | 2074 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); |
| 2050 scheduled_raster_task_limit = std::numeric_limits<size_t>::max(); | |
| 2051 } else { | 2075 } else { |
| 2052 task_graph_runner = RasterWorkerPool::GetTaskGraphRunner(); | 2076 task_graph_runner = RasterWorkerPool::GetTaskGraphRunner(); |
| 2053 } | 2077 } |
| 2054 | 2078 |
| 2055 raster_worker_pool_ = ZeroCopyRasterWorkerPool::Create( | 2079 *raster_worker_pool = ZeroCopyRasterWorkerPool::Create( |
| 2056 task_runner, task_graph_runner, resource_provider_.get()); | 2080 task_runner, task_graph_runner, resource_provider_.get()); |
| 2057 } else if (UseOneCopyRasterizer()) { | 2081 } else if (settings_.use_one_copy && CanUseOneCopyRasterizer()) { |
| 2058 // We need to create a staging resource pool when using copy rasterizer. | 2082 // We need to create a staging resource pool when using copy rasterizer. |
| 2059 staging_resource_pool_ = ResourcePool::Create( | 2083 *staging_resource_pool = ResourcePool::Create( |
| 2060 resource_provider_.get(), | 2084 resource_provider_.get(), |
| 2061 GetMapImageTextureTarget(context_provider->ContextCapabilities()), | 2085 GetMapImageTextureTarget(context_provider->ContextCapabilities()), |
| 2062 resource_provider_->best_texture_format()); | 2086 resource_provider_->best_texture_format()); |
| 2063 resource_pool_ = | 2087 *resource_pool = |
| 2064 ResourcePool::Create(resource_provider_.get(), | 2088 ResourcePool::Create(resource_provider_.get(), |
| 2065 GL_TEXTURE_2D, | 2089 GL_TEXTURE_2D, |
| 2066 resource_provider_->best_texture_format()); | 2090 resource_provider_->best_texture_format()); |
| 2067 | 2091 |
| 2068 raster_worker_pool_ = | 2092 *raster_worker_pool = |
| 2069 OneCopyRasterWorkerPool::Create(task_runner, | 2093 OneCopyRasterWorkerPool::Create(task_runner, |
| 2070 RasterWorkerPool::GetTaskGraphRunner(), | 2094 RasterWorkerPool::GetTaskGraphRunner(), |
| 2071 context_provider, | 2095 context_provider, |
| 2072 resource_provider_.get(), | 2096 resource_provider_.get(), |
| 2073 staging_resource_pool_.get()); | 2097 staging_resource_pool_.get()); |
| 2074 } else { | 2098 } else { |
| 2075 resource_pool_ = ResourcePool::Create( | 2099 *resource_pool = ResourcePool::Create( |
| 2076 resource_provider_.get(), | 2100 resource_provider_.get(), |
| 2077 GL_TEXTURE_2D, | 2101 GL_TEXTURE_2D, |
| 2078 resource_provider_->memory_efficient_texture_format()); | 2102 resource_provider_->memory_efficient_texture_format()); |
| 2079 | 2103 |
| 2080 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 2104 *raster_worker_pool = PixelBufferRasterWorkerPool::Create( |
| 2081 task_runner, | 2105 task_runner, |
| 2082 RasterWorkerPool::GetTaskGraphRunner(), | 2106 RasterWorkerPool::GetTaskGraphRunner(), |
| 2083 context_provider, | 2107 context_provider, |
| 2084 resource_provider_.get(), | 2108 resource_provider_.get(), |
| 2085 GetMaxTransferBufferUsageBytes(context_provider->ContextCapabilities(), | 2109 GetMaxTransferBufferUsageBytes(context_provider->ContextCapabilities(), |
| 2086 settings_.refresh_rate)); | 2110 settings_.refresh_rate)); |
| 2087 } | 2111 } |
| 2088 | |
| 2089 tile_manager_ = TileManager::Create(this, | |
| 2090 task_runner, | |
| 2091 resource_pool_.get(), | |
| 2092 raster_worker_pool_->AsRasterizer(), | |
| 2093 rendering_stats_instrumentation_, | |
| 2094 scheduled_raster_task_limit); | |
| 2095 | |
| 2096 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | |
| 2097 need_to_update_visible_tiles_before_draw_ = false; | |
| 2098 } | 2112 } |
| 2099 | 2113 |
| 2100 void LayerTreeHostImpl::DestroyTileManager() { | 2114 void LayerTreeHostImpl::DestroyTileManager() { |
| 2101 tile_manager_ = nullptr; | 2115 tile_manager_ = nullptr; |
| 2102 resource_pool_ = nullptr; | 2116 resource_pool_ = nullptr; |
| 2103 staging_resource_pool_ = nullptr; | 2117 staging_resource_pool_ = nullptr; |
| 2104 raster_worker_pool_ = nullptr; | 2118 raster_worker_pool_ = nullptr; |
| 2105 single_thread_synchronous_task_graph_runner_ = nullptr; | 2119 single_thread_synchronous_task_graph_runner_ = nullptr; |
| 2106 } | 2120 } |
| 2107 | 2121 |
| 2108 bool LayerTreeHostImpl::UsePendingTreeForSync() const { | 2122 bool LayerTreeHostImpl::UsePendingTreeForSync() const { |
| 2109 // In impl-side painting, synchronize to the pending tree so that it has | 2123 // In impl-side painting, synchronize to the pending tree so that it has |
| 2110 // time to raster before being displayed. | 2124 // time to raster before being displayed. |
| 2111 return settings_.impl_side_painting; | 2125 return settings_.impl_side_painting; |
| 2112 } | 2126 } |
| 2113 | 2127 |
| 2128 bool LayerTreeHostImpl::IsSynchronousSingleThreaded() const { |
| 2129 return !proxy_->HasImplThread() && !settings_.single_thread_proxy_scheduler; |
| 2130 } |
| 2131 |
| 2114 bool LayerTreeHostImpl::CanUseZeroCopyRasterizer() const { | 2132 bool LayerTreeHostImpl::CanUseZeroCopyRasterizer() const { |
| 2115 return GetRendererCapabilities().using_image; | 2133 return GetRendererCapabilities().using_image; |
| 2116 } | 2134 } |
| 2117 | 2135 |
| 2118 bool LayerTreeHostImpl::UseOneCopyRasterizer() const { | 2136 bool LayerTreeHostImpl::CanUseOneCopyRasterizer() const { |
| 2119 return settings_.use_one_copy && GetRendererCapabilities().using_image; | 2137 // Sync query support is required by one-copy rasterizer. |
| 2138 return GetRendererCapabilities().using_image && |
| 2139 resource_provider_->use_sync_query(); |
| 2120 } | 2140 } |
| 2121 | 2141 |
| 2122 void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) { | 2142 void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) { |
| 2123 SetManagedMemoryPolicy(cached_managed_memory_policy_, zero_budget); | 2143 SetManagedMemoryPolicy(cached_managed_memory_policy_, zero_budget); |
| 2124 } | 2144 } |
| 2125 | 2145 |
| 2126 bool LayerTreeHostImpl::InitializeRenderer( | 2146 bool LayerTreeHostImpl::InitializeRenderer( |
| 2127 scoped_ptr<OutputSurface> output_surface) { | 2147 scoped_ptr<OutputSurface> output_surface) { |
| 2128 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2148 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
| 2129 | 2149 |
| (...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3494 } | 3514 } |
| 3495 | 3515 |
| 3496 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3516 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 3497 std::vector<PictureLayerImpl*>::iterator it = | 3517 std::vector<PictureLayerImpl*>::iterator it = |
| 3498 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3518 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 3499 DCHECK(it != picture_layers_.end()); | 3519 DCHECK(it != picture_layers_.end()); |
| 3500 picture_layers_.erase(it); | 3520 picture_layers_.erase(it); |
| 3501 } | 3521 } |
| 3502 | 3522 |
| 3503 } // namespace cc | 3523 } // namespace cc |
| OLD | NEW |