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

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

Issue 288603002: ozone: Add egltest platform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deofficialize Created 6 years, 7 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 | Annotate | Revision Log
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/command_line.h"
8 #include "base/environment.h"
9 #include "base/files/file_path.h"
10 #include "base/path_service.h"
11 #include "library_loaders/libeglplatform_shim.h"
12 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
13 #include "ui/events/ozone/evdev/event_factory_evdev.h"
14 #include "ui/gfx/ozone/impl/file_surface_factory.h"
15 #include "ui/gfx/ozone/surface_ozone_egl.h"
16 #include "ui/gfx/vsync_provider.h"
17 #include "ui/ozone/ime/input_method_context_factory_ozone.h"
18 #include "ui/ozone/ozone_platform.h"
19 #include "ui/ozone/ozone_switches.h"
20
21 #if defined(OS_CHROMEOS)
22 #include "ui/ozone/common/chromeos/native_display_delegate_ozone.h"
23 #endif
24
25 namespace ui {
26
27 namespace {
28
29 const char kEglplatformShim[] = "EGLPLATFORM_SHIM";
30 const char kEglplatformShimDefault[] = "eglplatform_shim.so.1";
31 const char kDefaultEglSoname[] = "libEGL.so.1";
32 const char kDefaultGlesSoname[] = "libGLESv2.so.2";
33
34 // Get the library soname to load.
alexst (slow to review) 2014/05/13 22:11:14 add space in soname
spang 2014/05/13 22:28:08 one word http://en.wikipedia.org/wiki/Soname
35 std::string GetShimLibraryName() {
36 std::string library;
37 scoped_ptr<base::Environment> env(base::Environment::Create());
38 if (env->GetVar(kEglplatformShim, &library))
39 return library;
40 return kEglplatformShimDefault;
41 }
42
43 // EGL surface wrapper for libeglplatform_shim
alexst (slow to review) 2014/05/13 22:11:14 period at the end
spang 2014/05/13 22:28:08 Done.
44 //
45 // This just manages the native window lifetime using
46 // ShimGetNativeWindow & ShimReleaseNativeWindow.
47 class SurfaceOzoneEgltest : public gfx::SurfaceOzoneEGL {
48 public:
49 SurfaceOzoneEgltest(ShimNativeWindowId window_id,
50 LibeglplatformShimLoader* eglplatform_shim)
51 : eglplatform_shim_(eglplatform_shim) {
52 native_window_ = eglplatform_shim_->ShimGetNativeWindow(window_id);
53 }
54 virtual ~SurfaceOzoneEgltest() {
55 CHECK(eglplatform_shim_->ShimReleaseNativeWindow(native_window_));
56 }
57
58 virtual intptr_t GetNativeWindow() OVERRIDE { return native_window_; }
59
60 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE {
61 return true;
62 }
63
64 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
65 return scoped_ptr<gfx::VSyncProvider>();
66 }
67
68 private:
69 LibeglplatformShimLoader* eglplatform_shim_;
70 intptr_t native_window_;
71 };
72
73 // EGL surface factory for libeglplatform_shim
alexst (slow to review) 2014/05/13 22:11:14 period
spang 2014/05/13 22:28:08 Done.
74 //
75 // This finds the right EGL/GLES2 libraries for loading, and creates
76 // a single native window via ShimCreateWindow for drawing
77 // into.
78 class SurfaceFactoryEgltest : public gfx::SurfaceFactoryOzone {
79 public:
80 SurfaceFactoryEgltest(LibeglplatformShimLoader* eglplatform_shim)
81 : eglplatform_shim_(eglplatform_shim), window_id_(SHIM_NO_WINDOW_ID) {}
82 virtual ~SurfaceFactoryEgltest() { DestroySingleWindow(); }
83
84 // Create the window.
85 bool CreateSingleWindow();
86 void DestroySingleWindow();
87
88 // SurfaceFactoryOzone:
89 virtual HardwareState InitializeHardware() OVERRIDE;
90 virtual void ShutdownHardware() OVERRIDE;
91 virtual intptr_t GetNativeDisplay() OVERRIDE;
92 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
93 virtual scoped_ptr<gfx::SurfaceOzoneEGL> CreateEGLSurfaceForWidget(
94 gfx::AcceleratedWidget widget);
95 virtual const int32* GetEGLSurfaceProperties(
96 const int32* desired_list) OVERRIDE;
97
98 OVERRIDE;
alexst (slow to review) 2014/05/13 22:11:14 Does this belong to CreateEGLSurfaceForWidget?
spang 2014/05/13 22:28:08 Done.
99 virtual bool LoadEGLGLES2Bindings(
100 AddGLLibraryCallback add_gl_library,
101 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE;
102
103 private:
104 LibeglplatformShimLoader* eglplatform_shim_;
105
106 // TODO(spang): Remove once we have a windowing API. This limits to 1 window.
107 ShimNativeWindowId window_id_;
108 };
109
110 bool SurfaceFactoryEgltest::CreateSingleWindow() {
111 EGLint window_attribs[] = {EGL_NONE};
alexst (slow to review) 2014/05/13 22:11:14 This is unused, it seems.
spang 2014/05/13 22:28:08 Done.
112 window_id_ = eglplatform_shim_->ShimCreateWindow(window_attribs);
113 return (window_id_ != SHIM_NO_WINDOW_ID);
114 }
115
116 void SurfaceFactoryEgltest::DestroySingleWindow() {
117 if (window_id_ != SHIM_NO_WINDOW_ID)
118 CHECK(eglplatform_shim_->ShimDestroyWindow(window_id_));
119 }
120
121 SurfaceFactoryEgltest::HardwareState
122 SurfaceFactoryEgltest::InitializeHardware() {
123 return INITIALIZED;
124 }
125
126 void SurfaceFactoryEgltest::ShutdownHardware() {
127 }
128
129 intptr_t SurfaceFactoryEgltest::GetNativeDisplay() {
130 return eglplatform_shim_->ShimGetNativeDisplay();
131 }
132
133 gfx::AcceleratedWidget SurfaceFactoryEgltest::GetAcceleratedWidget() {
134 if (window_id_ == SHIM_NO_WINDOW_ID && !CreateSingleWindow())
135 LOG(FATAL) << "failed to create window";
136 return window_id_;
137 }
138
139 scoped_ptr<gfx::SurfaceOzoneEGL>
140 SurfaceFactoryEgltest::CreateEGLSurfaceForWidget(
141 gfx::AcceleratedWidget widget) {
142 return make_scoped_ptr<gfx::SurfaceOzoneEGL>(
143 new SurfaceOzoneEgltest(widget, eglplatform_shim_));
144 }
145
146 bool SurfaceFactoryEgltest::LoadEGLGLES2Bindings(
147 AddGLLibraryCallback add_gl_library,
148 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
149 const char* egl_soname = eglplatform_shim_->ShimQueryString(SHIM_EGL_LIBRARY);
150 const char* gles_soname =
151 eglplatform_shim_->ShimQueryString(SHIM_GLES_LIBRARY);
152 if (!egl_soname)
153 egl_soname = kDefaultEglSoname;
154 if (!gles_soname)
155 gles_soname = kDefaultGlesSoname;
156
157 base::NativeLibraryLoadError error;
158 base::NativeLibrary egl_library =
159 base::LoadNativeLibrary(base::FilePath(egl_soname), &error);
160 if (!egl_library) {
161 LOG(WARNING) << "Failed to load EGL library: " << error.ToString();
162 return false;
163 }
164
165 base::NativeLibrary gles_library =
166 base::LoadNativeLibrary(base::FilePath(gles_soname), &error);
167 if (!gles_library) {
168 LOG(WARNING) << "Failed to load GLES library: " << error.ToString();
169 base::UnloadNativeLibrary(egl_library);
170 return false;
171 }
172
173 GLGetProcAddressProc get_proc_address =
174 reinterpret_cast<GLGetProcAddressProc>(
175 base::GetFunctionPointerFromNativeLibrary(egl_library,
176 "eglGetProcAddress"));
177 if (!get_proc_address) {
178 LOG(ERROR) << "eglGetProcAddress not found.";
179 base::UnloadNativeLibrary(egl_library);
180 base::UnloadNativeLibrary(gles_library);
181 return false;
182 }
183
184 set_gl_get_proc_address.Run(get_proc_address);
185 add_gl_library.Run(egl_library);
186 add_gl_library.Run(gles_library);
187 return true;
188 }
189
190 const int32* SurfaceFactoryEgltest::GetEGLSurfaceProperties(
191 const int32* desired_list) {
192 static const int32 broken_props[] = {
193 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
194 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
195 EGL_NONE,
196 };
197 return broken_props;
198 }
199
200 // Test platform for EGL.
201 //
202 // This is a tiny EGL-based platform. Creation of the native window is
203 // handled by a separate library called eglplatform_shim.so.1 because
204 // this itself is platform specific and we want to test out multiple
205 // hardware platforms.
206 class OzonePlatformEgltest : public OzonePlatform {
207 public:
208 OzonePlatformEgltest()
209 : surface_factory_ozone_(&eglplatform_shim_), shim_initialized_(false) {}
210 virtual ~OzonePlatformEgltest() {
211 if (shim_initialized_)
212 eglplatform_shim_.ShimTerminate();
213 }
214
215 void LoadShim() {
216 std::string library = GetShimLibraryName();
217
218 if (eglplatform_shim_.Load(library))
219 return;
220
221 base::FilePath module_path;
222 if (!PathService::Get(base::DIR_MODULE, &module_path))
223 LOG(ERROR) << "failed to get DIR_MODULE from PathService";
224 base::FilePath library_path = module_path.Append(library);
225
226 if (eglplatform_shim_.Load(library_path.value()))
227 return;
228
229 LOG(FATAL) << "failed to load " << library;
230 }
231
232 void Initialize() {
233 LoadShim();
234 shim_initialized_ = eglplatform_shim_.ShimInitialize();
235 }
236
237 // OzonePlatform:
238 virtual gfx::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
239 return &surface_factory_ozone_;
240 }
241 virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE {
242 return &event_factory_ozone_;
243 }
244 virtual InputMethodContextFactoryOzone* GetInputMethodContextFactoryOzone()
245 OVERRIDE {
246 return &input_method_context_factory_ozone_;
247 }
248 virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE {
249 return &cursor_factory_ozone_;
250 }
251
252 #if defined(OS_CHROMEOS)
253 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
254 OVERRIDE {
255 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone());
256 }
257 #endif
258
259 private:
260 LibeglplatformShimLoader eglplatform_shim_;
261 SurfaceFactoryEgltest surface_factory_ozone_;
262 EventFactoryEvdev event_factory_ozone_;
263 InputMethodContextFactoryOzone input_method_context_factory_ozone_;
264 CursorFactoryOzone cursor_factory_ozone_;
265
266 bool shim_initialized_;
267
268 DISALLOW_COPY_AND_ASSIGN(OzonePlatformEgltest);
269 };
270
271 } // namespace
272
273 OzonePlatform* CreateOzonePlatformEgltest() {
274 OzonePlatformEgltest* platform = new OzonePlatformEgltest;
275 platform->Initialize();
276 return platform;
277 }
278
279 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698