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++) {
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, dpy, &c->Base, config, attrib_list);
151
printf("demoCreateContext\n");
153
/* generate handle and insert into hash table */
154
_eglSaveContext(&c->Base);
155
assert(c->Base.Handle);
157
return c->Base.Handle;
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));
217
return EGL_NO_SURFACE;
219
if (!_eglInitSurface(drv, dpy, &surf->Base, EGL_PBUFFER_BIT,
220
config, attrib_list)) {
222
return EGL_NO_SURFACE;
225
/* a real driver would allocate the pbuffer memory here */
227
return surf->Base.Handle;
232
demoDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface)
234
DemoSurface *fs = LookupDemoSurface(surface);
235
_eglRemoveSurface(&fs->Base);
236
if (fs->Base.IsBound) {
237
fs->Base.DeletePending = EGL_TRUE;
247
demoDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context)
249
DemoContext *fc = LookupDemoContext(context);
250
_eglRemoveContext(&fc->Base);
251
if (fc->Base.IsBound) {
252
fc->Base.DeletePending = EGL_TRUE;
262
demoMakeCurrent(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext context)
264
/*DemoDriver *demo = DEMO_DRIVER(dpy);*/
265
DemoSurface *readSurf = LookupDemoSurface(read);
266
DemoSurface *drawSurf = LookupDemoSurface(draw);
267
DemoContext *ctx = LookupDemoContext(context);
270
b = _eglMakeCurrent(drv, dpy, draw, read, context);
274
/* XXX this is where we'd do the hardware context switch */
279
printf("eglMakeCurrent()\n");
285
* The bootstrap function. Return a new DemoDriver object and
286
* plug in API functions.
289
_eglMain(_EGLDisplay *dpy)
293
demo = (DemoDriver *) calloc(1, sizeof(DemoDriver));
298
/* First fill in the dispatch table with defaults */
299
_eglInitDriverFallbacks(&demo->Base);
300
/* then plug in our Demo-specific functions */
301
demo->Base.API.Initialize = demoInitialize;
302
demo->Base.API.Terminate = demoTerminate;
303
demo->Base.API.CreateContext = demoCreateContext;
304
demo->Base.API.MakeCurrent = demoMakeCurrent;
305
demo->Base.API.CreateWindowSurface = demoCreateWindowSurface;
306
demo->Base.API.CreatePixmapSurface = demoCreatePixmapSurface;
307
demo->Base.API.CreatePbufferSurface = demoCreatePbufferSurface;
308
demo->Base.API.DestroySurface = demoDestroySurface;
309
demo->Base.API.DestroyContext = demoDestroyContext;
311
/* enable supported extensions */
312
demo->Base.Extensions.MESA_screen_surface = EGL_TRUE;
313
demo->Base.Extensions.MESA_copy_context = EGL_TRUE;