summaryrefslogtreecommitdiff
path: root/sample-implementation-tmp/0004-st-egl-Use-st_api.h-instead-of-st_public.h.patch
blob: 5c39b3c35462df60d1cbb39179ef5853c247d69d (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
From 2aa90754de3813d10d9a5ac2e066498283b09f2b Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olv@lunarg.com>
Date: Sun, 7 Feb 2010 00:52:11 +0800
Subject: [PATCH 4/6] st/egl: Use st_api.h instead of st_public.h.

---
 src/gallium/state_trackers/egl/common/egl_g3d.c    |  556 ++++++++------------
 src/gallium/state_trackers/egl/common/egl_g3d.h    |   21 +-
 src/gallium/state_trackers/egl/common/egl_st.c     |  131 -----
 src/gallium/state_trackers/egl/common/egl_st.h     |   73 ---
 src/gallium/state_trackers/egl/common/egl_st_api.c |   13 +
 .../state_trackers/egl/common/st_public_tmp.h      |   20 -
 6 files changed, 254 insertions(+), 560 deletions(-)
 delete mode 100644 src/gallium/state_trackers/egl/common/egl_st.c
 delete mode 100644 src/gallium/state_trackers/egl/common/egl_st.h
 delete mode 100644 src/gallium/state_trackers/egl/common/st_public_tmp.h

diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 7021617..deaab38 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -36,233 +36,26 @@
 
 #include "native.h"
 #include "egl_g3d.h"
-#include "egl_st.h"
-
-/**
- * Validate the draw/read surfaces of the context.
- */
-static void
-egl_g3d_validate_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
-   struct pipe_screen *screen = gdpy->native->screen;
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   const uint st_att_map[NUM_NATIVE_ATTACHMENTS] = {
-      ST_SURFACE_FRONT_LEFT,
-      ST_SURFACE_BACK_LEFT,
-      ST_SURFACE_FRONT_RIGHT,
-      ST_SURFACE_BACK_RIGHT,
-   };
-   EGLint num_surfaces, s;
-
-   /* validate draw and/or read buffers */
-   num_surfaces = (gctx->base.ReadSurface == gctx->base.DrawSurface) ? 1 : 2;
-   for (s = 0; s < num_surfaces; s++) {
-      struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
-      struct egl_g3d_surface *gsurf;
-      struct egl_g3d_buffer *gbuf;
-      EGLint att;
-
-      if (s == 0) {
-         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-         gbuf = &gctx->draw;
-      }
-      else {
-         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
-         gbuf = &gctx->read;
-      }
-
-      if (!gctx->force_validate) {
-         unsigned int seq_num;
-
-         gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
-               &seq_num, NULL, NULL, NULL);
-         /* skip validation */
-         if (gsurf->sequence_number == seq_num)
-            continue;
-      }
-
-      pipe_surface_reference(&gsurf->render_surface, NULL);
-      memset(textures, 0, sizeof(textures));
-
-      gsurf->native->validate(gsurf->native, gbuf->attachment_mask,
-            &gsurf->sequence_number, textures,
-            &gsurf->base.Width, &gsurf->base.Height);
-      for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
-         struct pipe_texture *pt = textures[att];
-         struct pipe_surface *ps;
-
-         if (native_attachment_mask_test(gbuf->attachment_mask, att) && pt) {
-            ps = screen->get_tex_surface(screen, pt, 0, 0, 0,
-                  PIPE_BUFFER_USAGE_GPU_READ |
-                  PIPE_BUFFER_USAGE_GPU_WRITE);
-            gctx->stapi->st_set_framebuffer_surface(gbuf->st_fb,
-                  st_att_map[att], ps);
-
-            if (gsurf->render_att == att)
-               pipe_surface_reference(&gsurf->render_surface, ps);
-
-            pipe_surface_reference(&ps, NULL);
-            pipe_texture_reference(&pt, NULL);
-         }
-      }
-
-      gctx->stapi->st_resize_framebuffer(gbuf->st_fb,
-            gsurf->base.Width, gsurf->base.Height);
-   }
-
-   gctx->force_validate = EGL_FALSE;
-
-}
-
-/**
- * Create a st_framebuffer.
- */
-static struct st_framebuffer *
-create_framebuffer(_EGLContext *ctx, _EGLSurface *surf)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
-   struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
-
-   return gctx->stapi->st_create_framebuffer(&gconf->native->mode,
-         gconf->native->color_format, gconf->native->depth_format,
-         gconf->native->stencil_format,
-         gsurf->base.Width, gsurf->base.Height, &gsurf->base);
-}
-
-/**
- * Update the attachments of draw/read surfaces.
- */
-static void
-egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   EGLint s;
-
-   /* route draw and read buffers' attachments */
-   for (s = 0; s < 2; s++) {
-      struct egl_g3d_surface *gsurf;
-      struct egl_g3d_buffer *gbuf;
-
-      if (s == 0) {
-         gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-         gbuf = &gctx->draw;
-      }
-      else {
-         gsurf = egl_g3d_surface(gctx->base.ReadSurface);
-         gbuf = &gctx->read;
-      }
-
-      gbuf->attachment_mask = (1 << gsurf->render_att);
-
-      /* FIXME OpenGL defaults to draw the front or back buffer when the
-       * context is single-buffered or double-buffered respectively.  In EGL,
-       * however, the buffer to be drawn is determined by the surface, instead
-       * of the context.  As a result, rendering to a pixmap surface with a
-       * double-buffered context does not work as expected.
-       *
-       * gctx->stapi->st_draw_front_buffer(gctx->st_ctx, natt ==
-       *    NATIVE_ATTACHMENT_FRONT_LEFT);
-       */
-
-      /*
-       * FIXME If the back buffer is asked for here, and the front buffer is
-       * later needed by the client API (e.g. glDrawBuffer is called to draw
-       * the front buffer), it will create a new pipe texture and draw there.
-       * One fix is to ask for both buffers here, but it would be a waste if
-       * the front buffer is never used.  A better fix is to add a callback to
-       * the pipe screen with context private (just like flush_frontbuffer).
-       */
-   }
-}
-
-/**
- * Reallocate the context's framebuffers after draw/read surfaces change.
- */
-static EGLBoolean
-egl_g3d_realloc_context(_EGLDisplay *dpy, _EGLContext *ctx)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   struct egl_g3d_surface *gdraw = egl_g3d_surface(gctx->base.DrawSurface);
-   struct egl_g3d_surface *gread = egl_g3d_surface(gctx->base.ReadSurface);
-
-   /* unreference the old framebuffers */
-   if (gctx->draw.st_fb) {
-      EGLBoolean is_equal = (gctx->draw.st_fb == gctx->read.st_fb);
-      void *priv;
-
-      priv = gctx->stapi->st_framebuffer_private(gctx->draw.st_fb);
-      if (!gdraw || priv != (void *) &gdraw->base) {
-         gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
-         gctx->draw.st_fb = NULL;
-         gctx->draw.attachment_mask = 0x0;
-      }
-
-      if (is_equal) {
-         gctx->read.st_fb = NULL;
-         gctx->draw.attachment_mask = 0x0;
-      }
-      else {
-         priv = gctx->stapi->st_framebuffer_private(gctx->read.st_fb);
-         if (!gread || priv != (void *) &gread->base) {
-            gctx->stapi->st_unreference_framebuffer(gctx->read.st_fb);
-            gctx->read.st_fb = NULL;
-            gctx->draw.attachment_mask = 0x0;
-         }
-      }
-   }
-
-   if (!gdraw)
-      return EGL_TRUE;
-
-   /* create the draw fb */
-   if (!gctx->draw.st_fb) {
-      gctx->draw.st_fb = create_framebuffer(&gctx->base, &gdraw->base);
-      if (!gctx->draw.st_fb)
-         return EGL_FALSE;
-   }
-
-   /* create the read fb */
-   if (!gctx->read.st_fb) {
-      if (gread != gdraw) {
-         gctx->read.st_fb = create_framebuffer(&gctx->base, &gread->base);
-         if (!gctx->read.st_fb) {
-            gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb);
-            gctx->draw.st_fb = NULL;
-            return EGL_FALSE;
-         }
-      }
-      else {
-         /* there is no st_reference_framebuffer... */
-         gctx->read.st_fb = gctx->draw.st_fb;
-      }
-   }
-
-   egl_g3d_route_context(dpy, &gctx->base);
-   gctx->force_validate = EGL_TRUE;
-
-   return EGL_TRUE;
-}
+#include "egl_st_api.h"
 
 /**
  * Return the state tracker for the given context.
  */
-static const struct egl_g3d_st *
+static struct st_api *
 egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx)
 {
    struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
-   const struct egl_g3d_st *stapi;
+   struct st_api *stapi;
    EGLint idx = -1;
 
    switch (ctx->ClientAPI) {
    case EGL_OPENGL_ES_API:
       switch (ctx->ClientVersion) {
       case 1:
-         idx = EGL_G3D_ST_OPENGL_ES;
+         idx = ST_API_OPENGL_ES1;
          break;
       case 2:
-         idx = EGL_G3D_ST_OPENGL_ES2;
+         idx = ST_API_OPENGL_ES2;
          break;
       default:
          _eglLog(_EGL_WARNING, "unknown client version %d",
@@ -271,10 +64,10 @@ egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx)
       }
       break;
    case EGL_OPENVG_API:
-      idx = EGL_G3D_ST_OPENVG;
+      idx = ST_API_OPENVG;
       break;
    case EGL_OPENGL_API:
-      idx = EGL_G3D_ST_OPENGL;
+      idx = ST_API_OPENGL;
       break;
    default:
       _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI);
@@ -298,10 +91,10 @@ egl_g3d_init_st(_EGLDriver *drv)
    if (gdrv->api_mask)
       return;
 
-   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
-      gdrv->stapis[i] = egl_g3d_get_st(i);
+   for (i = 0; i < ST_API_COUNT; i++) {
+      gdrv->stapis[i] = egl_g3d_create_st_api(i);
       if (gdrv->stapis[i])
-         gdrv->api_mask |= gdrv->stapis[i]->api_bit;
+         gdrv->api_mask |= egl_g3d_st_api_bit(i);
    }
 
    if (gdrv->api_mask)
@@ -379,6 +172,31 @@ get_mode_api_mask(const __GLcontextModes *mode, EGLint api_mask)
    return api_mask;
 }
 
+static void
+init_st_visual(_EGLConfig *conf)
+{
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   unsigned buffer_mask;
+
+   buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK;
+   if (gconf->native->mode.doubleBufferMode)
+      buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
+   if (gconf->native->mode.stereoMode) {
+      buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
+      if (gconf->native->mode.doubleBufferMode)
+         buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
+   }
+
+   gconf->stvis.buffer_mask = buffer_mask;
+   gconf->stvis.color_format = gconf->native->color_format;
+   gconf->stvis.depth_stencil_format = gconf->native->depth_format;
+   gconf->stvis.accum_format = PIPE_FORMAT_NONE;
+   gconf->stvis.samples = 0;
+
+   gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT) ?
+      ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT;
+}
+
 #ifdef EGL_MESA_screen_surface
 
 static void
@@ -499,6 +317,7 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
       }
 
       gconf->native = native_configs[i];
+      init_st_visual(&gconf->base);
       _eglAddConfig(dpy, &gconf->base);
       id++;
    }
@@ -507,36 +326,6 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id)
    return id;
 }
 
-/**
- * Flush the front buffer of the context's draw surface.
- */
-static void
-egl_g3d_flush_frontbuffer(struct pipe_screen *screen,
-                          struct pipe_surface *surf, void *context_private)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
-   struct egl_g3d_surface *gsurf = egl_g3d_surface(gctx->base.DrawSurface);
-
-   if (gsurf)
-      gsurf->native->flush_frontbuffer(gsurf->native);
-}
-
-/**
- * Re-validate the context.
- */
-static void
-egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private)
-{
-   struct egl_g3d_context *gctx = egl_g3d_context(context_private);
-
-   /**
-    * It is likely that the surface has changed when this function is called.
-    * Set force_validate to skip an unnecessary check.
-    */
-   gctx->force_validate = EGL_TRUE;
-   egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
-}
-
 static EGLBoolean
 egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -555,6 +344,9 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy)
       free(dpy->Screens);
    }
 
+   if (gdpy->smapi)
+      egl_g3d_destroy_st_manager(gdpy->smapi);
+
    if (gdpy->native)
       gdpy->native->destroy(gdpy->native);
 
@@ -587,9 +379,6 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
       goto fail;
    }
 
-   gdpy->native->screen->flush_frontbuffer = egl_g3d_flush_frontbuffer;
-   gdpy->native->screen->update_buffer = egl_g3d_update_buffer;
-
    egl_g3d_init_st(&gdrv->base);
    dpy->ClientAPIsMask = gdrv->api_mask;
 
@@ -598,6 +387,13 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy,
       goto fail;
    }
 
+   gdpy->smapi = egl_g3d_create_st_manager(dpy);
+   if (!gdpy->smapi) {
+      _eglError(EGL_NOT_INITIALIZED,
+            "eglInitialize(failed to create st manager)");
+      goto fail;
+   }
+
 #ifdef EGL_MESA_screen_surface
    /* enable MESA_screen_surface */
    if (gdpy->native->modeset) {
@@ -625,7 +421,6 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
    struct egl_g3d_context *gshare = egl_g3d_context(share);
    struct egl_g3d_config *gconf = egl_g3d_config(conf);
    struct egl_g3d_context *gctx;
-   const __GLcontextModes *mode;
 
    gctx = CALLOC_STRUCT(egl_g3d_context);
    if (!gctx) {
@@ -644,18 +439,9 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
       return NULL;
    }
 
-   mode = &gconf->native->mode;
-   gctx->pipe =
-      gdpy->native->create_context(gdpy->native, (void *) &gctx->base);
-   if (!gctx->pipe) {
-      free(gctx);
-      return NULL;
-   }
-
-   gctx->st_ctx = gctx->stapi->st_create_context(gctx->pipe, mode,
-                        (gshare) ? gshare->st_ctx : NULL);
-   if (!gctx->st_ctx) {
-      gctx->pipe->destroy(gctx->pipe);
+   gctx->stctxi = gctx->stapi->create_context(gctx->stapi, gdpy->smapi,
+         &gconf->stvis, (gshare) ? gshare->stctxi : NULL);
+   if (!gctx->stctxi) {
       free(gctx);
       return NULL;
    }
@@ -675,9 +461,7 @@ destroy_context(_EGLDisplay *dpy, _EGLContext *ctx)
    if (!dpy->Initialized)
       _eglLog(_EGL_FATAL, "destroy a context with an unitialized display");
 
-   egl_g3d_realloc_context(dpy, &gctx->base);
-   /* it will destroy the associated pipe context */
-   gctx->stapi->st_destroy_context(gctx->st_ctx);
+   gctx->stctxi->destroy(gctx->stctxi);
 
    free(gctx);
 }
@@ -690,6 +474,122 @@ egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
    return EGL_TRUE;
 }
 
+static boolean
+egl_g3d_framebuffer_flush_front(struct st_framebuffer_iface *stfbi,
+                                enum st_attachment_type statt)
+{
+   _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+
+   return gsurf->native->flush_frontbuffer(gsurf->native);
+}
+
+static boolean 
+egl_g3d_framebuffer_validate(struct st_framebuffer_iface *stfbi,
+                             const enum st_attachment_type *statts,
+                             unsigned count,
+                             struct pipe_texture **out)
+{
+   _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+   uint attachment_mask = 0;
+   unsigned i;
+
+   for (i = 0; i < count; i++) {
+      int natt;
+
+      switch (statts[i]) {
+      case ST_ATTACHMENT_FRONT_LEFT:
+         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+         break;
+      case ST_ATTACHMENT_BACK_LEFT:
+         natt = NATIVE_ATTACHMENT_BACK_LEFT;
+         break;
+      case ST_ATTACHMENT_FRONT_RIGHT:
+         natt = NATIVE_ATTACHMENT_FRONT_RIGHT;
+         break;
+      case ST_ATTACHMENT_BACK_RIGHT:
+         natt = NATIVE_ATTACHMENT_BACK_RIGHT;
+      default:
+         natt = -1;
+         break;
+      }
+
+      if (natt >= 0)
+         attachment_mask |= 1 << natt;
+   }
+
+   if (!gsurf->native->validate(gsurf->native, attachment_mask,
+         &gsurf->sequence_number, textures, &gsurf->base.Width,
+         &gsurf->base.Height))
+      return FALSE;
+
+   for (i = 0; i < count; i++) {
+      struct pipe_texture *tex;
+      int natt;
+
+      switch (statts[i]) {
+      case ST_ATTACHMENT_FRONT_LEFT:
+         natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+         break;
+      case ST_ATTACHMENT_BACK_LEFT:
+         natt = NATIVE_ATTACHMENT_BACK_LEFT;
+         break;
+      case ST_ATTACHMENT_FRONT_RIGHT:
+         natt = NATIVE_ATTACHMENT_FRONT_RIGHT;
+         break;
+      case ST_ATTACHMENT_BACK_RIGHT:
+         natt = NATIVE_ATTACHMENT_BACK_RIGHT;
+         break;
+      default:
+         natt = -1;
+         break;
+      }
+
+      if (natt >= 0) {
+         tex = textures[natt];
+
+         if (attachment_mask & (1 << natt)) {
+            /* transfer the ownership to the caller */
+            out[i] = tex;
+            attachment_mask &= ~(1 << natt);
+         }
+         else {
+            /* the attachment is listed more than once */
+            pipe_texture_reference(&out[i], tex);
+         }
+      }
+   }
+
+   return TRUE;
+}
+
+static EGLBoolean
+init_surface_framebuffer(_EGLSurface *surf, _EGLConfig *conf)
+{
+   struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct egl_g3d_config *gconf = egl_g3d_config(conf);
+   struct st_framebuffer_iface *stfbi;
+
+   stfbi = CALLOC_STRUCT(st_framebuffer_iface);
+   if (!stfbi)
+      return EGL_FALSE;
+
+   gsurf->stvis = gconf->stvis;
+   if (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER)
+      gsurf->stvis.render_buffer = ST_ATTACHMENT_FRONT_LEFT;
+
+   stfbi->visual = &gsurf->stvis;
+   stfbi->flush_front = egl_g3d_framebuffer_flush_front;
+   stfbi->validate = egl_g3d_framebuffer_validate;
+   stfbi->st_manager_private = (void *) &gsurf->base;
+
+   gsurf->stfbi = stfbi;
+
+   return EGL_TRUE;
+}
+
 static EGLBoolean
 init_surface_geometry(_EGLSurface *surf)
 {
@@ -727,16 +627,13 @@ egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!init_surface_geometry(&gsurf->base)) {
+   if (!init_surface_geometry(&gsurf->base) ||
+       !init_surface_framebuffer(&gsurf->base, &gconf->base)) {
       gsurf->native->destroy(gsurf->native);
       free(gsurf);
       return NULL;
    }
 
-   gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER ||
-                        !gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
    return &gsurf->base;
 }
 
@@ -767,14 +664,13 @@ egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!init_surface_geometry(&gsurf->base)) {
+   if (!init_surface_geometry(&gsurf->base) ||
+       !init_surface_framebuffer(&gsurf->base, &gconf->base)) {
       gsurf->native->destroy(gsurf->native);
       free(gsurf);
       return NULL;
    }
 
-   gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT;
-
    return &gsurf->base;
 }
 
@@ -805,15 +701,13 @@ egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   if (!init_surface_geometry(&gsurf->base)) {
+   if (!init_surface_geometry(&gsurf->base) ||
+       !init_surface_framebuffer(&gsurf->base, &gconf->base)) {
       gsurf->native->destroy(gsurf->native);
       free(gsurf);
       return NULL;
    }
 
-   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
    return &gsurf->base;
 }
 
@@ -831,6 +725,7 @@ destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf)
 
    pipe_surface_reference(&gsurf->render_surface, NULL);
    gsurf->native->destroy(gsurf->native);
+   free(gsurf->stfbi);
    free(gsurf);
 }
 
@@ -848,6 +743,7 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
 {
    struct egl_g3d_context *gctx = egl_g3d_context(ctx);
    struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
+   struct egl_g3d_surface *gread = egl_g3d_surface(read);
    struct egl_g3d_context *old_gctx;
    EGLBoolean ok = EGL_TRUE;
 
@@ -858,34 +754,29 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
 
    if (old_gctx) {
       /* flush old context */
-      old_gctx->stapi->st_flush(old_gctx->st_ctx,
+      old_gctx->stctxi->flush(old_gctx->stctxi,
             PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
-
-      /*
-       * The old context is no longer current, and egl_g3d_realloc_context()
-       * should be called to destroy the framebuffers.  However, it is possible
-       * that it will be made current again with the same draw/read surfaces.
-       * It might be better to keep it around.
-       */
    }
 
    if (gctx) {
-      ok = egl_g3d_realloc_context(dpy, &gctx->base);
+      ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi,
+            (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL);
       if (ok) {
-         ok = gctx->stapi->st_make_current(gctx->st_ctx,
-               gctx->draw.st_fb, gctx->read.st_fb);
-         if (ok) {
-            egl_g3d_validate_context(dpy, &gctx->base);
-            if (gdraw->base.Type == EGL_WINDOW_BIT) {
-               gctx->base.WindowRenderBuffer =
-                  (gdraw->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) ?
-                  EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
-            }
+         gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gdraw->stfbi);
+         if (gread != gdraw) {
+            gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi,
+                  gread->stfbi);
+         }
+
+         if (gdraw->base.Type == EGL_WINDOW_BIT) {
+            gctx->base.WindowRenderBuffer =
+               (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ?
+               EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
          }
       }
    }
    else if (old_gctx) {
-      ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL);
+      ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL);
       old_gctx->base.WindowRenderBuffer = EGL_NONE;
    }
 
@@ -912,15 +803,17 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
       return EGL_TRUE;
 
    /* or when the surface is single-buffered */
-   if (gsurf->render_att == NATIVE_ATTACHMENT_FRONT_LEFT)
+   if (gsurf->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT)
       return EGL_TRUE;
 
    if (ctx && ctx->DrawSurface == surf)
       gctx = egl_g3d_context(ctx);
 
    /* flush if the surface is current */
-   if (gctx)
-      gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb);
+   if (gctx) {
+      gctx->stctxi->flush(gctx->stctxi,
+            PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
+   }
 
    /*
     * We drew on the back buffer, unless there was no back buffer.
@@ -933,11 +826,9 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
    if (gctx) {
       struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config);
 
-      /* force validation if the swap method is not copy */
-      if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML) {
-         gctx->force_validate = EGL_TRUE;
-         egl_g3d_validate_context(dpy, &gctx->base);
-      }
+      /* validate if the swap method is not copy */
+      if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML)
+         gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi);
    }
 
    return EGL_TRUE;
@@ -1011,7 +902,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
    /* flush if the surface is current */
    if (ctx && ctx->DrawSurface == &gsurf->base) {
       struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-      gctx->stapi->st_flush(gctx->st_ctx,
+      gctx->stctxi->flush(gctx->stctxi,
             PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
    }
 
@@ -1041,8 +932,16 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
 static EGLBoolean
 egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
 {
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
    struct egl_g3d_context *gctx = egl_g3d_context(ctx);
-   gctx->stapi->st_finish(gctx->st_ctx);
+   struct pipe_screen *screen = gdpy->native->screen;
+   struct pipe_fence_handle *fence = NULL;
+
+   gctx->stctxi->flush(gctx->stctxi,
+         PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence);
+   screen->fence_finish(screen, fence, 0);
+   screen->fence_reference(screen, &fence, NULL);
+
    return EGL_TRUE;
 }
 
@@ -1072,10 +971,10 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname)
    /* in case this is called before a display is initialized */
    egl_g3d_init_st(&gdrv->base);
 
-   for (i = 0; i < NUM_EGL_G3D_STS; i++) {
-      const struct egl_g3d_st *stapi = gdrv->stapis[i];
+   for (i = 0; i < ST_API_COUNT; i++) {
+      struct st_api *stapi = gdrv->stapis[i];
       if (stapi) {
-         proc = (_EGLProc) stapi->st_get_proc_address(procname);
+         proc = (_EGLProc) stapi->get_proc_address(stapi, procname);
          if (proc)
             return proc;
       }
@@ -1091,8 +990,8 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
    _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API);
    struct egl_g3d_context *gctx;
-   enum pipe_format target_format;
-   int target;
+   enum pipe_format internal_format;
+   enum st_texture_type target;
 
    if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT)
       return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
@@ -1103,10 +1002,10 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
 
    switch (gsurf->base.TextureFormat) {
    case EGL_TEXTURE_RGB:
-      target_format = PIPE_FORMAT_R8G8B8_UNORM;
+      internal_format = PIPE_FORMAT_R8G8B8_UNORM;
       break;
    case EGL_TEXTURE_RGBA:
-      target_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+      internal_format = PIPE_FORMAT_A8R8G8B8_UNORM;
       break;
    default:
       return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
@@ -1128,15 +1027,18 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
    /* flush properly if the surface is bound */
    if (gsurf->base.CurrentContext) {
       gctx = egl_g3d_context(gsurf->base.CurrentContext);
-      gctx->stapi->st_flush(gctx->st_ctx,
+      gctx->stctxi->flush(gctx->stctxi,
             PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL);
    }
 
    gctx = egl_g3d_context(es1);
-   gctx->stapi->st_bind_texture_surface(gsurf->render_surface,
-         target, gsurf->base.MipmapLevel, target_format);
-
-   gsurf->base.BoundToTexture = EGL_TRUE;
+   if (gctx->stctxi->teximage) {
+      if (!gctx->stctxi->teximage(gctx->stctxi, target,
+               gsurf->base.MipmapLevel, internal_format,
+               gsurf->render_surface->texture, gsurf->base.MipmapTexture))
+         return EGL_FALSE;
+      gsurf->base.BoundToTexture = EGL_TRUE;
+   }
 
    return EGL_TRUE;
 }
@@ -1158,9 +1060,10 @@ egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy,
       struct egl_g3d_context *gctx = egl_g3d_context(ctx);
 
       /* what if the context the surface binds to is no longer current? */
-      if (gctx)
-         gctx->stapi->st_unbind_texture_surface(gsurf->render_surface,
-               ST_TEXTURE_2D, gsurf->base.MipmapLevel);
+      if (gctx) {
+         gctx->stctxi->teximage(gctx->stctxi, ST_TEXTURE_2D,
+               gsurf->base.MipmapLevel, PIPE_FORMAT_NONE, NULL, FALSE);
+      }
    }
 
    gsurf->base.BoundToTexture = EGL_FALSE;
@@ -1198,9 +1101,6 @@ egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy,
       return NULL;
    }
 
-   gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ?
-      NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT;
-
    return &gsurf->base;
 }
 
@@ -1294,6 +1194,12 @@ static void
 egl_g3d_unload(_EGLDriver *drv)
 {
    struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
+   EGLint i;
+
+   for (i = 0; i < ST_API_COUNT; i++) {
+      if (gdrv->stapis[i])
+         gdrv->stapis[i]->destroy(gdrv->stapis[i]);
+   }
 
    egl_g3d_destroy_probe(drv, NULL);
    free(gdrv);
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h
index 5d2d9c4..8dba070 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.h
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.h
@@ -38,11 +38,11 @@
 #include "eglmode.h"
 
 #include "native.h"
-#include "egl_st.h"
+#include "egl_st_api.h"
 
 struct egl_g3d_driver {
    _EGLDriver base;
-   const struct egl_g3d_st *stapis[NUM_EGL_G3D_STS];
+   struct st_api *stapis[ST_API_COUNT];
    EGLint api_mask;
 
    EGLint probe_key;
@@ -50,28 +50,26 @@ struct egl_g3d_driver {
 
 struct egl_g3d_display {
    struct native_display *native;
-};
 
-struct egl_g3d_buffer {
-   struct st_framebuffer *st_fb;
-   uint attachment_mask;
+   struct st_manager *smapi;
 };
 
 struct egl_g3d_context {
    _EGLContext base;
 
-   const struct egl_g3d_st *stapi;
-   struct pipe_context *pipe;
+   struct st_api *stapi;
 
-   struct st_context *st_ctx;
+   struct st_context_iface *stctxi;
    EGLBoolean force_validate;
-   struct egl_g3d_buffer draw, read;
 };
 
 struct egl_g3d_surface {
    _EGLSurface base;
+
+   struct st_visual stvis;
+   struct st_framebuffer_iface *stfbi;
+
    struct native_surface *native;
-   enum native_attachment render_att;
    struct pipe_surface *render_surface;
    unsigned int sequence_number;
 };
@@ -79,6 +77,7 @@ struct egl_g3d_surface {
 struct egl_g3d_config {
    _EGLConfig base;
    const struct native_config *native;
+   struct st_visual stvis;
 };
 
 struct egl_g3d_screen {
diff --git a/src/gallium/state_trackers/egl/common/egl_st.c b/src/gallium/state_trackers/egl/common/egl_st.c
deleted file mode 100644
index a88ff91..0000000
--- a/src/gallium/state_trackers/egl/common/egl_st.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <dlfcn.h>
-#include "pipe/p_compiler.h"
-#include "util/u_memory.h"
-#include "egllog.h"
-#include "EGL/egl.h" /* for EGL_api_BIT */
-
-#include "egl_st.h"
-
-#ifndef HAVE_DLADDR
-#define HAVE_DLADDR 1
-#endif
-
-#if HAVE_DLADDR
-
-static const char *
-egl_g3d_st_names[] = {
-#define ST_PUBLIC(name, ...) #name,
-#include "st_public_tmp.h"
-   NULL
-};
-
-static boolean
-egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
-{
-   st_proc *procs = (st_proc *) stapi;
-   void *handle;
-   Dl_info info;
-   const char **name;
-
-   if (!dladdr(sym, &info))
-      return FALSE;
-   handle = dlopen(info.dli_fname, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
-   if (!handle)
-      return FALSE;
-
-   for (name = egl_g3d_st_names; *name; name++) {
-      st_proc proc = (st_proc) dlsym(handle, *name);
-      if (!proc) {
-         _eglLog(_EGL_WARNING, "%s is missing in %s", *name, info.dli_fname);
-         memset(stapi, 0, sizeof(*stapi));
-         dlclose(handle);
-         return FALSE;
-      }
-      *procs++ = proc;
-   }
-
-   dlclose(handle);
-   return TRUE;
-}
-
-#else /* HAVE_DLADDR */
-
-static boolean
-egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym)
-{
-#define ST_PUBLIC(name, ...) stapi->name = name;
-#include "st_public_tmp.h"
-   return TRUE;
-}
-
-#endif /* HAVE_DLADDR */
-
-static boolean
-egl_g3d_init_st(struct egl_g3d_st *stapi, const char *api)
-{
-   void *handle, *sym;
-   boolean res = FALSE;
-
-   /* already initialized */
-   if (stapi->st_notify_swapbuffers != NULL)
-      return TRUE;
-
-   handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
-   if (!handle)
-      return FALSE;
-
-   sym = dlsym(handle, api);
-   if (sym && egl_g3d_fill_st(stapi, sym))
-      res = TRUE;
-
-   dlclose(handle);
-   return res;
-}
-
-static struct {
-   const char *symbol;
-   EGLint api_bit;
-} egl_g3d_st_info[NUM_EGL_G3D_STS] = {
-   { "st_api_OpenGL_ES1",  EGL_OPENGL_ES_BIT },
-   { "st_api_OpenVG",      EGL_OPENVG_BIT },
-   { "st_api_OpenGL_ES2",  EGL_OPENGL_ES2_BIT },
-   { "st_api_OpenGL",      EGL_OPENGL_BIT },
-};
-
-const struct egl_g3d_st *
-egl_g3d_get_st(enum egl_g3d_st_api api)
-{
-   static struct egl_g3d_st all_trackers[NUM_EGL_G3D_STS];
-
-   if (egl_g3d_init_st(&all_trackers[api], egl_g3d_st_info[api].symbol)) {
-      all_trackers[api].api_bit = egl_g3d_st_info[api].api_bit;
-      return &all_trackers[api];
-   }
-   else {
-      return NULL;
-   }
-}
diff --git a/src/gallium/state_trackers/egl/common/egl_st.h b/src/gallium/state_trackers/egl/common/egl_st.h
deleted file mode 100644
index 8fb464b..0000000
--- a/src/gallium/state_trackers/egl/common/egl_st.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.8
- *
- * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _EGL_ST_H_
-#define _EGL_ST_H_
-
-#include "GL/gl.h" /* for GL types */
-#include "GL/internal/glcore.h"  /* for __GLcontextModes */
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-#include "pipe/p_context.h"
-
-/* avoid calling st functions directly */
-#if 1
-
-#define ST_SURFACE_FRONT_LEFT   0
-#define ST_SURFACE_BACK_LEFT    1
-#define ST_SURFACE_FRONT_RIGHT  2
-#define ST_SURFACE_BACK_RIGHT   3
-
-#define ST_TEXTURE_2D    0x2
-
-struct st_context;
-struct st_framebuffer;
-typedef void (*st_proc)();
-
-#else
-#include "state_tracker/st_public.h"
-#endif
-
-/* remember to update egl_g3d_get_st() when update the enums */
-enum egl_g3d_st_api {
-   EGL_G3D_ST_OPENGL_ES = 0,
-   EGL_G3D_ST_OPENVG,
-   EGL_G3D_ST_OPENGL_ES2,
-   EGL_G3D_ST_OPENGL,
-
-   NUM_EGL_G3D_STS
-};
-
-struct egl_g3d_st {
-#define ST_PUBLIC(name, ret, ...) ret (*name)(__VA_ARGS__);
-#include "st_public_tmp.h"
-   /* fields must be added here */
-   EGLint api_bit;
-};
-
-const struct egl_g3d_st *
-egl_g3d_get_st(enum egl_g3d_st_api api);
-
-#endif /* _EGL_ST_H_ */
diff --git a/src/gallium/state_trackers/egl/common/egl_st_api.c b/src/gallium/state_trackers/egl/common/egl_st_api.c
index bfcc49e..465904c 100644
--- a/src/gallium/state_trackers/egl/common/egl_st_api.c
+++ b/src/gallium/state_trackers/egl/common/egl_st_api.c
@@ -2,6 +2,7 @@
 #include "util/u_dl.h"
 #include "eglimage.h"
 
+#include "egl_g3d.h"
 #include "egl_st_api.h"
 
 struct egl_g3d_st_manager {
@@ -52,17 +53,29 @@ egl_g3d_st_manager_unlock_resource(struct st_manager *smapi,
 {
 }
 
+static struct pipe_context * 
+egl_g3d_st_manager_create_pipe_context(struct st_manager *smapi)
+{
+   struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi);
+   struct egl_g3d_display *gdpy = egl_g3d_display(gsmapi->display);
+
+   return gdpy->native->create_context(gdpy->native, NULL);
+}
+
 struct st_manager *
 egl_g3d_create_st_manager(_EGLDisplay *dpy)
 {
+   struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
    struct egl_g3d_st_manager *gsmapi;
 
    gsmapi = CALLOC_STRUCT(egl_g3d_st_manager);
    if (gsmapi) {
       gsmapi->display = dpy;
 
+      gsmapi->base.screen = gdpy->native->screen;
       gsmapi->base.lock_resource = egl_g3d_st_manager_lock_resource;
       gsmapi->base.unlock_resource = egl_g3d_st_manager_unlock_resource;
+      gsmapi->base.create_pipe_context = egl_g3d_st_manager_create_pipe_context;
    }
 
    return &gsmapi->base;;
diff --git a/src/gallium/state_trackers/egl/common/st_public_tmp.h b/src/gallium/state_trackers/egl/common/st_public_tmp.h
deleted file mode 100644
index 507a0ec..0000000
--- a/src/gallium/state_trackers/egl/common/st_public_tmp.h
+++ /dev/null
@@ -1,20 +0,0 @@
-ST_PUBLIC(st_create_context,              struct st_context *,       struct pipe_context *pipe, const __GLcontextModes *visual, struct st_context *share)
-ST_PUBLIC(st_destroy_context,             void,                      struct st_context *st)
-ST_PUBLIC(st_copy_context_state,          void,                      struct st_context *dst, struct st_context *src, uint mask)
-ST_PUBLIC(st_create_framebuffer,          struct st_framebuffer *,   const __GLcontextModes *visual, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, uint width, uint height, void *privateData)
-ST_PUBLIC(st_resize_framebuffer,          void,                      struct st_framebuffer *stfb, uint width, uint height)
-ST_PUBLIC(st_set_framebuffer_surface,     void,                      struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface *surf)
-ST_PUBLIC(st_get_framebuffer_dimensions,  void,                      struct st_framebuffer *stfb, uint *width, uint *height)
-ST_PUBLIC(st_get_framebuffer_surface,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface **surface)
-ST_PUBLIC(st_get_framebuffer_texture,     int,                       struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture)
-ST_PUBLIC(st_framebuffer_private,         void *,                    struct st_framebuffer *stfb)
-ST_PUBLIC(st_unreference_framebuffer,     void,                      struct st_framebuffer *stfb)
-ST_PUBLIC(st_make_current,                GLboolean,                 struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read)
-ST_PUBLIC(st_get_current,                 struct st_context *,       void)
-ST_PUBLIC(st_flush,                       void,                      struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence)
-ST_PUBLIC(st_finish,                      void,                      struct st_context *st)
-ST_PUBLIC(st_notify_swapbuffers,          void,                      struct st_framebuffer *stfb)
-ST_PUBLIC(st_bind_texture_surface,        int,                       struct pipe_surface *ps, int target, int level, enum pipe_format format)
-ST_PUBLIC(st_unbind_texture_surface,      int,                       struct pipe_surface *ps, int target, int level)
-ST_PUBLIC(st_get_proc_address,            st_proc,                   const char *procname)
-#undef ST_PUBLIC
-- 
1.6.4.3