summaryrefslogtreecommitdiff
path: root/src/egl/main/eglscreen.c
blob: 14a1e9f8fe3a10672c531241f3267ca421ab4ceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Ideas for screen management extension to EGL.
 *
 * Each EGLDisplay has one or more screens (CRTs, Flat Panels, etc).
 * The screens' handles can be obtained with eglGetScreensMESA().
 *
 * A new kind of EGLSurface is possible- one which can be directly scanned
 * out on a screen.  Such a surface is created with eglCreateScreenSurface().
 *
 * To actually display a screen surface on a screen, the eglShowSurface()
 * function is called.
 */

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "egldisplay.h"
#include "eglglobals.h"
#include "eglmode.h"
#include "eglconfig.h"
#include "eglsurface.h"
#include "eglscreen.h"


/**
 * Return a new screen handle/ID.
 * NOTE: we never reuse these!
 */
EGLScreenMESA
_eglAllocScreenHandle(void)
{
   EGLScreenMESA s = _eglGlobal.FreeScreenHandle;
   _eglGlobal.FreeScreenHandle++;
   return s;
}


/**
 * Initialize an _EGLScreen object to default values.
 */
void
_eglInitScreen(_EGLScreen *screen)
{
   memset(screen, 0, sizeof(_EGLScreen));
   screen->StepX = 1;
   screen->StepY = 1;
}


/**
 * Given a public screen handle, return the internal _EGLScreen object.
 */
_EGLScreen *
_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display)
{
   EGLint i;

   for (i = 0; i < display->NumScreens; i++) {
      if (display->Screens[i]->Handle == screen)
         return display->Screens[i];
   }
   return NULL;
}


/**
 * Add the given _EGLScreen to the display's list of screens.
 */
void
_eglAddScreen(_EGLDisplay *display, _EGLScreen *screen)
{
   EGLint n;

   assert(display);
   assert(screen);

   screen->Handle = _eglAllocScreenHandle();
   n = display->NumScreens;
   display->Screens = realloc(display->Screens, (n+1) * sizeof(_EGLScreen *));
   display->Screens[n] = screen;
   display->NumScreens++;
}



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;

   return EGL_TRUE;
}


/**
 * Example function - drivers should do a proper implementation.
 */
_EGLSurface *
_eglCreateScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
                            const EGLint *attrib_list)
{
#if 0 /* THIS IS JUST EXAMPLE CODE */
   _EGLSurface *surf;

   surf = (_EGLSurface *) calloc(1, sizeof(_EGLSurface));
   if (!surf)
      return NULL;

   if (!_eglInitSurface(drv, surf, EGL_SCREEN_BIT_MESA,
                        conf, attrib_list)) {
      free(surf);
      return NULL;
   }

   return surf;
#endif
   return NULL;
}


/**
 * Show the given surface on the named screen.
 * If surface is EGL_NO_SURFACE, disable the screen's output.
 * 
 * This is just a placeholder function; drivers will always override
 * this with code that _really_ shows the surface.
 */
EGLBoolean
_eglShowScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy,
                          _EGLScreen *scrn, _EGLSurface *surf,
                          _EGLMode *mode)
{
   if (!surf) {
      scrn->CurrentSurface = NULL;
   }
   else {
      if (surf->Type != EGL_SCREEN_BIT_MESA) {
         _eglError(EGL_BAD_SURFACE, "eglShowSurfaceMESA");
         return EGL_FALSE;
      }
      if (surf->Width < mode->Width || surf->Height < mode->Height) {
         _eglError(EGL_BAD_SURFACE,
                   "eglShowSurfaceMESA(surface smaller than screen size)");
         return EGL_FALSE;
      }

      scrn->CurrentSurface = surf;
      scrn->CurrentMode = mode;
   }
   return EGL_TRUE;
}


/**
 * Set a screen's current display mode.
 * Note: mode = EGL_NO_MODE is valid (turns off the screen)
 *
 * This is just a placeholder function; drivers will always override
 * this with code that _really_ sets the mode.
 */
EGLBoolean
_eglScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
                   _EGLMode *m)
{
   scrn->CurrentMode = m;
   return EGL_TRUE;
}


/**
 * Set a screen's surface origin.
 */
EGLBoolean
_eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy,
                       _EGLScreen *scrn, EGLint x, EGLint y)
{
   scrn->OriginX = x;
   scrn->OriginY = y;

   return EGL_TRUE;
}


/**
 * Query a screen's current surface.
 */
EGLBoolean
_eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy,
                           _EGLScreen *scrn, _EGLSurface **surf)
{
   *surf = scrn->CurrentSurface;
   return EGL_TRUE;
}


/**
 * Query a screen's current mode.
 */
EGLBoolean
_eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
                        _EGLMode **m)
{
   *m = scrn->CurrentMode;
   return EGL_TRUE;
}


EGLBoolean
_eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
                    EGLint attribute, EGLint *value)
{
   switch (attribute) {
   case EGL_SCREEN_POSITION_MESA:
      value[0] = scrn->OriginX;
      value[1] = scrn->OriginY;
      break;
   case EGL_SCREEN_POSITION_GRANULARITY_MESA:
      value[0] = scrn->StepX;
      value[1] = scrn->StepY;
      break;
   default:
      _eglError(EGL_BAD_ATTRIBUTE, "eglQueryScreenMESA");
      return EGL_FALSE;
   }

   return EGL_TRUE;
}


/**
 * Delete the modes associated with given screen.
 */
void
_eglDestroyScreenModes(_EGLScreen *scrn)
{
   EGLint i;
   for (i = 0; i < scrn->NumModes; i++) {
      if (scrn->Modes[i].Name)
         free((char *) scrn->Modes[i].Name); /* cast away const */
   }
   if (scrn->Modes)
      free(scrn->Modes);
   scrn->Modes = NULL;
   scrn->NumModes = 0;
}

      
/**
 * Default fallback routine - drivers should usually override this.
 */
void
_eglDestroyScreen(_EGLScreen *scrn)
{
   _eglDestroyScreenModes(scrn);
   free(scrn);
}