9 #include "eglcontext.h"
10 #include "egldisplay.h"
11 #include "egldriver.h"
12 #include "eglglobals.h"
14 #include "eglscreen.h"
15 #include "eglsurface.h"
19 * Demo driver-specific driver class derived from _EGLDriver
21 typedef struct demo_driver
23 _EGLDriver Base
; /* base class/object */
27 #define DEMO_DRIVER(D) ((DemoDriver *) (D))
31 * Demo driver-specific surface class derived from _EGLSurface
33 typedef struct demo_surface
35 _EGLSurface Base
; /* base class/object */
41 * Demo driver-specific context class derived from _EGLContext
43 typedef struct demo_context
45 _EGLContext Base
; /* base class/object */
52 demoInitialize(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint
*major
, EGLint
*minor
)
58 scrn
= calloc(1, sizeof(*scrn
));
59 _eglAddScreen(disp
, scrn
);
61 /* Create the screen's modes - silly example */
62 _eglAddNewMode(scrn
, 1600, 1200, 72 * 1000, "1600x1200-72");
63 _eglAddNewMode(scrn
, 1280, 1024, 72 * 1000, "1280x1024-70");
64 _eglAddNewMode(scrn
, 1280, 1024, 70 * 1000, "1280x1024-70");
65 _eglAddNewMode(scrn
, 1024, 768, 72 * 1000, "1024x768-72");
67 /* Create the display's visual configs - silly example */
68 for (i
= 0; i
< 4; i
++) {
69 _EGLConfig
*config
= calloc(1, sizeof(_EGLConfig
));
70 _eglInitConfig(config
, i
+ 1);
71 _eglSetConfigAttrib(config
, EGL_RED_SIZE
, 8);
72 _eglSetConfigAttrib(config
, EGL_GREEN_SIZE
, 8);
73 _eglSetConfigAttrib(config
, EGL_BLUE_SIZE
, 8);
74 _eglSetConfigAttrib(config
, EGL_ALPHA_SIZE
, 8);
75 _eglSetConfigAttrib(config
, EGL_BUFFER_SIZE
, 32);
77 _eglSetConfigAttrib(config
, EGL_DEPTH_SIZE
, 32);
80 _eglSetConfigAttrib(config
, EGL_STENCIL_SIZE
, 8);
82 _eglSetConfigAttrib(config
, EGL_SURFACE_TYPE
,
83 (EGL_WINDOW_BIT
| EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
));
84 _eglAddConfig(disp
, config
);
87 drv
->Initialized
= EGL_TRUE
;
97 demoTerminate(_EGLDriver
*drv
, _EGLDisplay
*dpy
)
99 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
106 LookupDemoContext(_EGLContext
*c
)
108 return (DemoContext
*) c
;
113 LookupDemoSurface(_EGLSurface
*s
)
115 return (DemoSurface
*) s
;
120 demoCreateContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, _EGLContext
*share_list
, const EGLint
*attrib_list
)
125 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
126 switch (attrib_list
[i
]) {
127 /* no attribs defined for now */
129 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateContext");
134 c
= (DemoContext
*) calloc(1, sizeof(DemoContext
));
138 _eglInitContext(drv
, &c
->Base
, conf
, attrib_list
);
140 printf("demoCreateContext\n");
147 demoCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, NativeWindowType window
, const EGLint
*attrib_list
)
150 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
151 switch (attrib_list
[i
]) {
152 /* no attribs at this time */
154 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateWindowSurface");
158 printf("eglCreateWindowSurface()\n");
166 demoCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
170 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
171 switch (attrib_list
[i
]) {
172 /* no attribs at this time */
174 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreatePixmapSurface");
179 if (conf
->Attrib
[EGL_SURFACE_TYPE
- FIRST_ATTRIB
] == 0) {
180 _eglError(EGL_BAD_MATCH
, "eglCreatePixmapSurface");
184 printf("eglCreatePixmapSurface()\n");
190 demoCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
191 const EGLint
*attrib_list
)
193 DemoSurface
*surf
= (DemoSurface
*) calloc(1, sizeof(DemoSurface
));
198 if (!_eglInitSurface(drv
, &surf
->Base
, EGL_PBUFFER_BIT
,
199 conf
, attrib_list
)) {
204 /* a real driver would allocate the pbuffer memory here */
211 demoDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
)
213 DemoSurface
*fs
= LookupDemoSurface(surface
);
214 if (!_eglIsSurfaceBound(&fs
->Base
))
221 demoDestroyContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*context
)
223 DemoContext
*fc
= LookupDemoContext(context
);
224 if (!_eglIsContextBound(&fc
->Base
))
231 demoMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*drawSurf
, _EGLSurface
*readSurf
, _EGLContext
*ctx
)
233 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
236 b
= _eglMakeCurrent(drv
, dpy
, drawSurf
, readSurf
, ctx
);
240 /* XXX this is where we'd do the hardware context switch */
245 printf("eglMakeCurrent()\n");
251 * The bootstrap function. Return a new DemoDriver object and
252 * plug in API functions.
255 _eglMain(_EGLDisplay
*dpy
, const char *args
)
259 demo
= (DemoDriver
*) calloc(1, sizeof(DemoDriver
));
264 /* First fill in the dispatch table with defaults */
265 _eglInitDriverFallbacks(&demo
->Base
);
266 /* then plug in our Demo-specific functions */
267 demo
->Base
.API
.Initialize
= demoInitialize
;
268 demo
->Base
.API
.Terminate
= demoTerminate
;
269 demo
->Base
.API
.CreateContext
= demoCreateContext
;
270 demo
->Base
.API
.MakeCurrent
= demoMakeCurrent
;
271 demo
->Base
.API
.CreateWindowSurface
= demoCreateWindowSurface
;
272 demo
->Base
.API
.CreatePixmapSurface
= demoCreatePixmapSurface
;
273 demo
->Base
.API
.CreatePbufferSurface
= demoCreatePbufferSurface
;
274 demo
->Base
.API
.DestroySurface
= demoDestroySurface
;
275 demo
->Base
.API
.DestroyContext
= demoDestroyContext
;
277 /* enable supported extensions */
278 demo
->Base
.Extensions
.MESA_screen_surface
= EGL_TRUE
;
279 demo
->Base
.Extensions
.MESA_copy_context
= EGL_TRUE
;