Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: gpu/gles2_conform_support/egl/egl.cc

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

Powered by Google App Engine
This is Rietveld 408576698