OLD | NEW |
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 #ifndef COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | 5 #ifndef COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ |
6 #define COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | 6 #define COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/view_manager/native_viewport/native_viewport.h" |
14 #include "components/view_manager/public/interfaces/display.mojom.h" | 15 #include "components/view_manager/public/interfaces/display.mojom.h" |
15 #include "components/view_manager/public/interfaces/native_viewport.mojom.h" | |
16 #include "components/view_manager/public/interfaces/view_manager.mojom.h" | 16 #include "components/view_manager/public/interfaces/view_manager.mojom.h" |
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" | 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 class SurfaceIdAllocator; | 21 class SurfaceIdAllocator; |
22 } | 22 } // namespace cc |
| 23 |
| 24 namespace gles2 { |
| 25 class GpuState; |
| 26 } // namespace gles2 |
23 | 27 |
24 namespace mojo { | 28 namespace mojo { |
25 class ApplicationImpl; | 29 class ApplicationImpl; |
26 } | 30 } // namespace mojo |
27 | 31 |
28 namespace view_manager { | 32 namespace view_manager { |
29 | 33 |
30 class ConnectionManager; | 34 class ConnectionManager; |
31 class ServerView; | 35 class ServerView; |
32 | 36 |
33 // DisplayManager is used to connect the root ServerView to a display. | 37 // DisplayManager is used to connect the root ServerView to a display. |
34 class DisplayManager { | 38 class DisplayManager { |
35 public: | 39 public: |
36 virtual ~DisplayManager() {} | 40 virtual ~DisplayManager() {} |
37 | 41 |
38 virtual void Init( | 42 virtual void Init( |
39 ConnectionManager* connection_manager, | 43 ConnectionManager* connection_manager, |
40 mojo::NativeViewportEventDispatcherPtr event_dispatcher) = 0; | 44 EventDispatcher* event_dispatcher) = 0; |
41 | 45 |
42 // Schedules a paint for the specified region in the coordinates of |view|. | 46 // Schedules a paint for the specified region in the coordinates of |view|. |
43 virtual void SchedulePaint(const ServerView* view, | 47 virtual void SchedulePaint(const ServerView* view, |
44 const gfx::Rect& bounds) = 0; | 48 const gfx::Rect& bounds) = 0; |
45 | 49 |
46 virtual void SetViewportSize(const gfx::Size& size) = 0; | 50 virtual void SetViewportSize(const gfx::Size& size) = 0; |
47 | 51 |
48 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0; | 52 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0; |
49 }; | 53 }; |
50 | 54 |
51 // DisplayManager implementation that connects to the services necessary to | 55 // DisplayManager implementation that connects to the services necessary to |
52 // actually display. | 56 // actually display. |
53 class DefaultDisplayManager : public DisplayManager, | 57 class DefaultDisplayManager : public DisplayManager, |
54 public mojo::ErrorHandler { | 58 public NativeViewport::Delegate { |
55 public: | 59 public: |
56 DefaultDisplayManager( | 60 DefaultDisplayManager( |
| 61 bool is_headless, |
57 mojo::ApplicationImpl* app_impl, | 62 mojo::ApplicationImpl* app_impl, |
| 63 const scoped_refptr<gles2::GpuState>& gpu_state, |
58 const mojo::Callback<void()>& native_viewport_closed_callback); | 64 const mojo::Callback<void()>& native_viewport_closed_callback); |
59 ~DefaultDisplayManager() override; | 65 ~DefaultDisplayManager() override; |
60 | 66 |
61 // DisplayManager: | 67 // DisplayManager: |
62 void Init(ConnectionManager* connection_manager, | 68 void Init(ConnectionManager* connection_manager, |
63 mojo::NativeViewportEventDispatcherPtr event_dispatcher) override; | 69 EventDispatcher* event_dispatcher) override; |
64 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; | 70 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; |
65 void SetViewportSize(const gfx::Size& size) override; | 71 void SetViewportSize(const gfx::Size& size) override; |
66 const mojo::ViewportMetrics& GetViewportMetrics() override; | 72 const mojo::ViewportMetrics& GetViewportMetrics() override; |
67 | 73 |
68 private: | 74 private: |
69 void WantToDraw(); | 75 void WantToDraw(); |
70 void Draw(); | 76 void Draw(); |
71 void DidDraw(); | 77 void DidDraw(); |
72 | 78 |
73 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics); | 79 // NativeViewport::Delegate implementation: |
| 80 bool OnEvent(mojo::EventPtr event) override; |
| 81 void OnMetricsChanged(const gfx::Size& size, |
| 82 float device_scale_factor) override; |
| 83 void OnViewDestroyed() override; |
74 | 84 |
75 // ErrorHandler: | 85 bool is_headless_; |
76 void OnConnectionError() override; | |
77 | |
78 mojo::ApplicationImpl* app_impl_; | 86 mojo::ApplicationImpl* app_impl_; |
| 87 scoped_refptr<gles2::GpuState> gpu_state_; |
79 ConnectionManager* connection_manager_; | 88 ConnectionManager* connection_manager_; |
| 89 EventDispatcher* event_dispatcher_; |
80 | 90 |
81 mojo::ViewportMetrics metrics_; | 91 mojo::ViewportMetrics metrics_; |
82 gfx::Rect dirty_rect_; | 92 gfx::Rect dirty_rect_; |
83 base::Timer draw_timer_; | 93 base::Timer draw_timer_; |
84 bool frame_pending_; | 94 bool frame_pending_; |
85 | 95 |
86 mojo::DisplayPtr display_; | 96 mojo::DisplayPtr display_; |
87 mojo::NativeViewportPtr native_viewport_; | 97 scoped_ptr<NativeViewport> native_viewport_; |
88 mojo::Callback<void()> native_viewport_closed_callback_; | 98 mojo::Callback<void()> native_viewport_closed_callback_; |
| 99 |
89 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; | 100 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; |
90 | 101 |
91 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); | 102 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); |
92 }; | 103 }; |
93 | 104 |
94 } // namespace view_manager | 105 } // namespace view_manager |
95 | 106 |
96 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | 107 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ |
OLD | NEW |