src/video/cybergfx/SDL_cgxmodes.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 10 Jul 2006 21:04:37 +0000
changeset 1895 c121d94672cb
parent 1402 d910939febfa
permissions -rw-r--r--
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* Utilities for getting and setting the X display mode */
slouken@0
    25
slouken@0
    26
#include "SDL_timer.h"
slouken@0
    27
#include "SDL_events.h"
slouken@1361
    28
#include "../../events/SDL_events_c.h"
slouken@0
    29
#include "SDL_cgxvideo.h"
slouken@0
    30
#include "SDL_cgxwm_c.h"
slouken@0
    31
#include "SDL_cgxmodes_c.h"
slouken@0
    32
slouken@0
    33
#define CGX_DEBUG
slouken@0
    34
slouken@1895
    35
static void
slouken@1895
    36
set_best_resolution(_THIS, int width, int height)
slouken@0
    37
{
slouken@1895
    38
    Uint32 idok;
slouken@1895
    39
    int depth = 8;
slouken@0
    40
slouken@1895
    41
    if (SDL_Display)
slouken@1895
    42
        depth =
slouken@1895
    43
            GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
slouken@0
    44
slouken@1895
    45
    idok = BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
slouken@1895
    46
                           CYBRBIDTG_NominalHeight, height,
slouken@1895
    47
                           CYBRBIDTG_Depth, depth, TAG_DONE);
slouken@0
    48
slouken@1895
    49
    if (idok != INVALID_ID) {
slouken@1895
    50
        if (SDL_Display) {
slouken@1895
    51
            if (currently_fullscreen)
slouken@1895
    52
                CloseScreen(SDL_Display);
slouken@1895
    53
            else
slouken@1895
    54
                UnlockPubScreen(NULL, SDL_Display);
slouken@1895
    55
        }
slouken@1895
    56
        SDL_Display = GFX_Display =
slouken@1895
    57
            OpenScreenTags(NULL, SA_Width, width, SA_Height, height,
slouken@1895
    58
                           SA_Depth, depth, SA_DisplayID, idok,
slouken@1895
    59
                           SA_ShowTitle, FALSE, TAG_DONE);
slouken@1895
    60
    }
slouken@0
    61
}
slouken@0
    62
slouken@1895
    63
static void
slouken@1895
    64
get_real_resolution(_THIS, int *w, int *h)
slouken@0
    65
{
slouken@1895
    66
    *w = /*SDL_Display->Width */ SDL_Window->Width - SDL_Window->BorderLeft -
slouken@1895
    67
        SDL_Window->BorderRight;
slouken@1895
    68
    *h = /*SDL_Display->Height */ SDL_Window->Height -
slouken@1895
    69
        SDL_Window->BorderBottom - SDL_Window->BorderTop;
slouken@0
    70
}
slouken@0
    71
slouken@1895
    72
static void
slouken@1895
    73
move_cursor_to(_THIS, int x, int y)
slouken@21
    74
{
slouken@21
    75
/*    XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */
slouken@21
    76
slouken@21
    77
/* DA FARE! */
slouken@21
    78
}
slouken@21
    79
slouken@1895
    80
static void
slouken@1895
    81
add_visual(_THIS, int depth, int class)
slouken@0
    82
{
slouken@1895
    83
    Uint32 tID;
slouken@0
    84
slouken@1895
    85
    tID = BestCModeIDTags(CYBRBIDTG_Depth, depth,
slouken@1895
    86
                          CYBRBIDTG_NominalWidth, 640,
slouken@1895
    87
                          CYBRBIDTG_NominalHeight, 480, TAG_DONE);
slouken@0
    88
slouken@1895
    89
    if (tID != INVALID_ID) {
slouken@1895
    90
        int n = this->hidden->nvisuals;
slouken@0
    91
slouken@1895
    92
        this->hidden->visuals[n].depth = depth;
slouken@1895
    93
        this->hidden->visuals[n].visual = tID;
slouken@1895
    94
        this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX, tID);
slouken@1895
    95
        this->hidden->nvisuals++;
slouken@1895
    96
    }
slouken@0
    97
}
slouken@0
    98
slouken@0
    99
#define TrueColor 1
slouken@0
   100
#define PseudoColor 2
slouken@0
   101
slouken@1895
   102
int
slouken@1895
   103
CGX_GetVideoModes(_THIS)
slouken@0
   104
{
slouken@0
   105
    int i;
slouken@1895
   106
    ULONG nextid;
slouken@1895
   107
    int nmodes = 0;
slouken@0
   108
slouken@1895
   109
    SDL_modelist = NULL;
slouken@0
   110
slouken@1895
   111
    nextid = NextDisplayInfo(INVALID_ID);
slouken@0
   112
slouken@1895
   113
    while (nextid != INVALID_ID) {
slouken@1895
   114
        if (IsCyberModeID(nextid)) {
slouken@1895
   115
            DisplayInfoHandle h;
slouken@0
   116
slouken@1895
   117
            if (h = FindDisplayInfo(nextid)) {
slouken@1895
   118
                struct DimensionInfo info;
slouken@0
   119
slouken@1895
   120
                if (GetDisplayInfoData
slouken@1895
   121
                    (h, (char *) &info, sizeof(struct DimensionInfo),
slouken@1895
   122
                     DTAG_DIMS, NULL)) {
slouken@1895
   123
                    int ok = 0;
slouken@0
   124
slouken@1895
   125
                    for (i = 0; i < nmodes; i++) {
slouken@1895
   126
                        if (SDL_modelist[i]->w == (info.Nominal.MaxX + 1)
slouken@1895
   127
                            && SDL_modelist[i]->h == (info.Nominal.MaxY + 1))
slouken@1895
   128
                            ok = 1;
slouken@1895
   129
                    }
slouken@0
   130
slouken@1895
   131
                    if (!ok) {
slouken@1895
   132
                        nmodes++;
slouken@0
   133
slouken@1895
   134
                        SDL_modelist =
slouken@1895
   135
                            (SDL_Rect **) SDL_realloc(SDL_modelist,
slouken@1895
   136
                                                      (nmodes +
slouken@1895
   137
                                                       1) *
slouken@1895
   138
                                                      sizeof(SDL_Rect *));
slouken@1895
   139
                        SDL_modelist[nmodes] = NULL;
slouken@0
   140
slouken@1895
   141
                        if (SDL_modelist) {
slouken@1895
   142
                            SDL_modelist[nmodes - 1] = (SDL_Rect *)
slouken@1895
   143
                                SDL_malloc(sizeof(SDL_Rect));
slouken@0
   144
slouken@1895
   145
                            if (SDL_modelist[nmodes - 1] == NULL)
slouken@1895
   146
                                break;
slouken@0
   147
slouken@1895
   148
                            SDL_modelist[nmodes - 1]->x = 0;
slouken@1895
   149
                            SDL_modelist[nmodes - 1]->y = 0;
slouken@1895
   150
                            SDL_modelist[nmodes - 1]->w =
slouken@1895
   151
                                info.Nominal.MaxX + 1;
slouken@1895
   152
                            SDL_modelist[nmodes - 1]->h =
slouken@1895
   153
                                info.Nominal.MaxY + 1;
slouken@1895
   154
                        }
slouken@1895
   155
                    }
slouken@1895
   156
                }
slouken@1895
   157
            }
slouken@1895
   158
        }
slouken@1895
   159
        nextid = NextDisplayInfo(nextid);
slouken@1895
   160
    }
slouken@0
   161
slouken@0
   162
slouken@1895
   163
    this->hidden->nvisuals = 0;
slouken@1895
   164
    /* Search for the visuals in deepest-first order, so that the first
slouken@1895
   165
       will be the richest one */
slouken@1895
   166
    add_visual(this, 32, TrueColor);
slouken@1895
   167
    add_visual(this, 24, TrueColor);
slouken@1895
   168
    add_visual(this, 16, TrueColor);
slouken@1895
   169
    add_visual(this, 15, TrueColor);
slouken@1895
   170
    add_visual(this, 8, PseudoColor);
slouken@0
   171
slouken@1895
   172
    if (this->hidden->nvisuals == 0) {
slouken@1895
   173
        SDL_SetError("Found no sufficiently capable CGX visuals");
slouken@1895
   174
        return -1;
slouken@1895
   175
    }
slouken@0
   176
slouken@1895
   177
    if (SDL_modelist == NULL) {
slouken@1895
   178
        SDL_modelist = (SDL_Rect **) SDL_malloc((1 + 1) * sizeof(SDL_Rect *));
slouken@0
   179
        i = 0;
slouken@1895
   180
        if (SDL_modelist) {
slouken@1895
   181
            SDL_modelist[i] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
slouken@1895
   182
            if (SDL_modelist[i]) {
slouken@0
   183
                SDL_modelist[i]->x = 0;
slouken@0
   184
                SDL_modelist[i]->y = 0;
slouken@0
   185
                SDL_modelist[i]->w = SDL_Display->Width;
slouken@0
   186
                SDL_modelist[i]->h = SDL_Display->Height;
slouken@0
   187
                ++i;
slouken@0
   188
            }
slouken@0
   189
            SDL_modelist[i] = NULL;
slouken@0
   190
        }
slouken@0
   191
    }
slouken@0
   192
slouken@1895
   193
    D(if (SDL_modelist) {
slouken@1895
   194
      bug("CGX video mode list: (%ld)\n", nmodes);
slouken@1895
   195
      for (i = 0; SDL_modelist[i]; ++i) {
slouken@1895
   196
      bug("\t%ld x %ld\n", SDL_modelist[i]->w, SDL_modelist[i]->h);}
slouken@1895
   197
      }
slouken@0
   198
    );
slouken@0
   199
slouken@1895
   200
    D( {
slouken@1895
   201
      bug("CGX visuals list: (%ld)\n", this->hidden->nvisuals);
slouken@1895
   202
      for (i = 0; i < this->hidden->nvisuals; i++)
slouken@1895
   203
      bug("\t%lx - depth: %ld bpp: %ld\n",
slouken@1895
   204
          this->hidden->visuals[i].visual,
slouken@1895
   205
          this->hidden->visuals[i].depth, this->hidden->visuals[i].bpp);}
slouken@0
   206
    );
slouken@0
   207
    return 0;
slouken@0
   208
}
slouken@0
   209
slouken@1895
   210
int
slouken@1895
   211
CGX_SupportedVisual(_THIS, SDL_PixelFormat * format)
slouken@0
   212
{
slouken@0
   213
    int i;
slouken@1895
   214
    for (i = 0; i < this->hidden->nvisuals; i++) {
slouken@1895
   215
        if (this->hidden->visuals[i].depth == format->BitsPerPixel)     // Era bpp
slouken@1895
   216
            return 1;
slouken@1895
   217
    }
slouken@0
   218
    return 0;
slouken@0
   219
}
slouken@0
   220
slouken@1895
   221
SDL_Rect **
slouken@1895
   222
CGX_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
slouken@0
   223
{
slouken@1895
   224
    if (CGX_SupportedVisual(this, format)) {
slouken@1895
   225
        if (flags & SDL_FULLSCREEN) {
slouken@1895
   226
            return (SDL_modelist);
slouken@0
   227
        } else {
slouken@1895
   228
            return ((SDL_Rect **) - 1);
slouken@0
   229
        }
slouken@0
   230
    } else {
slouken@1895
   231
        return ((SDL_Rect **) 0);
slouken@0
   232
    }
slouken@0
   233
}
slouken@0
   234
slouken@1895
   235
void
slouken@1895
   236
CGX_FreeVideoModes(_THIS)
slouken@0
   237
{
slouken@0
   238
    int i;
slouken@0
   239
slouken@1895
   240
    if (SDL_modelist) {
slouken@1895
   241
        for (i = 0; SDL_modelist[i]; ++i) {
slouken@1336
   242
            SDL_free(SDL_modelist[i]);
slouken@0
   243
        }
slouken@1336
   244
        SDL_free(SDL_modelist);
slouken@0
   245
        SDL_modelist = NULL;
slouken@0
   246
    }
slouken@0
   247
}
slouken@0
   248
slouken@1895
   249
int
slouken@1895
   250
CGX_ResizeFullScreen(_THIS)
slouken@0
   251
{
slouken@0
   252
    int x, y;
slouken@0
   253
    int real_w, real_h;
slouken@0
   254
slouken@1895
   255
    if (currently_fullscreen) {
slouken@0
   256
/* Per ora non faccio nulla qui */
slouken@0
   257
    }
slouken@1895
   258
    return (1);
slouken@0
   259
}
slouken@0
   260
slouken@1895
   261
void
slouken@1895
   262
_QueueEnterFullScreen(_THIS)
slouken@0
   263
{
slouken@0
   264
}
slouken@0
   265
slouken@1895
   266
int
slouken@1895
   267
CGX_EnterFullScreen(_THIS)
slouken@0
   268
{
slouken@0
   269
    int okay;
slouken@1895
   270
    Uint32 saved_flags;
slouken@0
   271
slouken@0
   272
    okay = 1;
slouken@255
   273
    saved_flags = this->screen->flags;
slouken@255
   274
slouken@1895
   275
    if (!currently_fullscreen) {
slouken@0
   276
        int real_w, real_h;
slouken@0
   277
slouken@0
   278
        /* Map the fullscreen window to blank the screen */
slouken@0
   279
        get_real_resolution(this, &real_w, &real_h);
slouken@255
   280
slouken@1895
   281
        CGX_DestroyWindow(this, this->screen);
slouken@1895
   282
        set_best_resolution(this, real_w, real_h);
slouken@0
   283
slouken@0
   284
        currently_fullscreen = 1;
slouken@1895
   285
        this->screen->flags = saved_flags;
slouken@0
   286
slouken@1895
   287
        CGX_CreateWindow(this, this->screen, real_w, real_h,
slouken@1895
   288
                         GetCyberMapAttr(SDL_Display->RastPort.BitMap,
slouken@1895
   289
                                         CYBRMATTR_DEPTH),
slouken@1895
   290
                         this->screen->flags);
slouken@0
   291
slouken@0
   292
        /* Set the new resolution */
slouken@0
   293
        okay = CGX_ResizeFullScreen(this);
slouken@1895
   294
        if (!okay) {
slouken@0
   295
            CGX_LeaveFullScreen(this);
slouken@0
   296
        }
slouken@1895
   297
        /* Set the colormap */
slouken@0
   298
/*
slouken@0
   299
		if ( SDL_XColorMap ) {
slouken@0
   300
			XInstallColormap(SDL_Display, SDL_XColorMap);
slouken@0
   301
		}
slouken@0
   302
*/
slouken@255
   303
    }
slouken@0
   304
//    CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
slouken@1895
   305
    return (okay);
slouken@0
   306
}
slouken@0
   307
slouken@1895
   308
int
slouken@1895
   309
CGX_LeaveFullScreen(_THIS)
slouken@0
   310
{
slouken@1895
   311
    if (currently_fullscreen) {
slouken@1895
   312
        int width, height;
slouken@1895
   313
        if (SDL_Window) {
slouken@1895
   314
            CloseWindow(SDL_Window);
slouken@1895
   315
            SDL_Window = NULL;
slouken@1895
   316
        }
slouken@1895
   317
        CloseScreen(SDL_Display);
slouken@0
   318
slouken@1895
   319
        GFX_Display = SDL_Display = LockPubScreen(NULL);
slouken@0
   320
slouken@1895
   321
        currently_fullscreen = 0;
slouken@0
   322
slouken@1895
   323
        CGX_CreateWindow(this, this->screen, this->screen->w,
slouken@1895
   324
                         this->screen->h,
slouken@1895
   325
                         GetCyberMapAttr(SDL_Display->RastPort.BitMap,
slouken@1895
   326
                                         CYBRMATTR_DEPTH),
slouken@1895
   327
                         this->screen->flags);
slouken@1895
   328
        CGX_ResizeImage(this, this->screen, 0L);
slouken@0
   329
    }
slouken@0
   330
slouken@1895
   331
    return (0);
slouken@0
   332
}
slouken@1895
   333
slouken@1895
   334
/* vi: set ts=4 sw=4 expandtab: */