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 SERVICES_UI_WS_PLATFORM_DISPLAY_H_ | 5 #ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_H_ |
6 #define SERVICES_UI_WS_PLATFORM_DISPLAY_H_ | 6 #define SERVICES_UI_WS_PLATFORM_DISPLAY_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/timer/timer.h" | |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 #include "cc/surfaces/surface.h" | |
19 #include "services/ui/public/interfaces/window_manager.mojom.h" | 17 #include "services/ui/public/interfaces/window_manager.mojom.h" |
20 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 18 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
21 #include "services/ui/public/interfaces/window_tree.mojom.h" | 19 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 20 #include "services/ui/ws/frame_generator.h" |
| 21 #include "services/ui/ws/frame_generator_delegate.h" |
22 #include "services/ui/ws/platform_display_delegate.h" | 22 #include "services/ui/ws/platform_display_delegate.h" |
23 #include "services/ui/ws/platform_display_init_params.h" | |
24 #include "ui/gfx/geometry/rect.h" | |
25 #include "ui/platform_window/platform_window_delegate.h" | 23 #include "ui/platform_window/platform_window_delegate.h" |
26 | 24 |
27 namespace cc { | 25 namespace cc { |
28 class CompositorFrame; | |
29 class CopyOutputRequest; | 26 class CopyOutputRequest; |
30 class SurfaceIdAllocator; | |
31 class SurfaceManager; | |
32 } // namespace cc | 27 } // namespace cc |
33 | 28 |
34 namespace gles2 { | 29 namespace gfx { |
35 class GpuState; | 30 class Rect; |
36 } // namespace gles2 | 31 } |
37 | |
38 namespace shell { | |
39 class Connector; | |
40 } // namespace shell | |
41 | 32 |
42 namespace ui { | 33 namespace ui { |
43 class CursorLoader; | 34 class CursorLoader; |
44 class PlatformWindow; | 35 class PlatformWindow; |
45 struct TextInputState; | 36 struct TextInputState; |
46 } // namespace ui | 37 } // namespace ui |
47 | 38 |
48 namespace ui { | 39 namespace ui { |
49 | 40 |
50 class GpuState; | 41 class FrameGenerator; |
51 class SurfacesState; | |
52 class DisplayCompositor; | |
53 | 42 |
54 namespace ws { | 43 namespace ws { |
55 | 44 |
56 class EventDispatcher; | 45 class EventDispatcher; |
57 class PlatformDisplayFactory; | 46 class PlatformDisplayFactory; |
| 47 struct PlatformDisplayInitParams; |
58 class ServerWindow; | 48 class ServerWindow; |
59 | 49 |
60 struct ViewportMetrics { | |
61 gfx::Size size_in_pixels; | |
62 float device_scale_factor = 0.f; | |
63 }; | |
64 | |
65 // PlatformDisplay is used to connect the root ServerWindow to a display. | 50 // PlatformDisplay is used to connect the root ServerWindow to a display. |
66 class PlatformDisplay { | 51 class PlatformDisplay { |
67 public: | 52 public: |
68 virtual ~PlatformDisplay() {} | 53 virtual ~PlatformDisplay() {} |
69 | 54 |
70 static PlatformDisplay* Create(const PlatformDisplayInitParams& init_params); | 55 static PlatformDisplay* Create(const PlatformDisplayInitParams& init_params); |
71 | 56 |
72 virtual void Init(PlatformDisplayDelegate* delegate) = 0; | 57 virtual void Init(PlatformDisplayDelegate* delegate) = 0; |
73 | 58 |
74 // Schedules a paint for the specified region in the coordinates of |window|. | 59 // Schedules a paint for the specified region in the coordinates of |window|. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 92 } |
108 | 93 |
109 private: | 94 private: |
110 // Static factory instance (always NULL for non-test). | 95 // Static factory instance (always NULL for non-test). |
111 static PlatformDisplayFactory* factory_; | 96 static PlatformDisplayFactory* factory_; |
112 }; | 97 }; |
113 | 98 |
114 // PlatformDisplay implementation that connects to the services necessary to | 99 // PlatformDisplay implementation that connects to the services necessary to |
115 // actually display. | 100 // actually display. |
116 class DefaultPlatformDisplay : public PlatformDisplay, | 101 class DefaultPlatformDisplay : public PlatformDisplay, |
117 public ui::PlatformWindowDelegate { | 102 public ui::PlatformWindowDelegate, |
| 103 private FrameGeneratorDelegate { |
118 public: | 104 public: |
119 explicit DefaultPlatformDisplay(const PlatformDisplayInitParams& init_params); | 105 explicit DefaultPlatformDisplay(const PlatformDisplayInitParams& init_params); |
120 ~DefaultPlatformDisplay() override; | 106 ~DefaultPlatformDisplay() override; |
121 | 107 |
122 // PlatformDisplay: | 108 // PlatformDisplay: |
123 void Init(PlatformDisplayDelegate* delegate) override; | 109 void Init(PlatformDisplayDelegate* delegate) override; |
124 void SchedulePaint(const ServerWindow* window, | 110 void SchedulePaint(const ServerWindow* window, |
125 const gfx::Rect& bounds) override; | 111 const gfx::Rect& bounds) override; |
126 void SetViewportSize(const gfx::Size& size) override; | 112 void SetViewportSize(const gfx::Size& size) override; |
127 void SetTitle(const base::string16& title) override; | 113 void SetTitle(const base::string16& title) override; |
128 void SetCapture() override; | 114 void SetCapture() override; |
129 void ReleaseCapture() override; | 115 void ReleaseCapture() override; |
130 void SetCursorById(int32_t cursor) override; | 116 void SetCursorById(int32_t cursor) override; |
131 float GetDeviceScaleFactor() override; | 117 float GetDeviceScaleFactor() override; |
132 mojom::Rotation GetRotation() override; | 118 mojom::Rotation GetRotation() override; |
133 void UpdateTextInputState(const ui::TextInputState& state) override; | 119 void UpdateTextInputState(const ui::TextInputState& state) override; |
134 void SetImeVisibility(bool visible) override; | 120 void SetImeVisibility(bool visible) override; |
135 bool IsFramePending() const override; | 121 bool IsFramePending() const override; |
136 void RequestCopyOfOutput( | 122 void RequestCopyOfOutput( |
137 std::unique_ptr<cc::CopyOutputRequest> output_request) override; | 123 std::unique_ptr<cc::CopyOutputRequest> output_request) override; |
138 int64_t GetDisplayId() const override; | 124 int64_t GetDisplayId() const override; |
139 | 125 |
140 private: | 126 private: |
141 void WantToDraw(); | |
142 | |
143 // This method initiates a top level redraw of the display. | |
144 // TODO(fsamuel): This should use vblank as a signal rather than a timer | |
145 // http://crbug.com/533042 | |
146 void Draw(); | |
147 | |
148 // This is called after cc::Display has completed generating a new frame | |
149 // for the display. TODO(fsamuel): Idle time processing should happen here | |
150 // if there is budget for it. | |
151 void DidDraw(cc::SurfaceDrawStatus status); | |
152 void UpdateMetrics(const gfx::Size& size, float device_scale_factor); | 127 void UpdateMetrics(const gfx::Size& size, float device_scale_factor); |
153 cc::CompositorFrame GenerateCompositorFrame(); | |
154 | 128 |
155 // ui::PlatformWindowDelegate: | 129 // ui::PlatformWindowDelegate: |
156 void OnBoundsChanged(const gfx::Rect& new_bounds) override; | 130 void OnBoundsChanged(const gfx::Rect& new_bounds) override; |
157 void OnDamageRect(const gfx::Rect& damaged_region) override; | 131 void OnDamageRect(const gfx::Rect& damaged_region) override; |
158 void DispatchEvent(ui::Event* event) override; | 132 void DispatchEvent(ui::Event* event) override; |
159 void OnCloseRequest() override; | 133 void OnCloseRequest() override; |
160 void OnClosed() override; | 134 void OnClosed() override; |
161 void OnWindowStateChanged(ui::PlatformWindowState new_state) override; | 135 void OnWindowStateChanged(ui::PlatformWindowState new_state) override; |
162 void OnLostCapture() override; | 136 void OnLostCapture() override; |
163 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, | 137 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, |
164 float device_scale_factor) override; | 138 float device_scale_factor) override; |
165 void OnAcceleratedWidgetDestroyed() override; | 139 void OnAcceleratedWidgetDestroyed() override; |
166 void OnActivationChanged(bool active) override; | 140 void OnActivationChanged(bool active) override; |
167 | 141 |
| 142 // FrameGeneratorDelegate: |
| 143 ServerWindow* GetRootWindow() override; |
| 144 void OnCompositorFrameDrawn() override; |
| 145 const ViewportMetrics& GetViewportMetrics() override; |
| 146 |
168 int64_t display_id_; | 147 int64_t display_id_; |
169 | 148 |
170 scoped_refptr<GpuState> gpu_state_; | |
171 scoped_refptr<SurfacesState> surfaces_state_; | |
172 PlatformDisplayDelegate* delegate_; | |
173 | |
174 ViewportMetrics metrics_; | |
175 gfx::Rect dirty_rect_; | |
176 base::Timer draw_timer_; | |
177 bool frame_pending_; | |
178 | |
179 std::unique_ptr<DisplayCompositor> display_compositor_; | |
180 std::unique_ptr<ui::PlatformWindow> platform_window_; | |
181 | |
182 #if !defined(OS_ANDROID) | 149 #if !defined(OS_ANDROID) |
183 std::unique_ptr<ui::CursorLoader> cursor_loader_; | 150 std::unique_ptr<ui::CursorLoader> cursor_loader_; |
184 #endif | 151 #endif |
185 | 152 |
186 base::WeakPtrFactory<DefaultPlatformDisplay> weak_factory_; | 153 PlatformDisplayDelegate* delegate_ = nullptr; |
| 154 std::unique_ptr<FrameGenerator> frame_generator_; |
| 155 |
| 156 ViewportMetrics metrics_; |
| 157 std::unique_ptr<ui::PlatformWindow> platform_window_; |
187 | 158 |
188 DISALLOW_COPY_AND_ASSIGN(DefaultPlatformDisplay); | 159 DISALLOW_COPY_AND_ASSIGN(DefaultPlatformDisplay); |
189 }; | 160 }; |
190 | 161 |
191 } // namespace ws | 162 } // namespace ws |
192 | 163 |
193 } // namespace ui | 164 } // namespace ui |
194 | 165 |
195 #endif // SERVICES_UI_WS_PLATFORM_DISPLAY_H_ | 166 #endif // SERVICES_UI_WS_PLATFORM_DISPLAY_H_ |
OLD | NEW |