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 11 matching lines...) Expand all Loading... |
22 #include "cc/debug/overdraw_metrics.h" | 22 #include "cc/debug/overdraw_metrics.h" |
23 #include "cc/debug/rendering_stats_instrumentation.h" | 23 #include "cc/debug/rendering_stats_instrumentation.h" |
24 #include "cc/input/top_controls_manager.h" | 24 #include "cc/input/top_controls_manager.h" |
25 #include "cc/layers/heads_up_display_layer.h" | 25 #include "cc/layers/heads_up_display_layer.h" |
26 #include "cc/layers/heads_up_display_layer_impl.h" | 26 #include "cc/layers/heads_up_display_layer_impl.h" |
27 #include "cc/layers/layer.h" | 27 #include "cc/layers/layer.h" |
28 #include "cc/layers/layer_iterator.h" | 28 #include "cc/layers/layer_iterator.h" |
29 #include "cc/layers/render_surface.h" | 29 #include "cc/layers/render_surface.h" |
30 #include "cc/layers/scrollbar_layer.h" | 30 #include "cc/layers/scrollbar_layer.h" |
31 #include "cc/resources/prioritized_resource_manager.h" | 31 #include "cc/resources/prioritized_resource_manager.h" |
| 32 #include "cc/resources/ui_resource_client.h" |
32 #include "cc/trees/layer_tree_host_client.h" | 33 #include "cc/trees/layer_tree_host_client.h" |
33 #include "cc/trees/layer_tree_host_common.h" | 34 #include "cc/trees/layer_tree_host_common.h" |
34 #include "cc/trees/layer_tree_host_impl.h" | 35 #include "cc/trees/layer_tree_host_impl.h" |
35 #include "cc/trees/layer_tree_impl.h" | 36 #include "cc/trees/layer_tree_impl.h" |
36 #include "cc/trees/occlusion_tracker.h" | 37 #include "cc/trees/occlusion_tracker.h" |
37 #include "cc/trees/single_thread_proxy.h" | 38 #include "cc/trees/single_thread_proxy.h" |
38 #include "cc/trees/thread_proxy.h" | 39 #include "cc/trees/thread_proxy.h" |
39 #include "cc/trees/tree_synchronizer.h" | 40 #include "cc/trees/tree_synchronizer.h" |
40 #include "ui/gfx/size_conversions.h" | 41 #include "ui/gfx/size_conversions.h" |
41 | 42 |
(...skipping 10 matching lines...) Expand all Loading... |
52 using_egl_image(false), | 53 using_egl_image(false), |
53 allow_partial_texture_updates(false), | 54 allow_partial_texture_updates(false), |
54 using_offscreen_context3d(false), | 55 using_offscreen_context3d(false), |
55 max_texture_size(0), | 56 max_texture_size(0), |
56 avoid_pow2_textures(false), | 57 avoid_pow2_textures(false), |
57 using_map_image(false), | 58 using_map_image(false), |
58 using_shared_memory_resources(false) {} | 59 using_shared_memory_resources(false) {} |
59 | 60 |
60 RendererCapabilities::~RendererCapabilities() {} | 61 RendererCapabilities::~RendererCapabilities() {} |
61 | 62 |
| 63 UIResourceRequest::UIResourceRequest() |
| 64 : type(UIResourceInvalidRequest), id(0), bitmap(NULL) {} |
| 65 |
| 66 UIResourceRequest::~UIResourceRequest() {} |
| 67 |
62 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { | 68 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { |
63 return s_num_layer_tree_instances > 0; | 69 return s_num_layer_tree_instances > 0; |
64 } | 70 } |
65 | 71 |
66 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( | 72 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( |
67 LayerTreeHostClient* client, | 73 LayerTreeHostClient* client, |
68 const LayerTreeSettings& settings, | 74 const LayerTreeSettings& settings, |
69 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 75 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
70 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, | 76 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, |
71 settings)); | 77 settings)); |
72 if (!layer_tree_host->Initialize(impl_task_runner)) | 78 if (!layer_tree_host->Initialize(impl_task_runner)) |
73 return scoped_ptr<LayerTreeHost>(); | 79 return scoped_ptr<LayerTreeHost>(); |
74 return layer_tree_host.Pass(); | 80 return layer_tree_host.Pass(); |
75 } | 81 } |
76 | 82 |
77 static int s_next_tree_id = 1; | 83 static int s_next_tree_id = 1; |
78 | 84 |
79 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, | 85 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, |
80 const LayerTreeSettings& settings) | 86 const LayerTreeSettings& settings) |
81 : animating_(false), | 87 : next_ui_resource_id_(1), |
| 88 animating_(false), |
82 needs_full_tree_sync_(true), | 89 needs_full_tree_sync_(true), |
83 needs_filter_context_(false), | 90 needs_filter_context_(false), |
84 client_(client), | 91 client_(client), |
85 source_frame_number_(0), | 92 source_frame_number_(0), |
86 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 93 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
87 output_surface_can_be_initialized_(true), | 94 output_surface_can_be_initialized_(true), |
88 output_surface_lost_(true), | 95 output_surface_lost_(true), |
89 num_failed_recreate_attempts_(0), | 96 num_failed_recreate_attempts_(0), |
90 settings_(settings), | 97 settings_(settings), |
91 debug_state_(settings.initial_debug_state), | 98 debug_state_(settings.initial_debug_state), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (pending_page_scale_animation_) { | 354 if (pending_page_scale_animation_) { |
348 host_impl->StartPageScaleAnimation( | 355 host_impl->StartPageScaleAnimation( |
349 pending_page_scale_animation_->target_offset, | 356 pending_page_scale_animation_->target_offset, |
350 pending_page_scale_animation_->use_anchor, | 357 pending_page_scale_animation_->use_anchor, |
351 pending_page_scale_animation_->scale, | 358 pending_page_scale_animation_->scale, |
352 base::TimeTicks::Now(), | 359 base::TimeTicks::Now(), |
353 pending_page_scale_animation_->duration); | 360 pending_page_scale_animation_->duration); |
354 pending_page_scale_animation_.reset(); | 361 pending_page_scale_animation_.reset(); |
355 } | 362 } |
356 | 363 |
| 364 if (!ui_resource_request_queue_.empty()) { |
| 365 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); |
| 366 ui_resource_request_queue_.clear(); |
| 367 // Process any ui resource requests in the queue. For impl-side-painting, |
| 368 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree. |
| 369 if (!settings_.impl_side_painting) |
| 370 sync_tree->ProcessUIResourceRequestQueue(); |
| 371 } |
| 372 |
357 DCHECK(!sync_tree->ViewportSizeInvalid()); | 373 DCHECK(!sync_tree->ViewportSizeInvalid()); |
358 | 374 |
359 if (new_impl_tree_has_no_evicted_resources) { | 375 if (new_impl_tree_has_no_evicted_resources) { |
360 if (sync_tree->ContentsTexturesPurged()) | 376 if (sync_tree->ContentsTexturesPurged()) |
361 sync_tree->ResetContentsTexturesPurged(); | 377 sync_tree->ResetContentsTexturesPurged(); |
362 } | 378 } |
363 | 379 |
364 if (!settings_.impl_side_painting) { | 380 if (!settings_.impl_side_painting) { |
365 // If we're not in impl-side painting, the tree is immediately | 381 // If we're not in impl-side painting, the tree is immediately |
366 // considered active. | 382 // considered active. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return host_impl.Pass(); | 428 return host_impl.Pass(); |
413 } | 429 } |
414 | 430 |
415 void LayerTreeHost::DidLoseOutputSurface() { | 431 void LayerTreeHost::DidLoseOutputSurface() { |
416 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 432 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
417 DCHECK(proxy_->IsMainThread()); | 433 DCHECK(proxy_->IsMainThread()); |
418 | 434 |
419 if (output_surface_lost_) | 435 if (output_surface_lost_) |
420 return; | 436 return; |
421 | 437 |
| 438 DidLoseUIResources(); |
| 439 |
422 num_failed_recreate_attempts_ = 0; | 440 num_failed_recreate_attempts_ = 0; |
423 output_surface_lost_ = true; | 441 output_surface_lost_ = true; |
424 SetNeedsCommit(); | 442 SetNeedsCommit(); |
425 } | 443 } |
426 | 444 |
427 bool LayerTreeHost::CompositeAndReadback(void* pixels, | 445 bool LayerTreeHost::CompositeAndReadback(void* pixels, |
428 gfx::Rect rect_in_device_viewport) { | 446 gfx::Rect rect_in_device_viewport) { |
429 trigger_idle_updates_ = false; | 447 trigger_idle_updates_ = false; |
430 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); | 448 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); |
431 trigger_idle_updates_ = true; | 449 trigger_idle_updates_ = true; |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 | 1061 |
1044 bool LayerTreeHost::RequestPartialTextureUpdate() { | 1062 bool LayerTreeHost::RequestPartialTextureUpdate() { |
1045 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) | 1063 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) |
1046 return false; | 1064 return false; |
1047 | 1065 |
1048 partial_texture_update_requests_++; | 1066 partial_texture_update_requests_++; |
1049 return true; | 1067 return true; |
1050 } | 1068 } |
1051 | 1069 |
1052 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { | 1070 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { |
1053 if (device_scale_factor == device_scale_factor_) | 1071 if (device_scale_factor == device_scale_factor_) |
1054 return; | 1072 return; |
1055 device_scale_factor_ = device_scale_factor; | 1073 device_scale_factor_ = device_scale_factor; |
1056 | 1074 |
1057 SetNeedsCommit(); | 1075 SetNeedsCommit(); |
1058 } | 1076 } |
1059 | 1077 |
1060 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 1078 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
1061 TopControlsState current, | 1079 TopControlsState current, |
1062 bool animate) { | 1080 bool animate) { |
1063 if (!settings_.calculate_top_controls_position) | 1081 if (!settings_.calculate_top_controls_position) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 animation_registrar_->active_animation_controllers(); | 1117 animation_registrar_->active_animation_controllers(); |
1100 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 1118 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
1101 iter != copy.end(); | 1119 iter != copy.end(); |
1102 ++iter) { | 1120 ++iter) { |
1103 (*iter).second->Animate(monotonic_time); | 1121 (*iter).second->Animate(monotonic_time); |
1104 bool start_ready_animations = true; | 1122 bool start_ready_animations = true; |
1105 (*iter).second->UpdateState(start_ready_animations, NULL); | 1123 (*iter).second->UpdateState(start_ready_animations, NULL); |
1106 } | 1124 } |
1107 } | 1125 } |
1108 | 1126 |
| 1127 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
| 1128 DCHECK(client); |
| 1129 |
| 1130 UIResourceRequest request; |
| 1131 bool resource_lost = false; |
| 1132 request.type = UIResourceRequest::UIResourceCreate; |
| 1133 request.id = next_ui_resource_id_++; |
| 1134 |
| 1135 DCHECK(ui_resource_client_map_.find(request.id) == |
| 1136 ui_resource_client_map_.end()); |
| 1137 |
| 1138 request.bitmap = client->GetBitmap(request.id, resource_lost); |
| 1139 ui_resource_request_queue_.push_back(request); |
| 1140 ui_resource_client_map_[request.id] = client; |
| 1141 return request.id; |
| 1142 } |
| 1143 |
| 1144 // Deletes a UI resource. May safely be called more than once. |
| 1145 void LayerTreeHost::DeleteUIResource(UIResourceId uid) { |
| 1146 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); |
| 1147 if (iter == ui_resource_client_map_.end()) |
| 1148 return; |
| 1149 |
| 1150 UIResourceRequest request; |
| 1151 request.type = UIResourceRequest::UIResourceDelete; |
| 1152 request.id = uid; |
| 1153 ui_resource_request_queue_.push_back(request); |
| 1154 ui_resource_client_map_.erase(uid); |
| 1155 } |
| 1156 |
| 1157 void LayerTreeHost::UIResourceLost(UIResourceId uid) { |
| 1158 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); |
| 1159 if (iter == ui_resource_client_map_.end()) |
| 1160 return; |
| 1161 |
| 1162 UIResourceRequest request; |
| 1163 bool resource_lost = true; |
| 1164 request.type = UIResourceRequest::UIResourceCreate; |
| 1165 request.id = uid; |
| 1166 request.bitmap = iter->second->GetBitmap(uid, resource_lost); |
| 1167 DCHECK(request.bitmap.get()); |
| 1168 ui_resource_request_queue_.push_back(request); |
| 1169 } |
| 1170 |
| 1171 void LayerTreeHost::DidLoseUIResources() { |
| 1172 // When output surface is lost, we need to recreate the resource. |
| 1173 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); |
| 1174 iter != ui_resource_client_map_.end(); |
| 1175 ++iter) { |
| 1176 UIResourceLost(iter->first); |
| 1177 } |
| 1178 } |
| 1179 |
1109 } // namespace cc | 1180 } // namespace cc |
OLD | NEW |