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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1419 GetDrawMode(output_surface_.get()), resource_provider_.get()); | 1419 GetDrawMode(output_surface_.get()), resource_provider_.get()); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 if (output_surface_->ForcedDrawToSoftwareDevice()) { | 1422 if (output_surface_->ForcedDrawToSoftwareDevice()) { |
| 1423 bool disable_picture_quad_image_filtering = | 1423 bool disable_picture_quad_image_filtering = |
| 1424 IsCurrentlyScrolling() || needs_animate_layers(); | 1424 IsCurrentlyScrolling() || needs_animate_layers(); |
| 1425 | 1425 |
| 1426 scoped_ptr<SoftwareRenderer> temp_software_renderer = | 1426 scoped_ptr<SoftwareRenderer> temp_software_renderer = |
| 1427 SoftwareRenderer::Create(this, &settings_, output_surface_.get(), NULL); | 1427 SoftwareRenderer::Create(this, &settings_, output_surface_.get(), NULL); |
| 1428 temp_software_renderer->DrawFrame(&frame->render_passes, | 1428 temp_software_renderer->DrawFrame(&frame->render_passes, |
| 1429 NULL, | |
| 1430 device_scale_factor_, | 1429 device_scale_factor_, |
| 1431 DeviceViewport(), | 1430 DeviceViewport(), |
| 1432 DeviceClip(), | 1431 DeviceClip(), |
| 1433 disable_picture_quad_image_filtering); | 1432 disable_picture_quad_image_filtering); |
| 1434 } else { | 1433 } else { |
| 1435 renderer_->DrawFrame(&frame->render_passes, | 1434 renderer_->DrawFrame(&frame->render_passes, |
| 1436 offscreen_context_provider_.get(), | |
| 1437 device_scale_factor_, | 1435 device_scale_factor_, |
| 1438 DeviceViewport(), | 1436 DeviceViewport(), |
| 1439 DeviceClip(), | 1437 DeviceClip(), |
| 1440 false); | 1438 false); |
| 1441 } | 1439 } |
| 1442 // The render passes should be consumed by the renderer. | 1440 // The render passes should be consumed by the renderer. |
| 1443 DCHECK(frame->render_passes.empty()); | 1441 DCHECK(frame->render_passes.empty()); |
| 1444 frame->render_passes_by_id.clear(); | 1442 frame->render_passes_by_id.clear(); |
| 1445 | 1443 |
| 1446 // The next frame should start by assuming nothing has changed, and changes | 1444 // The next frame should start by assuming nothing has changed, and changes |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1910 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); | 1908 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); |
| 1911 | 1909 |
| 1912 resource_provider_ = resource_provider.Pass(); | 1910 resource_provider_ = resource_provider.Pass(); |
| 1913 output_surface_ = output_surface.Pass(); | 1911 output_surface_ = output_surface.Pass(); |
| 1914 | 1912 |
| 1915 client_->OnCanDrawStateChanged(CanDraw()); | 1913 client_->OnCanDrawStateChanged(CanDraw()); |
| 1916 | 1914 |
| 1917 return true; | 1915 return true; |
| 1918 } | 1916 } |
| 1919 | 1917 |
| 1920 bool LayerTreeHostImpl::DeferredInitialize( | 1918 void LayerTreeHostImpl::DeferredInitialize() { |
| 1921 scoped_refptr<ContextProvider> offscreen_context_provider) { | |
| 1922 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 1919 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
| 1923 DCHECK(settings_.impl_side_painting); | 1920 DCHECK(settings_.impl_side_painting); |
| 1924 DCHECK(output_surface_->context_provider()); | 1921 DCHECK(output_surface_->context_provider()); |
| 1925 | 1922 |
| 1926 ReleaseTreeResources(); | 1923 ReleaseTreeResources(); |
| 1927 renderer_.reset(); | 1924 renderer_.reset(); |
| 1928 | 1925 |
| 1929 resource_provider_->InitializeGL(); | 1926 resource_provider_->InitializeGL(); |
| 1930 | 1927 |
| 1931 bool skip_gl_renderer = false; | 1928 bool skip_gl_renderer = false; |
| 1932 CreateAndSetRenderer( | 1929 CreateAndSetRenderer( |
| 1933 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); | 1930 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); |
| 1934 | 1931 |
| 1935 bool success = true; | 1932 EnforceZeroBudget(false); |
|
boliu
2014/04/24 00:28:57
omg, this is awesome
| |
| 1936 if (offscreen_context_provider.get() && | 1933 client_->SetNeedsCommitOnImplThread(); |
| 1937 !offscreen_context_provider->BindToCurrentThread()) | |
| 1938 success = false; | |
| 1939 | |
| 1940 if (success) { | |
| 1941 EnforceZeroBudget(false); | |
| 1942 client_->SetNeedsCommitOnImplThread(); | |
| 1943 } else { | |
| 1944 if (offscreen_context_provider.get()) { | |
| 1945 if (offscreen_context_provider->BindToCurrentThread()) | |
| 1946 offscreen_context_provider->VerifyContexts(); | |
| 1947 offscreen_context_provider = NULL; | |
| 1948 } | |
| 1949 | |
| 1950 client_->DidLoseOutputSurfaceOnImplThread(); | |
| 1951 | |
| 1952 // If this method fails, the context provider will be dropped from the | |
| 1953 // output surface and destroyed. But the GLRenderer expects the output | |
| 1954 // surface to stick around - and hold onto the context3d - as long as it is | |
| 1955 // alive. | |
| 1956 // TODO(danakj): Remove the need for this code path: crbug.com/276411 | |
| 1957 renderer_.reset(); | |
| 1958 | |
| 1959 // The resource provider can't stay in GL mode or it tries to clean up GL | |
| 1960 // stuff, but the context provider is going away on the output surface | |
| 1961 // which contradicts being in GL mode. | |
| 1962 // TODO(danakj): Remove the need for this code path: crbug.com/276411 | |
| 1963 resource_provider_->InitializeSoftware(); | |
| 1964 } | |
| 1965 | |
| 1966 SetOffscreenContextProvider(offscreen_context_provider); | |
| 1967 return success; | |
| 1968 } | 1934 } |
| 1969 | 1935 |
| 1970 void LayerTreeHostImpl::ReleaseGL() { | 1936 void LayerTreeHostImpl::ReleaseGL() { |
| 1971 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 1937 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
| 1972 DCHECK(settings_.impl_side_painting); | 1938 DCHECK(settings_.impl_side_painting); |
| 1973 DCHECK(output_surface_->context_provider()); | 1939 DCHECK(output_surface_->context_provider()); |
| 1974 | 1940 |
| 1975 ReleaseTreeResources(); | 1941 ReleaseTreeResources(); |
| 1976 renderer_.reset(); | 1942 renderer_.reset(); |
| 1977 tile_manager_.reset(); | 1943 tile_manager_.reset(); |
| 1978 resource_pool_.reset(); | 1944 resource_pool_.reset(); |
| 1979 raster_worker_pool_.reset(); | 1945 raster_worker_pool_.reset(); |
| 1980 direct_raster_worker_pool_.reset(); | 1946 direct_raster_worker_pool_.reset(); |
| 1981 resource_provider_->InitializeSoftware(); | 1947 resource_provider_->InitializeSoftware(); |
| 1982 | 1948 |
| 1983 bool skip_gl_renderer = true; | 1949 bool skip_gl_renderer = true; |
| 1984 CreateAndSetRenderer( | 1950 CreateAndSetRenderer( |
| 1985 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); | 1951 output_surface_.get(), resource_provider_.get(), skip_gl_renderer); |
| 1986 | 1952 |
| 1987 EnforceZeroBudget(true); | 1953 EnforceZeroBudget(true); |
| 1988 CreateAndSetTileManager(resource_provider_.get(), | 1954 CreateAndSetTileManager(resource_provider_.get(), |
| 1989 NULL, | 1955 NULL, |
| 1990 GetRendererCapabilities().using_map_image, | 1956 GetRendererCapabilities().using_map_image, |
| 1991 GetRendererCapabilities().allow_rasterize_on_demand); | 1957 GetRendererCapabilities().allow_rasterize_on_demand); |
| 1992 DCHECK(tile_manager_); | 1958 DCHECK(tile_manager_); |
| 1993 | 1959 |
| 1994 SetOffscreenContextProvider(NULL); | |
| 1995 | |
| 1996 client_->SetNeedsCommitOnImplThread(); | 1960 client_->SetNeedsCommitOnImplThread(); |
| 1997 } | 1961 } |
| 1998 | 1962 |
| 1999 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { | 1963 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { |
| 2000 if (device_viewport_size == device_viewport_size_) | 1964 if (device_viewport_size == device_viewport_size_) |
| 2001 return; | 1965 return; |
| 2002 | 1966 |
| 2003 if (pending_tree_) | 1967 if (pending_tree_) |
| 2004 active_tree_->SetViewportSizeInvalid(); | 1968 active_tree_->SetViewportSizeInvalid(); |
| 2005 | 1969 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2814 DCHECK(current); | 2778 DCHECK(current); |
| 2815 current->ReleaseResources(); | 2779 current->ReleaseResources(); |
| 2816 if (current->mask_layer()) | 2780 if (current->mask_layer()) |
| 2817 SendReleaseResourcesRecursive(current->mask_layer()); | 2781 SendReleaseResourcesRecursive(current->mask_layer()); |
| 2818 if (current->replica_layer()) | 2782 if (current->replica_layer()) |
| 2819 SendReleaseResourcesRecursive(current->replica_layer()); | 2783 SendReleaseResourcesRecursive(current->replica_layer()); |
| 2820 for (size_t i = 0; i < current->children().size(); ++i) | 2784 for (size_t i = 0; i < current->children().size(); ++i) |
| 2821 SendReleaseResourcesRecursive(current->children()[i]); | 2785 SendReleaseResourcesRecursive(current->children()[i]); |
| 2822 } | 2786 } |
| 2823 | 2787 |
| 2824 void LayerTreeHostImpl::SetOffscreenContextProvider( | |
| 2825 const scoped_refptr<ContextProvider>& offscreen_context_provider) { | |
| 2826 if (!offscreen_context_provider.get()) { | |
| 2827 offscreen_context_provider_ = NULL; | |
| 2828 return; | |
| 2829 } | |
| 2830 | |
| 2831 if (!offscreen_context_provider->BindToCurrentThread()) { | |
| 2832 offscreen_context_provider_ = NULL; | |
| 2833 return; | |
| 2834 } | |
| 2835 | |
| 2836 offscreen_context_provider_ = offscreen_context_provider; | |
| 2837 } | |
| 2838 | |
| 2839 std::string LayerTreeHostImpl::LayerTreeAsJson() const { | 2788 std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
| 2840 std::string str; | 2789 std::string str; |
| 2841 if (active_tree_->root_layer()) { | 2790 if (active_tree_->root_layer()) { |
| 2842 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); | 2791 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
| 2843 base::JSONWriter::WriteWithOptions( | 2792 base::JSONWriter::WriteWithOptions( |
| 2844 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); | 2793 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
| 2845 } | 2794 } |
| 2846 return str; | 2795 return str; |
| 2847 } | 2796 } |
| 2848 | 2797 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3102 swap_promise_monitor_.erase(monitor); | 3051 swap_promise_monitor_.erase(monitor); |
| 3103 } | 3052 } |
| 3104 | 3053 |
| 3105 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3054 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
| 3106 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3055 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
| 3107 for (; it != swap_promise_monitor_.end(); it++) | 3056 for (; it != swap_promise_monitor_.end(); it++) |
| 3108 (*it)->OnSetNeedsRedrawOnImpl(); | 3057 (*it)->OnSetNeedsRedrawOnImpl(); |
| 3109 } | 3058 } |
| 3110 | 3059 |
| 3111 } // namespace cc | 3060 } // namespace cc |
| OLD | NEW |