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

Side by Side Diff: services/ui/ws/platform_display_default.cc

Issue 2507943002: Move PlatformDisplayDefault into it's own file. (Closed)
Patch Set: Fixes. Created 4 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/ws/platform_display_default.h ('k') | services/ui/ws/test_utils.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 2016 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 "services/ui/ws/platform_display.h" 5 #include "services/ui/ws/platform_display_default.h"
6 6
7 #include <utility>
8
9 #include "base/numerics/safe_conversions.h"
10 #include "build/build_config.h"
11 #include "cc/ipc/quads.mojom.h"
12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/delegated_frame_data.h"
14 #include "gpu/ipc/client/gpu_channel_host.h" 7 #include "gpu/ipc/client/gpu_channel_host.h"
15 #include "services/service_manager/public/cpp/connection.h"
16 #include "services/service_manager/public/cpp/connector.h"
17 #include "services/ui/display/platform_screen.h" 8 #include "services/ui/display/platform_screen.h"
18 #include "services/ui/surfaces/display_compositor.h"
19 #include "services/ui/ws/platform_display_factory.h"
20 #include "services/ui/ws/platform_display_init_params.h" 9 #include "services/ui/ws/platform_display_init_params.h"
21 #include "services/ui/ws/server_window.h" 10 #include "services/ui/ws/server_window.h"
22 #include "services/ui/ws/window_coordinate_conversions.h"
23 #include "third_party/skia/include/core/SkXfermode.h"
24 #include "ui/base/cursor/cursor_loader.h" 11 #include "ui/base/cursor/cursor_loader.h"
25 #include "ui/display/display.h" 12 #include "ui/display/display.h"
26 #include "ui/events/event.h" 13 #include "ui/events/event.h"
27 #include "ui/events/event_utils.h" 14 #include "ui/events/event_utils.h"
28 #include "ui/platform_window/platform_ime_controller.h" 15 #include "ui/platform_window/platform_ime_controller.h"
29 #include "ui/platform_window/platform_window.h" 16 #include "ui/platform_window/platform_window.h"
30 17
31 #if defined(OS_WIN) 18 #if defined(OS_WIN)
32 #include "ui/platform_window/win/win_window.h" 19 #include "ui/platform_window/win/win_window.h"
33 #elif defined(USE_X11) 20 #elif defined(USE_X11)
34 #include "ui/platform_window/x11/x11_window.h" 21 #include "ui/platform_window/x11/x11_window.h"
35 #elif defined(OS_ANDROID) 22 #elif defined(OS_ANDROID)
36 #include "ui/platform_window/android/platform_window_android.h" 23 #include "ui/platform_window/android/platform_window_android.h"
37 #elif defined(USE_OZONE) 24 #elif defined(USE_OZONE)
38 #include "ui/ozone/public/ozone_platform.h" 25 #include "ui/ozone/public/ozone_platform.h"
39 #endif 26 #endif
40 27
41 namespace ui { 28 namespace ui {
42
43 namespace ws { 29 namespace ws {
44 30
45 // static 31 PlatformDisplayDefault::PlatformDisplayDefault(
46 PlatformDisplayFactory* PlatformDisplay::factory_ = nullptr;
47
48 // static
49 std::unique_ptr<PlatformDisplay> PlatformDisplay::Create(
50 const PlatformDisplayInitParams& init_params) {
51 if (factory_)
52 return factory_->CreatePlatformDisplay();
53
54 return base::MakeUnique<DefaultPlatformDisplay>(init_params);
55 }
56
57 DefaultPlatformDisplay::DefaultPlatformDisplay(
58 const PlatformDisplayInitParams& init_params) 32 const PlatformDisplayInitParams& init_params)
59 : id_(init_params.display_id), 33 : display_id_(init_params.display_id),
60 #if !defined(OS_ANDROID) 34 #if !defined(OS_ANDROID)
61 cursor_loader_(ui::CursorLoader::Create()), 35 cursor_loader_(ui::CursorLoader::Create()),
62 #endif 36 #endif
63 frame_generator_(new FrameGenerator(this, init_params.root_window)), 37 frame_generator_(new FrameGenerator(this, init_params.root_window)),
64 metrics_(init_params.metrics) { 38 metrics_(init_params.metrics) {
65 } 39 }
66 40
67 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { 41 PlatformDisplayDefault::~PlatformDisplayDefault() {
42 // Don't notify the delegate from the destructor.
43 delegate_ = nullptr;
44
45 frame_generator_.reset();
46 // Destroy the PlatformWindow early on as it may call us back during
47 // destruction and we want to be in a known state. But destroy the surface
48 // first because it can still be using the platform window.
49 platform_window_.reset();
50 }
51
52 void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) {
68 delegate_ = delegate; 53 delegate_ = delegate;
69 54
70 DCHECK(!metrics_.pixel_size.IsEmpty()); 55 DCHECK(!metrics_.pixel_size.IsEmpty());
71 56
72 // TODO(kylechar): The origin here isn't right if any displays have 57 // TODO(kylechar): The origin here isn't right if any displays have
73 // scale_factor other than 1.0 but will prevent windows from being stacked. 58 // scale_factor other than 1.0 but will prevent windows from being stacked.
74 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size); 59 gfx::Rect bounds(metrics_.bounds.origin(), metrics_.pixel_size);
75 #if defined(OS_WIN) 60 #if defined(OS_WIN)
76 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds); 61 platform_window_ = base::MakeUnique<ui::WinWindow>(this, bounds);
77 #elif defined(USE_X11) 62 #elif defined(USE_X11)
78 platform_window_ = base::MakeUnique<ui::X11Window>(this); 63 platform_window_ = base::MakeUnique<ui::X11Window>(this);
79 platform_window_->SetBounds(bounds); 64 platform_window_->SetBounds(bounds);
80 #elif defined(OS_ANDROID) 65 #elif defined(OS_ANDROID)
81 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this); 66 platform_window_ = base::MakeUnique<ui::PlatformWindowAndroid>(this);
82 platform_window_->SetBounds(bounds); 67 platform_window_->SetBounds(bounds);
83 #elif defined(USE_OZONE) 68 #elif defined(USE_OZONE)
84 platform_window_ = 69 platform_window_ =
85 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); 70 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds);
86 #else 71 #else
87 NOTREACHED() << "Unsupported platform"; 72 NOTREACHED() << "Unsupported platform";
88 #endif 73 #endif
89 74
90 platform_window_->Show(); 75 platform_window_->Show();
91 } 76 }
92 77
93 int64_t DefaultPlatformDisplay::GetId() const { 78 int64_t PlatformDisplayDefault::GetId() const {
94 return id_; 79 return display_id_;
95 } 80 }
96 81
97 DefaultPlatformDisplay::~DefaultPlatformDisplay() { 82 void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) {
98 // Don't notify the delegate from the destructor.
99 delegate_ = nullptr;
100
101 frame_generator_.reset();
102 // Destroy the PlatformWindow early on as it may call us back during
103 // destruction and we want to be in a known state. But destroy the surface
104 // first because it can still be using the platform window.
105 platform_window_.reset();
106 }
107
108 void DefaultPlatformDisplay::SetViewportSize(const gfx::Size& size) {
109 platform_window_->SetBounds(gfx::Rect(size)); 83 platform_window_->SetBounds(gfx::Rect(size));
110 } 84 }
111 85
112 void DefaultPlatformDisplay::SetTitle(const base::string16& title) { 86 void PlatformDisplayDefault::SetTitle(const base::string16& title) {
113 platform_window_->SetTitle(title); 87 platform_window_->SetTitle(title);
114 } 88 }
115 89
116 void DefaultPlatformDisplay::SetCapture() { 90 void PlatformDisplayDefault::SetCapture() {
117 platform_window_->SetCapture(); 91 platform_window_->SetCapture();
118 } 92 }
119 93
120 void DefaultPlatformDisplay::ReleaseCapture() { 94 void PlatformDisplayDefault::ReleaseCapture() {
121 platform_window_->ReleaseCapture(); 95 platform_window_->ReleaseCapture();
122 } 96 }
123 97
124 void DefaultPlatformDisplay::SetCursorById(mojom::Cursor cursor_id) { 98 void PlatformDisplayDefault::SetCursorById(mojom::Cursor cursor_id) {
125 #if !defined(OS_ANDROID) 99 #if !defined(OS_ANDROID)
126 // TODO(erg): This still isn't sufficient, and will only use native cursors 100 // TODO(erg): This still isn't sufficient, and will only use native cursors
127 // that chrome would use, not custom image cursors. For that, we should 101 // that chrome would use, not custom image cursors. For that, we should
128 // delegate to the window manager to load images from resource packs. 102 // delegate to the window manager to load images from resource packs.
129 // 103 //
130 // We probably also need to deal with different DPIs. 104 // We probably also need to deal with different DPIs.
131 ui::Cursor cursor(static_cast<int32_t>(cursor_id)); 105 ui::Cursor cursor(static_cast<int32_t>(cursor_id));
132 cursor_loader_->SetPlatformCursor(&cursor); 106 cursor_loader_->SetPlatformCursor(&cursor);
133 platform_window_->SetCursor(cursor.platform()); 107 platform_window_->SetCursor(cursor.platform());
134 #endif 108 #endif
135 } 109 }
136 110
137 void DefaultPlatformDisplay::UpdateTextInputState( 111 void PlatformDisplayDefault::UpdateTextInputState(
138 const ui::TextInputState& state) { 112 const ui::TextInputState& state) {
139 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); 113 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController();
140 if (ime) 114 if (ime)
141 ime->UpdateTextInputState(state); 115 ime->UpdateTextInputState(state);
142 } 116 }
143 117
144 void DefaultPlatformDisplay::SetImeVisibility(bool visible) { 118 void PlatformDisplayDefault::SetImeVisibility(bool visible) {
145 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController(); 119 ui::PlatformImeController* ime = platform_window_->GetPlatformImeController();
146 if (ime) 120 if (ime)
147 ime->SetImeVisibility(visible); 121 ime->SetImeVisibility(visible);
148 } 122 }
149 123
150 gfx::Rect DefaultPlatformDisplay::GetBounds() const { 124 gfx::Rect PlatformDisplayDefault::GetBounds() const {
151 return metrics_.bounds; 125 return metrics_.bounds;
152 } 126 }
153 127
154 bool DefaultPlatformDisplay::IsPrimaryDisplay() const { 128 bool PlatformDisplayDefault::IsPrimaryDisplay() const {
155 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_; 129 return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() ==
130 display_id_;
156 } 131 }
157 132
158 void DefaultPlatformDisplay::OnGpuChannelEstablished( 133 void PlatformDisplayDefault::OnGpuChannelEstablished(
159 scoped_refptr<gpu::GpuChannelHost> channel) { 134 scoped_refptr<gpu::GpuChannelHost> channel) {
160 frame_generator_->OnGpuChannelEstablished(channel); 135 frame_generator_->OnGpuChannelEstablished(channel);
161 } 136 }
162 137
163 bool DefaultPlatformDisplay::UpdateViewportMetrics( 138 bool PlatformDisplayDefault::UpdateViewportMetrics(
164 const display::ViewportMetrics& metrics) { 139 const display::ViewportMetrics& metrics) {
165 if (metrics_ == metrics) 140 if (metrics_ == metrics)
166 return false; 141 return false;
167 142
168 gfx::Rect bounds = platform_window_->GetBounds(); 143 gfx::Rect bounds = platform_window_->GetBounds();
169 if (bounds.size() != metrics.pixel_size) { 144 if (bounds.size() != metrics.pixel_size) {
170 bounds.set_size(metrics.pixel_size); 145 bounds.set_size(metrics.pixel_size);
171 platform_window_->SetBounds(bounds); 146 platform_window_->SetBounds(bounds);
172 } 147 }
173 148
174 metrics_ = metrics; 149 metrics_ = metrics;
175 return true; 150 return true;
176 } 151 }
177 152
178 const display::ViewportMetrics& DefaultPlatformDisplay::GetViewportMetrics() 153 const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics()
179 const { 154 const {
180 return metrics_; 155 return metrics_;
181 } 156 }
182 157
183 void DefaultPlatformDisplay::UpdateEventRootLocation(ui::LocatedEvent* event) { 158 void PlatformDisplayDefault::UpdateEventRootLocation(ui::LocatedEvent* event) {
184 gfx::Point location = event->location(); 159 gfx::Point location = event->location();
185 location.Offset(metrics_.bounds.x(), metrics_.bounds.y()); 160 location.Offset(metrics_.bounds.x(), metrics_.bounds.y());
186 event->set_root_location(location); 161 event->set_root_location(location);
187 } 162 }
188 163
189 void DefaultPlatformDisplay::OnBoundsChanged(const gfx::Rect& new_bounds) { 164 void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) {
190 // We only care if the window size has changed. 165 // We only care if the window size has changed.
191 if (new_bounds.size() == metrics_.pixel_size) 166 if (new_bounds.size() == metrics_.pixel_size)
192 return; 167 return;
193 168
194 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support 169 // TODO(kylechar): Maybe do something here. For CrOS we don't need to support
195 // PlatformWindow initiated resizes. For other platforms we need to do 170 // PlatformWindow initiated resizes. For other platforms we need to do
196 // something but that isn't fully flushed out. 171 // something but that isn't fully flushed out.
197 } 172 }
198 173
199 void DefaultPlatformDisplay::OnDamageRect(const gfx::Rect& damaged_region) { 174 void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) {}
200 }
201 175
202 void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) { 176 void PlatformDisplayDefault::DispatchEvent(ui::Event* event) {
203 if (event->IsLocatedEvent()) 177 if (event->IsLocatedEvent())
204 UpdateEventRootLocation(event->AsLocatedEvent()); 178 UpdateEventRootLocation(event->AsLocatedEvent());
205 179
206 if (event->IsScrollEvent()) { 180 if (event->IsScrollEvent()) {
207 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as 181 // TODO(moshayedi): crbug.com/602859. Dispatch scroll events as
208 // they are once we have proper support for scroll events. 182 // they are once we have proper support for scroll events.
209 delegate_->OnEvent( 183 delegate_->OnEvent(
210 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent()))); 184 ui::PointerEvent(ui::MouseWheelEvent(*event->AsScrollEvent())));
211 } else if (event->IsMouseEvent()) { 185 } else if (event->IsMouseEvent()) {
212 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent())); 186 delegate_->OnEvent(ui::PointerEvent(*event->AsMouseEvent()));
(...skipping 23 matching lines...) Expand all
236 // We don't check that GetCharacter() is equal because changing a key event 210 // We don't check that GetCharacter() is equal because changing a key event
237 // with an accelerator to a character event can change the character, for 211 // with an accelerator to a character event can change the character, for
238 // example, from 'M' to '^M'. 212 // example, from 'M' to '^M'.
239 DCHECK_EQ(key_press_event->key_code(), char_event.key_code()); 213 DCHECK_EQ(key_press_event->key_code(), char_event.key_code());
240 DCHECK_EQ(key_press_event->flags(), char_event.flags()); 214 DCHECK_EQ(key_press_event->flags(), char_event.flags());
241 delegate_->OnEvent(char_event); 215 delegate_->OnEvent(char_event);
242 } 216 }
243 #endif 217 #endif
244 } 218 }
245 219
246 void DefaultPlatformDisplay::OnCloseRequest() { 220 void PlatformDisplayDefault::OnCloseRequest() {
247 display::PlatformScreen::GetInstance()->RequestCloseDisplay(GetId()); 221 display::PlatformScreen::GetInstance()->RequestCloseDisplay(GetId());
248 } 222 }
249 223
250 void DefaultPlatformDisplay::OnClosed() {} 224 void PlatformDisplayDefault::OnClosed() {}
251 225
252 void DefaultPlatformDisplay::OnWindowStateChanged( 226 void PlatformDisplayDefault::OnWindowStateChanged(
253 ui::PlatformWindowState new_state) {} 227 ui::PlatformWindowState new_state) {}
254 228
255 void DefaultPlatformDisplay::OnLostCapture() { 229 void PlatformDisplayDefault::OnLostCapture() {
256 delegate_->OnNativeCaptureLost(); 230 delegate_->OnNativeCaptureLost();
257 } 231 }
258 232
259 void DefaultPlatformDisplay::OnAcceleratedWidgetAvailable( 233 void PlatformDisplayDefault::OnAcceleratedWidgetAvailable(
260 gfx::AcceleratedWidget widget, 234 gfx::AcceleratedWidget widget,
261 float device_scale_factor) { 235 float device_scale_factor) {
262 // This will get called after Init() is called, either synchronously as part 236 // This will get called after Init() is called, either synchronously as part
263 // of the Init() callstack or async after Init() has returned, depending on 237 // of the Init() callstack or async after Init() has returned, depending on
264 // the platform. 238 // the platform.
265 delegate_->OnAcceleratedWidgetAvailable(); 239 delegate_->OnAcceleratedWidgetAvailable();
266 frame_generator_->OnAcceleratedWidgetAvailable(widget); 240 frame_generator_->OnAcceleratedWidgetAvailable(widget);
267 } 241 }
268 242
269 void DefaultPlatformDisplay::OnAcceleratedWidgetDestroyed() { 243 void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() {
270 NOTREACHED(); 244 NOTREACHED();
271 } 245 }
272 246
273 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} 247 void PlatformDisplayDefault::OnActivationChanged(bool active) {}
274 248
275 bool DefaultPlatformDisplay::IsInHighContrastMode() { 249 bool PlatformDisplayDefault::IsInHighContrastMode() {
276 return delegate_ ? delegate_->IsInHighContrastMode() : false; 250 return delegate_ ? delegate_->IsInHighContrastMode() : false;
277 } 251 }
278 252
279 } // namespace ws 253 } // namespace ws
280
281 } // namespace ui 254 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/platform_display_default.h ('k') | services/ui/ws/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698