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 dpy
, EGLint
*major
, EGLint
*minor
)
54 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
59 scrn
= calloc(1, sizeof(*scrn
));
60 _eglAddScreen(disp
, scrn
);
62 /* Create the screen's modes - silly example */
63 _eglAddNewMode(scrn
, 1600, 1200, 72 * 1000, "1600x1200-72");
64 _eglAddNewMode(scrn
, 1280, 1024, 72 * 1000, "1280x1024-70");
65 _eglAddNewMode(scrn
, 1280, 1024, 70 * 1000, "1280x1024-70");
66 _eglAddNewMode(scrn
, 1024, 768, 72 * 1000, "1024x768-72");
68 /* Create the display's visual configs - silly example */
69 for (i
= 0; i
< 4; i
++) {
70 _EGLConfig
*config
= calloc(1, sizeof(_EGLConfig
));
71 _eglInitConfig(config
, i
+ 1);
72 _eglSetConfigAttrib(config
, EGL_RED_SIZE
, 8);
73 _eglSetConfigAttrib(config
, EGL_GREEN_SIZE
, 8);
74 _eglSetConfigAttrib(config
, EGL_BLUE_SIZE
, 8);
75 _eglSetConfigAttrib(config
, EGL_ALPHA_SIZE
, 8);
76 _eglSetConfigAttrib(config
, EGL_BUFFER_SIZE
, 32);
78 _eglSetConfigAttrib(config
, EGL_DEPTH_SIZE
, 32);
81 _eglSetConfigAttrib(config
, EGL_STENCIL_SIZE
, 8);
83 _eglSetConfigAttrib(config
, EGL_SURFACE_TYPE
,
84 (EGL_WINDOW_BIT
| EGL_PIXMAP_BIT
| EGL_PBUFFER_BIT
));
85 _eglAddConfig(disp
, config
);
88 drv
->Initialized
= EGL_TRUE
;
98 demoTerminate(_EGLDriver
*drv
, EGLDisplay dpy
)
100 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
107 LookupDemoContext(EGLContext ctx
)
109 _EGLContext
*c
= _eglLookupContext(ctx
);
110 return (DemoContext
*) c
;
115 LookupDemoSurface(EGLSurface surf
)
117 _EGLSurface
*s
= _eglLookupSurface(surf
);
118 return (DemoSurface
*) s
;
124 demoCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
, const EGLint
*attrib_list
)
130 conf
= _eglLookupConfig(drv
, dpy
, config
);
132 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
133 return EGL_NO_CONTEXT
;
136 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
137 switch (attrib_list
[i
]) {
138 /* no attribs defined for now */
140 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateContext");
141 return EGL_NO_CONTEXT
;
145 c
= (DemoContext
*) calloc(1, sizeof(DemoContext
));
147 return EGL_NO_CONTEXT
;
149 _eglInitContext(drv
, &c
->Base
, conf
, attrib_list
);
151 printf("demoCreateContext\n");
153 /* link to display */
154 _eglLinkContext(&c
->Base
, _eglLookupDisplay(dpy
));
155 assert(_eglGetContextHandle(&c
->Base
));
157 return _eglGetContextHandle(&c
->Base
);
162 demoCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, NativeWindowType window
, const EGLint
*attrib_list
)
165 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
166 switch (attrib_list
[i
]) {
167 /* no attribs at this time */
169 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateWindowSurface");
170 return EGL_NO_SURFACE
;
173 printf("eglCreateWindowSurface()\n");
176 return EGL_NO_SURFACE
;
181 demoCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
186 conf
= _eglLookupConfig(drv
, dpy
, config
);
188 _eglError(EGL_BAD_CONFIG
, "eglCreatePixmapSurface");
189 return EGL_NO_SURFACE
;
192 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
193 switch (attrib_list
[i
]) {
194 /* no attribs at this time */
196 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreatePixmapSurface");
197 return EGL_NO_SURFACE
;
201 if (conf
->Attrib
[EGL_SURFACE_TYPE
- FIRST_ATTRIB
] == 0) {
202 _eglError(EGL_BAD_MATCH
, "eglCreatePixmapSurface");
203 return EGL_NO_SURFACE
;
206 printf("eglCreatePixmapSurface()\n");
207 return EGL_NO_SURFACE
;
212 demoCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
213 const EGLint
*attrib_list
)
215 DemoSurface
*surf
= (DemoSurface
*) calloc(1, sizeof(DemoSurface
));
219 return EGL_NO_SURFACE
;
221 conf
= _eglLookupConfig(drv
, dpy
, config
);
222 if (!_eglInitSurface(drv
, &surf
->Base
, EGL_PBUFFER_BIT
,
223 conf
, attrib_list
)) {
225 return EGL_NO_SURFACE
;
228 /* a real driver would allocate the pbuffer memory here */
230 return surf
->Base
.Handle
;
235 demoDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
237 DemoSurface
*fs
= LookupDemoSurface(surface
);
238 _eglUnlinkSurface(&fs
->Base
);
239 if (!fs
->Base
.IsBound
)
246 demoDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext context
)
248 DemoContext
*fc
= LookupDemoContext(context
);
249 _eglUnlinkContext(&fc
->Base
);
250 if (!fc
->Base
.IsBound
)
257 demoMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
, EGLContext context
)
259 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
260 DemoSurface
*readSurf
= LookupDemoSurface(read
);
261 DemoSurface
*drawSurf
= LookupDemoSurface(draw
);
262 DemoContext
*ctx
= LookupDemoContext(context
);
265 b
= _eglMakeCurrent(drv
, dpy
, draw
, read
, context
);
269 /* XXX this is where we'd do the hardware context switch */
274 printf("eglMakeCurrent()\n");
280 * The bootstrap function. Return a new DemoDriver object and
281 * plug in API functions.
284 _eglMain(_EGLDisplay
*dpy
, const char *args
)
288 demo
= (DemoDriver
*) calloc(1, sizeof(DemoDriver
));
293 /* First fill in the dispatch table with defaults */
294 _eglInitDriverFallbacks(&demo
->Base
);
295 /* then plug in our Demo-specific functions */
296 demo
->Base
.API
.Initialize
= demoInitialize
;
297 demo
->Base
.API
.Terminate
= demoTerminate
;
298 demo
->Base
.API
.CreateContext
= demoCreateContext
;
299 demo
->Base
.API
.MakeCurrent
= demoMakeCurrent
;
300 demo
->Base
.API
.CreateWindowSurface
= demoCreateWindowSurface
;
301 demo
->Base
.API
.CreatePixmapSurface
= demoCreatePixmapSurface
;
302 demo
->Base
.API
.CreatePbufferSurface
= demoCreatePbufferSurface
;
303 demo
->Base
.API
.DestroySurface
= demoDestroySurface
;
304 demo
->Base
.API
.DestroyContext
= demoDestroyContext
;
306 /* enable supported extensions */
307 demo
->Base
.Extensions
.MESA_screen_surface
= EGL_TRUE
;
308 demo
->Base
.Extensions
.MESA_copy_context
= EGL_TRUE
;