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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "library_loaders/libeglplatform_shim.h" | 11 #include "library_loaders/libeglplatform_shim.h" |
12 #include "ui/events/ozone/device/device_manager.h" | 12 #include "ui/events/ozone/device/device_manager.h" |
13 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 13 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 14 #include "ui/events/platform/platform_event_dispatcher.h" |
14 #include "ui/gfx/vsync_provider.h" | 15 #include "ui/gfx/vsync_provider.h" |
15 #include "ui/ozone/common/window/platform_window_compat.h" | |
16 #include "ui/ozone/public/cursor_factory_ozone.h" | 16 #include "ui/ozone/public/cursor_factory_ozone.h" |
17 #include "ui/ozone/public/gpu_platform_support.h" | 17 #include "ui/ozone/public/gpu_platform_support.h" |
18 #include "ui/ozone/public/gpu_platform_support_host.h" | 18 #include "ui/ozone/public/gpu_platform_support_host.h" |
19 #include "ui/ozone/public/ozone_platform.h" | 19 #include "ui/ozone/public/ozone_platform.h" |
20 #include "ui/ozone/public/ozone_switches.h" | 20 #include "ui/ozone/public/ozone_switches.h" |
21 #include "ui/ozone/public/surface_factory_ozone.h" | 21 #include "ui/ozone/public/surface_factory_ozone.h" |
22 #include "ui/ozone/public/surface_ozone_egl.h" | 22 #include "ui/ozone/public/surface_ozone_egl.h" |
| 23 #include "ui/platform_window/platform_window.h" |
| 24 #include "ui/platform_window/platform_window_delegate.h" |
23 | 25 |
24 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
25 #include "ui/ozone/common/chromeos/native_display_delegate_ozone.h" | 27 #include "ui/ozone/common/chromeos/native_display_delegate_ozone.h" |
26 #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" | 28 #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" |
27 #endif | 29 #endif |
28 | 30 |
29 #include <EGL/egl.h> | 31 #include <EGL/egl.h> |
30 | 32 |
31 namespace ui { | 33 namespace ui { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 const char kEglplatformShim[] = "EGLPLATFORM_SHIM"; | 37 const char kEglplatformShim[] = "EGLPLATFORM_SHIM"; |
36 const char kEglplatformShimDefault[] = "libeglplatform_shim.so.1"; | 38 const char kEglplatformShimDefault[] = "libeglplatform_shim.so.1"; |
37 const char kDefaultEglSoname[] = "libEGL.so.1"; | 39 const char kDefaultEglSoname[] = "libEGL.so.1"; |
38 const char kDefaultGlesSoname[] = "libGLESv2.so.2"; | 40 const char kDefaultGlesSoname[] = "libGLESv2.so.2"; |
39 | 41 |
40 // Get the library soname to load. | 42 // Get the library soname to load. |
41 std::string GetShimLibraryName() { | 43 std::string GetShimLibraryName() { |
42 std::string library; | 44 std::string library; |
43 scoped_ptr<base::Environment> env(base::Environment::Create()); | 45 scoped_ptr<base::Environment> env(base::Environment::Create()); |
44 if (env->GetVar(kEglplatformShim, &library)) | 46 if (env->GetVar(kEglplatformShim, &library)) |
45 return library; | 47 return library; |
46 return kEglplatformShimDefault; | 48 return kEglplatformShimDefault; |
47 } | 49 } |
48 | 50 |
| 51 class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher { |
| 52 public: |
| 53 EgltestWindow(PlatformWindowDelegate* delegate, |
| 54 LibeglplatformShimLoader* eglplatform_shim, |
| 55 const gfx::Rect& bounds); |
| 56 virtual ~EgltestWindow(); |
| 57 |
| 58 // PlatformWindow: |
| 59 virtual gfx::Rect GetBounds() OVERRIDE; |
| 60 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
| 61 virtual void Show() OVERRIDE; |
| 62 virtual void Hide() OVERRIDE; |
| 63 virtual void Close() OVERRIDE; |
| 64 virtual void SetCapture() OVERRIDE; |
| 65 virtual void ReleaseCapture() OVERRIDE; |
| 66 virtual void ToggleFullscreen() OVERRIDE; |
| 67 virtual void Maximize() OVERRIDE; |
| 68 virtual void Minimize() OVERRIDE; |
| 69 virtual void Restore() OVERRIDE; |
| 70 |
| 71 // PlatformEventDispatcher: |
| 72 virtual bool CanDispatchEvent(const PlatformEvent& event) OVERRIDE; |
| 73 virtual uint32_t DispatchEvent(const PlatformEvent& event) OVERRIDE; |
| 74 |
| 75 private: |
| 76 PlatformWindowDelegate* delegate_; |
| 77 LibeglplatformShimLoader* eglplatform_shim_; |
| 78 gfx::Rect bounds_; |
| 79 ShimNativeWindowId window_id_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(EgltestWindow); |
| 82 }; |
| 83 |
| 84 EgltestWindow::EgltestWindow(PlatformWindowDelegate* delegate, |
| 85 LibeglplatformShimLoader* eglplatform_shim, |
| 86 const gfx::Rect& bounds) |
| 87 : delegate_(delegate), |
| 88 eglplatform_shim_(eglplatform_shim), |
| 89 bounds_(bounds), |
| 90 window_id_(SHIM_NO_WINDOW_ID) { |
| 91 window_id_ = eglplatform_shim_->ShimCreateWindow(); |
| 92 delegate_->OnAcceleratedWidgetAvailable(window_id_); |
| 93 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
| 94 } |
| 95 |
| 96 EgltestWindow::~EgltestWindow() { |
| 97 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
| 98 if (window_id_ != SHIM_NO_WINDOW_ID) |
| 99 eglplatform_shim_->ShimDestroyWindow(window_id_); |
| 100 } |
| 101 |
| 102 gfx::Rect EgltestWindow::GetBounds() { |
| 103 return bounds_; |
| 104 } |
| 105 |
| 106 void EgltestWindow::SetBounds(const gfx::Rect& bounds) { |
| 107 bounds_ = bounds; |
| 108 delegate_->OnBoundsChanged(bounds); |
| 109 } |
| 110 |
| 111 void EgltestWindow::Show() { |
| 112 } |
| 113 |
| 114 void EgltestWindow::Hide() { |
| 115 } |
| 116 |
| 117 void EgltestWindow::Close() { |
| 118 } |
| 119 |
| 120 void EgltestWindow::SetCapture() { |
| 121 } |
| 122 |
| 123 void EgltestWindow::ReleaseCapture() { |
| 124 } |
| 125 |
| 126 void EgltestWindow::ToggleFullscreen() { |
| 127 } |
| 128 |
| 129 void EgltestWindow::Maximize() { |
| 130 } |
| 131 |
| 132 void EgltestWindow::Minimize() { |
| 133 } |
| 134 |
| 135 void EgltestWindow::Restore() { |
| 136 } |
| 137 |
| 138 bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) { |
| 139 return true; |
| 140 } |
| 141 |
| 142 uint32_t EgltestWindow::DispatchEvent(const ui::PlatformEvent& ne) { |
| 143 ui::Event* event = static_cast<ui::Event*>(ne); |
| 144 delegate_->DispatchEvent(event); |
| 145 return ui::POST_DISPATCH_STOP_PROPAGATION; |
| 146 } |
| 147 |
49 // EGL surface wrapper for libeglplatform_shim. | 148 // EGL surface wrapper for libeglplatform_shim. |
50 // | 149 // |
51 // This just manages the native window lifetime using | 150 // This just manages the native window lifetime using |
52 // ShimGetNativeWindow & ShimReleaseNativeWindow. | 151 // ShimGetNativeWindow & ShimReleaseNativeWindow. |
53 class SurfaceOzoneEgltest : public SurfaceOzoneEGL { | 152 class SurfaceOzoneEgltest : public SurfaceOzoneEGL { |
54 public: | 153 public: |
55 SurfaceOzoneEgltest(ShimNativeWindowId window_id, | 154 SurfaceOzoneEgltest(ShimNativeWindowId window_id, |
56 LibeglplatformShimLoader* eglplatform_shim) | 155 LibeglplatformShimLoader* eglplatform_shim) |
57 : eglplatform_shim_(eglplatform_shim) { | 156 : eglplatform_shim_(eglplatform_shim) { |
58 native_window_ = eglplatform_shim_->ShimGetNativeWindow(window_id); | 157 native_window_ = eglplatform_shim_->ShimGetNativeWindow(window_id); |
(...skipping 28 matching lines...) Expand all Loading... |
87 }; | 186 }; |
88 | 187 |
89 // EGL surface factory for libeglplatform_shim. | 188 // EGL surface factory for libeglplatform_shim. |
90 // | 189 // |
91 // This finds the right EGL/GLES2 libraries for loading, and creates | 190 // This finds the right EGL/GLES2 libraries for loading, and creates |
92 // a single native window via ShimCreateWindow for drawing | 191 // a single native window via ShimCreateWindow for drawing |
93 // into. | 192 // into. |
94 class SurfaceFactoryEgltest : public ui::SurfaceFactoryOzone { | 193 class SurfaceFactoryEgltest : public ui::SurfaceFactoryOzone { |
95 public: | 194 public: |
96 SurfaceFactoryEgltest(LibeglplatformShimLoader* eglplatform_shim) | 195 SurfaceFactoryEgltest(LibeglplatformShimLoader* eglplatform_shim) |
97 : eglplatform_shim_(eglplatform_shim), window_id_(SHIM_NO_WINDOW_ID) {} | 196 : eglplatform_shim_(eglplatform_shim) {} |
98 virtual ~SurfaceFactoryEgltest() { DestroySingleWindow(); } | 197 virtual ~SurfaceFactoryEgltest() {} |
99 | |
100 // Create the window. | |
101 bool CreateSingleWindow(); | |
102 void DestroySingleWindow(); | |
103 | 198 |
104 // SurfaceFactoryOzone: | 199 // SurfaceFactoryOzone: |
105 virtual HardwareState InitializeHardware() OVERRIDE; | 200 virtual HardwareState InitializeHardware() OVERRIDE; |
106 virtual void ShutdownHardware() OVERRIDE; | 201 virtual void ShutdownHardware() OVERRIDE; |
107 virtual intptr_t GetNativeDisplay() OVERRIDE; | 202 virtual intptr_t GetNativeDisplay() OVERRIDE; |
108 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 203 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
109 virtual scoped_ptr<SurfaceOzoneEGL> CreateEGLSurfaceForWidget( | 204 virtual scoped_ptr<SurfaceOzoneEGL> CreateEGLSurfaceForWidget( |
110 gfx::AcceleratedWidget widget) OVERRIDE; | 205 gfx::AcceleratedWidget widget) OVERRIDE; |
111 virtual const int32* GetEGLSurfaceProperties( | 206 virtual const int32* GetEGLSurfaceProperties( |
112 const int32* desired_list) OVERRIDE; | 207 const int32* desired_list) OVERRIDE; |
113 virtual bool LoadEGLGLES2Bindings( | 208 virtual bool LoadEGLGLES2Bindings( |
114 AddGLLibraryCallback add_gl_library, | 209 AddGLLibraryCallback add_gl_library, |
115 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE; | 210 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE; |
116 | 211 |
117 private: | 212 private: |
118 LibeglplatformShimLoader* eglplatform_shim_; | 213 LibeglplatformShimLoader* eglplatform_shim_; |
119 | |
120 // TODO(spang): Remove once we have a windowing API. This limits to 1 window. | |
121 ShimNativeWindowId window_id_; | |
122 }; | 214 }; |
123 | 215 |
124 bool SurfaceFactoryEgltest::CreateSingleWindow() { | |
125 window_id_ = eglplatform_shim_->ShimCreateWindow(); | |
126 return (window_id_ != SHIM_NO_WINDOW_ID); | |
127 } | |
128 | |
129 void SurfaceFactoryEgltest::DestroySingleWindow() { | |
130 if (window_id_ != SHIM_NO_WINDOW_ID) | |
131 CHECK(eglplatform_shim_->ShimDestroyWindow(window_id_)); | |
132 } | |
133 | |
134 SurfaceFactoryEgltest::HardwareState | 216 SurfaceFactoryEgltest::HardwareState |
135 SurfaceFactoryEgltest::InitializeHardware() { | 217 SurfaceFactoryEgltest::InitializeHardware() { |
136 return INITIALIZED; | 218 return INITIALIZED; |
137 } | 219 } |
138 | 220 |
139 void SurfaceFactoryEgltest::ShutdownHardware() { | 221 void SurfaceFactoryEgltest::ShutdownHardware() { |
140 } | 222 } |
141 | 223 |
142 intptr_t SurfaceFactoryEgltest::GetNativeDisplay() { | 224 intptr_t SurfaceFactoryEgltest::GetNativeDisplay() { |
143 return eglplatform_shim_->ShimGetNativeDisplay(); | 225 return eglplatform_shim_->ShimGetNativeDisplay(); |
144 } | 226 } |
145 | 227 |
146 gfx::AcceleratedWidget SurfaceFactoryEgltest::GetAcceleratedWidget() { | 228 gfx::AcceleratedWidget SurfaceFactoryEgltest::GetAcceleratedWidget() { |
147 if (window_id_ == SHIM_NO_WINDOW_ID && !CreateSingleWindow()) | 229 NOTREACHED(); |
148 LOG(FATAL) << "failed to create window"; | 230 return gfx::kNullAcceleratedWidget; |
149 return window_id_; | |
150 } | 231 } |
151 | 232 |
152 scoped_ptr<SurfaceOzoneEGL> SurfaceFactoryEgltest::CreateEGLSurfaceForWidget( | 233 scoped_ptr<SurfaceOzoneEGL> SurfaceFactoryEgltest::CreateEGLSurfaceForWidget( |
153 gfx::AcceleratedWidget widget) { | 234 gfx::AcceleratedWidget widget) { |
154 return make_scoped_ptr<SurfaceOzoneEGL>( | 235 return make_scoped_ptr<SurfaceOzoneEGL>( |
155 new SurfaceOzoneEgltest(widget, eglplatform_shim_)); | 236 new SurfaceOzoneEgltest(widget, eglplatform_shim_)); |
156 } | 237 } |
157 | 238 |
158 bool SurfaceFactoryEgltest::LoadEGLGLES2Bindings( | 239 bool SurfaceFactoryEgltest::LoadEGLGLES2Bindings( |
159 AddGLLibraryCallback add_gl_library, | 240 AddGLLibraryCallback add_gl_library, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE { | 339 virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE { |
259 return gpu_platform_support_.get(); | 340 return gpu_platform_support_.get(); |
260 } | 341 } |
261 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE { | 342 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE { |
262 return gpu_platform_support_host_.get(); | 343 return gpu_platform_support_host_.get(); |
263 } | 344 } |
264 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow( | 345 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow( |
265 PlatformWindowDelegate* delegate, | 346 PlatformWindowDelegate* delegate, |
266 const gfx::Rect& bounds) OVERRIDE { | 347 const gfx::Rect& bounds) OVERRIDE { |
267 return make_scoped_ptr<PlatformWindow>( | 348 return make_scoped_ptr<PlatformWindow>( |
268 new PlatformWindowCompat(delegate, bounds)); | 349 new EgltestWindow(delegate, &eglplatform_shim_, bounds)); |
269 } | 350 } |
270 | 351 |
271 #if defined(OS_CHROMEOS) | 352 #if defined(OS_CHROMEOS) |
272 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() | 353 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() |
273 OVERRIDE { | 354 OVERRIDE { |
274 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone()); | 355 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone()); |
275 } | 356 } |
276 virtual scoped_ptr<TouchscreenDeviceManager> | 357 virtual scoped_ptr<TouchscreenDeviceManager> |
277 CreateTouchscreenDeviceManager() OVERRIDE { | 358 CreateTouchscreenDeviceManager() OVERRIDE { |
278 return scoped_ptr<TouchscreenDeviceManager>( | 359 return scoped_ptr<TouchscreenDeviceManager>( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 395 |
315 } // namespace | 396 } // namespace |
316 | 397 |
317 OzonePlatform* CreateOzonePlatformEgltest() { | 398 OzonePlatform* CreateOzonePlatformEgltest() { |
318 OzonePlatformEgltest* platform = new OzonePlatformEgltest; | 399 OzonePlatformEgltest* platform = new OzonePlatformEgltest; |
319 platform->Initialize(); | 400 platform->Initialize(); |
320 return platform; | 401 return platform; |
321 } | 402 } |
322 | 403 |
323 } // namespace ui | 404 } // namespace ui |
OLD | NEW |