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

Side by Side Diff: ui/ozone/platform/egltest/ozone_platform_egltest.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months 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 | « ui/ozone/platform/egltest/ozone_platform_egltest.h ('k') | ui/ozone/platform/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/egltest/ozone_platform_egltest.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/files/file_path.h"
11 #include "base/path_service.h"
12 #include "library_loaders/libeglplatform_shim.h"
13 #include "third_party/khronos/EGL/egl.h"
14 #include "ui/events/ozone/device/device_manager.h"
15 #include "ui/events/ozone/evdev/event_factory_evdev.h"
16 #include "ui/events/ozone/events_ozone.h"
17 #include "ui/events/platform/platform_event_dispatcher.h"
18 #include "ui/gfx/vsync_provider.h"
19 #include "ui/ozone/common/native_display_delegate_ozone.h"
20 #include "ui/ozone/public/cursor_factory_ozone.h"
21 #include "ui/ozone/public/gpu_platform_support.h"
22 #include "ui/ozone/public/gpu_platform_support_host.h"
23 #include "ui/ozone/public/ozone_platform.h"
24 #include "ui/ozone/public/ozone_switches.h"
25 #include "ui/ozone/public/surface_factory_ozone.h"
26 #include "ui/ozone/public/surface_ozone_egl.h"
27 #include "ui/platform_window/platform_window.h"
28 #include "ui/platform_window/platform_window_delegate.h"
29
30 namespace ui {
31
32 namespace {
33
34 const char kEglplatformShim[] = "EGLPLATFORM_SHIM";
35 const char kEglplatformShimDefault[] = "libeglplatform_shim.so.1";
36 const char kDefaultEglSoname[] = "libEGL.so.1";
37 const char kDefaultGlesSoname[] = "libGLESv2.so.2";
38
39 // Get the library soname to load.
40 std::string GetShimLibraryName() {
41 std::string library;
42 scoped_ptr<base::Environment> env(base::Environment::Create());
43 if (env->GetVar(kEglplatformShim, &library))
44 return library;
45 return kEglplatformShimDefault;
46 }
47
48 class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher {
49 public:
50 EgltestWindow(PlatformWindowDelegate* delegate,
51 LibeglplatformShimLoader* eglplatform_shim,
52 EventFactoryEvdev* event_factory,
53 const gfx::Rect& bounds);
54 virtual ~EgltestWindow();
55
56 // PlatformWindow:
57 virtual gfx::Rect GetBounds() override;
58 virtual void SetBounds(const gfx::Rect& bounds) override;
59 virtual void Show() override;
60 virtual void Hide() override;
61 virtual void Close() override;
62 virtual void SetCapture() override;
63 virtual void ReleaseCapture() override;
64 virtual void ToggleFullscreen() override;
65 virtual void Maximize() override;
66 virtual void Minimize() override;
67 virtual void Restore() override;
68 virtual void SetCursor(PlatformCursor cursor) override;
69 virtual void MoveCursorTo(const gfx::Point& location) 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 EventFactoryEvdev* event_factory_;
79 gfx::Rect bounds_;
80 ShimNativeWindowId window_id_;
81
82 DISALLOW_COPY_AND_ASSIGN(EgltestWindow);
83 };
84
85 EgltestWindow::EgltestWindow(PlatformWindowDelegate* delegate,
86 LibeglplatformShimLoader* eglplatform_shim,
87 EventFactoryEvdev* event_factory,
88 const gfx::Rect& bounds)
89 : delegate_(delegate),
90 eglplatform_shim_(eglplatform_shim),
91 event_factory_(event_factory),
92 bounds_(bounds),
93 window_id_(SHIM_NO_WINDOW_ID) {
94 window_id_ = eglplatform_shim_->ShimCreateWindow();
95 delegate_->OnAcceleratedWidgetAvailable(window_id_);
96 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
97 }
98
99 EgltestWindow::~EgltestWindow() {
100 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
101 if (window_id_ != SHIM_NO_WINDOW_ID)
102 eglplatform_shim_->ShimDestroyWindow(window_id_);
103 }
104
105 gfx::Rect EgltestWindow::GetBounds() {
106 return bounds_;
107 }
108
109 void EgltestWindow::SetBounds(const gfx::Rect& bounds) {
110 bounds_ = bounds;
111 delegate_->OnBoundsChanged(bounds);
112 }
113
114 void EgltestWindow::Show() {
115 }
116
117 void EgltestWindow::Hide() {
118 }
119
120 void EgltestWindow::Close() {
121 }
122
123 void EgltestWindow::SetCapture() {
124 }
125
126 void EgltestWindow::ReleaseCapture() {
127 }
128
129 void EgltestWindow::ToggleFullscreen() {
130 }
131
132 void EgltestWindow::Maximize() {
133 }
134
135 void EgltestWindow::Minimize() {
136 }
137
138 void EgltestWindow::Restore() {
139 }
140
141 void EgltestWindow::SetCursor(PlatformCursor cursor) {
142 }
143
144 void EgltestWindow::MoveCursorTo(const gfx::Point& location) {
145 event_factory_->WarpCursorTo(window_id_, location);
146 }
147
148 bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) {
149 return true;
150 }
151
152 uint32_t EgltestWindow::DispatchEvent(const ui::PlatformEvent& native_event) {
153 DispatchEventFromNativeUiEvent(
154 native_event,
155 base::Bind(&PlatformWindowDelegate::DispatchEvent,
156 base::Unretained(delegate_)));
157
158 return ui::POST_DISPATCH_STOP_PROPAGATION;
159 }
160
161 // EGL surface wrapper for libeglplatform_shim.
162 //
163 // This just manages the native window lifetime using
164 // ShimGetNativeWindow & ShimReleaseNativeWindow.
165 class SurfaceOzoneEgltest : public SurfaceOzoneEGL {
166 public:
167 SurfaceOzoneEgltest(ShimNativeWindowId window_id,
168 LibeglplatformShimLoader* eglplatform_shim)
169 : eglplatform_shim_(eglplatform_shim) {
170 native_window_ = eglplatform_shim_->ShimGetNativeWindow(window_id);
171 }
172 virtual ~SurfaceOzoneEgltest() {
173 bool ret = eglplatform_shim_->ShimReleaseNativeWindow(native_window_);
174 DCHECK(ret);
175 }
176
177 virtual intptr_t GetNativeWindow() override { return native_window_; }
178
179 virtual bool OnSwapBuffers() override { return true; }
180
181 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) override {
182 return true;
183 }
184
185 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
186 return scoped_ptr<gfx::VSyncProvider>();
187 }
188
189 private:
190 LibeglplatformShimLoader* eglplatform_shim_;
191 intptr_t native_window_;
192 };
193
194 // EGL surface factory for libeglplatform_shim.
195 //
196 // This finds the right EGL/GLES2 libraries for loading, and creates
197 // a single native window via ShimCreateWindow for drawing
198 // into.
199 class SurfaceFactoryEgltest : public ui::SurfaceFactoryOzone {
200 public:
201 SurfaceFactoryEgltest(LibeglplatformShimLoader* eglplatform_shim)
202 : eglplatform_shim_(eglplatform_shim) {}
203 virtual ~SurfaceFactoryEgltest() {}
204
205 // SurfaceFactoryOzone:
206 virtual intptr_t GetNativeDisplay() override;
207 virtual scoped_ptr<SurfaceOzoneEGL> CreateEGLSurfaceForWidget(
208 gfx::AcceleratedWidget widget) override;
209 virtual const int32* GetEGLSurfaceProperties(
210 const int32* desired_list) override;
211 virtual bool LoadEGLGLES2Bindings(
212 AddGLLibraryCallback add_gl_library,
213 SetGLGetProcAddressProcCallback set_gl_get_proc_address) override;
214
215 private:
216 LibeglplatformShimLoader* eglplatform_shim_;
217 };
218
219 intptr_t SurfaceFactoryEgltest::GetNativeDisplay() {
220 return eglplatform_shim_->ShimGetNativeDisplay();
221 }
222
223 scoped_ptr<SurfaceOzoneEGL> SurfaceFactoryEgltest::CreateEGLSurfaceForWidget(
224 gfx::AcceleratedWidget widget) {
225 return make_scoped_ptr<SurfaceOzoneEGL>(
226 new SurfaceOzoneEgltest(widget, eglplatform_shim_));
227 }
228
229 bool SurfaceFactoryEgltest::LoadEGLGLES2Bindings(
230 AddGLLibraryCallback add_gl_library,
231 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
232 const char* egl_soname = eglplatform_shim_->ShimQueryString(SHIM_EGL_LIBRARY);
233 const char* gles_soname =
234 eglplatform_shim_->ShimQueryString(SHIM_GLES_LIBRARY);
235 if (!egl_soname)
236 egl_soname = kDefaultEglSoname;
237 if (!gles_soname)
238 gles_soname = kDefaultGlesSoname;
239
240 base::NativeLibraryLoadError error;
241 base::NativeLibrary egl_library =
242 base::LoadNativeLibrary(base::FilePath(egl_soname), &error);
243 if (!egl_library) {
244 LOG(WARNING) << "Failed to load EGL library: " << error.ToString();
245 return false;
246 }
247
248 base::NativeLibrary gles_library =
249 base::LoadNativeLibrary(base::FilePath(gles_soname), &error);
250 if (!gles_library) {
251 LOG(WARNING) << "Failed to load GLES library: " << error.ToString();
252 base::UnloadNativeLibrary(egl_library);
253 return false;
254 }
255
256 GLGetProcAddressProc get_proc_address =
257 reinterpret_cast<GLGetProcAddressProc>(
258 base::GetFunctionPointerFromNativeLibrary(egl_library,
259 "eglGetProcAddress"));
260 if (!get_proc_address) {
261 LOG(ERROR) << "eglGetProcAddress not found.";
262 base::UnloadNativeLibrary(egl_library);
263 base::UnloadNativeLibrary(gles_library);
264 return false;
265 }
266
267 set_gl_get_proc_address.Run(get_proc_address);
268 add_gl_library.Run(egl_library);
269 add_gl_library.Run(gles_library);
270 return true;
271 }
272
273 const int32* SurfaceFactoryEgltest::GetEGLSurfaceProperties(
274 const int32* desired_list) {
275 static const int32 broken_props[] = {
276 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
277 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
278 EGL_NONE,
279 };
280 return broken_props;
281 }
282
283 // Test platform for EGL.
284 //
285 // This is a tiny EGL-based platform. Creation of the native window is
286 // handled by a separate library called eglplatform_shim.so.1 because
287 // this itself is platform specific and we want to test out multiple
288 // hardware platforms.
289 class OzonePlatformEgltest : public OzonePlatform {
290 public:
291 OzonePlatformEgltest() : shim_initialized_(false) {}
292 virtual ~OzonePlatformEgltest() {
293 if (shim_initialized_)
294 eglplatform_shim_.ShimTerminate();
295 }
296
297 void LoadShim() {
298 std::string library = GetShimLibraryName();
299
300 if (eglplatform_shim_.Load(library))
301 return;
302
303 base::FilePath module_path;
304 if (!PathService::Get(base::DIR_MODULE, &module_path))
305 LOG(ERROR) << "failed to get DIR_MODULE from PathService";
306 base::FilePath library_path = module_path.Append(library);
307
308 if (eglplatform_shim_.Load(library_path.value()))
309 return;
310
311 LOG(FATAL) << "failed to load " << library;
312 }
313
314 void Initialize() {
315 LoadShim();
316 shim_initialized_ = eglplatform_shim_.ShimInitialize();
317 }
318
319 // OzonePlatform:
320 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
321 return surface_factory_ozone_.get();
322 }
323 virtual CursorFactoryOzone* GetCursorFactoryOzone() override {
324 return cursor_factory_ozone_.get();
325 }
326 virtual GpuPlatformSupport* GetGpuPlatformSupport() override {
327 return gpu_platform_support_.get();
328 }
329 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
330 return gpu_platform_support_host_.get();
331 }
332 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
333 PlatformWindowDelegate* delegate,
334 const gfx::Rect& bounds) override {
335 return make_scoped_ptr<PlatformWindow>(
336 new EgltestWindow(delegate,
337 &eglplatform_shim_,
338 event_factory_ozone_.get(),
339 bounds));
340 }
341 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
342 override {
343 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone());
344 }
345
346 virtual void InitializeUI() override {
347 device_manager_ = CreateDeviceManager();
348 if (!surface_factory_ozone_)
349 surface_factory_ozone_.reset(
350 new SurfaceFactoryEgltest(&eglplatform_shim_));
351 event_factory_ozone_.reset(
352 new EventFactoryEvdev(NULL, device_manager_.get()));
353 cursor_factory_ozone_.reset(new CursorFactoryOzone());
354 gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
355 }
356
357 virtual void InitializeGPU() override {
358 if (!surface_factory_ozone_)
359 surface_factory_ozone_.reset(
360 new SurfaceFactoryEgltest(&eglplatform_shim_));
361 gpu_platform_support_.reset(CreateStubGpuPlatformSupport());
362 }
363
364 private:
365 LibeglplatformShimLoader eglplatform_shim_;
366 scoped_ptr<DeviceManager> device_manager_;
367 scoped_ptr<SurfaceFactoryEgltest> surface_factory_ozone_;
368 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
369 scoped_ptr<CursorFactoryOzone> cursor_factory_ozone_;
370 scoped_ptr<GpuPlatformSupport> gpu_platform_support_;
371 scoped_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
372
373 bool shim_initialized_;
374
375 DISALLOW_COPY_AND_ASSIGN(OzonePlatformEgltest);
376 };
377
378 } // namespace
379
380 OzonePlatform* CreateOzonePlatformEgltest() {
381 OzonePlatformEgltest* platform = new OzonePlatformEgltest;
382 platform->Initialize();
383 return platform;
384 }
385
386 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/egltest/ozone_platform_egltest.h ('k') | ui/ozone/platform/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698