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