| 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.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <stack> | 8 #include <stack> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 using_offscreen_context3d(false), | 55 using_offscreen_context3d(false), |
| 56 max_texture_size(0), | 56 max_texture_size(0), |
| 57 avoid_pow2_textures(false), | 57 avoid_pow2_textures(false), |
| 58 using_map_image(false), | 58 using_map_image(false), |
| 59 using_shared_memory_resources(false), | 59 using_shared_memory_resources(false), |
| 60 using_discard_framebuffer(false) {} | 60 using_discard_framebuffer(false) {} |
| 61 | 61 |
| 62 RendererCapabilities::~RendererCapabilities() {} | 62 RendererCapabilities::~RendererCapabilities() {} |
| 63 | 63 |
| 64 UIResourceRequest::UIResourceRequest() | 64 UIResourceRequest::UIResourceRequest() |
| 65 : type(UIResourceInvalidRequest), id(0), bitmap(NULL) {} | 65 : type(UIResourceInvalidRequest), |
| 66 id(0), |
| 67 bitmap(NULL), |
| 68 eviction_count_recreated(0) {} |
| 66 | 69 |
| 67 UIResourceRequest::~UIResourceRequest() {} | 70 UIResourceRequest::~UIResourceRequest() {} |
| 68 | 71 |
| 69 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { | 72 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { |
| 70 return s_num_layer_tree_instances > 0; | 73 return s_num_layer_tree_instances > 0; |
| 71 } | 74 } |
| 72 | 75 |
| 73 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( | 76 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( |
| 74 LayerTreeHostClient* client, | 77 LayerTreeHostClient* client, |
| 75 const LayerTreeSettings& settings, | 78 const LayerTreeSettings& settings, |
| 76 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 79 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| 77 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, | 80 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, |
| 78 settings)); | 81 settings)); |
| 79 if (!layer_tree_host->Initialize(impl_task_runner)) | 82 if (!layer_tree_host->Initialize(impl_task_runner)) |
| 80 return scoped_ptr<LayerTreeHost>(); | 83 return scoped_ptr<LayerTreeHost>(); |
| 81 return layer_tree_host.Pass(); | 84 return layer_tree_host.Pass(); |
| 82 } | 85 } |
| 83 | 86 |
| 84 static int s_next_tree_id = 1; | 87 static int s_next_tree_id = 1; |
| 85 | 88 |
| 86 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, | 89 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, |
| 87 const LayerTreeSettings& settings) | 90 const LayerTreeSettings& settings) |
| 88 : next_ui_resource_id_(1), | 91 : next_ui_resource_id_(1), |
| 92 ui_resource_eviction_count_recreated_(0), |
| 89 animating_(false), | 93 animating_(false), |
| 90 needs_full_tree_sync_(true), | 94 needs_full_tree_sync_(true), |
| 91 needs_filter_context_(false), | 95 needs_filter_context_(false), |
| 92 client_(client), | 96 client_(client), |
| 93 source_frame_number_(0), | 97 source_frame_number_(0), |
| 94 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 98 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 95 output_surface_can_be_initialized_(true), | 99 output_surface_can_be_initialized_(true), |
| 96 output_surface_lost_(true), | 100 output_surface_lost_(true), |
| 97 num_failed_recreate_attempts_(0), | 101 num_failed_recreate_attempts_(0), |
| 98 settings_(settings), | 102 settings_(settings), |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree. | 376 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree. |
| 373 if (!settings_.impl_side_painting) | 377 if (!settings_.impl_side_painting) |
| 374 sync_tree->ProcessUIResourceRequestQueue(); | 378 sync_tree->ProcessUIResourceRequestQueue(); |
| 375 } | 379 } |
| 376 if (overhang_ui_resource_) { | 380 if (overhang_ui_resource_) { |
| 377 host_impl->SetOverhangUIResource( | 381 host_impl->SetOverhangUIResource( |
| 378 overhang_ui_resource_->id(), | 382 overhang_ui_resource_->id(), |
| 379 overhang_ui_resource_->GetSize()); | 383 overhang_ui_resource_->GetSize()); |
| 380 } | 384 } |
| 381 | 385 |
| 386 // If all UI resource evictions will not be recreated by this commit, then |
| 387 // another commit is required. |
| 388 if (ui_resource_eviction_count_recreated_ != |
| 389 host_impl->ui_resource_eviction_count()) { |
| 390 host_impl->SetNeedsCommit(); |
| 391 } |
| 392 |
| 382 DCHECK(!sync_tree->ViewportSizeInvalid()); | 393 DCHECK(!sync_tree->ViewportSizeInvalid()); |
| 383 | 394 |
| 384 if (new_impl_tree_has_no_evicted_resources) { | 395 if (new_impl_tree_has_no_evicted_resources) { |
| 385 if (sync_tree->ContentsTexturesPurged()) | 396 if (sync_tree->ContentsTexturesPurged()) |
| 386 sync_tree->ResetContentsTexturesPurged(); | 397 sync_tree->ResetContentsTexturesPurged(); |
| 387 } | 398 } |
| 388 | 399 |
| 389 if (!settings_.impl_side_painting) { | 400 if (!settings_.impl_side_painting) { |
| 390 // If we're not in impl-side painting, the tree is immediately | 401 // If we're not in impl-side painting, the tree is immediately |
| 391 // considered active. | 402 // considered active. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 return host_impl.Pass(); | 448 return host_impl.Pass(); |
| 438 } | 449 } |
| 439 | 450 |
| 440 void LayerTreeHost::DidLoseOutputSurface() { | 451 void LayerTreeHost::DidLoseOutputSurface() { |
| 441 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 452 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
| 442 DCHECK(proxy_->IsMainThread()); | 453 DCHECK(proxy_->IsMainThread()); |
| 443 | 454 |
| 444 if (output_surface_lost_) | 455 if (output_surface_lost_) |
| 445 return; | 456 return; |
| 446 | 457 |
| 447 bool resource_lost = true; | |
| 448 RecreateUIResources(resource_lost); | |
| 449 | |
| 450 num_failed_recreate_attempts_ = 0; | 458 num_failed_recreate_attempts_ = 0; |
| 451 output_surface_lost_ = true; | 459 output_surface_lost_ = true; |
| 452 SetNeedsCommit(); | 460 SetNeedsCommit(); |
| 453 } | 461 } |
| 454 | 462 |
| 455 bool LayerTreeHost::CompositeAndReadback(void* pixels, | 463 bool LayerTreeHost::CompositeAndReadback(void* pixels, |
| 456 gfx::Rect rect_in_device_viewport) { | 464 gfx::Rect rect_in_device_viewport) { |
| 457 trigger_idle_updates_ = false; | 465 trigger_idle_updates_ = false; |
| 458 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); | 466 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); |
| 459 trigger_idle_updates_ = true; | 467 trigger_idle_updates_ = true; |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 if (iter == ui_resource_client_map_.end()) | 1177 if (iter == ui_resource_client_map_.end()) |
| 1170 return; | 1178 return; |
| 1171 | 1179 |
| 1172 UIResourceRequest request; | 1180 UIResourceRequest request; |
| 1173 request.type = UIResourceRequest::UIResourceDelete; | 1181 request.type = UIResourceRequest::UIResourceDelete; |
| 1174 request.id = uid; | 1182 request.id = uid; |
| 1175 ui_resource_request_queue_.push_back(request); | 1183 ui_resource_request_queue_.push_back(request); |
| 1176 ui_resource_client_map_.erase(uid); | 1184 ui_resource_client_map_.erase(uid); |
| 1177 } | 1185 } |
| 1178 | 1186 |
| 1179 void LayerTreeHost::RecreateUIResources(bool resource_lost) { | 1187 bool LayerTreeHost::SetUIResourceEvictionCount( |
| 1188 uint64 ui_resource_eviction_count) { |
| 1189 if (ui_resource_eviction_count_recreated_ == ui_resource_eviction_count) |
| 1190 return false; |
| 1191 |
| 1180 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); | 1192 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); |
| 1181 iter != ui_resource_client_map_.end(); | 1193 iter != ui_resource_client_map_.end(); |
| 1182 ++iter) { | 1194 ++iter) { |
| 1183 UIResourceId uid = iter->first; | 1195 UIResourceId uid = iter->first; |
| 1184 UIResourceRequest request; | 1196 UIResourceRequest request; |
| 1185 request.type = UIResourceRequest::UIResourceCreate; | 1197 request.type = UIResourceRequest::UIResourceCreate; |
| 1186 request.id = uid; | 1198 request.id = uid; |
| 1199 bool resource_lost = true; |
| 1187 request.bitmap = iter->second->GetBitmap(uid, resource_lost); | 1200 request.bitmap = iter->second->GetBitmap(uid, resource_lost); |
| 1188 DCHECK(request.bitmap.get()); | 1201 DCHECK(request.bitmap.get()); |
| 1189 ui_resource_request_queue_.push_back(request); | 1202 ui_resource_request_queue_.push_back(request); |
| 1190 } | 1203 } |
| 1204 UIResourceRequest request; |
| 1205 request.type = UIResourceRequest::UIResourceEvictionRecreated; |
| 1206 request.eviction_count_recreated = ui_resource_eviction_count; |
| 1207 ui_resource_request_queue_.push_back(request); |
| 1208 ui_resource_eviction_count_recreated_ = ui_resource_eviction_count; |
| 1209 |
| 1210 return true; |
| 1191 } | 1211 } |
| 1192 | 1212 |
| 1193 } // namespace cc | 1213 } // namespace cc |
| OLD | NEW |