File: lnxscreenmode.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (310 lines) | stat: -rw-r--r-- 9,302 bytes parent folder | download | duplicates (2)
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
* Descent 3 
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.

--- HISTORICAL COMMENTS FOLLOW ---

 * $Logfile: /DescentIII/Main/renderer/lnxscreenmode.cpp $
 * $Revision: 1.6 $
 * $Date: 2000/06/29 18:48:13 $
 * $Author: icculus $
 *
 *
 *
 * $Log: lnxscreenmode.cpp,v $
 * Revision 1.6  2000/06/29 18:48:13  icculus
 * Dumb typo fixed.
 *
 * Revision 1.5  2000/06/29 06:41:24  icculus
 * mad commits.
 *
 * Revision 1.4  2000/06/24 01:15:15  icculus
 * patched to compile.
 *
 * Revision 1.3  2000/05/29 05:25:57  icculus
 * Command line fix: Changed "--nofullscreen" to "--windowed" (or "-w").
 *
 * Revision 1.2  2000/04/28 20:25:51  icculus
 * Updates, cleanups, and SDLification.
 *
 * Revision 1.1.1.1  2000/04/18 00:00:49  icculus
 * initial checkin
 *
 *
 * 4     9/09/99 4:38p Jeff
 * fixed crashes if lib not loaded
 *
 * 3     9/06/99 9:21p Jeff
 * lock video mode switching, don't set viewport when restoring (causing a
 * bunch of screen garbage)
 *
 * 2     9/05/99 9:41p Jeff
 * first checkin of Linux Screen manager
 *
 * $NoKeywords: $
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lnxscreenmode.h"
#include "pserror.h"
#include "args.h"

CLnxVideoModes LinuxVideoMode;

/*
typedef Bool (*VidModeQueryExtension_fp)(Display* dpy,int* event_base,int* error_base);
typedef Bool (*VidModeGetAllModeLines_fp)(Display* dpy,int screen,int* modecount,XF86VidModeModeInfo*** modelinesPtr);
typedef Bool (*VidModeSwitchToMode_fp)(Display* dpy,int screen,XF86VidModeModeInfo* modeline);
typedef Bool (*VidModeSetViewPort_fp)(Display* dpy,int screen,int x,int y);
typedef void (*VidModeFreeData_fp)(int num_modes,XF86VidModeModeInfo** modelinePtr);
typedef Bool (*VidModeGetModeLine_fp)(Display* dpy,int screen,int* dotclock,XF86VidModeModeLine* modeline);
typedef Bool (*VidModeLockModeSwitch_fp)(Display* dpy,int screen,int lock);

VidModeQueryExtension_fp VidModeQueryExtension;
VidModeGetAllModeLines_fp VidModeGetAllModeLines;
VidModeSwitchToMode_fp VidModeSwitchToMode;
VidModeSetViewPort_fp VidModeSetViewPort;
VidModeFreeData_fp VidModeFreeData;
VidModeGetModeLine_fp VidModeGetModeLine;
VidModeLockModeSwitch_fp VidModeLockModeSwitch;
*/

CLnxVideoModes::CLnxVideoModes() {
  m_Inited = false;
  m_NumVideoModes = 0;
  m_ModeInfoList = NULL;
  //	m_Display = NULL;
  m_VideoResolutionChanged = false;
  /*
          VidModeQueryExtension = NULL;
          VidModeGetAllModeLines = NULL;
          VidModeSwitchToMode = NULL;
          VidModeSetViewPort = NULL;
          VidModeFreeData = NULL;
          VidModeGetModeLine = NULL;
          VidModeLockModeSwitch = NULL;
  */
}

CLnxVideoModes::~CLnxVideoModes() {
  if (!m_Inited)
    return;

  // shutdown and free the memory
  RestoreVideoMode();

  //	VidModeFreeData(m_NumVideoModes,m_ModeInfoList);
}

// enumerate all the possible video modes
bool CLnxVideoModes::Init(void) // Display *dpy,int screen)
{
#if 0  // with SDL2, we'll just use FULLSCREEN_DESKTOP and never change the physical vidmode
  if (m_Inited)
    return true;

  //	m_Display = dpy;
  //	m_Screen = screen;
  m_NumVideoModes = 0;
  m_ModeInfoList = NULL;
  m_Inited = true;
  sdlflags = 0;
  /*
          if(!LoadLibraries())
          {
                  m_Inited = false;
                  fprintf(stdout,"LoadLib: Unable to load VideoMode libraries\n");
                  return false;
          }

          int dummy;
          if(!VidModeQueryExtension(dpy,&dummy,&dummy))
                  return false;

          if(!VidModeGetAllModeLines(m_Display,m_Screen,&m_NumVideoModes,&m_ModeInfoList))
          {
                  m_NumVideoModes = 0;
          }else
          {
  */

  const SDL_VideoInfo *vidInfo = NULL;

  sdlflags = SDL_HWSURFACE | SDL_FULLSCREEN;
  sdlflags = SDL_OPENGL | SDL_FULLSCREEN;
  if (FindArgChar("-windowed", 'w'))
    sdlflags &= ~SDL_FULLSCREEN;

  vidInfo = SDL_GetVideoInfo();

  m_ModeInfoList = SDL_ListModes(vidInfo->vfmt, sdlflags);
  if (m_ModeInfoList == NULL) {
    sdlflags &= ~SDL_FULLSCREEN;
    m_ModeInfoList = SDL_ListModes(vidInfo->vfmt, sdlflags); // try without fullscreen.
    if (m_ModeInfoList == NULL) {
      sdlflags = 0;
      m_ModeInfoList = SDL_ListModes(vidInfo->vfmt, sdlflags); // give me ANYTHING.
      if (m_ModeInfoList == NULL) {
        fprintf(stderr, "SDL: SDL_ListModes() failed.\n");
        return -3;
      } // if
    }   // if
  }     // if

  if (m_ModeInfoList == (SDL_Rect **)-1) // anything is fine.
  {
    mprintf(0, "Windowed surface is probably going to be used.");
    m_NumVideoModes = 0;
  } // if
  else {
    mprintf(0, "-------------------------\n");
    mprintf(0, "Supported Mode Lines:\n");
    for (int i = 0; m_ModeInfoList[i] != NULL; i++) {
      //,m_ModeInfoList[i]->hdisplay,m_ModeInfoList[i]->vdisplay);
      mprintf(0, "     Mode %d: %dX%d\n", i, m_ModeInfoList[i]->w, m_ModeInfoList[i]->h);
      m_NumVideoModes++;
    } // for
    mprintf(0, "-------------------------\n");
  } // else
#endif

  return true;
}

bool CLnxVideoModes::SwitchResolution(int width, int height) {
  /*
          if(!m_Inited)
                  return false;

          int i;
          for(i=0;i<m_NumVideoModes;i++)
          {
                  if(m_ModeInfoList[i]->hdisplay==width && m_ModeInfoList[i]->vdisplay==height)
                  {
                          // found a matching resolution, try to change to it
                          if(SwitchToMode(m_ModeInfoList[i]))
                          {
                                  fprintf(stdout,"Mode switch to %dX%d OK!\n",width,height);
                                  m_VideoResolutionChanged = (i==0)?false:true;
                                  return true;
                          }
                  }
          }

          return false;
  */
  return (true);
}

void CLnxVideoModes::RestoreVideoMode(void) {
  /*
          if(!m_Inited)
                  return;

          if(!m_VideoResolutionChanged)
                  return;

          // index 0 is the original mode
          if(m_NumVideoModes<=1)
                  return;

          m_VideoResolutionChanged = false;

          VidModeSwitchToMode(m_Display,m_Screen,m_ModeInfoList[0]);
  */
  return;
}

/*
bool CLnxVideoModes::SwitchToMode(XF86VidModeModeInfo *mode)
{
        if(!m_Inited)
                return false;

        if(!VidModeSwitchToMode(m_Display,m_Screen,mode))
        {
                fprintf(stdout,"Video: Unable to switch mode to %dX%d\n",mode->hdisplay,mode->vdisplay);
                return false;
        }

        VidModeSetViewPort(m_Display,m_Screen,0,0);
        return true;
}

bool CLnxVideoModes::QueryExtension(Display *dpy)
{
        if(!m_Inited)
                return false;

        int dummy;
        if(!VidModeQueryExtension(dpy,&dummy,&dummy))
                return false;
        return true;
}

void CLnxVideoModes::GetModeLine(Display *dpy,int screen,int *dotclock,XF86VidModeModeLine *modeline)
{
        if(!m_Inited)
                return;

        VidModeGetModeLine(dpy,screen,dotclock,modeline);
}
*/

void CLnxVideoModes::Lock(bool lock) {
  /*
          if(!m_Inited)
                  return;

          VidModeLockModeSwitch(m_Display,m_Screen,(lock)?1:0);
  */
}

bool CLnxVideoModes::LoadLibraries(void) {
  /*
          void *handle;
          char *libname = "OutrageDynXLib.so";
          handle = dlopen(libname,RTLD_NOW|RTLD_GLOBAL);
          if(!handle)
          {
                  fprintf(stderr,"Library Load Failed: %s (%s)\n",libname,dlerror());
                  return false;
          }

          VidModeQueryExtension = (VidModeQueryExtension_fp)dlsym(handle,"VidModeQueryExtension");
          VidModeGetAllModeLines = (VidModeGetAllModeLines_fp)dlsym(handle,"VidModeGetAllModeLines");
          VidModeSwitchToMode = (VidModeSwitchToMode_fp)dlsym(handle,"VidModeSwitchToMode");
          VidModeSetViewPort = (VidModeSetViewPort_fp)dlsym(handle,"VidModeSetViewPort");
          VidModeFreeData = (VidModeFreeData_fp)dlsym(handle,"VidModeFreeData");
          VidModeGetModeLine = (VidModeGetModeLine_fp)dlsym(handle,"VidModeGetModeLine");
          VidModeLockModeSwitch = (VidModeLockModeSwitch_fp)dlsym(handle,"VidModeLockModeSwitch");

          if(	!VidModeQueryExtension	||
                  !VidModeGetAllModeLines	||
                  !VidModeSwitchToMode	||
                  !VidModeSetViewPort		||
                  !VidModeFreeData		||
                  !VidModeGetModeLine		||
                  !VidModeLockModeSwitch)
          {
                  fprintf(stderr,"Symbol Resolve Error: %s\n",libname);
                  return false;
          }
  */
  return true;
}