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

Side by Side Diff: services/ui/launcher/launcher_view_tree.cc

Issue 1404423007: mozart: Initial commit of the launcher. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « services/ui/launcher/launcher_view_tree.h ('k') | services/ui/launcher/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_)
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 // TODO(jeffbrown): We should probably shut down the launcher.
70 LOG(ERROR) << "Root view terminated unexpectedly.";
71 SetRoot(mojo::ui::ViewTokenPtr());
72 }
73 callback.Run();
74 }
75
76 void LauncherViewTree::LayoutRoot() {
77 if (!root_)
78 return;
79
80 auto params = mojo::ui::ViewLayoutParams::New();
81 params->constraints = mojo::ui::BoxConstraints::New();
82 params->constraints->min_width = viewport_metrics_->size->width;
83 params->constraints->max_width = viewport_metrics_->size->width;
84 params->constraints->min_height = viewport_metrics_->size->height;
85 params->constraints->max_height = viewport_metrics_->size->height;
86 params->device_pixel_ratio = viewport_metrics_->device_pixel_ratio;
87 view_tree_host_->LayoutRoot(
88 params.Pass(),
89 base::Bind(&LauncherViewTree::OnLayoutResult, base::Unretained(this)));
90 }
91
92 void LauncherViewTree::OnLayoutResult(mojo::ui::ViewLayoutInfoPtr info) {
93 if (!info) {
94 DVLOG(1) << "Root layout: <stale>";
95 return;
96 }
97
98 DVLOG(1) << "Root layout: size.width=" << info->size->width
99 << ", size.height=" << info->size->height
100 << ", surface_id.id_namespace=" << info->surface_id->id_namespace
101 << ", surface_id.local=" << info->surface_id->local;
102
103 root_layout_info_ = info.Pass();
104 ScheduleFrame();
105 }
106
107 void LauncherViewTree::ScheduleFrame() {
108 frame_scheduled_ = true;
109 FinishFrame();
110 }
111
112 void LauncherViewTree::FinishFrame() {
113 if (!frame_scheduled_ || frame_pending_)
114 return;
115 frame_scheduled_ = false;
116
117 mojo::FramePtr frame = mojo::Frame::New();
118 frame->resources.resize(0u);
119
120 mojo::Rect bounds;
121 bounds.width = viewport_metrics_->size->width;
122 bounds.height = viewport_metrics_->size->height;
123 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds);
124 pass->shared_quad_states.push_back(
125 mojo::CreateDefaultSQS(*viewport_metrics_->size));
126
127 mojo::QuadPtr quad = mojo::Quad::New();
128 quad->rect = bounds.Clone();
129 quad->opaque_rect = bounds.Clone();
130 quad->visible_rect = bounds.Clone();
131 quad->shared_quad_state_index = 0u;
132
133 if (root_layout_info_) {
134 quad->material = mojo::Material::SURFACE_CONTENT;
135 quad->surface_quad_state = mojo::SurfaceQuadState::New();
136 quad->surface_quad_state->surface = root_layout_info_->surface_id.Clone();
137 } else {
138 quad->material = mojo::Material::SOLID_COLOR;
139 quad->solid_color_quad_state = mojo::SolidColorQuadState::New();
140 quad->solid_color_quad_state->color = mojo::Color::New();
141 quad->solid_color_quad_state->color->rgba = 0xffff0000;
142 }
143
144 pass->quads.push_back(quad.Pass());
145 frame->passes.push_back(pass.Pass());
146
147 frame_pending_ = true;
148 display_->SubmitFrame(
149 frame.Pass(),
150 base::Bind(&LauncherViewTree::OnFrameSubmitted, base::Unretained(this)));
151 }
152
153 void LauncherViewTree::OnFrameSubmitted() {
154 DCHECK(frame_pending_);
155 frame_pending_ = false;
156 FinishFrame();
157 }
158
159 } // namespace launcher
OLDNEW
« no previous file with comments | « services/ui/launcher/launcher_view_tree.h ('k') | services/ui/launcher/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698