9b751959590718d14527c9c96c9fb44703fed3ac
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 _eglAddMode(scrn
, 1600, 1200, 72 * 1000, "1600x1200-72");
64 _eglAddMode(scrn
, 1280, 1024, 72 * 1000, "1280x1024-70");
65 _eglAddMode(scrn
, 1280, 1024, 70 * 1000, "1280x1024-70");
66 _eglAddMode(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
)
128 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
131 conf
= _eglLookupConfig(drv
, dpy
, config
);
133 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
134 return EGL_NO_CONTEXT
;
137 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
138 switch (attrib_list
[i
]) {
139 /* no attribs defined for now */
141 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateContext");
142 return EGL_NO_CONTEXT
;
146 c
= (DemoContext
*) calloc(1, sizeof(DemoContext
));
148 return EGL_NO_CONTEXT
;
150 _eglInitContext(&c
->Base
);
151 c
->Base
.Display
= disp
;
152 c
->Base
.Config
= conf
;
153 c
->Base
.DrawSurface
= EGL_NO_SURFACE
;
154 c
->Base
.ReadSurface
= EGL_NO_SURFACE
;
156 printf("demoCreateContext\n");
158 /* generate handle and insert into hash table */
159 _eglSaveContext(&c
->Base
);
160 assert(c
->Base
.Handle
);
162 return c
->Base
.Handle
;
167 demoCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, NativeWindowType window
, 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
, "eglCreateWindowSurface");
175 return EGL_NO_SURFACE
;
178 printf("eglCreateWindowSurface()\n");
181 return EGL_NO_SURFACE
;
186 demoCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, NativePixmapType pixmap
, const EGLint
*attrib_list
)
191 conf
= _eglLookupConfig(drv
, dpy
, config
);
193 _eglError(EGL_BAD_CONFIG
, "eglCreatePixmapSurface");
194 return EGL_NO_SURFACE
;
197 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
198 switch (attrib_list
[i
]) {
199 /* no attribs at this time */
201 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreatePixmapSurface");
202 return EGL_NO_SURFACE
;
206 if (conf
->Attrib
[EGL_SURFACE_TYPE
- FIRST_ATTRIB
] == 0) {
207 _eglError(EGL_BAD_MATCH
, "eglCreatePixmapSurface");
208 return EGL_NO_SURFACE
;
211 printf("eglCreatePixmapSurface()\n");
212 return EGL_NO_SURFACE
;
217 demoCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
218 const EGLint
*attrib_list
)
220 DemoSurface
*surf
= (DemoSurface
*) calloc(1, sizeof(DemoSurface
));
222 return EGL_NO_SURFACE
;
224 if (_eglInitPbufferSurface(&surf
->Base
, drv
, dpy
, config
, attrib_list
)
227 return EGL_NO_SURFACE
;
230 /* a real driver would allocate the pbuffer memory here */
232 return surf
->Base
.Handle
;
237 demoDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
239 DemoSurface
*fs
= LookupDemoSurface(surface
);
240 _eglRemoveSurface(&fs
->Base
);
241 if (fs
->Base
.IsBound
) {
242 fs
->Base
.DeletePending
= EGL_TRUE
;
252 demoDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext context
)
254 DemoContext
*fc
= LookupDemoContext(context
);
255 _eglRemoveContext(&fc
->Base
);
256 if (fc
->Base
.IsBound
) {
257 fc
->Base
.DeletePending
= EGL_TRUE
;
267 demoMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
, EGLSurface read
, EGLContext context
)
269 /*DemoDriver *demo = DEMO_DRIVER(dpy);*/
270 DemoSurface
*readSurf
= LookupDemoSurface(read
);
271 DemoSurface
*drawSurf
= LookupDemoSurface(draw
);
272 DemoContext
*ctx
= LookupDemoContext(context
);
275 b
= _eglMakeCurrent(drv
, dpy
, draw
, read
, context
);
279 /* XXX this is where we'd do the hardware context switch */
284 printf("eglMakeCurrent()\n");
290 * Just to silence warning
293 _eglMain(NativeDisplayType dpy
);
297 * The bootstrap function. Return a new DemoDriver object and
298 * plug in API functions.
301 _eglMain(NativeDisplayType dpy
)
305 demo
= (DemoDriver
*) calloc(1, sizeof(DemoDriver
));
310 /* First fill in the dispatch table with defaults */
311 _eglInitDriverFallbacks(&demo
->Base
);
312 /* then plug in our Demo-specific functions */
313 demo
->Base
.Initialize
= demoInitialize
;
314 demo
->Base
.Terminate
= demoTerminate
;
315 demo
->Base
.CreateContext
= demoCreateContext
;
316 demo
->Base
.MakeCurrent
= demoMakeCurrent
;
317 demo
->Base
.CreateWindowSurface
= demoCreateWindowSurface
;
318 demo
->Base
.CreatePixmapSurface
= demoCreatePixmapSurface
;
319 demo
->Base
.CreatePbufferSurface
= demoCreatePbufferSurface
;
320 demo
->Base
.DestroySurface
= demoDestroySurface
;
321 demo
->Base
.DestroyContext
= demoDestroyContext
;
323 /* enable supported extensions */
324 demo
->Base
.MESA_screen_surface
= EGL_TRUE
;
325 demo
->Base
.MESA_copy_context
= EGL_TRUE
;