| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <EGL/egl.h> | 5 #include <EGL/egl.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/command_line.h" | |
| 9 #include "base/environment.h" | |
| 10 #include "base/strings/string_split.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "gpu/command_buffer/client/gles2_lib.h" | 8 #include "gpu/command_buffer/client/gles2_lib.h" |
| 14 #include "gpu/command_buffer/service/gpu_switches.h" | 9 #include "gpu/gles2_conform_support/egl/config.h" |
| 15 #include "gpu/config/gpu_info_collector.h" | 10 #include "gpu/gles2_conform_support/egl/context.h" |
| 16 #include "gpu/config/gpu_util.h" | |
| 17 #include "gpu/gles2_conform_support/egl/display.h" | 11 #include "gpu/gles2_conform_support/egl/display.h" |
| 18 #include "ui/gl/gl_context.h" | 12 #include "gpu/gles2_conform_support/egl/surface.h" |
| 19 #include "ui/gl/gl_surface.h" | 13 #include "gpu/gles2_conform_support/egl/thread_state.h" |
| 20 | |
| 21 #if REGAL_STATIC_EGL | |
| 22 extern "C" { | |
| 23 | |
| 24 typedef EGLContext RegalSystemContext; | |
| 25 #define REGAL_DECL | |
| 26 REGAL_DECL void RegalMakeCurrent( RegalSystemContext ctx ); | |
| 27 | |
| 28 } // extern "C" | |
| 29 #endif | |
| 30 | |
| 31 namespace { | |
| 32 void SetCurrentError(EGLint error_code) { | |
| 33 } | |
| 34 | |
| 35 template<typename T> | |
| 36 T EglError(EGLint error_code, T return_value) { | |
| 37 SetCurrentError(error_code); | |
| 38 return return_value; | |
| 39 } | |
| 40 | |
| 41 template<typename T> | |
| 42 T EglSuccess(T return_value) { | |
| 43 SetCurrentError(EGL_SUCCESS); | |
| 44 return return_value; | |
| 45 } | |
| 46 | |
| 47 EGLint ValidateDisplay(EGLDisplay dpy) { | |
| 48 if (dpy == EGL_NO_DISPLAY) | |
| 49 return EGL_BAD_DISPLAY; | |
| 50 | |
| 51 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 52 if (!display->is_initialized()) | |
| 53 return EGL_NOT_INITIALIZED; | |
| 54 | |
| 55 return EGL_SUCCESS; | |
| 56 } | |
| 57 | |
| 58 EGLint ValidateDisplayConfig(EGLDisplay dpy, EGLConfig config) { | |
| 59 EGLint error_code = ValidateDisplay(dpy); | |
| 60 if (error_code != EGL_SUCCESS) | |
| 61 return error_code; | |
| 62 | |
| 63 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 64 if (!display->IsValidConfig(config)) | |
| 65 return EGL_BAD_CONFIG; | |
| 66 | |
| 67 return EGL_SUCCESS; | |
| 68 } | |
| 69 | |
| 70 EGLint ValidateDisplaySurface(EGLDisplay dpy, EGLSurface surface) { | |
| 71 EGLint error_code = ValidateDisplay(dpy); | |
| 72 if (error_code != EGL_SUCCESS) | |
| 73 return error_code; | |
| 74 | |
| 75 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 76 if (!display->IsValidSurface(surface)) | |
| 77 return EGL_BAD_SURFACE; | |
| 78 | |
| 79 return EGL_SUCCESS; | |
| 80 } | |
| 81 | |
| 82 EGLint ValidateDisplayContext(EGLDisplay dpy, EGLContext context) { | |
| 83 EGLint error_code = ValidateDisplay(dpy); | |
| 84 if (error_code != EGL_SUCCESS) | |
| 85 return error_code; | |
| 86 | |
| 87 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 88 if (!display->IsValidContext(context)) | |
| 89 return EGL_BAD_CONTEXT; | |
| 90 | |
| 91 return EGL_SUCCESS; | |
| 92 } | |
| 93 } // namespace | |
| 94 | 14 |
| 95 extern "C" { | 15 extern "C" { |
| 96 EGLAPI EGLint EGLAPIENTRY eglGetError() { | 16 EGLAPI EGLint EGLAPIENTRY eglGetError() { |
| 97 // TODO(alokp): Fix me. | 17 return egl::ThreadState::Get()->ConsumeErrorCode(); |
| 98 return EGL_SUCCESS; | |
| 99 } | 18 } |
| 100 | 19 |
| 101 EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) { | 20 EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) { |
| 102 return new egl::Display(display_id); | 21 if (display_id != EGL_DEFAULT_DISPLAY) |
| 22 return EGL_NO_DISPLAY; |
| 23 return egl::ThreadState::Get()->GetDefaultDisplay(); |
| 103 } | 24 } |
| 104 | 25 |
| 105 EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, | 26 EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, |
| 106 EGLint* major, | 27 EGLint* major, |
| 107 EGLint* minor) { | 28 EGLint* minor) { |
| 108 if (dpy == EGL_NO_DISPLAY) | 29 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 109 return EglError(EGL_BAD_DISPLAY, EGL_FALSE); | 30 egl::Display* display = ts->GetDisplay(dpy); |
| 110 | 31 if (!display) |
| 111 egl::Display* display = static_cast<egl::Display*>(dpy); | 32 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 112 if (!display->Initialize()) | 33 return display->Initialize(ts, major, minor); |
| 113 return EglError(EGL_NOT_INITIALIZED, EGL_FALSE); | |
| 114 | |
| 115 // eglInitialize can be called multiple times, prevent InitializeOneOff from | |
| 116 // being called multiple times. | |
| 117 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | |
| 118 base::CommandLine::StringVector argv; | |
| 119 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 120 std::string env_string; | |
| 121 env->GetVar("CHROME_COMMAND_BUFFER_GLES2_ARGS", &env_string); | |
| 122 #if defined(OS_WIN) | |
| 123 argv = base::SplitString(base::UTF8ToUTF16(env_string), | |
| 124 base::kWhitespaceUTF16, base::TRIM_WHITESPACE, | |
| 125 base::SPLIT_WANT_NONEMPTY); | |
| 126 argv.insert(argv.begin(), base::UTF8ToUTF16("dummy")); | |
| 127 #else | |
| 128 argv = base::SplitString(env_string, | |
| 129 base::kWhitespaceASCII, base::TRIM_WHITESPACE, | |
| 130 base::SPLIT_WANT_NONEMPTY); | |
| 131 argv.insert(argv.begin(), "dummy"); | |
| 132 #endif | |
| 133 base::CommandLine::Init(0, nullptr); | |
| 134 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 135 // Need to call both Init and InitFromArgv, since Windows does not use | |
| 136 // argc, argv in CommandLine::Init(argc, argv). | |
| 137 command_line->InitFromArgv(argv); | |
| 138 if (!command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds)) { | |
| 139 gpu::GPUInfo gpu_info; | |
| 140 gpu::CollectBasicGraphicsInfo(&gpu_info); | |
| 141 gpu::ApplyGpuDriverBugWorkarounds(gpu_info, command_line); | |
| 142 } | |
| 143 | |
| 144 gfx::GLSurface::InitializeOneOff(); | |
| 145 } | |
| 146 if (major) | |
| 147 *major = 1; | |
| 148 if (minor) | |
| 149 *minor = 4; | |
| 150 return EglSuccess(EGL_TRUE); | |
| 151 } | 34 } |
| 152 | 35 |
| 153 EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { | 36 EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { |
| 154 EGLint error_code = ValidateDisplay(dpy); | 37 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 155 if (error_code != EGL_SUCCESS) | 38 egl::Display* display = ts->GetDisplay(dpy); |
| 156 return EglError(error_code, EGL_FALSE); | 39 if (!display) |
| 157 | 40 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 158 egl::Display* display = static_cast<egl::Display*>(dpy); | 41 return display->Terminate(ts); |
| 159 delete display; | |
| 160 | |
| 161 // TODO: EGL specifies that the objects are marked for deletion and they will | |
| 162 // remain alive as long as "contexts or surfaces associated with display is | |
| 163 // current to any thread". | |
| 164 // Currently we delete the display here, and may also call exit handlers. | |
| 165 | |
| 166 return EglSuccess(EGL_TRUE); | |
| 167 } | 42 } |
| 168 | 43 |
| 169 EGLAPI const char* EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { | 44 EGLAPI const char* EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { |
| 170 EGLint error_code = ValidateDisplay(dpy); | 45 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 171 if (error_code != EGL_SUCCESS) | 46 if (dpy == EGL_NO_DISPLAY) { |
| 172 return EglError(error_code, static_cast<const char*>(NULL)); | 47 switch (name) { |
| 173 | 48 case EGL_EXTENSIONS: |
| 174 switch (name) { | 49 return ts->ReturnSuccess(""); |
| 175 case EGL_CLIENT_APIS: | 50 case EGL_VERSION: |
| 176 return EglSuccess("OpenGL_ES"); | 51 return ts->ReturnSuccess("1.4"); |
| 177 case EGL_EXTENSIONS: | 52 default: |
| 178 return EglSuccess(""); | 53 break; |
| 179 case EGL_VENDOR: | 54 } |
| 180 return EglSuccess("Google Inc."); | |
| 181 case EGL_VERSION: | |
| 182 return EglSuccess("1.4"); | |
| 183 default: | |
| 184 return EglError(EGL_BAD_PARAMETER, static_cast<const char*>(NULL)); | |
| 185 } | 55 } |
| 56 egl::Display* display = ts->GetDisplay(dpy); |
| 57 if (!display) |
| 58 return ts->ReturnError<const char*>(EGL_BAD_DISPLAY, nullptr); |
| 59 return display->QueryString(ts, name); |
| 186 } | 60 } |
| 187 | 61 |
| 188 EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, | 62 EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, |
| 189 const EGLint* attrib_list, | 63 const EGLint* attrib_list, |
| 190 EGLConfig* configs, | 64 EGLConfig* configs, |
| 191 EGLint config_size, | 65 EGLint config_size, |
| 192 EGLint* num_config) { | 66 EGLint* num_config) { |
| 193 EGLint error_code = ValidateDisplay(dpy); | 67 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 194 if (error_code != EGL_SUCCESS) | 68 egl::Display* display = ts->GetDisplay(dpy); |
| 195 return EglError(error_code, EGL_FALSE); | 69 if (!display) |
| 196 | 70 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 197 if (num_config == NULL) | 71 return display->ChooseConfig(ts, attrib_list, configs, config_size, |
| 198 return EglError(EGL_BAD_PARAMETER, EGL_FALSE); | 72 num_config); |
| 199 | |
| 200 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 201 if (!display->ChooseConfigs(configs, config_size, num_config)) | |
| 202 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | |
| 203 | |
| 204 return EglSuccess(EGL_TRUE); | |
| 205 } | 73 } |
| 206 | 74 |
| 207 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, | 75 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, |
| 208 EGLConfig* configs, | 76 EGLConfig* configs, |
| 209 EGLint config_size, | 77 EGLint config_size, |
| 210 EGLint* num_config) { | 78 EGLint* num_config) { |
| 211 EGLint error_code = ValidateDisplay(dpy); | 79 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 212 if (error_code != EGL_SUCCESS) | 80 egl::Display* display = ts->GetDisplay(dpy); |
| 213 return EglError(error_code, EGL_FALSE); | 81 if (!display) |
| 214 | 82 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 215 if (num_config == NULL) | 83 return display->GetConfigs(ts, configs, config_size, num_config); |
| 216 return EglError(EGL_BAD_PARAMETER, EGL_FALSE); | |
| 217 | |
| 218 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 219 if (!display->GetConfigs(configs, config_size, num_config)) | |
| 220 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | |
| 221 | |
| 222 return EglSuccess(EGL_TRUE); | |
| 223 } | 84 } |
| 224 | 85 |
| 225 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, | 86 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, |
| 226 EGLConfig config, | 87 EGLConfig cfg, |
| 227 EGLint attribute, | 88 EGLint attribute, |
| 228 EGLint* value) { | 89 EGLint* value) { |
| 229 EGLint error_code = ValidateDisplayConfig(dpy, config); | 90 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 230 if (error_code != EGL_SUCCESS) | 91 egl::Display* display = ts->GetDisplay(dpy); |
| 231 return EglError(error_code, EGL_FALSE); | 92 if (!display) |
| 232 | 93 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 233 egl::Display* display = static_cast<egl::Display*>(dpy); | 94 return display->GetConfigAttrib(ts, cfg, attribute, value); |
| 234 if (!display->GetConfigAttrib(config, attribute, value)) | |
| 235 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | |
| 236 | |
| 237 return EglSuccess(EGL_TRUE); | |
| 238 } | 95 } |
| 239 | 96 |
| 240 EGLAPI EGLSurface EGLAPIENTRY | 97 EGLAPI EGLSurface EGLAPIENTRY |
| 241 eglCreateWindowSurface(EGLDisplay dpy, | 98 eglCreateWindowSurface(EGLDisplay dpy, |
| 242 EGLConfig config, | 99 EGLConfig cfg, |
| 243 EGLNativeWindowType win, | 100 EGLNativeWindowType win, |
| 244 const EGLint* attrib_list) { | 101 const EGLint* attrib_list) { |
| 245 EGLint error_code = ValidateDisplayConfig(dpy, config); | 102 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 246 if (error_code != EGL_SUCCESS) | 103 egl::Display* display = ts->GetDisplay(dpy); |
| 247 return EglError(error_code, EGL_NO_SURFACE); | 104 if (!display) |
| 248 | 105 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); |
| 249 egl::Display* display = static_cast<egl::Display*>(dpy); | 106 return display->CreateWindowSurface(ts, cfg, win, attrib_list); |
| 250 if (!display->IsValidNativeWindow(win)) | |
| 251 return EglError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | |
| 252 | |
| 253 EGLSurface surface = display->CreateWindowSurface(config, win, attrib_list); | |
| 254 if (surface == EGL_NO_SURFACE) | |
| 255 return EglError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | |
| 256 | |
| 257 return EglSuccess(surface); | |
| 258 } | 107 } |
| 259 | 108 |
| 260 EGLAPI EGLSurface EGLAPIENTRY | 109 EGLAPI EGLSurface EGLAPIENTRY |
| 261 eglCreatePbufferSurface(EGLDisplay dpy, | 110 eglCreatePbufferSurface(EGLDisplay dpy, |
| 262 EGLConfig config, | 111 EGLConfig cfg, |
| 263 const EGLint* attrib_list) { | 112 const EGLint* attrib_list) { |
| 264 EGLint error_code = ValidateDisplayConfig(dpy, config); | 113 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 265 if (error_code != EGL_SUCCESS) | 114 egl::Display* display = ts->GetDisplay(dpy); |
| 266 return EglError(error_code, EGL_NO_SURFACE); | 115 if (!display) |
| 267 | 116 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); |
| 268 egl::Display* display = static_cast<egl::Display*>(dpy); | 117 return display->CreatePbufferSurface(ts, cfg, attrib_list); |
| 269 int width = 1; | |
| 270 int height = 1; | |
| 271 if (attrib_list) { | |
| 272 for (const int32_t* attr = attrib_list; attr[0] != EGL_NONE; attr += 2) { | |
| 273 switch (attr[0]) { | |
| 274 case EGL_WIDTH: | |
| 275 width = attr[1]; | |
| 276 break; | |
| 277 case EGL_HEIGHT: | |
| 278 height = attr[1]; | |
| 279 break; | |
| 280 } | |
| 281 } | |
| 282 } | |
| 283 display->SetCreateOffscreen(width, height); | |
| 284 | |
| 285 EGLSurface surface = display->CreateWindowSurface(config, 0, attrib_list); | |
| 286 if (surface == EGL_NO_SURFACE) | |
| 287 return EglError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | |
| 288 | |
| 289 return EglSuccess(surface); | |
| 290 } | 118 } |
| 291 | 119 |
| 292 EGLAPI EGLSurface EGLAPIENTRY | 120 EGLAPI EGLSurface EGLAPIENTRY |
| 293 eglCreatePixmapSurface(EGLDisplay dpy, | 121 eglCreatePixmapSurface(EGLDisplay dpy, |
| 294 EGLConfig config, | 122 EGLConfig config, |
| 295 EGLNativePixmapType pixmap, | 123 EGLNativePixmapType pixmap, |
| 296 const EGLint* attrib_list) { | 124 const EGLint* attrib_list) { |
| 297 return EGL_NO_SURFACE; | 125 return EGL_NO_SURFACE; |
| 298 } | 126 } |
| 299 | 127 |
| 300 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, | 128 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, |
| 301 EGLSurface surface) { | 129 EGLSurface sfe) { |
| 302 EGLint error_code = ValidateDisplaySurface(dpy, surface); | 130 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 303 if (error_code != EGL_SUCCESS) | 131 egl::Display* display = ts->GetDisplay(dpy); |
| 304 return EglError(error_code, EGL_FALSE); | 132 if (!display) |
| 305 | 133 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 306 egl::Display* display = static_cast<egl::Display*>(dpy); | 134 return display->DestroySurface(ts, sfe); |
| 307 display->DestroySurface(surface); | |
| 308 return EglSuccess(EGL_TRUE); | |
| 309 } | 135 } |
| 310 | 136 |
| 311 EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, | 137 EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, |
| 312 EGLSurface surface, | 138 EGLSurface surface, |
| 313 EGLint attribute, | 139 EGLint attribute, |
| 314 EGLint* value) { | 140 EGLint* value) { |
| 315 return EGL_FALSE; | 141 return EGL_FALSE; |
| 316 } | 142 } |
| 317 | 143 |
| 318 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api) { | 144 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api) { |
| 319 return EGL_FALSE; | 145 return EGL_FALSE; |
| 320 } | 146 } |
| 321 | 147 |
| 322 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI() { | 148 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI() { |
| 323 return EGL_OPENGL_ES_API; | 149 return EGL_OPENGL_ES_API; |
| 324 } | 150 } |
| 325 | 151 |
| 326 EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void) { | 152 EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void) { |
| 327 return EGL_FALSE; | 153 return EGL_FALSE; |
| 328 } | 154 } |
| 329 | 155 |
| 330 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { | 156 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { |
| 331 return EGL_FALSE; | 157 egl::ThreadState::ReleaseThread(); |
| 158 return EGL_TRUE; |
| 332 } | 159 } |
| 333 | 160 |
| 334 EGLAPI EGLSurface EGLAPIENTRY | 161 EGLAPI EGLSurface EGLAPIENTRY |
| 335 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, | 162 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, |
| 336 EGLenum buftype, | 163 EGLenum buftype, |
| 337 EGLClientBuffer buffer, | 164 EGLClientBuffer buffer, |
| 338 EGLConfig config, | 165 EGLConfig config, |
| 339 const EGLint* attrib_list) { | 166 const EGLint* attrib_list) { |
| 340 return EGL_NO_SURFACE; | 167 return EGL_NO_SURFACE; |
| 341 } | 168 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 357 EGLSurface surface, | 184 EGLSurface surface, |
| 358 EGLint buffer) { | 185 EGLint buffer) { |
| 359 return EGL_FALSE; | 186 return EGL_FALSE; |
| 360 } | 187 } |
| 361 | 188 |
| 362 EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { | 189 EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { |
| 363 return EGL_FALSE; | 190 return EGL_FALSE; |
| 364 } | 191 } |
| 365 | 192 |
| 366 EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, | 193 EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, |
| 367 EGLConfig config, | 194 EGLConfig cfg, |
| 368 EGLContext share_context, | 195 EGLContext share_ctx, |
| 369 const EGLint* attrib_list) { | 196 const EGLint* attrib_list) { |
| 370 EGLint error_code = ValidateDisplayConfig(dpy, config); | 197 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 371 if (error_code != EGL_SUCCESS) | 198 egl::Display* display = ts->GetDisplay(dpy); |
| 372 return EglError(error_code, EGL_NO_CONTEXT); | 199 if (!display) |
| 373 | 200 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_CONTEXT); |
| 374 if (share_context != EGL_NO_CONTEXT) { | 201 return display->CreateContext(ts, cfg, share_ctx, attrib_list); |
| 375 error_code = ValidateDisplayContext(dpy, share_context); | |
| 376 if (error_code != EGL_SUCCESS) | |
| 377 return EglError(error_code, EGL_NO_CONTEXT); | |
| 378 } | |
| 379 | |
| 380 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 381 EGLContext context = display->CreateContext( | |
| 382 config, share_context, attrib_list); | |
| 383 if (context == EGL_NO_CONTEXT) | |
| 384 return EglError(EGL_BAD_ALLOC, EGL_NO_CONTEXT); | |
| 385 | |
| 386 return EglSuccess(context); | |
| 387 } | 202 } |
| 388 | 203 |
| 389 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, | 204 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, |
| 390 EGLContext ctx) { | 205 EGLContext ctx) { |
| 391 EGLint error_code = ValidateDisplayContext(dpy, ctx); | 206 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 392 if (error_code != EGL_SUCCESS) | 207 egl::Display* display = ts->GetDisplay(dpy); |
| 393 return EglError(error_code, EGL_FALSE); | 208 if (!display) |
| 394 | 209 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 395 egl::Display* display = static_cast<egl::Display*>(dpy); | 210 return display->DestroyContext(ts, ctx); |
| 396 display->DestroyContext(ctx); | |
| 397 return EGL_TRUE; | |
| 398 } | 211 } |
| 399 | 212 |
| 400 EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, | 213 EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, |
| 401 EGLSurface draw, | 214 EGLSurface draw, |
| 402 EGLSurface read, | 215 EGLSurface read, |
| 403 EGLContext ctx) { | 216 EGLContext ctx) { |
| 404 if (ctx != EGL_NO_CONTEXT) { | 217 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 405 EGLint error_code = ValidateDisplaySurface(dpy, draw); | 218 if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && |
| 406 if (error_code != EGL_SUCCESS) | 219 ctx == EGL_NO_CONTEXT) { |
| 407 return EglError(error_code, EGL_FALSE); | 220 egl::Display* display = |
| 408 error_code = ValidateDisplaySurface(dpy, read); | 221 dpy == EGL_NO_DISPLAY ? ts->GetDefaultDisplay() : ts->GetDisplay(dpy); |
| 409 if (error_code != EGL_SUCCESS) | 222 if (!display) |
| 410 return EglError(error_code, EGL_FALSE); | 223 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 411 error_code = ValidateDisplayContext(dpy, ctx); | 224 return display->ReleaseCurrent(ts); |
| 412 if (error_code != EGL_SUCCESS) | |
| 413 return EglError(error_code, EGL_FALSE); | |
| 414 } | 225 } |
| 415 | 226 egl::Display* display = ts->GetDisplay(dpy); |
| 416 egl::Display* display = static_cast<egl::Display*>(dpy); | 227 if (!display) |
| 417 if (!display->MakeCurrent(draw, read, ctx)) | 228 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 418 return EglError(EGL_CONTEXT_LOST, EGL_FALSE); | 229 return display->MakeCurrent(ts, draw, read, ctx); |
| 419 | |
| 420 #if REGAL_STATIC_EGL | |
| 421 RegalMakeCurrent(ctx); | |
| 422 #endif | |
| 423 | |
| 424 return EGL_TRUE; | |
| 425 } | 230 } |
| 426 | 231 |
| 427 EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext() { | 232 EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext() { |
| 428 return EGL_NO_CONTEXT; | 233 return EGL_NO_CONTEXT; |
| 429 } | 234 } |
| 430 | 235 |
| 431 EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { | 236 EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { |
| 432 return EGL_NO_SURFACE; | 237 return EGL_NO_SURFACE; |
| 433 } | 238 } |
| 434 | 239 |
| 435 EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay() { | 240 EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay() { |
| 436 return EGL_NO_DISPLAY; | 241 return EGL_NO_DISPLAY; |
| 437 } | 242 } |
| 438 | 243 |
| 439 EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, | 244 EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, |
| 440 EGLContext ctx, | 245 EGLContext ctx, |
| 441 EGLint attribute, | 246 EGLint attribute, |
| 442 EGLint* value) { | 247 EGLint* value) { |
| 443 return EGL_FALSE; | 248 return EGL_FALSE; |
| 444 } | 249 } |
| 445 | 250 |
| 446 EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL() { | 251 EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL() { |
| 447 return EGL_FALSE; | 252 return EGL_FALSE; |
| 448 } | 253 } |
| 449 | 254 |
| 450 EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { | 255 EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { |
| 451 return EGL_FALSE; | 256 return EGL_FALSE; |
| 452 } | 257 } |
| 453 | 258 |
| 454 EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, | 259 EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface sfe) { |
| 455 EGLSurface surface) { | 260 egl::ThreadState* ts = egl::ThreadState::Get(); |
| 456 EGLint error_code = ValidateDisplaySurface(dpy, surface); | 261 egl::Display* display = ts->GetDisplay(dpy); |
| 457 if (error_code != EGL_SUCCESS) | 262 if (!display) |
| 458 return EglError(error_code, EGL_FALSE); | 263 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 459 | 264 return display->SwapBuffers(ts, sfe); |
| 460 egl::Display* display = static_cast<egl::Display*>(dpy); | |
| 461 display->SwapBuffers(surface); | |
| 462 return EglSuccess(EGL_TRUE); | |
| 463 } | 265 } |
| 464 | 266 |
| 465 EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, | 267 EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, |
| 466 EGLSurface surface, | 268 EGLSurface surface, |
| 467 EGLNativePixmapType target) { | 269 EGLNativePixmapType target) { |
| 468 return EGL_FALSE; | 270 return EGL_FALSE; |
| 469 } | 271 } |
| 470 | 272 |
| 471 /* Now, define eglGetProcAddress using the generic function ptr. type */ | 273 /* Now, define eglGetProcAddress using the generic function ptr. type */ |
| 472 EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY | 274 EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY |
| 473 eglGetProcAddress(const char* procname) { | 275 eglGetProcAddress(const char* procname) { |
| 474 return reinterpret_cast<__eglMustCastToProperFunctionPointerType>( | 276 return reinterpret_cast<__eglMustCastToProperFunctionPointerType>( |
| 475 gles2::GetGLFunctionPointer(procname)); | 277 gles2::GetGLFunctionPointer(procname)); |
| 476 } | 278 } |
| 477 } // extern "C" | 279 } // extern "C" |
| OLD | NEW |