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

Side by Side Diff: mojo/services/view_manager/display_manager.cc

Issue 513923004: More viewmanager renaming: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sim30 Created 6 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
« no previous file with comments | « mojo/services/view_manager/display_manager.h ('k') | mojo/services/view_manager/ids.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/services/view_manager/display_manager.h" 5 #include "mojo/services/view_manager/display_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 10 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
11 #include "mojo/services/view_manager/connection_manager.h"
11 #include "mojo/services/view_manager/display_manager_delegate.h" 12 #include "mojo/services/view_manager/display_manager_delegate.h"
12 #include "mojo/services/view_manager/root_node_manager.h"
13 #include "mojo/services/view_manager/screen_impl.h" 13 #include "mojo/services/view_manager/screen_impl.h"
14 #include "mojo/services/view_manager/window_tree_host_impl.h" 14 #include "mojo/services/view_manager/window_tree_host_impl.h"
15 #include "ui/aura/client/default_capture_client.h" 15 #include "ui/aura/client/default_capture_client.h"
16 #include "ui/aura/client/focus_client.h" 16 #include "ui/aura/client/focus_client.h"
17 #include "ui/aura/client/window_tree_client.h" 17 #include "ui/aura/client/window_tree_client.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/aura/window_delegate.h" 19 #include "ui/aura/window_delegate.h"
20 #include "ui/base/cursor/cursor.h" 20 #include "ui/base/cursor/cursor.h"
21 #include "ui/base/hit_test.h" 21 #include "ui/base/hit_test.h"
22 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
23 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
26 26
27 namespace mojo { 27 namespace mojo {
28 namespace service { 28 namespace service {
29 namespace { 29 namespace {
30 30
31 gfx::Rect ConvertRectToRoot(const Node* node, const gfx::Rect& bounds) { 31 gfx::Rect ConvertRectToRoot(const ServerView* view, const gfx::Rect& bounds) {
32 gfx::Point origin(bounds.origin()); 32 gfx::Point origin(bounds.origin());
33 while (node->parent()) { 33 while (view->parent()) {
34 origin += node->bounds().OffsetFromOrigin(); 34 origin += view->bounds().OffsetFromOrigin();
35 node = node->parent(); 35 view = view->parent();
36 } 36 }
37 return gfx::Rect(origin, bounds.size()); 37 return gfx::Rect(origin, bounds.size());
38 } 38 }
39 39
40 void PaintNodeTree(gfx::Canvas* canvas, 40 void PaintViewTree(gfx::Canvas* canvas,
41 const Node* node, 41 const ServerView* view,
42 const gfx::Point& origin) { 42 const gfx::Point& origin) {
43 if (!node->visible()) 43 if (!view->visible())
44 return; 44 return;
45 45
46 canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(node->bitmap()), 46 canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(view->bitmap()),
47 origin.x(), origin.y()); 47 origin.x(),
48 std::vector<const Node*> children(node->GetChildren()); 48 origin.y());
49 std::vector<const ServerView*> children(view->GetChildren());
49 for (size_t i = 0; i < children.size(); ++i) { 50 for (size_t i = 0; i < children.size(); ++i) {
50 PaintNodeTree(canvas, children[i], 51 PaintViewTree(
51 origin + children[i]->bounds().OffsetFromOrigin()); 52 canvas, children[i], origin + children[i]->bounds().OffsetFromOrigin());
52 } 53 }
53 } 54 }
54 55
55 } // namespace 56 } // namespace
56 57
57 class DisplayManager::RootWindowDelegateImpl : public aura::WindowDelegate { 58 class DisplayManager::RootWindowDelegateImpl : public aura::WindowDelegate {
58 public: 59 public:
59 explicit RootWindowDelegateImpl(const Node* root_node) 60 explicit RootWindowDelegateImpl(const ServerView* root_view)
60 : root_node_(root_node) {} 61 : root_view_(root_view) {}
61 virtual ~RootWindowDelegateImpl() {} 62 virtual ~RootWindowDelegateImpl() {}
62 63
63 // aura::WindowDelegate: 64 // aura::WindowDelegate:
64 virtual gfx::Size GetMinimumSize() const OVERRIDE { 65 virtual gfx::Size GetMinimumSize() const OVERRIDE {
65 return gfx::Size(); 66 return gfx::Size();
66 } 67 }
67 virtual gfx::Size GetMaximumSize() const OVERRIDE { 68 virtual gfx::Size GetMaximumSize() const OVERRIDE {
68 return gfx::Size(); 69 return gfx::Size();
69 } 70 }
70 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 71 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
71 const gfx::Rect& new_bounds) OVERRIDE { 72 const gfx::Rect& new_bounds) OVERRIDE {
72 } 73 }
73 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { 74 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
74 return gfx::kNullCursor; 75 return gfx::kNullCursor;
75 } 76 }
76 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { 77 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
77 return HTCAPTION; 78 return HTCAPTION;
78 } 79 }
79 virtual bool ShouldDescendIntoChildForEventHandling( 80 virtual bool ShouldDescendIntoChildForEventHandling(
80 aura::Window* child, 81 aura::Window* child,
81 const gfx::Point& location) OVERRIDE { 82 const gfx::Point& location) OVERRIDE {
82 return true; 83 return true;
83 } 84 }
84 virtual bool CanFocus() OVERRIDE { 85 virtual bool CanFocus() OVERRIDE {
85 return true; 86 return true;
86 } 87 }
87 virtual void OnCaptureLost() OVERRIDE { 88 virtual void OnCaptureLost() OVERRIDE {
88 } 89 }
89 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 90 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
90 PaintNodeTree(canvas, root_node_, gfx::Point()); 91 PaintViewTree(canvas, root_view_, gfx::Point());
91 } 92 }
92 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { 93 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
93 } 94 }
94 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 95 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
95 } 96 }
96 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { 97 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
97 } 98 }
98 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE { 99 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
99 } 100 }
100 virtual bool HasHitTestMask() const OVERRIDE { 101 virtual bool HasHitTestMask() const OVERRIDE {
101 return false; 102 return false;
102 } 103 }
103 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE { 104 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
104 } 105 }
105 106
106 private: 107 private:
107 const Node* root_node_; 108 const ServerView* root_view_;
108 109
109 DISALLOW_COPY_AND_ASSIGN(RootWindowDelegateImpl); 110 DISALLOW_COPY_AND_ASSIGN(RootWindowDelegateImpl);
110 }; 111 };
111 112
112 // TODO(sky): Remove once aura is removed from the service. 113 // TODO(sky): Remove once aura is removed from the service.
113 class FocusClientImpl : public aura::client::FocusClient { 114 class FocusClientImpl : public aura::client::FocusClient {
114 public: 115 public:
115 FocusClientImpl() {} 116 FocusClientImpl() {}
116 virtual ~FocusClientImpl() {} 117 virtual ~FocusClientImpl() {}
117 118
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 private: 153 private:
153 aura::Window* window_; 154 aura::Window* window_;
154 155
155 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; 156 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
156 157
157 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); 158 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl);
158 }; 159 };
159 160
160 DisplayManager::DisplayManager( 161 DisplayManager::DisplayManager(
161 ApplicationConnection* app_connection, 162 ApplicationConnection* app_connection,
162 RootNodeManager* root_node, 163 ConnectionManager* connection_manager,
163 DisplayManagerDelegate* delegate, 164 DisplayManagerDelegate* delegate,
164 const Callback<void()>& native_viewport_closed_callback) 165 const Callback<void()>& native_viewport_closed_callback)
165 : delegate_(delegate), 166 : delegate_(delegate),
166 root_node_manager_(root_node), 167 connection_manager_(connection_manager),
167 in_setup_(false), 168 in_setup_(false),
168 root_window_(NULL) { 169 root_window_(NULL) {
169 screen_.reset(ScreenImpl::Create()); 170 screen_.reset(ScreenImpl::Create());
170 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 171 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
171 NativeViewportPtr viewport; 172 NativeViewportPtr viewport;
172 app_connection->ConnectToService( 173 app_connection->ConnectToService(
173 "mojo:mojo_native_viewport_service", &viewport); 174 "mojo:mojo_native_viewport_service", &viewport);
174 GpuPtr gpu_service; 175 GpuPtr gpu_service;
175 // TODO(jamesr): Should be mojo:mojo_gpu_service 176 // TODO(jamesr): Should be mojo:mojo_gpu_service
176 app_connection->ConnectToService("mojo:mojo_native_viewport_service", 177 app_connection->ConnectToService("mojo:mojo_native_viewport_service",
177 &gpu_service); 178 &gpu_service);
178 window_tree_host_.reset(new WindowTreeHostImpl( 179 window_tree_host_.reset(new WindowTreeHostImpl(
179 viewport.Pass(), 180 viewport.Pass(),
180 gpu_service.Pass(), 181 gpu_service.Pass(),
181 gfx::Rect(800, 600), 182 gfx::Rect(800, 600),
182 base::Bind(&DisplayManager::OnCompositorCreated, base::Unretained(this)), 183 base::Bind(&DisplayManager::OnCompositorCreated, base::Unretained(this)),
183 native_viewport_closed_callback, 184 native_viewport_closed_callback,
184 base::Bind(&RootNodeManager::DispatchNodeInputEventToWindowManager, 185 base::Bind(&ConnectionManager::DispatchViewInputEventToWindowManager,
185 base::Unretained(root_node_manager_)))); 186 base::Unretained(connection_manager_))));
186 } 187 }
187 188
188 DisplayManager::~DisplayManager() { 189 DisplayManager::~DisplayManager() {
189 window_tree_client_.reset(); 190 window_tree_client_.reset();
190 window_tree_host_.reset(); 191 window_tree_host_.reset();
191 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); 192 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
192 } 193 }
193 194
194 void DisplayManager::SchedulePaint(const Node* node, const gfx::Rect& bounds) { 195 void DisplayManager::SchedulePaint(const ServerView* view,
196 const gfx::Rect& bounds) {
195 if (root_window_) 197 if (root_window_)
196 root_window_->SchedulePaintInRect(ConvertRectToRoot(node, bounds)); 198 root_window_->SchedulePaintInRect(ConvertRectToRoot(view, bounds));
197 } 199 }
198 200
199 void DisplayManager::OnCompositorCreated() { 201 void DisplayManager::OnCompositorCreated() {
200 base::AutoReset<bool> resetter(&in_setup_, true); 202 base::AutoReset<bool> resetter(&in_setup_, true);
201 window_tree_host_->InitHost(); 203 window_tree_host_->InitHost();
202 204
203 window_delegate_.reset( 205 window_delegate_.reset(
204 new RootWindowDelegateImpl(root_node_manager_->root())); 206 new RootWindowDelegateImpl(connection_manager_->root()));
205 root_window_ = new aura::Window(window_delegate_.get()); 207 root_window_ = new aura::Window(window_delegate_.get());
206 root_window_->Init(aura::WINDOW_LAYER_TEXTURED); 208 root_window_->Init(aura::WINDOW_LAYER_TEXTURED);
207 root_window_->Show(); 209 root_window_->Show();
208 root_window_->SetBounds( 210 root_window_->SetBounds(
209 gfx::Rect(window_tree_host_->window()->bounds().size())); 211 gfx::Rect(window_tree_host_->window()->bounds().size()));
210 window_tree_host_->window()->AddChild(root_window_); 212 window_tree_host_->window()->AddChild(root_window_);
211 213
212 root_node_manager_->root()->SetBounds( 214 connection_manager_->root()->SetBounds(
213 gfx::Rect(window_tree_host_->window()->bounds().size())); 215 gfx::Rect(window_tree_host_->window()->bounds().size()));
214 216
215 window_tree_client_.reset( 217 window_tree_client_.reset(
216 new WindowTreeClientImpl(window_tree_host_->window())); 218 new WindowTreeClientImpl(window_tree_host_->window()));
217 219
218 focus_client_.reset(new FocusClientImpl); 220 focus_client_.reset(new FocusClientImpl);
219 aura::client::SetFocusClient(window_tree_host_->window(), 221 aura::client::SetFocusClient(window_tree_host_->window(),
220 focus_client_.get()); 222 focus_client_.get());
221 223
222 window_tree_host_->Show(); 224 window_tree_host_->Show();
223 225
224 delegate_->OnDisplayManagerWindowTreeHostCreated(); 226 delegate_->OnDisplayManagerWindowTreeHostCreated();
225 } 227 }
226 228
227 } // namespace service 229 } // namespace service
228 } // namespace mojo 230 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/display_manager.h ('k') | mojo/services/view_manager/ids.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698