1 // Copyright (c) 2012 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.
7 #include "base/command_line.h"
8 #include "gpu/command_buffer/client/gles2_lib.h"
9 #include "gpu/gles2_conform_support/egl/display.h"
10 #include "ui/gl/gl_context.h"
11 #include "ui/gl/gl_surface.h"
16 typedef EGLContext RegalSystemContext
;
18 REGAL_DECL
void RegalMakeCurrent( RegalSystemContext ctx
);
24 void SetCurrentError(EGLint error_code
) {
28 T
EglError(EGLint error_code
, T return_value
) {
29 SetCurrentError(error_code
);
34 T
EglSuccess(T return_value
) {
35 SetCurrentError(EGL_SUCCESS
);
39 EGLint
ValidateDisplay(EGLDisplay dpy
) {
40 if (dpy
== EGL_NO_DISPLAY
)
41 return EGL_BAD_DISPLAY
;
43 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
44 if (!display
->is_initialized())
45 return EGL_NOT_INITIALIZED
;
50 EGLint
ValidateDisplayConfig(EGLDisplay dpy
, EGLConfig config
) {
51 EGLint error_code
= ValidateDisplay(dpy
);
52 if (error_code
!= EGL_SUCCESS
)
55 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
56 if (!display
->IsValidConfig(config
))
57 return EGL_BAD_CONFIG
;
62 EGLint
ValidateDisplaySurface(EGLDisplay dpy
, EGLSurface surface
) {
63 EGLint error_code
= ValidateDisplay(dpy
);
64 if (error_code
!= EGL_SUCCESS
)
67 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
68 if (!display
->IsValidSurface(surface
))
69 return EGL_BAD_SURFACE
;
74 EGLint
ValidateDisplayContext(EGLDisplay dpy
, EGLContext context
) {
75 EGLint error_code
= ValidateDisplay(dpy
);
76 if (error_code
!= EGL_SUCCESS
)
79 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
80 if (!display
->IsValidContext(context
))
81 return EGL_BAD_CONTEXT
;
88 EGLint
eglGetError() {
89 // TODO(alokp): Fix me.
93 EGLDisplay
eglGetDisplay(EGLNativeDisplayType display_id
) {
94 return new egl::Display(display_id
);
97 EGLBoolean
eglInitialize(EGLDisplay dpy
, EGLint
*major
, EGLint
*minor
) {
98 if (dpy
== EGL_NO_DISPLAY
)
99 return EglError(EGL_BAD_DISPLAY
, EGL_FALSE
);
101 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
102 if (!display
->Initialize())
103 return EglError(EGL_NOT_INITIALIZED
, EGL_FALSE
);
106 const char* const argv
[] = {
109 base::CommandLine::Init(argc
, argv
);
110 gfx::GLSurface::InitializeOneOff();
114 return EglSuccess(EGL_TRUE
);
117 EGLBoolean
eglTerminate(EGLDisplay dpy
) {
118 EGLint error_code
= ValidateDisplay(dpy
);
119 if (error_code
!= EGL_SUCCESS
)
120 return EglError(error_code
, EGL_FALSE
);
122 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
125 return EglSuccess(EGL_TRUE
);
128 const char* eglQueryString(EGLDisplay dpy
, EGLint name
) {
129 EGLint error_code
= ValidateDisplay(dpy
);
130 if (error_code
!= EGL_SUCCESS
)
131 return EglError(error_code
, static_cast<const char*>(NULL
));
134 case EGL_CLIENT_APIS
:
135 return EglSuccess("OpenGL_ES");
137 return EglSuccess("");
139 return EglSuccess("Google Inc.");
141 return EglSuccess("1.4");
143 return EglError(EGL_BAD_PARAMETER
, static_cast<const char*>(NULL
));
147 EGLBoolean
eglChooseConfig(EGLDisplay dpy
,
148 const EGLint
* attrib_list
,
151 EGLint
* num_config
) {
152 EGLint error_code
= ValidateDisplay(dpy
);
153 if (error_code
!= EGL_SUCCESS
)
154 return EglError(error_code
, EGL_FALSE
);
156 if (num_config
== NULL
)
157 return EglError(EGL_BAD_PARAMETER
, EGL_FALSE
);
159 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
160 if (!display
->ChooseConfigs(configs
, config_size
, num_config
))
161 return EglError(EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
163 return EglSuccess(EGL_TRUE
);
166 EGLBoolean
eglGetConfigs(EGLDisplay dpy
,
169 EGLint
* num_config
) {
170 EGLint error_code
= ValidateDisplay(dpy
);
171 if (error_code
!= EGL_SUCCESS
)
172 return EglError(error_code
, EGL_FALSE
);
174 if (num_config
== NULL
)
175 return EglError(EGL_BAD_PARAMETER
, EGL_FALSE
);
177 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
178 if (!display
->GetConfigs(configs
, config_size
, num_config
))
179 return EglError(EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
181 return EglSuccess(EGL_TRUE
);
184 EGLBoolean
eglGetConfigAttrib(EGLDisplay dpy
,
188 EGLint error_code
= ValidateDisplayConfig(dpy
, config
);
189 if (error_code
!= EGL_SUCCESS
)
190 return EglError(error_code
, EGL_FALSE
);
192 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
193 if (!display
->GetConfigAttrib(config
, attribute
, value
))
194 return EglError(EGL_BAD_ATTRIBUTE
, EGL_FALSE
);
196 return EglSuccess(EGL_TRUE
);
199 EGLSurface
eglCreateWindowSurface(EGLDisplay dpy
,
201 EGLNativeWindowType win
,
202 const EGLint
* attrib_list
) {
203 EGLint error_code
= ValidateDisplayConfig(dpy
, config
);
204 if (error_code
!= EGL_SUCCESS
)
205 return EglError(error_code
, EGL_NO_SURFACE
);
207 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
208 if (!display
->IsValidNativeWindow(win
))
209 return EglError(EGL_BAD_NATIVE_WINDOW
, EGL_NO_SURFACE
);
211 EGLSurface surface
= display
->CreateWindowSurface(config
, win
, attrib_list
);
212 if (surface
== EGL_NO_SURFACE
)
213 return EglError(EGL_BAD_ALLOC
, EGL_NO_SURFACE
);
215 return EglSuccess(surface
);
218 EGLSurface
eglCreatePbufferSurface(EGLDisplay dpy
,
220 const EGLint
* attrib_list
) {
221 return EGL_NO_SURFACE
;
224 EGLSurface
eglCreatePixmapSurface(EGLDisplay dpy
,
226 EGLNativePixmapType pixmap
,
227 const EGLint
* attrib_list
) {
228 return EGL_NO_SURFACE
;
231 EGLBoolean
eglDestroySurface(EGLDisplay dpy
,
232 EGLSurface surface
) {
233 EGLint error_code
= ValidateDisplaySurface(dpy
, surface
);
234 if (error_code
!= EGL_SUCCESS
)
235 return EglError(error_code
, EGL_FALSE
);
237 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
238 display
->DestroySurface(surface
);
239 return EglSuccess(EGL_TRUE
);
242 EGLBoolean
eglQuerySurface(EGLDisplay dpy
,
249 EGLBoolean
eglBindAPI(EGLenum api
) {
253 EGLenum
eglQueryAPI() {
254 return EGL_OPENGL_ES_API
;
257 EGLBoolean
eglWaitClient(void) {
261 EGLBoolean
eglReleaseThread(void) {
265 EGLSurface
eglCreatePbufferFromClientBuffer(EGLDisplay dpy
,
267 EGLClientBuffer buffer
,
269 const EGLint
* attrib_list
) {
270 return EGL_NO_SURFACE
;
273 EGLBoolean
eglSurfaceAttrib(EGLDisplay dpy
,
280 EGLBoolean
eglBindTexImage(EGLDisplay dpy
,
286 EGLBoolean
eglReleaseTexImage(EGLDisplay dpy
,
292 EGLBoolean
eglSwapInterval(EGLDisplay dpy
, EGLint interval
) {
296 EGLContext
eglCreateContext(EGLDisplay dpy
,
298 EGLContext share_context
,
299 const EGLint
* attrib_list
) {
300 EGLint error_code
= ValidateDisplayConfig(dpy
, config
);
301 if (error_code
!= EGL_SUCCESS
)
302 return EglError(error_code
, EGL_NO_CONTEXT
);
304 if (share_context
!= EGL_NO_CONTEXT
) {
305 error_code
= ValidateDisplayContext(dpy
, share_context
);
306 if (error_code
!= EGL_SUCCESS
)
307 return EglError(error_code
, EGL_NO_CONTEXT
);
310 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
311 EGLContext context
= display
->CreateContext(
312 config
, share_context
, attrib_list
);
313 if (context
== EGL_NO_CONTEXT
)
314 return EglError(EGL_BAD_ALLOC
, EGL_NO_CONTEXT
);
316 return EglSuccess(context
);
319 EGLBoolean
eglDestroyContext(EGLDisplay dpy
, EGLContext ctx
) {
320 EGLint error_code
= ValidateDisplayContext(dpy
, ctx
);
321 if (error_code
!= EGL_SUCCESS
)
322 return EglError(error_code
, EGL_FALSE
);
324 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
325 display
->DestroyContext(ctx
);
329 EGLBoolean
eglMakeCurrent(EGLDisplay dpy
,
333 if (ctx
!= EGL_NO_CONTEXT
) {
334 EGLint error_code
= ValidateDisplaySurface(dpy
, draw
);
335 if (error_code
!= EGL_SUCCESS
)
336 return EglError(error_code
, EGL_FALSE
);
337 error_code
= ValidateDisplaySurface(dpy
, read
);
338 if (error_code
!= EGL_SUCCESS
)
339 return EglError(error_code
, EGL_FALSE
);
340 error_code
= ValidateDisplayContext(dpy
, ctx
);
341 if (error_code
!= EGL_SUCCESS
)
342 return EglError(error_code
, EGL_FALSE
);
345 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
346 if (!display
->MakeCurrent(draw
, read
, ctx
))
347 return EglError(EGL_CONTEXT_LOST
, EGL_FALSE
);
350 RegalMakeCurrent(ctx
);
356 EGLContext
eglGetCurrentContext() {
357 return EGL_NO_CONTEXT
;
360 EGLSurface
eglGetCurrentSurface(EGLint readdraw
) {
361 return EGL_NO_SURFACE
;
364 EGLDisplay
eglGetCurrentDisplay() {
365 return EGL_NO_DISPLAY
;
368 EGLBoolean
eglQueryContext(EGLDisplay dpy
,
375 EGLBoolean
eglWaitGL() {
379 EGLBoolean
eglWaitNative(EGLint engine
) {
383 EGLBoolean
eglSwapBuffers(EGLDisplay dpy
, EGLSurface surface
) {
384 EGLint error_code
= ValidateDisplaySurface(dpy
, surface
);
385 if (error_code
!= EGL_SUCCESS
)
386 return EglError(error_code
, EGL_FALSE
);
388 egl::Display
* display
= static_cast<egl::Display
*>(dpy
);
389 display
->SwapBuffers(surface
);
390 return EglSuccess(EGL_TRUE
);
393 EGLBoolean
eglCopyBuffers(EGLDisplay dpy
,
395 EGLNativePixmapType target
) {
399 /* Now, define eglGetProcAddress using the generic function ptr. type */
400 __eglMustCastToProperFunctionPointerType
401 eglGetProcAddress(const char* procname
) {
402 return reinterpret_cast<__eglMustCastToProperFunctionPointerType
>(
403 gles2::GetGLFunctionPointer(procname
));