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

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 commit_number_(0), 86 commit_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 // Remove all pending UI resource requests because there might be deletion
aelias_OOO_until_Jul13 2013/07/24 02:57:46 We need to honor both creation and deletion reques
powei 2013/07/25 20:48:45 Done. And added tests in layer_tree_host_unittest
433 // requests, which can no longer be honored (or already gone anyways).
434 ui_resource_request_queue_.clear();
435
436 // When output surface is lost, we need to recreate the resource.
437 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin();
438 iter != ui_resource_client_map_.end();
439 iter++) {
440 UIResourceLost(iter->first);
441 }
442
422 num_failed_recreate_attempts_ = 0; 443 num_failed_recreate_attempts_ = 0;
423 output_surface_lost_ = true; 444 output_surface_lost_ = true;
424 SetNeedsCommit(); 445 SetNeedsCommit();
425 } 446 }
426 447
427 bool LayerTreeHost::CompositeAndReadback(void* pixels, 448 bool LayerTreeHost::CompositeAndReadback(void* pixels,
428 gfx::Rect rect_in_device_viewport) { 449 gfx::Rect rect_in_device_viewport) {
429 trigger_idle_updates_ = false; 450 trigger_idle_updates_ = false;
430 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport); 451 bool ret = proxy_->CompositeAndReadback(pixels, rect_in_device_viewport);
431 trigger_idle_updates_ = true; 452 trigger_idle_updates_ = true;
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1038
1018 bool LayerTreeHost::RequestPartialTextureUpdate() { 1039 bool LayerTreeHost::RequestPartialTextureUpdate() {
1019 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates) 1040 if (partial_texture_update_requests_ >= settings_.max_partial_texture_updates)
1020 return false; 1041 return false;
1021 1042
1022 partial_texture_update_requests_++; 1043 partial_texture_update_requests_++;
1023 return true; 1044 return true;
1024 } 1045 }
1025 1046
1026 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { 1047 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) {
1027 if (device_scale_factor == device_scale_factor_) 1048 if (device_scale_factor == device_scale_factor_)
1028 return; 1049 return;
1029 device_scale_factor_ = device_scale_factor; 1050 device_scale_factor_ = device_scale_factor;
1030 1051
1031 SetNeedsCommit(); 1052 SetNeedsCommit();
1032 } 1053 }
1033 1054
1034 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 1055 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
1035 TopControlsState current, 1056 TopControlsState current,
1036 bool animate) { 1057 bool animate) {
1037 if (!settings_.calculate_top_controls_position) 1058 if (!settings_.calculate_top_controls_position)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 animation_registrar_->active_animation_controllers(); 1094 animation_registrar_->active_animation_controllers();
1074 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); 1095 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
1075 iter != copy.end(); 1096 iter != copy.end();
1076 ++iter) { 1097 ++iter) {
1077 (*iter).second->Animate(monotonic_time); 1098 (*iter).second->Animate(monotonic_time);
1078 bool start_ready_animations = true; 1099 bool start_ready_animations = true;
1079 (*iter).second->UpdateState(start_ready_animations, NULL); 1100 (*iter).second->UpdateState(start_ready_animations, NULL);
1080 } 1101 }
1081 } 1102 }
1082 1103
1104 UIResourceId LayerTreeHost::CreateUIResource(
1105 const UIResourceCallback& bitmap_cb) {
1106 UIResourceRequest request;
1107 bool resource_lost = false;
1108 request.type = UIResourceCreate;
1109 request.id = ui_resource_id_++;
1110
1111 DCHECK(ui_resource_client_map_.find(request.id) ==
1112 ui_resource_client_map_.end());
1113
1114 request.bitmap = bitmap_cb.Run(resource_lost);
1115 ui_resource_request_queue_.push_back(request);
1116 ui_resource_client_map_[request.id] = bitmap_cb;
1117 return request.id;
1118 }
1119
1120 // Deletes a UI resource. May safely be called more than once.
1121 void LayerTreeHost::DeleteUIResource(UIResourceId uid) {
1122 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1123 if (iter != ui_resource_client_map_.end()) {
1124 UIResourceRequest request;
1125 request.type = UIResourceDelete;
1126 request.id = uid;
1127 ui_resource_request_queue_.push_back(request);
1128 ui_resource_client_map_.erase(uid);
1129 }
1130 }
1131
1132 void LayerTreeHost::UIResourceLost(UIResourceId uid) {
1133 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
1134 if (iter != ui_resource_client_map_.end()) {
1135 UIResourceRequest request;
1136 bool resource_lost = true;
1137 request.type = UIResourceCreate;
1138 request.id = uid;
1139 request.bitmap = iter->second.Run(resource_lost);
1140 ui_resource_request_queue_.push_back(request);
1141 }
1142 }
1143
1083 } // namespace cc 1144 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698