OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 <EGL/egl.h> | |
6 | |
7 #include "ui/gfx/gl/gl_context.h" | |
8 #include "ui/gfx/gl/gl_surface.h" | |
9 #include "base/command_line.h" | |
10 #include "gpu/gles2_conform_support/egl/display.h" | |
11 | |
12 namespace { | |
13 void SetCurrentError(EGLint error_code) { | |
14 } | |
15 | |
16 template<typename T> | |
17 T EglError(EGLint error_code, T return_value) { | |
18 SetCurrentError(error_code); | |
19 return return_value; | |
20 } | |
21 | |
22 template<typename T> | |
23 T EglSuccess(T return_value) { | |
24 SetCurrentError(EGL_SUCCESS); | |
25 return return_value; | |
26 } | |
27 | |
28 EGLint ValidateDisplay(EGLDisplay dpy) { | |
29 if (dpy == EGL_NO_DISPLAY) | |
30 return EGL_BAD_DISPLAY; | |
31 | |
32 egl::Display* display = static_cast<egl::Display*>(dpy); | |
33 if (!display->is_initialized()) | |
34 return EGL_NOT_INITIALIZED; | |
35 | |
36 return EGL_SUCCESS; | |
37 } | |
38 | |
39 EGLint ValidateDisplayConfig(EGLDisplay dpy, EGLConfig config) { | |
40 EGLint error_code = ValidateDisplay(dpy); | |
41 if (error_code != EGL_SUCCESS) | |
42 return error_code; | |
43 | |
44 egl::Display* display = static_cast<egl::Display*>(dpy); | |
45 if (!display->IsValidConfig(config)) | |
46 return EGL_BAD_CONFIG; | |
47 | |
48 return EGL_SUCCESS; | |
49 } | |
50 | |
51 EGLint ValidateDisplaySurface(EGLDisplay dpy, EGLSurface surface) { | |
52 EGLint error_code = ValidateDisplay(dpy); | |
53 if (error_code != EGL_SUCCESS) | |
54 return error_code; | |
55 | |
56 egl::Display* display = static_cast<egl::Display*>(dpy); | |
57 if (!display->IsValidSurface(surface)) | |
58 return EGL_BAD_SURFACE; | |
59 | |
60 return EGL_SUCCESS; | |
61 } | |
62 | |
63 EGLint ValidateDisplayContext(EGLDisplay dpy, EGLContext context) { | |
64 EGLint error_code = ValidateDisplay(dpy); | |
65 if (error_code != EGL_SUCCESS) | |
66 return error_code; | |
67 | |
68 egl::Display* display = static_cast<egl::Display*>(dpy); | |
69 if (!display->IsValidContext(context)) | |
70 return EGL_BAD_CONTEXT; | |
71 | |
72 return EGL_SUCCESS; | |
73 } | |
74 } // namespace | |
75 | |
76 extern "C" { | |
77 EGLint eglGetError() { | |
78 // TODO(alokp): Fix me. | |
79 return EGL_SUCCESS; | |
80 } | |
81 | |
82 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) { | |
83 return new egl::Display(display_id); | |
84 } | |
85 | |
86 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { | |
87 if (dpy == EGL_NO_DISPLAY) | |
88 return EglError(EGL_BAD_DISPLAY, EGL_FALSE); | |
89 | |
90 egl::Display* display = static_cast<egl::Display*>(dpy); | |
91 if (!display->Initialize()) | |
92 return EglError(EGL_NOT_INITIALIZED, EGL_FALSE); | |
93 | |
94 int argc = 1; | |
95 const char* const argv[] = { | |
96 "dummy" | |
97 }; | |
98 CommandLine::Init(argc, argv); | |
99 gfx::GLSurface::InitializeOneOff(); | |
100 | |
101 *major = 1; | |
102 *minor = 4; | |
103 return EglSuccess(EGL_TRUE); | |
104 } | |
105 | |
106 EGLBoolean eglTerminate(EGLDisplay dpy) { | |
107 EGLint error_code = ValidateDisplay(dpy); | |
108 if (error_code != EGL_SUCCESS) | |
109 return EglError(error_code, EGL_FALSE); | |
110 | |
111 egl::Display* display = static_cast<egl::Display*>(dpy); | |
112 delete display; | |
113 | |
114 return EglSuccess(EGL_TRUE); | |
115 } | |
116 | |
117 const char* eglQueryString(EGLDisplay dpy, EGLint name) { | |
118 EGLint error_code = ValidateDisplay(dpy); | |
119 if (error_code != EGL_SUCCESS) | |
120 return EglError(error_code, static_cast<const char*>(NULL)); | |
121 | |
122 switch (name) { | |
123 case EGL_CLIENT_APIS: | |
124 return EglSuccess("OpenGL_ES"); | |
125 case EGL_EXTENSIONS: | |
126 return EglSuccess(""); | |
127 case EGL_VENDOR: | |
128 return EglSuccess("Google Inc."); | |
129 case EGL_VERSION: | |
130 return EglSuccess("1.4"); | |
131 default: | |
132 return EglError(EGL_BAD_PARAMETER, static_cast<const char*>(NULL)); | |
133 } | |
134 } | |
135 | |
136 EGLBoolean eglGetConfigs(EGLDisplay dpy, | |
137 EGLConfig* configs, | |
138 EGLint config_size, | |
139 EGLint* num_config) { | |
140 EGLint error_code = ValidateDisplay(dpy); | |
141 if (error_code != EGL_SUCCESS) | |
142 return EglError(error_code, EGL_FALSE); | |
143 | |
144 if (num_config == NULL) | |
145 return EglError(EGL_BAD_PARAMETER, EGL_FALSE); | |
146 | |
147 egl::Display* display = static_cast<egl::Display*>(dpy); | |
148 if (!display->GetConfigs(configs, config_size, num_config)) | |
149 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | |
150 | |
151 return EglSuccess(EGL_TRUE); | |
152 } | |
153 | |
154 EGLBoolean eglChooseConfig(EGLDisplay dpy, | |
155 const EGLint* attrib_list, | |
156 EGLConfig* configs, | |
157 EGLint config_size, | |
158 EGLint* num_config) { | |
159 return EGL_FALSE; | |
160 } | |
161 | |
162 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, | |
163 EGLConfig config, | |
164 EGLint attribute, | |
165 EGLint* value) { | |
166 EGLint error_code = ValidateDisplayConfig(dpy, config); | |
167 if (error_code != EGL_SUCCESS) | |
168 return EglError(error_code, EGL_FALSE); | |
169 | |
170 egl::Display* display = static_cast<egl::Display*>(dpy); | |
171 if (!display->GetConfigAttrib(config, attribute, value)) | |
172 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | |
173 | |
174 return EglSuccess(EGL_TRUE); | |
175 } | |
176 | |
177 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, | |
178 EGLConfig config, | |
179 EGLNativeWindowType win, | |
180 const EGLint* attrib_list) { | |
181 EGLint error_code = ValidateDisplayConfig(dpy, config); | |
182 if (error_code != EGL_SUCCESS) | |
183 return EglError(error_code, EGL_NO_SURFACE); | |
184 | |
185 egl::Display* display = static_cast<egl::Display*>(dpy); | |
186 if (!display->IsValidNativeWindow(win)) | |
187 return EglError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | |
188 | |
189 EGLSurface surface = display->CreateWindowSurface(config, win, attrib_list); | |
190 if (surface == EGL_NO_SURFACE) | |
191 return EglError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | |
192 | |
193 return EglSuccess(surface); | |
194 } | |
195 | |
196 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, | |
197 EGLConfig config, | |
198 const EGLint* attrib_list) { | |
199 return EGL_NO_SURFACE; | |
200 } | |
201 | |
202 EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, | |
203 EGLConfig config, | |
204 EGLNativePixmapType pixmap, | |
205 const EGLint* attrib_list) { | |
206 return EGL_NO_SURFACE; | |
207 } | |
208 | |
209 EGLBoolean eglDestroySurface(EGLDisplay dpy, | |
210 EGLSurface surface) { | |
211 EGLint error_code = ValidateDisplaySurface(dpy, surface); | |
212 if (error_code != EGL_SUCCESS) | |
213 return EglError(error_code, EGL_FALSE); | |
214 | |
215 egl::Display* display = static_cast<egl::Display*>(dpy); | |
216 display->DestroySurface(surface); | |
217 return EglSuccess(EGL_TRUE); | |
218 } | |
219 | |
220 EGLBoolean eglQuerySurface(EGLDisplay dpy, | |
221 EGLSurface surface, | |
222 EGLint attribute, | |
223 EGLint* value) { | |
224 return EGL_FALSE; | |
225 } | |
226 | |
227 EGLBoolean eglBindAPI(EGLenum api) { | |
228 return EGL_FALSE; | |
229 } | |
230 | |
231 EGLenum eglQueryAPI() { | |
232 return EGL_OPENGL_ES_API; | |
233 } | |
234 | |
235 EGLBoolean eglWaitClient(void) { | |
236 return EGL_FALSE; | |
237 } | |
238 | |
239 EGLBoolean eglReleaseThread(void) { | |
240 return EGL_FALSE; | |
241 } | |
242 | |
243 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, | |
244 EGLenum buftype, | |
245 EGLClientBuffer buffer, | |
246 EGLConfig config, | |
247 const EGLint* attrib_list) { | |
248 return EGL_NO_SURFACE; | |
249 } | |
250 | |
251 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, | |
252 EGLSurface surface, | |
253 EGLint attribute, | |
254 EGLint value) { | |
255 return EGL_FALSE; | |
256 } | |
257 | |
258 EGLBoolean eglBindTexImage(EGLDisplay dpy, | |
259 EGLSurface surface, | |
260 EGLint buffer) { | |
261 return EGL_FALSE; | |
262 } | |
263 | |
264 EGLBoolean eglReleaseTexImage(EGLDisplay dpy, | |
265 EGLSurface surface, | |
266 EGLint buffer) { | |
267 return EGL_FALSE; | |
268 } | |
269 | |
270 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) { | |
271 return EGL_FALSE; | |
272 } | |
273 | |
274 EGLContext eglCreateContext(EGLDisplay dpy, | |
275 EGLConfig config, | |
276 EGLContext share_context, | |
277 const EGLint* attrib_list) { | |
278 EGLint error_code = ValidateDisplayConfig(dpy, config); | |
279 if (error_code != EGL_SUCCESS) | |
280 return EglError(error_code, EGL_NO_CONTEXT); | |
281 | |
282 if (share_context != EGL_NO_CONTEXT) { | |
283 error_code = ValidateDisplayContext(dpy, share_context); | |
284 if (error_code != EGL_SUCCESS) | |
285 return EglError(error_code, EGL_NO_CONTEXT); | |
286 } | |
287 | |
288 egl::Display* display = static_cast<egl::Display*>(dpy); | |
289 EGLContext context = display->CreateContext( | |
290 config, share_context, attrib_list); | |
291 if (context == EGL_NO_CONTEXT) | |
292 return EglError(EGL_BAD_ALLOC, EGL_NO_CONTEXT); | |
293 | |
294 return EglSuccess(context); | |
295 } | |
296 | |
297 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { | |
298 EGLint error_code = ValidateDisplayContext(dpy, ctx); | |
299 if (error_code != EGL_SUCCESS) | |
300 return EglError(error_code, EGL_FALSE); | |
301 | |
302 egl::Display* display = static_cast<egl::Display*>(dpy); | |
303 display->DestroyContext(ctx); | |
304 return EGL_TRUE; | |
305 } | |
306 | |
307 EGLBoolean eglMakeCurrent(EGLDisplay dpy, | |
308 EGLSurface draw, | |
309 EGLSurface read, | |
310 EGLContext ctx) { | |
311 if (ctx != EGL_NO_CONTEXT) { | |
312 EGLint error_code = ValidateDisplaySurface(dpy, draw); | |
313 if (error_code != EGL_SUCCESS) | |
314 return EglError(error_code, EGL_FALSE); | |
315 error_code = ValidateDisplaySurface(dpy, read); | |
316 if (error_code != EGL_SUCCESS) | |
317 return EglError(error_code, EGL_FALSE); | |
318 error_code = ValidateDisplayContext(dpy, ctx); | |
319 if (error_code != EGL_SUCCESS) | |
320 return EglError(error_code, EGL_FALSE); | |
321 } | |
322 | |
323 egl::Display* display = static_cast<egl::Display*>(dpy); | |
324 if (!display->MakeCurrent(draw, read, ctx)) | |
325 return EglError(EGL_CONTEXT_LOST, EGL_FALSE); | |
326 return EGL_TRUE; | |
327 } | |
328 | |
329 EGLContext eglGetCurrentContext() { | |
330 return EGL_NO_CONTEXT; | |
331 } | |
332 | |
333 EGLSurface eglGetCurrentSurface(EGLint readdraw) { | |
334 return EGL_NO_SURFACE; | |
335 } | |
336 | |
337 EGLDisplay eglGetCurrentDisplay() { | |
338 return EGL_NO_DISPLAY; | |
339 } | |
340 | |
341 EGLBoolean eglQueryContext(EGLDisplay dpy, | |
342 EGLContext ctx, | |
343 EGLint attribute, | |
344 EGLint* value) { | |
345 return EGL_FALSE; | |
346 } | |
347 | |
348 EGLBoolean eglWaitGL() { | |
349 return EGL_FALSE; | |
350 } | |
351 | |
352 EGLBoolean eglWaitNative(EGLint engine) { | |
353 return EGL_FALSE; | |
354 } | |
355 | |
356 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { | |
357 EGLint error_code = ValidateDisplaySurface(dpy, surface); | |
358 if (error_code != EGL_SUCCESS) | |
359 return EglError(error_code, EGL_FALSE); | |
360 | |
361 egl::Display* display = static_cast<egl::Display*>(dpy); | |
362 display->SwapBuffers(surface); | |
363 return EglSuccess(EGL_TRUE); | |
364 } | |
365 | |
366 EGLBoolean eglCopyBuffers(EGLDisplay dpy, | |
367 EGLSurface surface, | |
368 EGLNativePixmapType target) { | |
369 return EGL_FALSE; | |
370 } | |
371 | |
372 /* Now, define eglGetProcAddress using the generic function ptr. type */ | |
373 __eglMustCastToProperFunctionPointerType | |
374 eglGetProcAddress(const char* procname) { | |
375 return NULL; | |
376 } | |
377 } // extern "C" | |
OLD | NEW |