diff options
author | Chia-I Wu <olv@lunarg.com> | 2010-06-30 18:02:23 +0800 |
---|---|---|
committer | Chia-I Wu <olv@lunarg.com> | 2010-06-30 18:32:48 +0800 |
commit | 8b0c6c4a8dc1899d56e52fe3b0a9e1165c30ecae (patch) | |
tree | 8c92befc4b999c6b67e5c30e5edb4f0bbc76ec8c /src/egl | |
parent | 6717a313f26e42a7864f46f499637462a7cc3d57 (diff) |
egl: Store screens in a dynamic array.
Diffstat (limited to 'src/egl')
-rw-r--r-- | src/egl/main/egldisplay.h | 4 | ||||
-rw-r--r-- | src/egl/main/eglmode.c | 7 | ||||
-rw-r--r-- | src/egl/main/eglscreen.c | 50 |
3 files changed, 31 insertions, 30 deletions
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index e729038f9e..0b2f26a4c0 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 66446c0495..859e9318b4 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 c47afd6abd..8f96fd935c 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; } |