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" |
8 #include "gpu/command_buffer/client/gles2_lib.h" | 13 #include "gpu/command_buffer/client/gles2_lib.h" |
9 #include "gpu/gles2_conform_support/egl/config.h" | 14 #include "gpu/command_buffer/service/gpu_switches.h" |
10 #include "gpu/gles2_conform_support/egl/context.h" | 15 #include "gpu/config/gpu_info_collector.h" |
| 16 #include "gpu/config/gpu_util.h" |
11 #include "gpu/gles2_conform_support/egl/display.h" | 17 #include "gpu/gles2_conform_support/egl/display.h" |
12 #include "gpu/gles2_conform_support/egl/surface.h" | 18 #include "ui/gl/gl_context.h" |
13 #include "gpu/gles2_conform_support/egl/thread_state.h" | 19 #include "ui/gl/gl_surface.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 |
14 | 94 |
15 extern "C" { | 95 extern "C" { |
16 EGLAPI EGLint EGLAPIENTRY eglGetError() { | 96 EGLAPI EGLint EGLAPIENTRY eglGetError() { |
17 return egl::ThreadState::Get()->ConsumeErrorCode(); | 97 // TODO(alokp): Fix me. |
| 98 return EGL_SUCCESS; |
18 } | 99 } |
19 | 100 |
20 EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) { | 101 EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) { |
21 if (display_id != EGL_DEFAULT_DISPLAY) | 102 return new egl::Display(display_id); |
22 return EGL_NO_DISPLAY; | |
23 return egl::ThreadState::Get()->GetDefaultDisplay(); | |
24 } | 103 } |
25 | 104 |
26 EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, | 105 EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, |
27 EGLint* major, | 106 EGLint* major, |
28 EGLint* minor) { | 107 EGLint* minor) { |
29 egl::ThreadState* ts = egl::ThreadState::Get(); | 108 if (dpy == EGL_NO_DISPLAY) |
30 egl::Display* display = ts->GetDisplay(dpy); | 109 return EglError(EGL_BAD_DISPLAY, EGL_FALSE); |
31 if (!display) | 110 |
32 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 111 egl::Display* display = static_cast<egl::Display*>(dpy); |
33 return display->Initialize(ts, major, minor); | 112 if (!display->Initialize()) |
| 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); |
34 } | 151 } |
35 | 152 |
36 EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { | 153 EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { |
37 egl::ThreadState* ts = egl::ThreadState::Get(); | 154 EGLint error_code = ValidateDisplay(dpy); |
38 egl::Display* display = ts->GetDisplay(dpy); | 155 if (error_code != EGL_SUCCESS) |
39 if (!display) | 156 return EglError(error_code, EGL_FALSE); |
40 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 157 |
41 return display->Terminate(ts); | 158 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 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); |
42 } | 167 } |
43 | 168 |
44 EGLAPI const char* EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { | 169 EGLAPI const char* EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { |
45 egl::ThreadState* ts = egl::ThreadState::Get(); | 170 EGLint error_code = ValidateDisplay(dpy); |
46 if (dpy == EGL_NO_DISPLAY) { | 171 if (error_code != EGL_SUCCESS) |
47 switch (name) { | 172 return EglError(error_code, static_cast<const char*>(NULL)); |
48 case EGL_EXTENSIONS: | 173 |
49 return ts->ReturnSuccess(""); | 174 switch (name) { |
50 case EGL_VERSION: | 175 case EGL_CLIENT_APIS: |
51 return ts->ReturnSuccess("1.4"); | 176 return EglSuccess("OpenGL_ES"); |
52 default: | 177 case EGL_EXTENSIONS: |
53 break; | 178 return EglSuccess(""); |
54 } | 179 case EGL_VENDOR: |
| 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)); |
55 } | 185 } |
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); | |
60 } | 186 } |
61 | 187 |
62 EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, | 188 EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, |
63 const EGLint* attrib_list, | 189 const EGLint* attrib_list, |
64 EGLConfig* configs, | 190 EGLConfig* configs, |
65 EGLint config_size, | 191 EGLint config_size, |
66 EGLint* num_config) { | 192 EGLint* num_config) { |
67 egl::ThreadState* ts = egl::ThreadState::Get(); | 193 EGLint error_code = ValidateDisplay(dpy); |
68 egl::Display* display = ts->GetDisplay(dpy); | 194 if (error_code != EGL_SUCCESS) |
69 if (!display) | 195 return EglError(error_code, EGL_FALSE); |
70 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 196 |
71 return display->ChooseConfig(ts, attrib_list, configs, config_size, | 197 if (num_config == NULL) |
72 num_config); | 198 return EglError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 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); |
73 } | 205 } |
74 | 206 |
75 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, | 207 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, |
76 EGLConfig* configs, | 208 EGLConfig* configs, |
77 EGLint config_size, | 209 EGLint config_size, |
78 EGLint* num_config) { | 210 EGLint* num_config) { |
79 egl::ThreadState* ts = egl::ThreadState::Get(); | 211 EGLint error_code = ValidateDisplay(dpy); |
80 egl::Display* display = ts->GetDisplay(dpy); | 212 if (error_code != EGL_SUCCESS) |
81 if (!display) | 213 return EglError(error_code, EGL_FALSE); |
82 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 214 |
83 return display->GetConfigs(ts, configs, config_size, num_config); | 215 if (num_config == NULL) |
| 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); |
84 } | 223 } |
85 | 224 |
86 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, | 225 EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, |
87 EGLConfig cfg, | 226 EGLConfig config, |
88 EGLint attribute, | 227 EGLint attribute, |
89 EGLint* value) { | 228 EGLint* value) { |
90 egl::ThreadState* ts = egl::ThreadState::Get(); | 229 EGLint error_code = ValidateDisplayConfig(dpy, config); |
91 egl::Display* display = ts->GetDisplay(dpy); | 230 if (error_code != EGL_SUCCESS) |
92 if (!display) | 231 return EglError(error_code, EGL_FALSE); |
93 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 232 |
94 return display->GetConfigAttrib(ts, cfg, attribute, value); | 233 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 234 if (!display->GetConfigAttrib(config, attribute, value)) |
| 235 return EglError(EGL_BAD_ATTRIBUTE, EGL_FALSE); |
| 236 |
| 237 return EglSuccess(EGL_TRUE); |
95 } | 238 } |
96 | 239 |
97 EGLAPI EGLSurface EGLAPIENTRY | 240 EGLAPI EGLSurface EGLAPIENTRY |
98 eglCreateWindowSurface(EGLDisplay dpy, | 241 eglCreateWindowSurface(EGLDisplay dpy, |
99 EGLConfig cfg, | 242 EGLConfig config, |
100 EGLNativeWindowType win, | 243 EGLNativeWindowType win, |
101 const EGLint* attrib_list) { | 244 const EGLint* attrib_list) { |
102 egl::ThreadState* ts = egl::ThreadState::Get(); | 245 EGLint error_code = ValidateDisplayConfig(dpy, config); |
103 egl::Display* display = ts->GetDisplay(dpy); | 246 if (error_code != EGL_SUCCESS) |
104 if (!display) | 247 return EglError(error_code, EGL_NO_SURFACE); |
105 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 248 |
106 return display->CreateWindowSurface(ts, cfg, win, attrib_list); | 249 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 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); |
107 } | 258 } |
108 | 259 |
109 EGLAPI EGLSurface EGLAPIENTRY | 260 EGLAPI EGLSurface EGLAPIENTRY |
110 eglCreatePbufferSurface(EGLDisplay dpy, | 261 eglCreatePbufferSurface(EGLDisplay dpy, |
111 EGLConfig cfg, | 262 EGLConfig config, |
112 const EGLint* attrib_list) { | 263 const EGLint* attrib_list) { |
113 egl::ThreadState* ts = egl::ThreadState::Get(); | 264 EGLint error_code = ValidateDisplayConfig(dpy, config); |
114 egl::Display* display = ts->GetDisplay(dpy); | 265 if (error_code != EGL_SUCCESS) |
115 if (!display) | 266 return EglError(error_code, EGL_NO_SURFACE); |
116 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 267 |
117 return display->CreatePbufferSurface(ts, cfg, attrib_list); | 268 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 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); |
118 } | 290 } |
119 | 291 |
120 EGLAPI EGLSurface EGLAPIENTRY | 292 EGLAPI EGLSurface EGLAPIENTRY |
121 eglCreatePixmapSurface(EGLDisplay dpy, | 293 eglCreatePixmapSurface(EGLDisplay dpy, |
122 EGLConfig config, | 294 EGLConfig config, |
123 EGLNativePixmapType pixmap, | 295 EGLNativePixmapType pixmap, |
124 const EGLint* attrib_list) { | 296 const EGLint* attrib_list) { |
125 return EGL_NO_SURFACE; | 297 return EGL_NO_SURFACE; |
126 } | 298 } |
127 | 299 |
128 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, | 300 EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, |
129 EGLSurface sfe) { | 301 EGLSurface surface) { |
130 egl::ThreadState* ts = egl::ThreadState::Get(); | 302 EGLint error_code = ValidateDisplaySurface(dpy, surface); |
131 egl::Display* display = ts->GetDisplay(dpy); | 303 if (error_code != EGL_SUCCESS) |
132 if (!display) | 304 return EglError(error_code, EGL_FALSE); |
133 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 305 |
134 return display->DestroySurface(ts, sfe); | 306 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 307 display->DestroySurface(surface); |
| 308 return EglSuccess(EGL_TRUE); |
135 } | 309 } |
136 | 310 |
137 EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, | 311 EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, |
138 EGLSurface surface, | 312 EGLSurface surface, |
139 EGLint attribute, | 313 EGLint attribute, |
140 EGLint* value) { | 314 EGLint* value) { |
141 return EGL_FALSE; | 315 return EGL_FALSE; |
142 } | 316 } |
143 | 317 |
144 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api) { | 318 EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api) { |
145 return EGL_FALSE; | 319 return EGL_FALSE; |
146 } | 320 } |
147 | 321 |
148 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI() { | 322 EGLAPI EGLenum EGLAPIENTRY eglQueryAPI() { |
149 return EGL_OPENGL_ES_API; | 323 return EGL_OPENGL_ES_API; |
150 } | 324 } |
151 | 325 |
152 EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void) { | 326 EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void) { |
153 return EGL_FALSE; | 327 return EGL_FALSE; |
154 } | 328 } |
155 | 329 |
156 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { | 330 EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { |
157 egl::ThreadState::ReleaseThread(); | 331 return EGL_FALSE; |
158 return EGL_TRUE; | |
159 } | 332 } |
160 | 333 |
161 EGLAPI EGLSurface EGLAPIENTRY | 334 EGLAPI EGLSurface EGLAPIENTRY |
162 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, | 335 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, |
163 EGLenum buftype, | 336 EGLenum buftype, |
164 EGLClientBuffer buffer, | 337 EGLClientBuffer buffer, |
165 EGLConfig config, | 338 EGLConfig config, |
166 const EGLint* attrib_list) { | 339 const EGLint* attrib_list) { |
167 return EGL_NO_SURFACE; | 340 return EGL_NO_SURFACE; |
168 } | 341 } |
(...skipping 15 matching lines...) Expand all Loading... |
184 EGLSurface surface, | 357 EGLSurface surface, |
185 EGLint buffer) { | 358 EGLint buffer) { |
186 return EGL_FALSE; | 359 return EGL_FALSE; |
187 } | 360 } |
188 | 361 |
189 EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { | 362 EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { |
190 return EGL_FALSE; | 363 return EGL_FALSE; |
191 } | 364 } |
192 | 365 |
193 EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, | 366 EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, |
194 EGLConfig cfg, | 367 EGLConfig config, |
195 EGLContext share_ctx, | 368 EGLContext share_context, |
196 const EGLint* attrib_list) { | 369 const EGLint* attrib_list) { |
197 egl::ThreadState* ts = egl::ThreadState::Get(); | 370 EGLint error_code = ValidateDisplayConfig(dpy, config); |
198 egl::Display* display = ts->GetDisplay(dpy); | 371 if (error_code != EGL_SUCCESS) |
199 if (!display) | 372 return EglError(error_code, EGL_NO_CONTEXT); |
200 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_NO_CONTEXT); | 373 |
201 return display->CreateContext(ts, cfg, share_ctx, attrib_list); | 374 if (share_context != EGL_NO_CONTEXT) { |
| 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); |
202 } | 387 } |
203 | 388 |
204 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, | 389 EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, |
205 EGLContext ctx) { | 390 EGLContext ctx) { |
206 egl::ThreadState* ts = egl::ThreadState::Get(); | 391 EGLint error_code = ValidateDisplayContext(dpy, ctx); |
207 egl::Display* display = ts->GetDisplay(dpy); | 392 if (error_code != EGL_SUCCESS) |
208 if (!display) | 393 return EglError(error_code, EGL_FALSE); |
209 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 394 |
210 return display->DestroyContext(ts, ctx); | 395 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 396 display->DestroyContext(ctx); |
| 397 return EGL_TRUE; |
211 } | 398 } |
212 | 399 |
213 EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, | 400 EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, |
214 EGLSurface draw, | 401 EGLSurface draw, |
215 EGLSurface read, | 402 EGLSurface read, |
216 EGLContext ctx) { | 403 EGLContext ctx) { |
217 egl::ThreadState* ts = egl::ThreadState::Get(); | 404 if (ctx != EGL_NO_CONTEXT) { |
218 if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && | 405 EGLint error_code = ValidateDisplaySurface(dpy, draw); |
219 ctx == EGL_NO_CONTEXT) { | 406 if (error_code != EGL_SUCCESS) |
220 egl::Display* display = | 407 return EglError(error_code, EGL_FALSE); |
221 dpy == EGL_NO_DISPLAY ? ts->GetDefaultDisplay() : ts->GetDisplay(dpy); | 408 error_code = ValidateDisplaySurface(dpy, read); |
222 if (!display) | 409 if (error_code != EGL_SUCCESS) |
223 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 410 return EglError(error_code, EGL_FALSE); |
224 return display->ReleaseCurrent(ts); | 411 error_code = ValidateDisplayContext(dpy, ctx); |
| 412 if (error_code != EGL_SUCCESS) |
| 413 return EglError(error_code, EGL_FALSE); |
225 } | 414 } |
226 egl::Display* display = ts->GetDisplay(dpy); | 415 |
227 if (!display) | 416 egl::Display* display = static_cast<egl::Display*>(dpy); |
228 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 417 if (!display->MakeCurrent(draw, read, ctx)) |
229 return display->MakeCurrent(ts, draw, read, ctx); | 418 return EglError(EGL_CONTEXT_LOST, EGL_FALSE); |
| 419 |
| 420 #if REGAL_STATIC_EGL |
| 421 RegalMakeCurrent(ctx); |
| 422 #endif |
| 423 |
| 424 return EGL_TRUE; |
230 } | 425 } |
231 | 426 |
232 EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext() { | 427 EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext() { |
233 return EGL_NO_CONTEXT; | 428 return EGL_NO_CONTEXT; |
234 } | 429 } |
235 | 430 |
236 EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { | 431 EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { |
237 return EGL_NO_SURFACE; | 432 return EGL_NO_SURFACE; |
238 } | 433 } |
239 | 434 |
240 EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay() { | 435 EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay() { |
241 return EGL_NO_DISPLAY; | 436 return EGL_NO_DISPLAY; |
242 } | 437 } |
243 | 438 |
244 EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, | 439 EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, |
245 EGLContext ctx, | 440 EGLContext ctx, |
246 EGLint attribute, | 441 EGLint attribute, |
247 EGLint* value) { | 442 EGLint* value) { |
248 return EGL_FALSE; | 443 return EGL_FALSE; |
249 } | 444 } |
250 | 445 |
251 EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL() { | 446 EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL() { |
252 return EGL_FALSE; | 447 return EGL_FALSE; |
253 } | 448 } |
254 | 449 |
255 EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { | 450 EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { |
256 return EGL_FALSE; | 451 return EGL_FALSE; |
257 } | 452 } |
258 | 453 |
259 EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface sfe) { | 454 EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, |
260 egl::ThreadState* ts = egl::ThreadState::Get(); | 455 EGLSurface surface) { |
261 egl::Display* display = ts->GetDisplay(dpy); | 456 EGLint error_code = ValidateDisplaySurface(dpy, surface); |
262 if (!display) | 457 if (error_code != EGL_SUCCESS) |
263 return ts->ReturnError(EGL_BAD_DISPLAY, EGL_FALSE); | 458 return EglError(error_code, EGL_FALSE); |
264 return display->SwapBuffers(ts, sfe); | 459 |
| 460 egl::Display* display = static_cast<egl::Display*>(dpy); |
| 461 display->SwapBuffers(surface); |
| 462 return EglSuccess(EGL_TRUE); |
265 } | 463 } |
266 | 464 |
267 EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, | 465 EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, |
268 EGLSurface surface, | 466 EGLSurface surface, |
269 EGLNativePixmapType target) { | 467 EGLNativePixmapType target) { |
270 return EGL_FALSE; | 468 return EGL_FALSE; |
271 } | 469 } |
272 | 470 |
273 /* Now, define eglGetProcAddress using the generic function ptr. type */ | 471 /* Now, define eglGetProcAddress using the generic function ptr. type */ |
274 EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY | 472 EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY |
275 eglGetProcAddress(const char* procname) { | 473 eglGetProcAddress(const char* procname) { |
276 return reinterpret_cast<__eglMustCastToProperFunctionPointerType>( | 474 return reinterpret_cast<__eglMustCastToProperFunctionPointerType>( |
277 gles2::GetGLFunctionPointer(procname)); | 475 gles2::GetGLFunctionPointer(procname)); |
278 } | 476 } |
279 } // extern "C" | 477 } // extern "C" |
OLD | NEW |