From 8b0c6c4a8dc1899d56e52fe3b0a9e1165c30ecae Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 30 Jun 2010 18:02:23 +0800 Subject: [PATCH] egl: Store screens in a dynamic array. --- src/egl/main/egldisplay.h | 4 +- src/egl/main/eglmode.c | 7 ++- src/egl/main/eglscreen.c | 50 +++++++++---------- .../state_trackers/egl/common/egl_g3d.c | 17 ++++--- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index e729038f9e0..0b2f26a4c07 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -90,9 +90,7 @@ struct _egl_display _EGLExtensions Extensions; - EGLint NumScreens; - _EGLScreen **Screens; /* array [NumScreens] */ - + _EGLArray *Screens; _EGLArray *Configs; /* lists of resources */ diff --git a/src/egl/main/eglmode.c b/src/egl/main/eglmode.c index 66446c0495d..859e9318b4a 100644 --- a/src/egl/main/eglmode.c +++ b/src/egl/main/eglmode.c @@ -22,9 +22,12 @@ _eglLookupMode(EGLModeMESA mode, _EGLDisplay *disp) { EGLint scrnum; + if (!disp->Screens) + return NULL; + /* loop over all screens on the display */ - for (scrnum = 0; scrnum < disp->NumScreens; scrnum++) { - const _EGLScreen *scrn = disp->Screens[scrnum]; + for (scrnum = 0; scrnum < disp->Screens->Size; scrnum++) { + const _EGLScreen *scrn = disp->Screens->Elements[scrnum]; EGLint i; /* search list of modes for handle */ for (i = 0; i < scrn->NumModes; i++) { diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c index c47afd6abda..8f96fd935c7 100644 --- a/src/egl/main/eglscreen.c +++ b/src/egl/main/eglscreen.c @@ -62,9 +62,13 @@ _eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display) { EGLint i; - for (i = 0; i < display->NumScreens; i++) { - if (display->Screens[i]->Handle == screen) - return display->Screens[i]; + if (!display->Screens) + return NULL; + + for (i = 0; i < display->Screens->Size; i++) { + _EGLScreen *scr = (_EGLScreen *) display->Screens->Elements[i]; + if (scr->Handle == screen) + return scr; } return NULL; } @@ -76,40 +80,36 @@ _eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display) void _eglAddScreen(_EGLDisplay *display, _EGLScreen *screen) { - EGLint n; - assert(display); assert(screen); + if (!display->Screens) { + display->Screens = _eglCreateArray("Screen", 4); + if (!display->Screens) + return; + } screen->Handle = _eglAllocScreenHandle(); - n = display->NumScreens; - display->Screens = realloc(display->Screens, (n+1) * sizeof(_EGLScreen *)); - display->Screens[n] = screen; - display->NumScreens++; + _eglAppendArray(display->Screens, (void *) screen); } +static EGLBoolean +_eglFlattenScreen(void *elem, void *buffer) +{ + _EGLScreen *scr = (_EGLScreen *) elem; + EGLScreenMESA *handle = (EGLScreenMESA *) buffer; + *handle = scr->Handle; + return EGL_TRUE; +} + + EGLBoolean _eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *display, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens) { - EGLint n; - - if (display->NumScreens > max_screens) { - n = max_screens; - } - else { - n = display->NumScreens; - } - - if (screens) { - EGLint i; - for (i = 0; i < n; i++) - screens[i] = display->Screens[i]->Handle; - } - if (num_screens) - *num_screens = n; + *num_screens = _eglFlattenArray(display->Screens, (void *) screens, + sizeof(screens[0]), max_screens, _eglFlattenScreen); return EGL_TRUE; } diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index d7a2aa8b8ea..4815a8a3222 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -424,11 +424,18 @@ static struct native_event_handler egl_g3d_native_event_handler = { egl_g3d_new_sw_screen }; +static void +egl_g3d_free_screen(void *scr) +{ + struct egl_g3d_screen *gscr = egl_g3d_screen((_EGLScreen *) scr); + FREE(gscr->native_modes); + FREE(gscr); +} + static EGLBoolean egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - EGLint i; _eglReleaseDisplayResources(drv, dpy); _eglCleanupDisplay(dpy); @@ -437,12 +444,8 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) gdpy->pipe->destroy(gdpy->pipe); if (dpy->Screens) { - for (i = 0; i < dpy->NumScreens; i++) { - struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]); - FREE(gscr->native_modes); - FREE(gscr); - } - FREE(dpy->Screens); + _eglDestroyArray(dpy->Screens, egl_g3d_free_screen); + dpy->Screens = NULL; } if (gdpy->smapi) -- 2.30.2