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

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

Issue 18191020: UI Resource Manager (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 5 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
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.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 settings)); 71 settings));
72 if (!layer_tree_host->Initialize(impl_task_runner)) 72 if (!layer_tree_host->Initialize(impl_task_runner))
73 return scoped_ptr<LayerTreeHost>(); 73 return scoped_ptr<LayerTreeHost>();
74 return layer_tree_host.Pass(); 74 return layer_tree_host.Pass();
75 } 75 }
76 76
77 static int s_next_tree_id = 1; 77 static int s_next_tree_id = 1;
78 78
79 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, 79 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client,
80 const LayerTreeSettings& settings) 80 const LayerTreeSettings& settings)
81 : animating_(false), 81 : ui_resource_id_(1),
82 animating_(false),
82 needs_full_tree_sync_(true), 83 needs_full_tree_sync_(true),
83 needs_filter_context_(false), 84 needs_filter_context_(false),
84 client_(client), 85 client_(client),
85 source_frame_number_(0), 86 source_frame_number_(0),
86 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 87 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
87 output_surface_can_be_initialized_(true), 88 output_surface_can_be_initialized_(true),
88 output_surface_lost_(true), 89 output_surface_lost_(true),
89 num_failed_recreate_attempts_(0), 90 num_failed_recreate_attempts_(0),
90 settings_(settings), 91 settings_(settings),
91 debug_state_(settings.initial_debug_state), 92 debug_state_(settings.initial_debug_state),
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if (pending_page_scale_animation_) { 348 if (pending_page_scale_animation_) {
348 host_impl->StartPageScaleAnimation( 349 host_impl->StartPageScaleAnimation(
349 pending_page_scale_animation_->target_offset, 350 pending_page_scale_animation_->target_offset,
350 pending_page_scale_animation_->use_anchor, 351 pending_page_scale_animation_->use_anchor,
351 pending_page_scale_animation_->scale, 352 pending_page_scale_animation_->scale,
352 base::TimeTicks::Now(), 353 base::TimeTicks::Now(),
353 pending_page_scale_animation_->duration); 354 pending_page_scale_animation_->duration);
354 pending_page_scale_animation_.reset(); 355 pending_page_scale_animation_.reset();
355 } 356 }
356 357
358 if (!ui_resource_request_queue_.empty()) {
359 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_);
360 ui_resource_request_queue_.clear();
361 // Process any ui resource requests in the queue. For impl-side-painting,
362 // the queue is processed in LayerTreeHostImpl::ActivatePendingTree.
363 if (!settings_.impl_side_painting)
364 sync_tree->ProcessUIResourceRequestQueue();
365 }
366
357 DCHECK(!sync_tree->ViewportSizeInvalid()); 367 DCHECK(!sync_tree->ViewportSizeInvalid());
358 368
359 if (new_impl_tree_has_no_evicted_resources) { 369 if (new_impl_tree_has_no_evicted_resources) {
360 if (sync_tree->ContentsTexturesPurged()) 370 if (sync_tree->ContentsTexturesPurged())
361 sync_tree->ResetContentsTexturesPurged(); 371 sync_tree->ResetContentsTexturesPurged();
362 } 372 }
363 373
364 if (!settings_.impl_side_painting) { 374 if (!settings_.impl_side_painting) {
365 // If we're not in impl-side painting, the tree is immediately 375 // If we're not in impl-side painting, the tree is immediately
366 // considered active. 376 // considered active.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return host_impl.Pass(); 422 return host_impl.Pass();
413 } 423 }
414 424
415 void LayerTreeHost::DidLoseOutputSurface() { 425 void LayerTreeHost::DidLoseOutputSurface() {
416 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); 426 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface");
417 DCHECK(proxy_->IsMainThread()); 427 DCHECK(proxy_->IsMainThread());
418 428
419 if (output_surface_lost_) 429 if (output_surface_lost_)
420 return; 430 return;
421 431
432 DidLoseUIResources();
433
422 num_failed_recreate_attempts_ = 0; 434 num_failed_recreate_attempts_ = 0;
423 output_surface_lost_ = true; 435 output_surface_lost_ = true;
424 SetNeedsCommit(); 436 SetNeedsCommit();
425 } 437 }
426 438
427 bool LayerTreeHost::CompositeAndReadback(void* pixels, 439 bool LayerTreeHost::CompositeAndReadback(void* pixels,
428 gfx::Rect rect_in_device_viewport) { 440 gfx::Rect rect_in_device_viewport) {
429 trigger_idle_updates_ = false; 441 trigger_idle_updates_ = false;
430 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); 442 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport);
431 trigger_idle_updates_ = true; 443 trigger_idle_updates_ = true;
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1029
1018 bool LayerTreeHost::RequestPartialTextureUpdate() { 1030 bool LayerTreeHost::RequestPartialTextureUpdate() {
1019 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) 1031 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates)
1020 return false; 1032 return false;
1021 1033
1022 partial_texture_update_requests_++; 1034 partial_texture_update_requests_++;
1023 return true; 1035 return true;
1024 } 1036 }
1025 1037
1026 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { 1038 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) {
1027 if (device_scale_factor == device_scale_factor_) 1039 if (device_scale_factor == device_scale_factor_)
1028 return; 1040 return;
1029 device_scale_factor_ = device_scale_factor; 1041 device_scale_factor_ = device_scale_factor;
1030 1042
1031 SetNeedsCommit(); 1043 SetNeedsCommit();
1032 } 1044 }
1033 1045
1034 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 1046 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
1035 TopControlsState current, 1047 TopControlsState current,
1036 bool animate) { 1048 bool animate) {
1037 if (!settings_.calculate_top_controls_position) 1049 if (!settings_.calculate_top_controls_position)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 animation_registrar_->active_animation_controllers(); 1085 animation_registrar_->active_animation_controllers();
1074 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); 1086 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
1075 iter != copy.end(); 1087 iter != copy.end();
1076 ++iter) { 1088 ++iter) {
1077 (*iter).second->Animate(monotonic_time); 1089 (*iter).second->Animate(monotonic_time);
1078 bool start_ready_animations = true; 1090 bool start_ready_animations = true;
1079 (*iter).second->UpdateState(start_ready_animations, NULL); 1091 (*iter).second->UpdateState(start_ready_animations, NULL);
1080 } 1092 }
1081 } 1093 }
1082 1094
1095 UIResourceId LayerTreeHost::CreateUIResource(
1096 const UIResourceCallback& bitmap_cb) {
1097 UIResourceRequest request;
1098 bool resource_lost = false;
1099 request.type = UIResourceCreate;
1100 request.id = ui_resource_id_++;
1101
1102 DCHECK(ui_resource_client_map_.find(request.id) ==
1103 ui_resource_client_map_.end());
1104
1105 request.bitmap = bitmap_cb.Run(resource_lost);
1106 ui_resource_request_queue_.push_back(request);
1107 ui_resource_client_map_[request.id] = bitmap_cb;
1108 return request.id;
1109 }
1110
1111 // Deletes a UI resource. May safely be called more than once.
1112 void LayerTreeHost::DeleteUIResource(UIResourceId uid) {
1113 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1114 if (iter != ui_resource_client_map_.end()) {
1115 UIResourceRequest request;
1116 request.type = UIResourceDelete;
1117 request.id = uid;
1118 ui_resource_request_queue_.push_back(request);
1119 ui_resource_client_map_.erase(uid);
1120 }
1121 }
1122
1123 void LayerTreeHost::UIResourceLost(UIResourceId uid) {
1124 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1125 if (iter != ui_resource_client_map_.end()) {
1126 UIResourceRequest request;
1127 bool resource_lost = true;
1128 request.type = UIResourceCreate;
1129 request.id = uid;
1130 request.bitmap = iter->second.Run(resource_lost);
1131 ui_resource_request_queue_.push_back(request);
1132 }
1133 }
1134
1135 void LayerTreeHost::DidLoseUIResources() {
1136 typedef base::hash_set<UIResourceId> UIResourceIdSet;
1137 UIResourceIdSet create_resource_set;
1138 UIResourceRequestQueue request_recovery_queue;
1139
1140 for (UIResourceRequestQueue::iterator iter =
1141 ui_resource_request_queue_.begin();
1142 iter != ui_resource_request_queue_.end();
1143 iter++) {
1144 // Only add the create request if a delete has not been issued for the same
1145 // resource. If a delete has been issued, then this resource would not have
1146 // an entry in the map.
1147 if (iter->type == UIResourceCreate &&
aelias_OOO_until_Jul13 2013/07/25 23:59:45 I suggest removing this if() and just creating a "
powei 2013/07/26 23:07:27 Done.
1148 ui_resource_client_map_.find(iter->id) !=
1149 ui_resource_client_map_.end()) {
1150 create_resource_set.insert(iter->id);
1151 request_recovery_queue.push_back(*iter);
1152 }
1153 }
1154
1155 ui_resource_request_queue_ = request_recovery_queue;
aelias_OOO_until_Jul13 2013/07/25 23:59:45 I don't see the need for this assignment. It seem
powei 2013/07/26 23:07:27 Done.
1156
1157 // When output surface is lost, we need to recreate the resource.
1158 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin();
1159 iter != ui_resource_client_map_.end();
1160 iter++) {
1161 // If the resource was to be created, then the original request will be
1162 // honored instead of treating it as resource lost.
1163 if (create_resource_set.find(iter->first) == create_resource_set.end())
1164 UIResourceLost(iter->first);
1165 }
1166 }
1167
1083 } // namespace cc 1168 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698