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 /* enable supported extensions */
88 disp
->Extensions
.MESA_screen_surface
= EGL_TRUE
;
89 disp
->Extensions
.MESA_copy_context
= EGL_TRUE
;
99 demoTerminate(_EGLDriver
*drv
, _EGLDisplay
*dpy
)
101 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
107 LookupDemoContext(_EGLContext
*c
)
109 return (DemoContext
*) c
;
114 LookupDemoSurface(_EGLSurface
*s
)
116 return (DemoSurface
*) s
;
121 demoCreateContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, _EGLContext
*share_list
, const EGLint
*attrib_list
)
126 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
127 switch (attrib_list
[i
]) {
128 /* no attribs defined for now */
130 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateContext");
135 c
= (DemoContext
*) calloc(1, sizeof(DemoContext
));
139 _eglInitContext(drv
, &c
->Base
, conf
, attrib_list
);
141 printf("demoCreateContext\n");
148 demoCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, NativeWindowType window
, const EGLint
*attrib_list
)
151 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
152 switch (attrib_list
[i
]) {
153 /* no attribs at this time */
155 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateWindowSurface");
159 printf("eglCreateWindowSurface()\n");
167 demoCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
171 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
172 switch (attrib_list
[i
]) {
173 /* no attribs at this time */
175 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreatePixmapSurface");
180 if (GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) == 0) {
181 _eglError(EGL_BAD_MATCH
, "eglCreatePixmapSurface");
185 printf("eglCreatePixmapSurface()\n");
191 demoCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
192 const EGLint
*attrib_list
)
194 DemoSurface
*surf
= (DemoSurface
*) calloc(1, sizeof(DemoSurface
));
199 if (!_eglInitSurface(drv
, &surf
->Base
, EGL_PBUFFER_BIT
,
200 conf
, attrib_list
)) {
205 /* a real driver would allocate the pbuffer memory here */
212 demoDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
)
214 DemoSurface
*fs
= LookupDemoSurface(surface
);
215 if (!_eglIsSurfaceBound(&fs
->Base
))
222 demoDestroyContext(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*context
)
224 DemoContext
*fc
= LookupDemoContext(context
);
225 if (!_eglIsContextBound(&fc
->Base
))
232 demoMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*drawSurf
, _EGLSurface
*readSurf
, _EGLContext
*ctx
)
234 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
237 b
= _eglMakeCurrent(drv
, dpy
, drawSurf
, readSurf
, ctx
);
241 /* XXX this is where we'd do the hardware context switch */
246 printf("eglMakeCurrent()\n");
252 demoUnload(_EGLDriver
*drv
)
259 * The bootstrap function. Return a new DemoDriver object and
260 * plug in API functions.
263 _eglMain(const char *args
)
267 demo
= (DemoDriver
*) calloc(1, sizeof(DemoDriver
));
272 /* First fill in the dispatch table with defaults */
273 _eglInitDriverFallbacks(&demo
->Base
);
274 /* then plug in our Demo-specific functions */
275 demo
->Base
.API
.Initialize
= demoInitialize
;
276 demo
->Base
.API
.Terminate
= demoTerminate
;
277 demo
->Base
.API
.CreateContext
= demoCreateContext
;
278 demo
->Base
.API
.MakeCurrent
= demoMakeCurrent
;
279 demo
->Base
.API
.CreateWindowSurface
= demoCreateWindowSurface
;
280 demo
->Base
.API
.CreatePixmapSurface
= demoCreatePixmapSurface
;
281 demo
->Base
.API
.CreatePbufferSurface
= demoCreatePbufferSurface
;
282 demo
->Base
.API
.DestroySurface
= demoDestroySurface
;
283 demo
->Base
.API
.DestroyContext
= demoDestroyContext
;
285 demo
->Base
.Name
= "egl/demo";
286 demo
->Base
.Unload
= demoUnload
;