/
entry_points_egl.cpp
1704 lines (1451 loc) · 53.8 KB
/
entry_points_egl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright(c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_egl.cpp : Implements the EGL entry points.
#include "libGLESv2/entry_points_egl.h"
#include "libGLESv2/entry_points_egl_ext.h"
#include "libGLESv2/entry_points_gles_2_0.h"
#include "libGLESv2/entry_points_gles_2_0_ext.h"
#include "libGLESv2/entry_points_gles_3_0.h"
#include "libGLESv2/global_state.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/Texture.h"
#include "libANGLE/Surface.h"
#include "libANGLE/validationEGL.h"
#include "common/debug.h"
#include "common/version.h"
#include <EGL/eglext.h>
namespace egl
{
// EGL 1.0
EGLint EGLAPIENTRY GetError(void)
{
EVENT("()");
EGLint error = GetGlobalError();
SetGlobalError(Error(EGL_SUCCESS));
return error;
}
EGLDisplay EGLAPIENTRY GetDisplay(EGLNativeDisplayType display_id)
{
EVENT("(EGLNativeDisplayType display_id = 0x%0.8p)", display_id);
return Display::GetDisplayFromAttribs(reinterpret_cast<void *>(display_id), AttributeMap());
}
EGLBoolean EGLAPIENTRY Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint *major = 0x%0.8p, EGLint *minor = 0x%0.8p)",
dpy, major, minor);
Display *display = static_cast<Display *>(dpy);
if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
{
SetGlobalError(Error(EGL_BAD_DISPLAY));
return EGL_FALSE;
}
Error error = display->initialize();
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (major) *major = 1;
if (minor) *minor = 4;
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy)
{
EVENT("(EGLDisplay dpy = 0x%0.8p)", dpy);
Display *display = static_cast<Display *>(dpy);
if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
{
SetGlobalError(Error(EGL_BAD_DISPLAY));
return EGL_FALSE;
}
gl::Context *context = GetGlobalContext();
if (display->isValidContext(context))
{
SetGlobalContext(NULL);
SetGlobalDisplay(NULL);
}
display->terminate();
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
const char *EGLAPIENTRY QueryString(EGLDisplay dpy, EGLint name)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint name = %d)", dpy, name);
Display *display = static_cast<Display*>(dpy);
if (!(display == EGL_NO_DISPLAY && name == EGL_EXTENSIONS))
{
Error error = ValidateDisplay(display);
if (error.isError())
{
SetGlobalError(error);
return NULL;
}
}
const char *result;
switch (name)
{
case EGL_CLIENT_APIS:
result = "OpenGL_ES";
break;
case EGL_EXTENSIONS:
if (display == EGL_NO_DISPLAY)
{
result = Display::getClientExtensionString().c_str();
}
else
{
result = display->getExtensionString().c_str();
}
break;
case EGL_VENDOR:
result = display->getVendorString().c_str();
break;
case EGL_VERSION:
result = "1.4 (ANGLE " ANGLE_VERSION_STRING ")";
break;
default:
SetGlobalError(Error(EGL_BAD_PARAMETER));
return NULL;
}
SetGlobalError(Error(EGL_SUCCESS));
return result;
}
EGLBoolean EGLAPIENTRY GetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig *configs = 0x%0.8p, "
"EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
dpy, configs, config_size, num_config);
Display *display = static_cast<Display*>(dpy);
Error error = ValidateDisplay(display);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (!num_config)
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_FALSE;
}
std::vector<const Config*> filteredConfigs = display->getConfigs(AttributeMap());
if (configs)
{
filteredConfigs.resize(std::min<size_t>(filteredConfigs.size(), config_size));
for (size_t i = 0; i < filteredConfigs.size(); i++)
{
configs[i] = const_cast<Config*>(filteredConfigs[i]);
}
}
*num_config = static_cast<EGLint>(filteredConfigs.size());
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY ChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p, "
"EGLConfig *configs = 0x%0.8p, EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
dpy, attrib_list, configs, config_size, num_config);
Display *display = static_cast<Display*>(dpy);
Error error = ValidateDisplay(display);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (!num_config)
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_FALSE;
}
std::vector<const Config*> filteredConfigs = display->getConfigs(AttributeMap(attrib_list));
if (configs)
{
filteredConfigs.resize(std::min<size_t>(filteredConfigs.size(), config_size));
for (size_t i = 0; i < filteredConfigs.size(); i++)
{
configs[i] = const_cast<Config*>(filteredConfigs[i]);
}
}
*num_config = static_cast<EGLint>(filteredConfigs.size());
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY GetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
dpy, config, attribute, value);
Display *display = static_cast<Display*>(dpy);
Config *configuration = static_cast<Config*>(config);
Error error = ValidateConfig(display, configuration);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (!display->getConfigAttrib(configuration, attribute, value))
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLSurface EGLAPIENTRY CreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativeWindowType win = 0x%0.8p, "
"const EGLint *attrib_list = 0x%0.8p)", dpy, config, win, attrib_list);
Display *display = static_cast<Display*>(dpy);
Config *configuration = static_cast<Config*>(config);
AttributeMap attributes(attrib_list);
Error error = ValidateCreateWindowSurface(display, configuration, win, attributes);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_SURFACE;
}
egl::Surface *surface = nullptr;
error = display->createWindowSurface(configuration, win, attributes, &surface);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_SURFACE;
}
return static_cast<EGLSurface>(surface);
}
EGLSurface EGLAPIENTRY CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
dpy, config, attrib_list);
Display *display = static_cast<Display*>(dpy);
Config *configuration = static_cast<Config*>(config);
AttributeMap attributes(attrib_list);
Error error = ValidateCreatePbufferSurface(display, configuration, attributes);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_SURFACE;
}
egl::Surface *surface = nullptr;
error = display->createPbufferSurface(configuration, attributes, &surface);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_SURFACE;
}
return static_cast<EGLSurface>(surface);
}
EGLSurface EGLAPIENTRY CreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativePixmapType pixmap = 0x%0.8p, "
"const EGLint *attrib_list = 0x%0.8p)", dpy, config, pixmap, attrib_list);
Display *display = static_cast<Display*>(dpy);
Config *configuration = static_cast<Config*>(config);
Error error = ValidateConfig(display, configuration);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_SURFACE;
}
UNIMPLEMENTED(); // FIXME
SetGlobalError(Error(EGL_SUCCESS));
return EGL_NO_SURFACE;
}
EGLBoolean EGLAPIENTRY DestroySurface(EGLDisplay dpy, EGLSurface surface)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
display->destroySurface((Surface*)surface);
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY QuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
dpy, surface, attribute, value);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = (Surface*)surface;
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
switch (attribute)
{
case EGL_VG_ALPHA_FORMAT:
UNIMPLEMENTED(); // FIXME
break;
case EGL_VG_COLORSPACE:
UNIMPLEMENTED(); // FIXME
break;
case EGL_CONFIG_ID:
*value = eglSurface->getConfig()->configID;
break;
case EGL_HEIGHT:
*value = eglSurface->getHeight();
break;
case EGL_HORIZONTAL_RESOLUTION:
UNIMPLEMENTED(); // FIXME
break;
case EGL_LARGEST_PBUFFER:
UNIMPLEMENTED(); // FIXME
break;
case EGL_MIPMAP_TEXTURE:
UNIMPLEMENTED(); // FIXME
break;
case EGL_MIPMAP_LEVEL:
UNIMPLEMENTED(); // FIXME
break;
case EGL_MULTISAMPLE_RESOLVE:
UNIMPLEMENTED(); // FIXME
break;
case EGL_PIXEL_ASPECT_RATIO:
*value = eglSurface->getPixelAspectRatio();
break;
case EGL_RENDER_BUFFER:
*value = eglSurface->getRenderBuffer();
break;
case EGL_SWAP_BEHAVIOR:
*value = eglSurface->getSwapBehavior();
break;
case EGL_TEXTURE_FORMAT:
*value = eglSurface->getTextureFormat();
break;
case EGL_TEXTURE_TARGET:
*value = eglSurface->getTextureTarget();
break;
case EGL_VERTICAL_RESOLUTION:
UNIMPLEMENTED(); // FIXME
break;
case EGL_WIDTH:
*value = eglSurface->getWidth();
break;
case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
if (!display->getExtensions().postSubBuffer)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
*value = eglSurface->isPostSubBufferSupported();
break;
case EGL_FIXED_SIZE_ANGLE:
if (!display->getExtensions().windowFixedSize)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
*value = eglSurface->isFixedSize();
break;
case EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE:
if (!display->getExtensions().flexibleSurfaceCompatibility)
{
SetGlobalError(
Error(EGL_BAD_ATTRIBUTE,
"EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE cannot be used without "
"EGL_ANGLE_flexible_surface_compatibility support."));
return EGL_FALSE;
}
*value = eglSurface->flexibleSurfaceCompatibilityRequested();
break;
case EGL_SURFACE_ORIENTATION_ANGLE:
if (!display->getExtensions().surfaceOrientation)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE,
"EGL_SURFACE_ORIENTATION_ANGLE cannot be queried without "
"EGL_ANGLE_surface_orientation support."));
return EGL_FALSE;
}
*value = eglSurface->getOrientation();
break;
case EGL_DIRECT_COMPOSITION_ANGLE:
if (!display->getExtensions().directComposition)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE,
"EGL_DIRECT_COMPOSITION_ANGLE cannot be used without "
"EGL_ANGLE_direct_composition support."));
return EGL_FALSE;
}
*value = eglSurface->directComposition();
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLContext EGLAPIENTRY CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLContext share_context = 0x%0.8p, "
"const EGLint *attrib_list = 0x%0.8p)", dpy, config, share_context, attrib_list);
Display *display = static_cast<Display*>(dpy);
Config *configuration = static_cast<Config*>(config);
gl::Context* sharedGLContext = static_cast<gl::Context*>(share_context);
AttributeMap attributes(attrib_list);
Error error = ValidateCreateContext(display, configuration, sharedGLContext, attributes);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_CONTEXT;
}
gl::Context *context = nullptr;
error = display->createContext(configuration, sharedGLContext, attributes, &context);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_CONTEXT;
}
SetGlobalError(Error(EGL_SUCCESS));
return static_cast<EGLContext>(context);
}
EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p)", dpy, ctx);
Display *display = static_cast<Display*>(dpy);
gl::Context *context = static_cast<gl::Context*>(ctx);
Error error = ValidateContext(display, context);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (ctx == EGL_NO_CONTEXT)
{
SetGlobalError(Error(EGL_BAD_CONTEXT));
return EGL_FALSE;
}
if (context == GetGlobalContext())
{
SetGlobalDisplay(NULL);
SetGlobalContext(NULL);
}
display->destroyContext(context);
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
dpy, draw, read, ctx);
Display *display = static_cast<Display*>(dpy);
gl::Context *context = static_cast<gl::Context*>(ctx);
// If ctx is EGL_NO_CONTEXT and either draw or read are not EGL_NO_SURFACE, an EGL_BAD_MATCH
// error is generated.
if (ctx == EGL_NO_CONTEXT && (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE))
{
SetGlobalError(Error(EGL_BAD_MATCH));
return EGL_FALSE;
}
if (ctx != EGL_NO_CONTEXT && draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_MATCH));
return EGL_FALSE;
}
// If either of draw or read is a valid surface and the other is EGL_NO_SURFACE, an
// EGL_BAD_MATCH error is generated.
if ((read == EGL_NO_SURFACE) != (draw == EGL_NO_SURFACE))
{
SetGlobalError(Error(
EGL_BAD_MATCH, "read and draw must both be valid surfaces, or both be EGL_NO_SURFACE"));
return EGL_FALSE;
}
if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
{
SetGlobalError(Error(EGL_BAD_DISPLAY, "'dpy' not a valid EGLDisplay handle"));
return EGL_FALSE;
}
// EGL 1.5 spec: dpy can be uninitialized if all other parameters are null
if (!display->isInitialized() && (ctx != EGL_NO_CONTEXT || draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE))
{
SetGlobalError(Error(EGL_NOT_INITIALIZED, "'dpy' not initialized"));
return EGL_FALSE;
}
if (ctx != EGL_NO_CONTEXT)
{
Error error = ValidateContext(display, context);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
}
if (display->isInitialized())
{
if (display->testDeviceLost())
{
display->notifyDeviceLost();
return EGL_FALSE;
}
if (display->isDeviceLost())
{
SetGlobalError(Error(EGL_CONTEXT_LOST));
return EGL_FALSE;
}
}
Surface *drawSurface = static_cast<Surface*>(draw);
if (draw != EGL_NO_SURFACE)
{
Error error = ValidateSurface(display, drawSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
}
Surface *readSurface = static_cast<Surface*>(read);
if (read != EGL_NO_SURFACE)
{
Error error = ValidateSurface(display, readSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
}
if (readSurface)
{
Error readCompatError =
ValidateCompatibleConfigs(display, readSurface->getConfig(), readSurface,
context->getConfig(), readSurface->getType());
if (readCompatError.isError())
{
SetGlobalError(readCompatError);
return EGL_FALSE;
}
}
if (draw != read)
{
UNIMPLEMENTED(); // FIXME
if (drawSurface)
{
Error drawCompatError =
ValidateCompatibleConfigs(display, drawSurface->getConfig(), drawSurface,
context->getConfig(), drawSurface->getType());
if (drawCompatError.isError())
{
SetGlobalError(drawCompatError);
return EGL_FALSE;
}
}
}
Error makeCurrentError = display->makeCurrent(drawSurface, readSurface, context);
if (makeCurrentError.isError())
{
SetGlobalError(makeCurrentError);
return EGL_FALSE;
}
gl::Context *previousContext = GetGlobalContext();
SetGlobalDisplay(display);
SetGlobalDrawSurface(drawSurface);
SetGlobalReadSurface(readSurface);
SetGlobalContext(context);
// Release the surface from the previously-current context, to allow
// destroyed surfaces to delete themselves.
if (previousContext != nullptr && context != previousContext)
{
previousContext->releaseSurface();
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLSurface EGLAPIENTRY GetCurrentSurface(EGLint readdraw)
{
EVENT("(EGLint readdraw = %d)", readdraw);
if (readdraw == EGL_READ)
{
SetGlobalError(Error(EGL_SUCCESS));
return GetGlobalReadSurface();
}
else if (readdraw == EGL_DRAW)
{
SetGlobalError(Error(EGL_SUCCESS));
return GetGlobalDrawSurface();
}
else
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_NO_SURFACE;
}
}
EGLDisplay EGLAPIENTRY GetCurrentDisplay(void)
{
EVENT("()");
EGLDisplay dpy = GetGlobalDisplay();
SetGlobalError(Error(EGL_SUCCESS));
return dpy;
}
EGLBoolean EGLAPIENTRY QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
dpy, ctx, attribute, value);
Display *display = static_cast<Display*>(dpy);
gl::Context *context = static_cast<gl::Context*>(ctx);
Error error = ValidateContext(display, context);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
switch (attribute)
{
case EGL_CONFIG_ID:
*value = context->getConfig()->configID;
break;
case EGL_CONTEXT_CLIENT_TYPE:
*value = context->getClientType();
break;
case EGL_CONTEXT_CLIENT_VERSION:
*value = context->getClientVersion();
break;
case EGL_RENDER_BUFFER:
*value = context->getRenderBuffer();
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY WaitGL(void)
{
EVENT("()");
Display *display = GetGlobalDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
// eglWaitGL like calling eglWaitClient with the OpenGL ES API bound. Since we only implement
// OpenGL ES we can do the call directly.
error = display->waitClient();
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
{
EVENT("(EGLint engine = %d)", engine);
Display *display = GetGlobalDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (engine != EGL_CORE_NATIVE_ENGINE)
{
SetGlobalError(
Error(EGL_BAD_PARAMETER, "the 'engine' parameter has an unrecognized value"));
}
error = display->waitNative(engine, GetGlobalDrawSurface(), GetGlobalReadSurface());
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY SwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = (Surface*)surface;
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (display->isDeviceLost())
{
SetGlobalError(Error(EGL_CONTEXT_LOST));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
error = eglSurface->swap();
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLNativePixmapType target = 0x%0.8p)", dpy, surface, target);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (display->isDeviceLost())
{
SetGlobalError(Error(EGL_CONTEXT_LOST));
return EGL_FALSE;
}
UNIMPLEMENTED(); // FIXME
SetGlobalError(Error(EGL_SUCCESS));
return 0;
}
// EGL 1.1
EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (buffer != EGL_BACK_BUFFER)
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE || eglSurface->getType() == EGL_WINDOW_BIT)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
if (eglSurface->getBoundTexture())
{
SetGlobalError(Error(EGL_BAD_ACCESS));
return EGL_FALSE;
}
if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
{
SetGlobalError(Error(EGL_BAD_MATCH));
return EGL_FALSE;
}
gl::Context *context = GetGlobalContext();
if (context)
{
gl::Texture *textureObject = context->getTargetTexture(GL_TEXTURE_2D);
ASSERT(textureObject != NULL);
if (textureObject->getImmutableFormat())
{
SetGlobalError(Error(EGL_BAD_MATCH));
return EGL_FALSE;
}
error = eglSurface->bindTexImage(textureObject, buffer);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY SurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint value = %d)",
dpy, surface, attribute, value);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
switch (attribute)
{
case EGLEXT_WAIT_FOR_VBLANK_ANGLE:
{
Error error = display->updateWindowSurfaceAttributeBoolean(eglSurface, attribute, static_cast<EGLBoolean>(value));
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
break;
}
default:
UNIMPLEMENTED();
break;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY ExtSurfaceAttribPointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLNativeWindowType value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLNativeWindowType value = %d)",
dpy, surface, attribute, value);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
error = display->updateWindowSurfaceAttributePointer(eglSurface, attribute, value);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}