Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "services/ui/launcher/launcher_view_tree.h" | |
| 7 | |
| 8 namespace launcher { | |
| 9 | |
| 10 LauncherViewTree::LauncherViewTree(mojo::ApplicationImpl* app_impl, | |
| 11 mojo::DisplayPtr display, | |
| 12 mojo::ViewportMetricsPtr viewport_metrics) | |
| 13 : display_(display.Pass()), | |
| 14 viewport_metrics_(viewport_metrics.Pass()), | |
| 15 binding_(this), | |
| 16 root_key_(0), | |
| 17 frame_scheduled_(false), | |
| 18 frame_pending_(false) { | |
| 19 app_impl->ConnectToService("mojo:view_manager_service", &view_manager_); | |
| 20 view_manager_.set_connection_error_handler(base::Bind( | |
| 21 &LauncherViewTree::OnViewManagerConnectionError, base::Unretained(this))); | |
| 22 | |
| 23 mojo::ui::ViewTreePtr view_tree; | |
| 24 binding_.Bind(mojo::GetProxy(&view_tree)); | |
| 25 view_manager_->RegisterViewTree( | |
| 26 view_tree.Pass(), mojo::GetProxy(&view_tree_host_), | |
| 27 base::Bind(&LauncherViewTree::OnViewTreeRegistered, | |
| 28 base::Unretained(this))); | |
| 29 | |
| 30 ScheduleFrame(); | |
| 31 } | |
| 32 | |
| 33 LauncherViewTree::~LauncherViewTree() {} | |
| 34 | |
| 35 void LauncherViewTree::SetRoot(mojo::ui::ViewTokenPtr token) { | |
| 36 root_ = token.Pass(); | |
| 37 if (root_.get()) | |
|
jamesr
2015/10/26 20:13:25
StructPtr types have appropriate bool conversions,
jeffbrown
2015/10/27 02:05:03
Done.
| |
| 38 view_tree_host_->SetRoot(++root_key_, root_.Clone()); | |
| 39 else | |
| 40 view_tree_host_->ResetRoot(); | |
| 41 root_layout_info_.reset(); | |
| 42 } | |
| 43 | |
| 44 void LauncherViewTree::SetViewportMetrics( | |
| 45 mojo::ViewportMetricsPtr viewport_metrics) { | |
| 46 viewport_metrics_ = viewport_metrics.Pass(); | |
| 47 view_tree_host_->RequestLayout(); | |
| 48 } | |
| 49 | |
| 50 void LauncherViewTree::DispatchEvent(mojo::EventPtr event) { | |
| 51 // TODO(jeffbrown): Support input dispatch. | |
| 52 } | |
| 53 | |
| 54 void LauncherViewTree::OnViewManagerConnectionError() { | |
| 55 LOG(ERROR) << "View manager connection error."; | |
| 56 } | |
| 57 | |
| 58 void LauncherViewTree::OnViewTreeRegistered() {} | |
| 59 | |
| 60 void LauncherViewTree::OnLayout(const OnLayoutCallback& callback) { | |
| 61 LayoutRoot(); | |
| 62 callback.Run(); | |
| 63 } | |
| 64 | |
| 65 void LauncherViewTree::OnRootUnavailable( | |
| 66 uint32_t root_key, | |
| 67 const OnRootUnavailableCallback& callback) { | |
| 68 if (root_key_ == root_key) { | |
| 69 LOG(ERROR) << "Root view terminated unexpectedly."; | |
| 70 SetRoot(mojo::ui::ViewTokenPtr()); | |
|
abarth
2015/10/24 06:07:21
Should we terminate the launcher in this case?
jeffbrown
2015/10/27 02:05:03
Probably. I'll leave a TODO.
Shutdown in Mojo is
| |
| 71 } | |
| 72 callback.Run(); | |
| 73 } | |
| 74 | |
| 75 void LauncherViewTree::LayoutRoot() { | |
| 76 if (!root_.get()) | |
|
jamesr
2015/10/26 20:13:25
if (!root_)
jeffbrown
2015/10/27 02:05:03
Done.
| |
| 77 return; | |
| 78 | |
| 79 auto params = mojo::ui::ViewLayoutParams::New(); | |
| 80 params->constraints = mojo::ui::BoxConstraints::New(); | |
| 81 params->constraints->min_width = viewport_metrics_->size->width; | |
| 82 params->constraints->max_width = viewport_metrics_->size->width; | |
| 83 params->constraints->min_height = viewport_metrics_->size->height; | |
| 84 params->constraints->max_height = viewport_metrics_->size->height; | |
| 85 params->device_pixel_ratio = viewport_metrics_->device_pixel_ratio; | |
| 86 view_tree_host_->LayoutRoot( | |
| 87 params.Pass(), true /*provide_size*/, | |
|
jamesr
2015/10/26 20:13:24
maybe this should be an enum
jeffbrown
2015/10/27 02:05:03
I'm going to remove it for now. Layout needs a lo
| |
| 88 base::Bind(&LauncherViewTree::OnLayoutResult, base::Unretained(this))); | |
| 89 } | |
| 90 | |
| 91 void LauncherViewTree::OnLayoutResult(mojo::ui::ViewLayoutInfoPtr info) { | |
| 92 if (!info.get()) { | |
| 93 DVLOG(1) << "Root layout: <stale>"; | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 DVLOG(1) << "Root layout: size.width=" << info->size->width | |
| 98 << ", size.height=" << info->size->height | |
| 99 << ", surface_id.id_namespace=" << info->surface_id->id_namespace | |
| 100 << ", surface_id.local=" << info->surface_id->local; | |
| 101 | |
| 102 root_layout_info_ = info.Pass(); | |
| 103 ScheduleFrame(); | |
| 104 } | |
| 105 | |
| 106 void LauncherViewTree::ScheduleFrame() { | |
| 107 frame_scheduled_ = true; | |
| 108 FinishFrame(); | |
| 109 } | |
| 110 | |
| 111 void LauncherViewTree::FinishFrame() { | |
| 112 if (!frame_scheduled_ || frame_pending_) | |
| 113 return; | |
| 114 frame_scheduled_ = false; | |
| 115 | |
| 116 mojo::FramePtr frame = mojo::Frame::New(); | |
| 117 frame->resources.resize(0u); | |
| 118 | |
| 119 mojo::Rect bounds; | |
| 120 bounds.width = viewport_metrics_->size->width; | |
| 121 bounds.height = viewport_metrics_->size->height; | |
| 122 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | |
| 123 pass->shared_quad_states.push_back( | |
| 124 mojo::CreateDefaultSQS(*viewport_metrics_->size)); | |
| 125 | |
| 126 mojo::QuadPtr quad = mojo::Quad::New(); | |
| 127 quad->rect = bounds.Clone(); | |
| 128 quad->opaque_rect = bounds.Clone(); | |
| 129 quad->visible_rect = bounds.Clone(); | |
| 130 quad->shared_quad_state_index = 0u; | |
| 131 | |
| 132 if (root_layout_info_.get()) { | |
| 133 quad->material = mojo::Material::SURFACE_CONTENT; | |
| 134 quad->surface_quad_state = mojo::SurfaceQuadState::New(); | |
| 135 quad->surface_quad_state->surface = root_layout_info_->surface_id.Clone(); | |
| 136 } else { | |
| 137 quad->material = mojo::Material::SOLID_COLOR; | |
| 138 quad->solid_color_quad_state = mojo::SolidColorQuadState::New(); | |
| 139 quad->solid_color_quad_state->color = mojo::Color::New(); | |
| 140 quad->solid_color_quad_state->color->rgba = 0xffff0000; | |
| 141 } | |
| 142 | |
| 143 pass->quads.push_back(quad.Pass()); | |
| 144 frame->passes.push_back(pass.Pass()); | |
| 145 | |
| 146 frame_pending_ = true; | |
| 147 display_->SubmitFrame( | |
| 148 frame.Pass(), | |
| 149 base::Bind(&LauncherViewTree::OnFrameSubmitted, base::Unretained(this))); | |
| 150 } | |
| 151 | |
| 152 void LauncherViewTree::OnFrameSubmitted() { | |
| 153 DCHECK(frame_pending_); | |
| 154 frame_pending_ = false; | |
| 155 FinishFrame(); | |
| 156 } | |
| 157 | |
| 158 } // namespace launcher | |
| OLD | NEW |