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 #include "ui/ozone/platform/egltest/ozone_platform_egltest.h" | 5 #include "ui/ozone/platform/egltest/ozone_platform_egltest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "library_loaders/libeglplatform_shim.h" | 12 #include "library_loaders/libeglplatform_shim.h" |
13 #include "third_party/khronos/EGL/egl.h" | 13 #include "third_party/khronos/EGL/egl.h" |
| 14 #include "ui/events/devices/device_data_manager.h" |
| 15 #include "ui/events/event.h" |
14 #include "ui/events/ozone/device/device_manager.h" | 16 #include "ui/events/ozone/device/device_manager.h" |
15 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 17 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
16 #include "ui/events/ozone/events_ozone.h" | 18 #include "ui/events/ozone/events_ozone.h" |
17 #include "ui/events/platform/platform_event_dispatcher.h" | 19 #include "ui/events/platform/platform_event_dispatcher.h" |
18 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
19 #include "ui/ozone/common/native_display_delegate_ozone.h" | 21 #include "ui/ozone/common/native_display_delegate_ozone.h" |
20 #include "ui/ozone/public/cursor_factory_ozone.h" | 22 #include "ui/ozone/public/cursor_factory_ozone.h" |
21 #include "ui/ozone/public/gpu_platform_support.h" | 23 #include "ui/ozone/public/gpu_platform_support.h" |
22 #include "ui/ozone/public/gpu_platform_support_host.h" | 24 #include "ui/ozone/public/gpu_platform_support_host.h" |
23 #include "ui/ozone/public/ozone_platform.h" | 25 #include "ui/ozone/public/ozone_platform.h" |
(...skipping 14 matching lines...) Expand all Loading... |
38 | 40 |
39 // Get the library soname to load. | 41 // Get the library soname to load. |
40 std::string GetShimLibraryName() { | 42 std::string GetShimLibraryName() { |
41 std::string library; | 43 std::string library; |
42 scoped_ptr<base::Environment> env(base::Environment::Create()); | 44 scoped_ptr<base::Environment> env(base::Environment::Create()); |
43 if (env->GetVar(kEglplatformShim, &library)) | 45 if (env->GetVar(kEglplatformShim, &library)) |
44 return library; | 46 return library; |
45 return kEglplatformShimDefault; | 47 return kEglplatformShimDefault; |
46 } | 48 } |
47 | 49 |
| 50 // Touch events are reported in device coordinates. This scales the event to the |
| 51 // window's coordinate space. |
| 52 void ScaleTouchEvent(TouchEvent* event, const gfx::SizeF& size) { |
| 53 for (const auto& device : |
| 54 DeviceDataManager::GetInstance()->touchscreen_devices()) { |
| 55 if (device.id == static_cast<unsigned int>(event->source_device_id())) { |
| 56 gfx::SizeF touchscreen_size = device.size; |
| 57 gfx::PointF location = event->location_f(); |
| 58 |
| 59 location.Scale(size.width() / touchscreen_size.width(), |
| 60 size.height() / touchscreen_size.height()); |
| 61 double ratio = std::sqrt(size.GetArea() / touchscreen_size.GetArea()); |
| 62 |
| 63 event->set_location(location); |
| 64 event->set_radius_x(event->radius_x() * ratio); |
| 65 event->set_radius_y(event->radius_y() * ratio); |
| 66 return; |
| 67 } |
| 68 } |
| 69 } |
| 70 |
48 class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher { | 71 class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher { |
49 public: | 72 public: |
50 EgltestWindow(PlatformWindowDelegate* delegate, | 73 EgltestWindow(PlatformWindowDelegate* delegate, |
51 LibeglplatformShimLoader* eglplatform_shim, | 74 LibeglplatformShimLoader* eglplatform_shim, |
52 EventFactoryEvdev* event_factory, | 75 EventFactoryEvdev* event_factory, |
53 const gfx::Rect& bounds); | 76 const gfx::Rect& bounds); |
54 ~EgltestWindow() override; | 77 ~EgltestWindow() override; |
55 | 78 |
56 // PlatformWindow: | 79 // PlatformWindow: |
57 gfx::Rect GetBounds() override; | 80 gfx::Rect GetBounds() override; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 166 |
144 void EgltestWindow::MoveCursorTo(const gfx::Point& location) { | 167 void EgltestWindow::MoveCursorTo(const gfx::Point& location) { |
145 event_factory_->WarpCursorTo(window_id_, location); | 168 event_factory_->WarpCursorTo(window_id_, location); |
146 } | 169 } |
147 | 170 |
148 bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) { | 171 bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) { |
149 return true; | 172 return true; |
150 } | 173 } |
151 | 174 |
152 uint32_t EgltestWindow::DispatchEvent(const ui::PlatformEvent& native_event) { | 175 uint32_t EgltestWindow::DispatchEvent(const ui::PlatformEvent& native_event) { |
| 176 DCHECK(native_event); |
| 177 Event* event = static_cast<Event*>(native_event); |
| 178 if (event->IsTouchEvent()) |
| 179 ScaleTouchEvent(static_cast<TouchEvent*>(event), bounds_.size()); |
| 180 |
153 DispatchEventFromNativeUiEvent( | 181 DispatchEventFromNativeUiEvent( |
154 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, | 182 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
155 base::Unretained(delegate_))); | 183 base::Unretained(delegate_))); |
156 | 184 |
157 return ui::POST_DISPATCH_STOP_PROPAGATION; | 185 return ui::POST_DISPATCH_STOP_PROPAGATION; |
158 } | 186 } |
159 | 187 |
160 // EGL surface wrapper for libeglplatform_shim. | 188 // EGL surface wrapper for libeglplatform_shim. |
161 // | 189 // |
162 // This just manages the native window lifetime using | 190 // This just manages the native window lifetime using |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 402 |
375 } // namespace | 403 } // namespace |
376 | 404 |
377 OzonePlatform* CreateOzonePlatformEgltest() { | 405 OzonePlatform* CreateOzonePlatformEgltest() { |
378 OzonePlatformEgltest* platform = new OzonePlatformEgltest; | 406 OzonePlatformEgltest* platform = new OzonePlatformEgltest; |
379 platform->Initialize(); | 407 platform->Initialize(); |
380 return platform; | 408 return platform; |
381 } | 409 } |
382 | 410 |
383 } // namespace ui | 411 } // namespace ui |
OLD | NEW |