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

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

Powered by Google App Engine
This is Rietveld 408576698