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

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

Issue 2322943003: cc: Move UI Resource management out of LayerTreeHost. (Closed)
Patch Set: format Created 4 years, 3 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 30 matching lines...) Expand all
41 #include "cc/input/page_scale_animation.h" 41 #include "cc/input/page_scale_animation.h"
42 #include "cc/layers/heads_up_display_layer.h" 42 #include "cc/layers/heads_up_display_layer.h"
43 #include "cc/layers/heads_up_display_layer_impl.h" 43 #include "cc/layers/heads_up_display_layer_impl.h"
44 #include "cc/layers/layer.h" 44 #include "cc/layers/layer.h"
45 #include "cc/layers/layer_iterator.h" 45 #include "cc/layers/layer_iterator.h"
46 #include "cc/layers/layer_proto_converter.h" 46 #include "cc/layers/layer_proto_converter.h"
47 #include "cc/layers/painted_scrollbar_layer.h" 47 #include "cc/layers/painted_scrollbar_layer.h"
48 #include "cc/proto/gfx_conversions.h" 48 #include "cc/proto/gfx_conversions.h"
49 #include "cc/proto/layer_tree.pb.h" 49 #include "cc/proto/layer_tree.pb.h"
50 #include "cc/proto/layer_tree_host.pb.h" 50 #include "cc/proto/layer_tree_host.pb.h"
51 #include "cc/resources/ui_resource_request.h" 51 #include "cc/resources/ui_resource_manager.h"
52 #include "cc/scheduler/begin_frame_source.h" 52 #include "cc/scheduler/begin_frame_source.h"
53 #include "cc/trees/draw_property_utils.h" 53 #include "cc/trees/draw_property_utils.h"
54 #include "cc/trees/layer_tree_host_client.h" 54 #include "cc/trees/layer_tree_host_client.h"
55 #include "cc/trees/layer_tree_host_common.h" 55 #include "cc/trees/layer_tree_host_common.h"
56 #include "cc/trees/layer_tree_host_impl.h" 56 #include "cc/trees/layer_tree_host_impl.h"
57 #include "cc/trees/layer_tree_impl.h" 57 #include "cc/trees/layer_tree_impl.h"
58 #include "cc/trees/property_tree_builder.h" 58 #include "cc/trees/property_tree_builder.h"
59 #include "cc/trees/proxy_main.h" 59 #include "cc/trees/proxy_main.h"
60 #include "cc/trees/remote_channel_impl.h" 60 #include "cc/trees/remote_channel_impl.h"
61 #include "cc/trees/single_thread_proxy.h" 61 #include "cc/trees/single_thread_proxy.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(impl_task_runner.get()); 136 DCHECK(impl_task_runner.get());
137 DCHECK(params->settings); 137 DCHECK(params->settings);
138 std::unique_ptr<LayerTreeHost> layer_tree_host( 138 std::unique_ptr<LayerTreeHost> layer_tree_host(
139 new LayerTreeHost(params, CompositorMode::THREADED)); 139 new LayerTreeHost(params, CompositorMode::THREADED));
140 layer_tree_host->InitializeThreaded( 140 layer_tree_host->InitializeThreaded(
141 params->main_task_runner, impl_task_runner, 141 params->main_task_runner, impl_task_runner,
142 std::move(params->external_begin_frame_source)); 142 std::move(params->external_begin_frame_source));
143 return std::move(layer_tree_host); 143 return std::move(layer_tree_host);
144 } 144 }
145 145
146 std::unique_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded( 146 std::unique_ptr<LayerTreeHostInterface> LayerTreeHost::CreateSingleThreaded(
147 LayerTreeHostSingleThreadClient* single_thread_client, 147 LayerTreeHostSingleThreadClient* single_thread_client,
148 InitParams* params) { 148 InitParams* params) {
149 DCHECK(params->settings); 149 DCHECK(params->settings);
150 std::unique_ptr<LayerTreeHost> layer_tree_host( 150 std::unique_ptr<LayerTreeHost> layer_tree_host(
151 new LayerTreeHost(params, CompositorMode::SINGLE_THREADED)); 151 new LayerTreeHost(params, CompositorMode::SINGLE_THREADED));
152 layer_tree_host->InitializeSingleThreaded( 152 layer_tree_host->InitializeSingleThreaded(
153 single_thread_client, params->main_task_runner, 153 single_thread_client, params->main_task_runner,
154 std::move(params->external_begin_frame_source)); 154 std::move(params->external_begin_frame_source));
155 return layer_tree_host; 155 return std::move(layer_tree_host);
156 } 156 }
157 157
158 std::unique_ptr<LayerTreeHostInterface> LayerTreeHost::CreateRemoteServer( 158 std::unique_ptr<LayerTreeHostInterface> LayerTreeHost::CreateRemoteServer(
159 RemoteProtoChannel* remote_proto_channel, 159 RemoteProtoChannel* remote_proto_channel,
160 InitParams* params) { 160 InitParams* params) {
161 DCHECK(params->main_task_runner.get()); 161 DCHECK(params->main_task_runner.get());
162 DCHECK(params->settings); 162 DCHECK(params->settings);
163 DCHECK(remote_proto_channel); 163 DCHECK(remote_proto_channel);
164 TRACE_EVENT0("cc.remote", "LayerTreeHost::CreateRemoteServer"); 164 TRACE_EVENT0("cc.remote", "LayerTreeHost::CreateRemoteServer");
165 165
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 params, 203 params,
204 mode, 204 mode,
205 base::MakeUnique<LayerTree>(std::move(params->animation_host), 205 base::MakeUnique<LayerTree>(std::move(params->animation_host),
206 this)) {} 206 this)) {}
207 207
208 LayerTreeHost::LayerTreeHost(InitParams* params, 208 LayerTreeHost::LayerTreeHost(InitParams* params,
209 CompositorMode mode, 209 CompositorMode mode,
210 std::unique_ptr<LayerTree> layer_tree) 210 std::unique_ptr<LayerTree> layer_tree)
211 : micro_benchmark_controller_(this), 211 : micro_benchmark_controller_(this),
212 layer_tree_(std::move(layer_tree)), 212 layer_tree_(std::move(layer_tree)),
213 next_ui_resource_id_(1),
214 compositor_mode_(mode), 213 compositor_mode_(mode),
214 ui_resource_manager_(base::MakeUnique<UIResourceManager>()),
215 client_(params->client), 215 client_(params->client),
216 source_frame_number_(0), 216 source_frame_number_(0),
217 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), 217 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
218 settings_(*params->settings), 218 settings_(*params->settings),
219 debug_state_(settings_.initial_debug_state), 219 debug_state_(settings_.initial_debug_state),
220 visible_(false), 220 visible_(false),
221 has_gpu_rasterization_trigger_(false), 221 has_gpu_rasterization_trigger_(false),
222 content_is_suitable_for_gpu_rasterization_(true), 222 content_is_suitable_for_gpu_rasterization_(true),
223 gpu_rasterization_histogram_recorded_(false), 223 gpu_rasterization_histogram_recorded_(false),
224 did_complete_scale_animation_(false), 224 did_complete_scale_animation_(false),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 client_picture_cache_ = 319 client_picture_cache_ =
320 image_serialization_processor_->CreateClientPictureCache(); 320 image_serialization_processor_->CreateClientPictureCache();
321 } 321 }
322 322
323 void LayerTreeHost::SetTaskRunnerProviderForTesting( 323 void LayerTreeHost::SetTaskRunnerProviderForTesting(
324 std::unique_ptr<TaskRunnerProvider> task_runner_provider) { 324 std::unique_ptr<TaskRunnerProvider> task_runner_provider) {
325 DCHECK(!task_runner_provider_); 325 DCHECK(!task_runner_provider_);
326 task_runner_provider_ = std::move(task_runner_provider); 326 task_runner_provider_ = std::move(task_runner_provider);
327 } 327 }
328 328
329 void LayerTreeHost::SetUIResourceManagerForTesting(
330 std::unique_ptr<UIResourceManager> ui_resource_manager) {
331 ui_resource_manager_ = std::move(ui_resource_manager);
332 }
333
329 void LayerTreeHost::InitializeProxy( 334 void LayerTreeHost::InitializeProxy(
330 std::unique_ptr<Proxy> proxy, 335 std::unique_ptr<Proxy> proxy,
331 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { 336 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
332 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 337 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
333 DCHECK(task_runner_provider_); 338 DCHECK(task_runner_provider_);
334 339
335 proxy_ = std::move(proxy); 340 proxy_ = std::move(proxy);
336 proxy_->Start(std::move(external_begin_frame_source)); 341 proxy_->Start(std::move(external_begin_frame_source));
337 342
338 layer_tree_->animation_host()->SetSupportsScrollAnimations( 343 layer_tree_->animation_host()->SetSupportsScrollAnimations(
(...skipping 28 matching lines...) Expand all
367 } 372 }
368 373
369 LayerTree* LayerTreeHost::GetLayerTree() { 374 LayerTree* LayerTreeHost::GetLayerTree() {
370 return layer_tree_.get(); 375 return layer_tree_.get();
371 } 376 }
372 377
373 const LayerTree* LayerTreeHost::GetLayerTree() const { 378 const LayerTree* LayerTreeHost::GetLayerTree() const {
374 return layer_tree_.get(); 379 return layer_tree_.get();
375 } 380 }
376 381
382 UIResourceManager* LayerTreeHost::GetUIResourceManager() const {
383 return ui_resource_manager_.get();
384 }
385
377 TaskRunnerProvider* LayerTreeHost::GetTaskRunnerProvider() const { 386 TaskRunnerProvider* LayerTreeHost::GetTaskRunnerProvider() const {
378 return task_runner_provider_.get(); 387 return task_runner_provider_.get();
379 } 388 }
380 389
381 const LayerTreeSettings& LayerTreeHost::GetSettings() const { 390 const LayerTreeSettings& LayerTreeHost::GetSettings() const {
382 return settings_; 391 return settings_;
383 } 392 }
384 393
385 void LayerTreeHost::WillBeginMainFrame() { 394 void LayerTreeHost::WillBeginMainFrame() {
386 devtools_instrumentation::WillBeginMainThreadFrame(GetId(), 395 devtools_instrumentation::WillBeginMainThreadFrame(GetId(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 RecordGpuRasterizationHistogram(); 462 RecordGpuRasterizationHistogram();
454 463
455 host_impl->SetViewportSize(layer_tree_->device_viewport_size()); 464 host_impl->SetViewportSize(layer_tree_->device_viewport_size());
456 // TODO(senorblanco): Move this to LayerTree::PushPropertiesTo so that it 465 // TODO(senorblanco): Move this to LayerTree::PushPropertiesTo so that it
457 // happens before GPU rasterization properties are set, since those trigger an 466 // happens before GPU rasterization properties are set, since those trigger an
458 // update of GPU rasterization status, which depends on the device scale 467 // update of GPU rasterization status, which depends on the device scale
459 // factor. (crbug.com/535700) 468 // factor. (crbug.com/535700)
460 sync_tree->SetDeviceScaleFactor(layer_tree_->device_scale_factor()); 469 sync_tree->SetDeviceScaleFactor(layer_tree_->device_scale_factor());
461 host_impl->SetDebugState(debug_state_); 470 host_impl->SetDebugState(debug_state_);
462 471
463 if (!ui_resource_request_queue_.empty()) { 472 std::vector<UIResourceRequest> ui_resource_request_queue =
464 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); 473 ui_resource_manager_->TakeUIResourcesRequests();
465 ui_resource_request_queue_.clear(); 474
475 if (!ui_resource_request_queue.empty()) {
476 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue);
danakj 2016/09/08 20:57:35 Why not just move the queue here? In fact why isnt
Khushal 2016/09/08 22:05:24 Much cooler. Done.
477 ui_resource_request_queue.clear();
466 } 478 }
467 479
468 { 480 {
469 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); 481 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
470 482
471 TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree); 483 TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree);
472 484
473 // This must happen after synchronizing property trees and after push 485 // This must happen after synchronizing property trees and after push
474 // properties, which updates property tree indices, but before animation 486 // properties, which updates property tree indices, but before animation
475 // host pushes properties as animation host push properties can change 487 // host pushes properties as animation host push properties can change
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 AnimationHost* animation_host = layer_tree_->animation_host(); 917 AnimationHost* animation_host = layer_tree_->animation_host();
906 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); 918 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents();
907 919
908 if (animation_host->AnimateLayers(monotonic_time)) 920 if (animation_host->AnimateLayers(monotonic_time))
909 animation_host->UpdateAnimationState(true, events.get()); 921 animation_host->UpdateAnimationState(true, events.get());
910 922
911 if (!events->events_.empty()) 923 if (!events->events_.empty())
912 layer_tree_->property_trees()->needs_rebuild = true; 924 layer_tree_->property_trees()->needs_rebuild = true;
913 } 925 }
914 926
915 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) {
916 DCHECK(client);
917
918 UIResourceId next_id = next_ui_resource_id_++;
919 DCHECK(ui_resource_client_map_.find(next_id) ==
920 ui_resource_client_map_.end());
921
922 bool resource_lost = false;
923 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_CREATE, next_id,
924 client->GetBitmap(next_id, resource_lost));
925 ui_resource_request_queue_.push_back(request);
926
927 UIResourceClientData data;
928 data.client = client;
929 data.size = request.GetBitmap().GetSize();
930
931 ui_resource_client_map_[request.GetId()] = data;
932 return request.GetId();
933 }
934
935 // Deletes a UI resource. May safely be called more than once.
936 void LayerTreeHost::DeleteUIResource(UIResourceId uid) {
937 UIResourceClientMap::iterator iter = ui_resource_client_map_.find(uid);
938 if (iter == ui_resource_client_map_.end())
939 return;
940
941 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_DELETE, uid);
942 ui_resource_request_queue_.push_back(request);
943 ui_resource_client_map_.erase(iter);
944 }
945
946 void LayerTreeHost::RecreateUIResources() {
947 for (UIResourceClientMap::iterator iter = ui_resource_client_map_.begin();
948 iter != ui_resource_client_map_.end();
949 ++iter) {
950 UIResourceId uid = iter->first;
951 const UIResourceClientData& data = iter->second;
952 bool resource_lost = true;
953 auto it = std::find_if(ui_resource_request_queue_.begin(),
954 ui_resource_request_queue_.end(),
955 [uid](const UIResourceRequest& request) {
956 return request.GetId() == uid;
957 });
958 if (it == ui_resource_request_queue_.end()) {
959 UIResourceRequest request(UIResourceRequest::UI_RESOURCE_CREATE, uid,
960 data.client->GetBitmap(uid, resource_lost));
961 ui_resource_request_queue_.push_back(request);
962 }
963 }
964 }
965
966 // Returns the size of a resource given its id.
967 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const {
968 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid);
969 if (iter == ui_resource_client_map_.end())
970 return gfx::Size();
971
972 const UIResourceClientData& data = iter->second;
973 return data.size;
974 }
975
976 int LayerTreeHost::ScheduleMicroBenchmark( 927 int LayerTreeHost::ScheduleMicroBenchmark(
977 const std::string& benchmark_name, 928 const std::string& benchmark_name,
978 std::unique_ptr<base::Value> value, 929 std::unique_ptr<base::Value> value,
979 const MicroBenchmark::DoneCallback& callback) { 930 const MicroBenchmark::DoneCallback& callback) {
980 return micro_benchmark_controller_.ScheduleRun(benchmark_name, 931 return micro_benchmark_controller_.ScheduleRun(benchmark_name,
981 std::move(value), callback); 932 std::move(value), callback);
982 } 933 }
983 934
984 bool LayerTreeHost::SendMessageToMicroBenchmark( 935 bool LayerTreeHost::SendMessageToMicroBenchmark(
985 int id, 936 int id,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 content_is_suitable_for_gpu_rasterization_ = 1093 content_is_suitable_for_gpu_rasterization_ =
1143 proto.content_is_suitable_for_gpu_rasterization(); 1094 proto.content_is_suitable_for_gpu_rasterization();
1144 id_ = proto.id(); 1095 id_ = proto.id();
1145 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); 1096 next_commit_forces_redraw_ = proto.next_commit_forces_redraw();
1146 1097
1147 surface_client_id_ = proto.surface_client_id(); 1098 surface_client_id_ = proto.surface_client_id();
1148 next_surface_sequence_ = proto.next_surface_sequence(); 1099 next_surface_sequence_ = proto.next_surface_sequence();
1149 } 1100 }
1150 1101
1151 } // namespace cc 1102 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698