Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include "cc/output/compositor_frame_metadata.h" | 37 #include "cc/output/compositor_frame_metadata.h" |
| 38 #include "cc/output/copy_output_request.h" | 38 #include "cc/output/copy_output_request.h" |
| 39 #include "cc/output/delegating_renderer.h" | 39 #include "cc/output/delegating_renderer.h" |
| 40 #include "cc/output/gl_renderer.h" | 40 #include "cc/output/gl_renderer.h" |
| 41 #include "cc/output/software_renderer.h" | 41 #include "cc/output/software_renderer.h" |
| 42 #include "cc/quads/render_pass_draw_quad.h" | 42 #include "cc/quads/render_pass_draw_quad.h" |
| 43 #include "cc/quads/shared_quad_state.h" | 43 #include "cc/quads/shared_quad_state.h" |
| 44 #include "cc/quads/solid_color_draw_quad.h" | 44 #include "cc/quads/solid_color_draw_quad.h" |
| 45 #include "cc/quads/texture_draw_quad.h" | 45 #include "cc/quads/texture_draw_quad.h" |
| 46 #include "cc/resources/direct_raster_worker_pool.h" | 46 #include "cc/resources/direct_raster_worker_pool.h" |
| 47 #include "cc/resources/image_copy_raster_worker_pool.h" | |
| 47 #include "cc/resources/image_raster_worker_pool.h" | 48 #include "cc/resources/image_raster_worker_pool.h" |
| 48 #include "cc/resources/memory_history.h" | 49 #include "cc/resources/memory_history.h" |
| 49 #include "cc/resources/picture_layer_tiling.h" | 50 #include "cc/resources/picture_layer_tiling.h" |
| 50 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 51 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 51 #include "cc/resources/prioritized_resource_manager.h" | 52 #include "cc/resources/prioritized_resource_manager.h" |
| 52 #include "cc/resources/raster_worker_pool.h" | 53 #include "cc/resources/raster_worker_pool.h" |
| 53 #include "cc/resources/resource_pool.h" | 54 #include "cc/resources/resource_pool.h" |
| 54 #include "cc/resources/texture_mailbox_deleter.h" | 55 #include "cc/resources/texture_mailbox_deleter.h" |
| 55 #include "cc/resources/ui_resource_bitmap.h" | 56 #include "cc/resources/ui_resource_bitmap.h" |
| 56 #include "cc/scheduler/delay_based_time_source.h" | 57 #include "cc/scheduler/delay_based_time_source.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return GL_TEXTURE_2D; | 116 return GL_TEXTURE_2D; |
| 116 | 117 |
| 117 if (context_provider->ContextCapabilities().gpu.egl_image_external) | 118 if (context_provider->ContextCapabilities().gpu.egl_image_external) |
| 118 return GL_TEXTURE_EXTERNAL_OES; | 119 return GL_TEXTURE_EXTERNAL_OES; |
| 119 if (context_provider->ContextCapabilities().gpu.texture_rectangle) | 120 if (context_provider->ContextCapabilities().gpu.texture_rectangle) |
| 120 return GL_TEXTURE_RECTANGLE_ARB; | 121 return GL_TEXTURE_RECTANGLE_ARB; |
| 121 | 122 |
| 122 return GL_TEXTURE_2D; | 123 return GL_TEXTURE_2D; |
| 123 } | 124 } |
| 124 | 125 |
| 126 unsigned GetCopyImageTextureTarget(cc::ContextProvider* context_provider) { | |
| 127 if (!context_provider) | |
| 128 return GL_TEXTURE_2D; | |
| 129 | |
| 130 if (context_provider->ContextCapabilities().gpu.egl_image_external) | |
| 131 return GL_TEXTURE_EXTERNAL_OES; | |
| 132 | |
| 133 return GL_TEXTURE_2D; | |
| 134 } | |
| 135 | |
| 125 } // namespace | 136 } // namespace |
| 126 | 137 |
| 127 namespace cc { | 138 namespace cc { |
| 128 | 139 |
| 129 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | 140 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { |
| 130 public: | 141 public: |
| 131 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( | 142 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( |
| 132 LayerTreeHostImpl* layer_tree_host_impl, | 143 LayerTreeHostImpl* layer_tree_host_impl, |
| 133 scoped_refptr<DelayBasedTimeSource> time_source) { | 144 scoped_refptr<DelayBasedTimeSource> time_source) { |
| 134 return make_scoped_ptr( | 145 return make_scoped_ptr( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 if (pending_tree_) | 314 if (pending_tree_) |
| 304 pending_tree_->Shutdown(); | 315 pending_tree_->Shutdown(); |
| 305 active_tree_->Shutdown(); | 316 active_tree_->Shutdown(); |
| 306 recycle_tree_.reset(); | 317 recycle_tree_.reset(); |
| 307 pending_tree_.reset(); | 318 pending_tree_.reset(); |
| 308 active_tree_.reset(); | 319 active_tree_.reset(); |
| 309 tile_manager_.reset(); | 320 tile_manager_.reset(); |
| 310 resource_pool_.reset(); | 321 resource_pool_.reset(); |
| 311 raster_worker_pool_.reset(); | 322 raster_worker_pool_.reset(); |
| 312 direct_raster_worker_pool_.reset(); | 323 direct_raster_worker_pool_.reset(); |
| 324 staging_resource_pool_.reset(); | |
| 313 } | 325 } |
| 314 | 326 |
| 315 void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) { | 327 void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) { |
| 316 // If the begin frame data was handled, then scroll and scale set was applied | 328 // If the begin frame data was handled, then scroll and scale set was applied |
| 317 // by the main thread, so the active tree needs to be updated as if these sent | 329 // by the main thread, so the active tree needs to be updated as if these sent |
| 318 // values were applied and committed. | 330 // values were applied and committed. |
| 319 if (did_handle) { | 331 if (did_handle) { |
| 320 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 332 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
| 321 active_tree_->ResetContentsTexturesPurged(); | 333 active_tree_->ResetContentsTexturesPurged(); |
| 322 } | 334 } |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1193 | 1205 |
| 1194 DCHECK(resource_pool_); | 1206 DCHECK(resource_pool_); |
| 1195 resource_pool_->CheckBusyResources(); | 1207 resource_pool_->CheckBusyResources(); |
| 1196 // Soft limit is used for resource pool such that memory returns to soft | 1208 // Soft limit is used for resource pool such that memory returns to soft |
| 1197 // limit after going over. | 1209 // limit after going over. |
| 1198 resource_pool_->SetResourceUsageLimits( | 1210 resource_pool_->SetResourceUsageLimits( |
| 1199 global_tile_state_.soft_memory_limit_in_bytes, | 1211 global_tile_state_.soft_memory_limit_in_bytes, |
| 1200 global_tile_state_.unused_memory_limit_in_bytes, | 1212 global_tile_state_.unused_memory_limit_in_bytes, |
| 1201 global_tile_state_.num_resources_limit); | 1213 global_tile_state_.num_resources_limit); |
| 1202 | 1214 |
| 1215 // We currently use hard-coded limits for staging pool limits. | |
|
vmpstr
2014/04/25 19:05:41
nit: Is this comment still correct? We're using Ge
reveman
2014/04/25 20:18:25
Updated comment.
| |
| 1216 if (staging_resource_pool_) { | |
| 1217 size_t memory_limit_when_visible = GetMaxTransferBufferUsageBytes( | |
| 1218 output_surface_->context_provider().get()); | |
| 1219 staging_resource_pool_->CheckBusyResources(); | |
| 1220 staging_resource_pool_->SetResourceUsageLimits( | |
| 1221 visible_ ? memory_limit_when_visible : 0, | |
| 1222 memory_limit_when_visible, | |
| 1223 std::numeric_limits<size_t>::max()); | |
| 1224 } | |
| 1225 | |
| 1203 DidModifyTilePriorities(); | 1226 DidModifyTilePriorities(); |
| 1204 } | 1227 } |
| 1205 | 1228 |
| 1206 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1229 void LayerTreeHostImpl::DidModifyTilePriorities() { |
| 1207 DCHECK(settings_.impl_side_painting); | 1230 DCHECK(settings_.impl_side_painting); |
| 1208 // Mark priorities as dirty and schedule a ManageTiles(). | 1231 // Mark priorities as dirty and schedule a ManageTiles(). |
| 1209 tile_priorities_dirty_ = true; | 1232 tile_priorities_dirty_ = true; |
| 1210 client_->SetNeedsManageTilesOnImplThread(); | 1233 client_->SetNeedsManageTilesOnImplThread(); |
| 1211 } | 1234 } |
| 1212 | 1235 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1799 if (pending_tree_) | 1822 if (pending_tree_) |
| 1800 pending_tree_->set_needs_update_draw_properties(); | 1823 pending_tree_->set_needs_update_draw_properties(); |
| 1801 client_->UpdateRendererCapabilitiesOnImplThread(); | 1824 client_->UpdateRendererCapabilitiesOnImplThread(); |
| 1802 } | 1825 } |
| 1803 } | 1826 } |
| 1804 | 1827 |
| 1805 void LayerTreeHostImpl::CreateAndSetTileManager( | 1828 void LayerTreeHostImpl::CreateAndSetTileManager( |
| 1806 ResourceProvider* resource_provider, | 1829 ResourceProvider* resource_provider, |
| 1807 ContextProvider* context_provider, | 1830 ContextProvider* context_provider, |
| 1808 bool using_map_image, | 1831 bool using_map_image, |
| 1832 bool use_zero_copy, | |
| 1809 bool allow_rasterize_on_demand) { | 1833 bool allow_rasterize_on_demand) { |
| 1810 DCHECK(settings_.impl_side_painting); | 1834 DCHECK(settings_.impl_side_painting); |
| 1811 DCHECK(resource_provider); | 1835 DCHECK(resource_provider); |
| 1812 DCHECK(proxy_->ImplThreadTaskRunner()); | 1836 DCHECK(proxy_->ImplThreadTaskRunner()); |
| 1813 | 1837 |
| 1814 if (using_map_image) { | 1838 if (using_map_image) { |
| 1815 raster_worker_pool_ = | 1839 // We need to create a staging resource pool unless we're using |
| 1816 ImageRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(), | 1840 // ImageRasterWorkerPool that implements zero-copy. |
| 1817 RasterWorkerPool::GetTaskGraphRunner(), | 1841 if (use_zero_copy || !resource_provider_->use_sync_query()) { |
| 1818 resource_provider); | 1842 resource_pool_ = |
| 1819 resource_pool_ = | 1843 ResourcePool::Create(resource_provider, |
| 1820 ResourcePool::Create(resource_provider, | 1844 GetMapImageTextureTarget(context_provider), |
| 1821 GetMapImageTextureTarget(context_provider), | 1845 resource_provider->best_texture_format()); |
| 1822 resource_provider->best_texture_format()); | 1846 raster_worker_pool_ = |
| 1847 ImageRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(), | |
| 1848 RasterWorkerPool::GetTaskGraphRunner(), | |
| 1849 resource_provider); | |
| 1850 } else { | |
| 1851 // TODO(reveman): Use GetMapImageTextureTarget instead of | |
| 1852 // GetCopyImageTextureTarget when GL_TEXTURE_RECTANGLE_ARB support has | |
| 1853 // been added to CHROMIUM_copy_texture. | |
| 1854 staging_resource_pool_ = | |
| 1855 ResourcePool::Create(resource_provider, | |
| 1856 GetCopyImageTextureTarget(context_provider), | |
| 1857 resource_provider->best_texture_format()); | |
| 1858 resource_pool_ = | |
| 1859 ResourcePool::Create(resource_provider, | |
| 1860 GL_TEXTURE_2D, | |
| 1861 resource_provider->best_texture_format()); | |
| 1862 | |
| 1863 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create( | |
| 1864 proxy_->ImplThreadTaskRunner(), | |
| 1865 RasterWorkerPool::GetTaskGraphRunner(), | |
| 1866 resource_provider, | |
| 1867 staging_resource_pool_.get()); | |
| 1868 } | |
| 1823 } else { | 1869 } else { |
| 1824 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 1870 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( |
| 1825 proxy_->ImplThreadTaskRunner(), | 1871 proxy_->ImplThreadTaskRunner(), |
| 1826 RasterWorkerPool::GetTaskGraphRunner(), | 1872 RasterWorkerPool::GetTaskGraphRunner(), |
| 1827 resource_provider, | 1873 resource_provider, |
| 1828 GetMaxTransferBufferUsageBytes(context_provider)); | 1874 GetMaxTransferBufferUsageBytes(context_provider)); |
| 1829 resource_pool_ = ResourcePool::Create( | 1875 resource_pool_ = ResourcePool::Create( |
| 1830 resource_provider, | 1876 resource_provider, |
| 1831 GL_TEXTURE_2D, | 1877 GL_TEXTURE_2D, |
| 1832 resource_provider->memory_efficient_texture_format()); | 1878 resource_provider->memory_efficient_texture_format()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1858 | 1904 |
| 1859 // Since we will create a new resource provider, we cannot continue to use | 1905 // Since we will create a new resource provider, we cannot continue to use |
| 1860 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 1906 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 1861 // before we destroy the old resource provider. | 1907 // before we destroy the old resource provider. |
| 1862 ReleaseTreeResources(); | 1908 ReleaseTreeResources(); |
| 1863 | 1909 |
| 1864 // Note: order is important here. | 1910 // Note: order is important here. |
| 1865 renderer_.reset(); | 1911 renderer_.reset(); |
| 1866 tile_manager_.reset(); | 1912 tile_manager_.reset(); |
| 1867 resource_pool_.reset(); | 1913 resource_pool_.reset(); |
| 1914 staging_resource_pool_.reset(); | |
| 1868 raster_worker_pool_.reset(); | 1915 raster_worker_pool_.reset(); |
| 1869 direct_raster_worker_pool_.reset(); | 1916 direct_raster_worker_pool_.reset(); |
| 1870 resource_provider_.reset(); | 1917 resource_provider_.reset(); |
| 1871 output_surface_.reset(); | 1918 output_surface_.reset(); |
| 1872 | 1919 |
| 1873 if (!output_surface->BindToClient(this)) | 1920 if (!output_surface->BindToClient(this)) |
| 1874 return false; | 1921 return false; |
| 1875 | 1922 |
| 1876 scoped_ptr<ResourceProvider> resource_provider = | 1923 scoped_ptr<ResourceProvider> resource_provider = |
| 1877 ResourceProvider::Create(output_surface.get(), | 1924 ResourceProvider::Create(output_surface.get(), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1890 output_surface.get(), resource_provider.get(), skip_gl_renderer); | 1937 output_surface.get(), resource_provider.get(), skip_gl_renderer); |
| 1891 | 1938 |
| 1892 if (!renderer_) | 1939 if (!renderer_) |
| 1893 return false; | 1940 return false; |
| 1894 | 1941 |
| 1895 if (settings_.impl_side_painting) { | 1942 if (settings_.impl_side_painting) { |
| 1896 CreateAndSetTileManager( | 1943 CreateAndSetTileManager( |
| 1897 resource_provider.get(), | 1944 resource_provider.get(), |
| 1898 output_surface->context_provider().get(), | 1945 output_surface->context_provider().get(), |
| 1899 GetRendererCapabilities().using_map_image, | 1946 GetRendererCapabilities().using_map_image, |
| 1947 settings_.use_zero_copy, | |
| 1900 GetRendererCapabilities().allow_rasterize_on_demand); | 1948 GetRendererCapabilities().allow_rasterize_on_demand); |
| 1901 } | 1949 } |
| 1902 | 1950 |
| 1903 if (!settings_.throttle_frame_production) { | 1951 if (!settings_.throttle_frame_production) { |
| 1904 // Disable VSync | 1952 // Disable VSync |
| 1905 output_surface->SetThrottleFrameProduction(false); | 1953 output_surface->SetThrottleFrameProduction(false); |
| 1906 } else if (!settings_.begin_impl_frame_scheduling_enabled) { | 1954 } else if (!settings_.begin_impl_frame_scheduling_enabled) { |
| 1907 // Setup BeginFrameEmulation if it's not supported natively | 1955 // Setup BeginFrameEmulation if it's not supported natively |
| 1908 const base::TimeDelta display_refresh_interval = | 1956 const base::TimeDelta display_refresh_interval = |
| 1909 base::TimeDelta::FromMicroseconds( | 1957 base::TimeDelta::FromMicroseconds( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1990 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 2038 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
| 1991 DCHECK(settings_.impl_side_painting); | 2039 DCHECK(settings_.impl_side_painting); |
| 1992 DCHECK(output_surface_->context_provider()); | 2040 DCHECK(output_surface_->context_provider()); |
| 1993 | 2041 |
| 1994 ReleaseTreeResources(); | 2042 ReleaseTreeResources(); |
| 1995 renderer_.reset(); | 2043 renderer_.reset(); |
| 1996 tile_manager_.reset(); | 2044 tile_manager_.reset(); |
| 1997 resource_pool_.reset(); | 2045 resource_pool_.reset(); |
| 1998 raster_worker_pool_.reset(); | 2046 raster_worker_pool_.reset(); |
| 1999 direct_raster_worker_pool_.reset(); | 2047 direct_raster_worker_pool_.reset(); |
| 2048 staging_resource_pool_.reset(); | |
| 2000 resource_provider_->InitializeSoftware(); | 2049 resource_provider_->InitializeSoftware(); |
| 2001 | 2050 |
| 2002 bool skip_gl_renderer = true; | 2051 bool skip_gl_renderer = true; |
| 2003 CreateAndSetRenderer( | 2052 CreateAndSetRenderer( |
| 2004 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); | 2053 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); |
| 2005 DCHECK(renderer_); | 2054 DCHECK(renderer_); |
| 2006 | 2055 |
| 2007 EnforceZeroBudget(true); | 2056 EnforceZeroBudget(true); |
| 2008 CreateAndSetTileManager(resource_provider_.get(), | 2057 CreateAndSetTileManager(resource_provider_.get(), |
| 2009 NULL, | 2058 NULL, |
| 2010 GetRendererCapabilities().using_map_image, | 2059 GetRendererCapabilities().using_map_image, |
| 2060 settings_.use_zero_copy, | |
| 2011 GetRendererCapabilities().allow_rasterize_on_demand); | 2061 GetRendererCapabilities().allow_rasterize_on_demand); |
| 2012 DCHECK(tile_manager_); | 2062 DCHECK(tile_manager_); |
| 2013 | 2063 |
| 2014 SetOffscreenContextProvider(NULL); | 2064 SetOffscreenContextProvider(NULL); |
| 2015 | 2065 |
| 2016 client_->SetNeedsCommitOnImplThread(); | 2066 client_->SetNeedsCommitOnImplThread(); |
| 2017 } | 2067 } |
| 2018 | 2068 |
| 2019 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { | 2069 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { |
| 2020 if (device_viewport_size == device_viewport_size_) | 2070 if (device_viewport_size == device_viewport_size_) |
| (...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3122 swap_promise_monitor_.erase(monitor); | 3172 swap_promise_monitor_.erase(monitor); |
| 3123 } | 3173 } |
| 3124 | 3174 |
| 3125 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3175 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
| 3126 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3176 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
| 3127 for (; it != swap_promise_monitor_.end(); it++) | 3177 for (; it != swap_promise_monitor_.end(); it++) |
| 3128 (*it)->OnSetNeedsRedrawOnImpl(); | 3178 (*it)->OnSetNeedsRedrawOnImpl(); |
| 3129 } | 3179 } |
| 3130 | 3180 |
| 3131 } // namespace cc | 3181 } // namespace cc |
| OLD | NEW |