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

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

Issue 899313003: cc: Split ReleaseResources into Release and Recreate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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_impl.h » ('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 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 delta = outer_->ScrollBy(delta); 109 delta = outer_->ScrollBy(delta);
110 inner_->ScrollBy(delta); 110 inner_->ScrollBy(delta);
111 } 111 }
112 112
113 private: 113 private:
114 LayerImpl* inner_; 114 LayerImpl* inner_;
115 LayerImpl* outer_; 115 LayerImpl* outer_;
116 gfx::ScrollOffset viewport_in_content_coordinates_; 116 gfx::ScrollOffset viewport_in_content_coordinates_;
117 }; 117 };
118 118
119 template <typename Object>
120 class ScopedCaller {
danakj 2015/02/05 20:45:49 did you look around in base/ for something like th
vmpstr 2015/02/05 21:41:32 I couldn't really find anything that would do a si
121 public:
122 using Function = void (Object::*)();
123 ScopedCaller(Object* object, Function on_entry, Function on_exit)
124 : object_(object), on_exit_(on_exit) {
125 (object_->*on_entry)();
126 }
127
128 ~ScopedCaller() { (object_->*on_exit_)(); }
129
130 private:
131 Object* object_;
132 Function on_exit_;
133 };
119 134
120 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) { 135 void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) {
121 if (visible) { 136 if (visible) {
122 TRACE_EVENT_ASYNC_BEGIN1("cc", "LayerTreeHostImpl::SetVisible", id, 137 TRACE_EVENT_ASYNC_BEGIN1("cc", "LayerTreeHostImpl::SetVisible", id,
123 "LayerTreeHostImpl", id); 138 "LayerTreeHostImpl", id);
124 return; 139 return;
125 } 140 }
126 141
127 TRACE_EVENT_ASYNC_END0("cc", "LayerTreeHostImpl::SetVisible", id); 142 TRACE_EVENT_ASYNC_END0("cc", "LayerTreeHostImpl::SetVisible", id);
128 } 143 }
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 void LayerTreeHostImpl::SetUseGpuRasterization(bool use_gpu) { 1619 void LayerTreeHostImpl::SetUseGpuRasterization(bool use_gpu) {
1605 if (use_gpu == use_gpu_rasterization_) 1620 if (use_gpu == use_gpu_rasterization_)
1606 return; 1621 return;
1607 1622
1608 // Note that this must happen first, in case the rest of the calls want to 1623 // Note that this must happen first, in case the rest of the calls want to
1609 // query the new state of |use_gpu_rasterization_|. 1624 // query the new state of |use_gpu_rasterization_|.
1610 use_gpu_rasterization_ = use_gpu; 1625 use_gpu_rasterization_ = use_gpu;
1611 1626
1612 // Clean up and replace existing tile manager with another one that uses 1627 // Clean up and replace existing tile manager with another one that uses
1613 // appropriate rasterizer. 1628 // appropriate rasterizer.
1614 ReleaseTreeResources(); 1629 ScopedCaller<LayerTreeHostImpl> scoped_release_resources(
1630 this, &LayerTreeHostImpl::ReleaseTreeResources,
1631 &LayerTreeHostImpl::RecreateTreeResources);
1615 if (tile_manager_) { 1632 if (tile_manager_) {
1616 DestroyTileManager(); 1633 DestroyTileManager();
1617 CreateAndSetTileManager(); 1634 CreateAndSetTileManager();
1618 } 1635 }
1619 1636
1620 // We have released tilings for both active and pending tree. 1637 // We have released tilings for both active and pending tree.
1621 // We would not have any content to draw until the pending tree is activated. 1638 // We would not have any content to draw until the pending tree is activated.
1622 // Prevent the active tree from drawing until activation. 1639 // Prevent the active tree from drawing until activation.
1623 SetRequiresHighResToDraw(); 1640 SetRequiresHighResToDraw();
1624 } 1641 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 void LayerTreeHostImpl::ReleaseTreeResources() { 1944 void LayerTreeHostImpl::ReleaseTreeResources() {
1928 active_tree_->ReleaseResources(); 1945 active_tree_->ReleaseResources();
1929 if (pending_tree_) 1946 if (pending_tree_)
1930 pending_tree_->ReleaseResources(); 1947 pending_tree_->ReleaseResources();
1931 if (recycle_tree_) 1948 if (recycle_tree_)
1932 recycle_tree_->ReleaseResources(); 1949 recycle_tree_->ReleaseResources();
1933 1950
1934 EvictAllUIResources(); 1951 EvictAllUIResources();
1935 } 1952 }
1936 1953
1954 void LayerTreeHostImpl::RecreateTreeResources() {
1955 active_tree_->RecreateResources();
1956 if (pending_tree_)
1957 pending_tree_->RecreateResources();
1958 if (recycle_tree_)
1959 recycle_tree_->RecreateResources();
1960 }
1961
1937 void LayerTreeHostImpl::CreateAndSetRenderer() { 1962 void LayerTreeHostImpl::CreateAndSetRenderer() {
1938 DCHECK(!renderer_); 1963 DCHECK(!renderer_);
1939 DCHECK(output_surface_); 1964 DCHECK(output_surface_);
1940 DCHECK(resource_provider_); 1965 DCHECK(resource_provider_);
1941 1966
1942 if (output_surface_->capabilities().delegated_rendering) { 1967 if (output_surface_->capabilities().delegated_rendering) {
1943 renderer_ = DelegatingRenderer::Create(this, &settings_.renderer_settings, 1968 renderer_ = DelegatingRenderer::Create(this, &settings_.renderer_settings,
1944 output_surface_.get(), 1969 output_surface_.get(),
1945 resource_provider_.get()); 1970 resource_provider_.get());
1946 } else if (output_surface_->context_provider()) { 1971 } else if (output_surface_->context_provider()) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2143 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2119 // before we destroy the old resource provider. 2144 // before we destroy the old resource provider.
2120 ReleaseTreeResources(); 2145 ReleaseTreeResources();
2121 2146
2122 // Note: order is important here. 2147 // Note: order is important here.
2123 renderer_ = nullptr; 2148 renderer_ = nullptr;
2124 DestroyTileManager(); 2149 DestroyTileManager();
2125 resource_provider_ = nullptr; 2150 resource_provider_ = nullptr;
2126 output_surface_ = nullptr; 2151 output_surface_ = nullptr;
2127 2152
2128 if (!output_surface->BindToClient(this)) 2153 if (!output_surface->BindToClient(this)) {
2154 // Avoid recreating tree resources because we might not have enough
2155 // information to do this yet (eg. we don't have a TileManager at this
2156 // point).
2129 return false; 2157 return false;
2158 }
2130 2159
2131 output_surface_ = output_surface.Pass(); 2160 output_surface_ = output_surface.Pass();
2132 resource_provider_ = ResourceProvider::Create( 2161 resource_provider_ = ResourceProvider::Create(
2133 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, 2162 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_,
2134 proxy_->blocking_main_thread_task_runner(), 2163 proxy_->blocking_main_thread_task_runner(),
2135 settings_.renderer_settings.highp_threshold_min, 2164 settings_.renderer_settings.highp_threshold_min,
2136 settings_.renderer_settings.use_rgba_4444_textures, 2165 settings_.renderer_settings.use_rgba_4444_textures,
2137 settings_.renderer_settings.texture_id_allocation_chunk_size); 2166 settings_.renderer_settings.texture_id_allocation_chunk_size);
2138 2167
2139 if (output_surface_->capabilities().deferred_gl_initialization) 2168 if (output_surface_->capabilities().deferred_gl_initialization)
2140 EnforceZeroBudget(true); 2169 EnforceZeroBudget(true);
2141 2170
2142 CreateAndSetRenderer(); 2171 CreateAndSetRenderer();
2143 2172
2144 if (settings_.impl_side_painting) 2173 if (settings_.impl_side_painting)
2145 CreateAndSetTileManager(); 2174 CreateAndSetTileManager();
2175 RecreateTreeResources();
2146 2176
2147 // Initialize vsync parameters to sane values. 2177 // Initialize vsync parameters to sane values.
2148 const base::TimeDelta display_refresh_interval = 2178 const base::TimeDelta display_refresh_interval =
2149 base::TimeDelta::FromMicroseconds( 2179 base::TimeDelta::FromMicroseconds(
2150 base::Time::kMicrosecondsPerSecond / 2180 base::Time::kMicrosecondsPerSecond /
2151 settings_.renderer_settings.refresh_rate); 2181 settings_.renderer_settings.refresh_rate);
2152 CommitVSyncParameters(base::TimeTicks(), display_refresh_interval); 2182 CommitVSyncParameters(base::TimeTicks(), display_refresh_interval);
2153 2183
2154 // TODO(brianderson): Don't use a hard-coded parent draw time. 2184 // TODO(brianderson): Don't use a hard-coded parent draw time.
2155 base::TimeDelta parent_draw_time = 2185 base::TimeDelta parent_draw_time =
(...skipping 20 matching lines...) Expand all
2176 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, 2206 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase,
2177 base::TimeDelta interval) { 2207 base::TimeDelta interval) {
2178 client_->CommitVSyncParameters(timebase, interval); 2208 client_->CommitVSyncParameters(timebase, interval);
2179 } 2209 }
2180 2210
2181 void LayerTreeHostImpl::DeferredInitialize() { 2211 void LayerTreeHostImpl::DeferredInitialize() {
2182 DCHECK(output_surface_->capabilities().deferred_gl_initialization); 2212 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
2183 DCHECK(settings_.impl_side_painting); 2213 DCHECK(settings_.impl_side_painting);
2184 DCHECK(output_surface_->context_provider()); 2214 DCHECK(output_surface_->context_provider());
2185 2215
2186 ReleaseTreeResources(); 2216 ScopedCaller<LayerTreeHostImpl> scoped_release_resources(
enne (OOO) 2015/02/05 20:43:52 This seems like overkill. Neither of the function
vmpstr 2015/02/05 21:41:32 It's ReleaseResources is also implemented in textu
2217 this, &LayerTreeHostImpl::ReleaseTreeResources,
2218 &LayerTreeHostImpl::RecreateTreeResources);
2187 renderer_ = nullptr; 2219 renderer_ = nullptr;
2188 DestroyTileManager(); 2220 DestroyTileManager();
2189 2221
2190 resource_provider_->InitializeGL(); 2222 resource_provider_->InitializeGL();
2191 2223
2192 CreateAndSetRenderer(); 2224 CreateAndSetRenderer();
2193 EnforceZeroBudget(false); 2225 EnforceZeroBudget(false);
2194 CreateAndSetTileManager(); 2226 CreateAndSetTileManager();
2195 2227
2196 client_->SetNeedsCommitOnImplThread(); 2228 client_->SetNeedsCommitOnImplThread();
2197 } 2229 }
2198 2230
2199 void LayerTreeHostImpl::ReleaseGL() { 2231 void LayerTreeHostImpl::ReleaseGL() {
2200 DCHECK(output_surface_->capabilities().deferred_gl_initialization); 2232 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
2201 DCHECK(settings_.impl_side_painting); 2233 DCHECK(settings_.impl_side_painting);
2202 DCHECK(output_surface_->context_provider()); 2234 DCHECK(output_surface_->context_provider());
2203 2235
2204 ReleaseTreeResources(); 2236 ScopedCaller<LayerTreeHostImpl> scoped_release_resources(
2237 this, &LayerTreeHostImpl::ReleaseTreeResources,
2238 &LayerTreeHostImpl::RecreateTreeResources);
2205 renderer_ = nullptr; 2239 renderer_ = nullptr;
2206 DestroyTileManager(); 2240 DestroyTileManager();
2207 2241
2208 resource_provider_->InitializeSoftware(); 2242 resource_provider_->InitializeSoftware();
2209 output_surface_->ReleaseContextProvider(); 2243 output_surface_->ReleaseContextProvider();
2210 2244
2211 CreateAndSetRenderer(); 2245 CreateAndSetRenderer();
2212 EnforceZeroBudget(true); 2246 EnforceZeroBudget(true);
2213 CreateAndSetTileManager(); 2247 CreateAndSetTileManager();
2214 2248
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3501 } 3535 }
3502 3536
3503 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 3537 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3504 std::vector<PictureLayerImpl*>::iterator it = 3538 std::vector<PictureLayerImpl*>::iterator it =
3505 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 3539 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3506 DCHECK(it != picture_layers_.end()); 3540 DCHECK(it != picture_layers_.end());
3507 picture_layers_.erase(it); 3541 picture_layers_.erase(it);
3508 } 3542 }
3509 3543
3510 } // namespace cc 3544 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698