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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1039 | 1057 |
1040 bool LayerTreeHost::RequestPartialTextureUpdate() { | 1058 bool LayerTreeHost::RequestPartialTextureUpdate() { |
1041 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) | 1059 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) |
1042 return false; | 1060 return false; |
1043 | 1061 |
1044 partial_texture_update_requests_++; | 1062 partial_texture_update_requests_++; |
1045 return true; | 1063 return true; |
1046 } | 1064 } |
1047 | 1065 |
1048 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { | 1066 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { |
1049 if (device_scale_factor == device_scale_factor_) | 1067 if (device_scale_factor == device_scale_factor_) |
1050 return; | 1068 return; |
1051 device_scale_factor_ = device_scale_factor; | 1069 device_scale_factor_ = device_scale_factor; |
1052 | 1070 |
1053 SetNeedsCommit(); | 1071 SetNeedsCommit(); |
1054 } | 1072 } |
1055 | 1073 |
1056 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 1074 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
1057 TopControlsState current, | 1075 TopControlsState current, |
1058 bool animate) { | 1076 bool animate) { |
1059 if (!settings_.calculate_top_controls_position) | 1077 if (!settings_.calculate_top_controls_position) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 animation_registrar_->active_animation_controllers(); | 1113 animation_registrar_->active_animation_controllers(); |
1096 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 1114 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
1097 iter != copy.end(); | 1115 iter != copy.end(); |
1098 ++iter) { | 1116 ++iter) { |
1099 (*iter).second->Animate(monotonic_time); | 1117 (*iter).second->Animate(monotonic_time); |
1100 bool start_ready_animations = true; | 1118 bool start_ready_animations = true; |
1101 (*iter).second->UpdateState(start_ready_animations, NULL); | 1119 (*iter).second->UpdateState(start_ready_animations, NULL); |
1102 } | 1120 } |
1103 } | 1121 } |
1104 | 1122 |
1123 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | |
1124 DCHECK(client); | |
1125 | |
1126 UIResourceRequest request; | |
1127 bool resource_lost = false; | |
1128 request.type = UIResourceCreate; | |
1129 request.id = next_ui_resource_id_++; | |
1130 | |
1131 DCHECK(ui_resource_client_map_.find(request.id) == | |
1132 ui_resource_client_map_.end()); | |
1133 | |
1134 request.bitmap = client->GetBitmap(request.id, resource_lost); | |
1135 ui_resource_request_queue_.push_back(request); | |
1136 ui_resource_client_map_[request.id] = client; | |
1137 return request.id; | |
1138 } | |
1139 | |
1140 // Deletes a UI resource. May safely be called more than once. | |
1141 void LayerTreeHost::DeleteUIResource(UIResourceId uid) { | |
1142 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); | |
1143 if (iter != ui_resource_client_map_.end()) { | |
enne (OOO)
2013/07/31 22:02:40
style nit: make this an early return rather than a
powei
2013/08/01 00:05:10
Done.
| |
1144 UIResourceRequest request; | |
1145 request.type = UIResourceDelete; | |
1146 request.id = uid; | |
1147 ui_resource_request_queue_.push_back(request); | |
1148 ui_resource_client_map_.erase(uid); | |
1149 } | |
1150 } | |
1151 | |
1152 void LayerTreeHost::UIResourceLost(UIResourceId uid) { | |
1153 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid); | |
1154 if (iter != ui_resource_client_map_.end()) { | |
1155 UIResourceRequest request; | |
1156 bool resource_lost = true; | |
1157 request.type = UIResourceCreate; | |
1158 request.id = uid; | |
1159 request.bitmap = iter->second->GetBitmap(uid, resource_lost); | |
1160 DCHECK(request.bitmap.get()); | |
1161 ui_resource_request_queue_.push_back(request); | |
1162 } | |
1163 } | |
1164 | |
1165 void LayerTreeHost::DidLoseUIResources() { | |
1166 typedef base::hash_set<UIResourceId> UIResourceIdSet; | |
1167 UIResourceIdSet request_set; | |
aelias_OOO_until_Jul13
2013/07/31 21:00:30
Is this needed anymore? For simplicity, can we ju
powei
2013/07/31 21:29:39
If a user has created a resource, but the context
aelias_OOO_until_Jul13
2013/07/31 21:56:51
It doesn't matter much as long as we don't crash,
powei
2013/08/01 00:05:10
Done.
| |
1168 | |
1169 for (UIResourceRequestQueue::iterator iter = | |
1170 ui_resource_request_queue_.begin(); | |
1171 iter != ui_resource_request_queue_.end(); | |
1172 ++iter) { | |
1173 request_set.insert(iter->id); | |
1174 } | |
1175 | |
1176 // When output surface is lost, we need to recreate the resource. | |
1177 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin(); | |
1178 iter != ui_resource_client_map_.end(); | |
1179 ++iter) { | |
1180 // If the resource was to be created/deleted, then the original request will | |
1181 // be honored instead of treating it as resource lost. | |
1182 if (request_set.find(iter->first) == request_set.end()) | |
1183 UIResourceLost(iter->first); | |
1184 } | |
1185 } | |
1186 | |
1105 } // namespace cc | 1187 } // namespace cc |
OLD | NEW |