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

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

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

Powered by Google App Engine
This is Rietveld 408576698