OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 | 7 |
| 8 #include "base/bind.h" |
8 #include "mojo/aura/screen_mojo.h" | 9 #include "mojo/aura/screen_mojo.h" |
9 #include "mojo/aura/window_tree_host_mojo.h" | 10 #include "mojo/examples/aura_demo/context_factory_view_manager.h" |
| 11 #include "mojo/examples/aura_demo/window_tree_host_view_manager.h" |
10 #include "mojo/public/cpp/application/application.h" | 12 #include "mojo/public/cpp/application/application.h" |
11 #include "mojo/public/cpp/gles2/gles2.h" | |
12 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
14 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 15 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
15 #include "ui/aura/client/default_capture_client.h" | 17 #include "ui/aura/client/default_capture_client.h" |
16 #include "ui/aura/client/window_tree_client.h" | 18 #include "ui/aura/client/window_tree_client.h" |
17 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
20 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
21 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
22 | 24 |
23 namespace mojo { | 25 namespace mojo { |
24 namespace examples { | 26 namespace examples { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 canvas->DrawColor(color_, SkXfermode::kSrc_Mode); | 58 canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
57 } | 59 } |
58 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} | 60 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
59 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} | 61 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} |
60 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} | 62 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} |
61 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} | 63 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
62 virtual bool HasHitTestMask() const OVERRIDE { return false; } | 64 virtual bool HasHitTestMask() const OVERRIDE { return false; } |
63 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | 65 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
64 | 66 |
65 private: | 67 private: |
66 SkColor color_; | 68 const SkColor color_; |
67 | 69 |
68 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
69 }; | 71 }; |
70 | 72 |
71 class DemoWindowTreeClient : public aura::client::WindowTreeClient { | 73 class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
72 public: | 74 public: |
73 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { | 75 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
74 aura::client::SetWindowTreeClient(window_, this); | 76 aura::client::SetWindowTreeClient(window_, this); |
75 } | 77 } |
76 | 78 |
(...skipping 12 matching lines...) Expand all Loading... |
89 return window_; | 91 return window_; |
90 } | 92 } |
91 | 93 |
92 private: | 94 private: |
93 aura::Window* window_; | 95 aura::Window* window_; |
94 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 96 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
95 | 97 |
96 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); | 98 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
97 }; | 99 }; |
98 | 100 |
| 101 class AuraDemo; |
| 102 |
| 103 // Trivial IViewManagerClient implementation. Forwards to AuraDemo when |
| 104 // connection established. |
| 105 class IViewManagerClientImpl |
| 106 : public InterfaceImpl<view_manager::IViewManagerClient> { |
| 107 public: |
| 108 explicit IViewManagerClientImpl(AuraDemo* aura_demo) |
| 109 : aura_demo_(aura_demo) {} |
| 110 virtual ~IViewManagerClientImpl() {} |
| 111 |
| 112 private: |
| 113 void OnResult(bool result) { |
| 114 VLOG(1) << "IViewManagerClientImpl::::OnResult result=" << result; |
| 115 DCHECK(result); |
| 116 } |
| 117 |
| 118 // IViewManagerClient: |
| 119 virtual void OnViewManagerConnectionEstablished( |
| 120 uint16_t connection_id, |
| 121 uint32_t next_server_change_id, |
| 122 mojo::Array<view_manager::INodePtr> nodes) OVERRIDE; |
| 123 virtual void OnServerChangeIdAdvanced( |
| 124 uint32_t next_server_change_id) OVERRIDE { |
| 125 } |
| 126 virtual void OnNodeBoundsChanged(uint32_t node, |
| 127 mojo::RectPtr old_bounds, |
| 128 mojo::RectPtr new_bounds) OVERRIDE { |
| 129 } |
| 130 virtual void OnNodeHierarchyChanged( |
| 131 uint32_t node, |
| 132 uint32_t new_parent, |
| 133 uint32_t old_parent, |
| 134 uint32_t server_change_id, |
| 135 mojo::Array<view_manager::INodePtr> nodes) OVERRIDE { |
| 136 } |
| 137 virtual void OnNodeDeleted(uint32_t node, uint32_t server_change_id) |
| 138 OVERRIDE { |
| 139 } |
| 140 virtual void OnNodeViewReplaced(uint32_t node, |
| 141 uint32_t new_view_id, |
| 142 uint32_t old_view_id) OVERRIDE { |
| 143 } |
| 144 virtual void OnViewDeleted(uint32_t view) OVERRIDE { |
| 145 } |
| 146 |
| 147 AuraDemo* aura_demo_; |
| 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(IViewManagerClientImpl); |
| 150 }; |
| 151 |
99 class AuraDemo : public Application { | 152 class AuraDemo : public Application { |
100 public: | 153 public: |
101 AuraDemo() {} | 154 AuraDemo() { |
| 155 AddService<IViewManagerClientImpl>(this); |
| 156 } |
102 virtual ~AuraDemo() {} | 157 virtual ~AuraDemo() {} |
103 | 158 |
104 virtual void Initialize() OVERRIDE { | 159 void SetRoot(view_manager::IViewManager* view_manager, uint32_t node_id) { |
| 160 context_factory_.reset( |
| 161 new ContextFactoryViewManager(view_manager, node_id)); |
105 aura::Env::CreateInstance(true); | 162 aura::Env::CreateInstance(true); |
| 163 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); |
106 screen_.reset(ScreenMojo::Create()); | 164 screen_.reset(ScreenMojo::Create()); |
107 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 165 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
108 | 166 |
109 NativeViewportPtr native_viewport; | 167 window_tree_host_.reset(new WindowTreeHostViewManager(gfx::Rect(800, 600))); |
110 ConnectTo("mojo:mojo_native_viewport_service", &native_viewport); | |
111 | |
112 window_tree_host_.reset(new WindowTreeHostMojo( | |
113 native_viewport.Pass(), | |
114 gfx::Rect(800, 600), | |
115 base::Bind(&AuraDemo::HostContextCreated, base::Unretained(this)))); | |
116 } | |
117 | |
118 private: | |
119 void HostContextCreated() { | |
120 window_tree_host_->InitHost(); | 168 window_tree_host_->InitHost(); |
121 | 169 |
122 window_tree_client_.reset( | 170 window_tree_client_.reset( |
123 new DemoWindowTreeClient(window_tree_host_->window())); | 171 new DemoWindowTreeClient(window_tree_host_->window())); |
124 | 172 |
125 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); | 173 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); |
126 window1_ = new aura::Window(delegate1_.get()); | 174 window1_ = new aura::Window(delegate1_.get()); |
127 window1_->Init(aura::WINDOW_LAYER_TEXTURED); | 175 window1_->Init(aura::WINDOW_LAYER_TEXTURED); |
128 window1_->SetBounds(gfx::Rect(100, 100, 400, 400)); | 176 window1_->SetBounds(gfx::Rect(100, 100, 400, 400)); |
129 window1_->Show(); | 177 window1_->Show(); |
130 window_tree_host_->window()->AddChild(window1_); | 178 window_tree_host_->window()->AddChild(window1_); |
131 | 179 |
132 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED)); | 180 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED)); |
133 window2_ = new aura::Window(delegate2_.get()); | 181 window2_ = new aura::Window(delegate2_.get()); |
134 window2_->Init(aura::WINDOW_LAYER_TEXTURED); | 182 window2_->Init(aura::WINDOW_LAYER_TEXTURED); |
135 window2_->SetBounds(gfx::Rect(200, 200, 350, 350)); | 183 window2_->SetBounds(gfx::Rect(200, 200, 350, 350)); |
136 window2_->Show(); | 184 window2_->Show(); |
137 window_tree_host_->window()->AddChild(window2_); | 185 window_tree_host_->window()->AddChild(window2_); |
138 | 186 |
139 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); | 187 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); |
140 window21_ = new aura::Window(delegate21_.get()); | 188 window21_ = new aura::Window(delegate21_.get()); |
141 window21_->Init(aura::WINDOW_LAYER_TEXTURED); | 189 window21_->Init(aura::WINDOW_LAYER_TEXTURED); |
142 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); | 190 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); |
143 window21_->Show(); | 191 window21_->Show(); |
144 window2_->AddChild(window21_); | 192 window2_->AddChild(window21_); |
145 | 193 |
146 window_tree_host_->Show(); | 194 window_tree_host_->Show(); |
147 } | 195 } |
148 | 196 |
149 mojo::GLES2Initializer gles2; | 197 virtual void Initialize() OVERRIDE { |
| 198 } |
| 199 |
| 200 scoped_ptr<ContextFactoryViewManager> context_factory_; |
| 201 |
150 scoped_ptr<ScreenMojo> screen_; | 202 scoped_ptr<ScreenMojo> screen_; |
151 | 203 |
152 scoped_ptr<DemoWindowTreeClient> window_tree_client_; | 204 scoped_ptr<DemoWindowTreeClient> window_tree_client_; |
153 | 205 |
154 scoped_ptr<DemoWindowDelegate> delegate1_; | 206 scoped_ptr<DemoWindowDelegate> delegate1_; |
155 scoped_ptr<DemoWindowDelegate> delegate2_; | 207 scoped_ptr<DemoWindowDelegate> delegate2_; |
156 scoped_ptr<DemoWindowDelegate> delegate21_; | 208 scoped_ptr<DemoWindowDelegate> delegate21_; |
157 | 209 |
158 aura::Window* window1_; | 210 aura::Window* window1_; |
159 aura::Window* window2_; | 211 aura::Window* window2_; |
160 aura::Window* window21_; | 212 aura::Window* window21_; |
161 | 213 |
162 scoped_ptr<aura::WindowTreeHost> window_tree_host_; | 214 scoped_ptr<aura::WindowTreeHost> window_tree_host_; |
163 | 215 |
164 DISALLOW_COPY_AND_ASSIGN(AuraDemo); | 216 DISALLOW_COPY_AND_ASSIGN(AuraDemo); |
165 }; | 217 }; |
166 | 218 |
| 219 void IViewManagerClientImpl::OnViewManagerConnectionEstablished( |
| 220 uint16_t connection_id, |
| 221 uint32_t next_server_change_id, |
| 222 mojo::Array<view_manager::INodePtr> nodes) { |
| 223 const uint32_t view_id = connection_id << 16 | 1; |
| 224 client()->CreateView(view_id, base::Bind(&IViewManagerClientImpl::OnResult, |
| 225 base::Unretained(this))); |
| 226 client()->SetView(nodes[0]->node_id, view_id, |
| 227 base::Bind(&IViewManagerClientImpl::OnResult, |
| 228 base::Unretained(this))); |
| 229 |
| 230 aura_demo_->SetRoot(client(), view_id); |
| 231 } |
| 232 |
167 } // namespace examples | 233 } // namespace examples |
168 | 234 |
169 // static | 235 // static |
170 Application* Application::Create() { | 236 Application* Application::Create() { |
171 return new examples::AuraDemo(); | 237 return new examples::AuraDemo(); |
172 } | 238 } |
173 | 239 |
174 } // namespace mojo | 240 } // namespace mojo |
175 | 241 |
OLD | NEW |