src/video/cybergfx/SDL_cgxmodes.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1402 d910939febfa
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
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@1662
    35
static void
slouken@1662
    36
set_best_resolution (_THIS, int width, int height)
slouken@0
    37
{
slouken@1662
    38
    Uint32 idok;
slouken@1662
    39
    int depth = 8;
slouken@0
    40
slouken@1662
    41
    if (SDL_Display)
slouken@1662
    42
        depth =
slouken@1662
    43
            GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
slouken@0
    44
slouken@1662
    45
    idok = BestCModeIDTags (CYBRBIDTG_NominalWidth, width,
slouken@1662
    46
                            CYBRBIDTG_NominalHeight, height,
slouken@1662
    47
                            CYBRBIDTG_Depth, depth, TAG_DONE);
slouken@0
    48
slouken@1662
    49
    if (idok != INVALID_ID) {
slouken@1662
    50
        if (SDL_Display) {
slouken@1662
    51
            if (currently_fullscreen)
slouken@1662
    52
                CloseScreen (SDL_Display);
slouken@1662
    53
            else
slouken@1662
    54
                UnlockPubScreen (NULL, SDL_Display);
slouken@1662
    55
        }
slouken@1662
    56
        SDL_Display = GFX_Display =
slouken@1662
    57
            OpenScreenTags (NULL, SA_Width, width, SA_Height, height,
slouken@1662
    58
                            SA_Depth, depth, SA_DisplayID, idok,
slouken@1662
    59
                            SA_ShowTitle, FALSE, TAG_DONE);
slouken@1662
    60
    }
slouken@0
    61
}
slouken@0
    62
slouken@1662
    63
static void
slouken@1662
    64
get_real_resolution (_THIS, int *w, int *h)
slouken@0
    65
{
slouken@1662
    66
    *w = /*SDL_Display->Width */ SDL_Window->Width - SDL_Window->BorderLeft -
slouken@1662
    67
        SDL_Window->BorderRight;
slouken@1662
    68
    *h = /*SDL_Display->Height */ SDL_Window->Height -
slouken@1662
    69
        SDL_Window->BorderBottom - SDL_Window->BorderTop;
slouken@0
    70
}
slouken@0
    71
slouken@1662
    72
static void
slouken@1662
    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@1662
    80
static void
slouken@1662
    81
add_visual (_THIS, int depth, int class)
slouken@0
    82
{
slouken@1662
    83
    Uint32 tID;
slouken@0
    84
slouken@1662
    85
    tID = BestCModeIDTags (CYBRBIDTG_Depth, depth,
slouken@1662
    86
                           CYBRBIDTG_NominalWidth, 640,
slouken@1662
    87
                           CYBRBIDTG_NominalHeight, 480, TAG_DONE);
slouken@0
    88
slouken@1662
    89
    if (tID != INVALID_ID) {
slouken@1662
    90
        int n = this->hidden->nvisuals;
slouken@0
    91
slouken@1662
    92
        this->hidden->visuals[n].depth = depth;
slouken@1662
    93
        this->hidden->visuals[n].visual = tID;
slouken@1662
    94
        this->hidden->visuals[n].bpp = GetCyberIDAttr (CYBRIDATTR_BPPIX, tID);
slouken@1662
    95
        this->hidden->nvisuals++;
slouken@1662
    96
    }
slouken@0
    97
}
slouken@0
    98
slouken@0
    99
#define TrueColor 1
slouken@0
   100
#define PseudoColor 2
slouken@0
   101
slouken@1662
   102
int
slouken@1662
   103
CGX_GetVideoModes (_THIS)
slouken@0
   104
{
slouken@0
   105
    int i;
slouken@1662
   106
    ULONG nextid;
slouken@1662
   107
    int nmodes = 0;
slouken@0
   108
slouken@1662
   109
    SDL_modelist = NULL;
slouken@0
   110
slouken@1662
   111
    nextid = NextDisplayInfo (INVALID_ID);
slouken@0
   112
slouken@1662
   113
    while (nextid != INVALID_ID) {
slouken@1662
   114
        if (IsCyberModeID (nextid)) {
slouken@1662
   115
            DisplayInfoHandle h;
slouken@0
   116
slouken@1662
   117
            if (h = FindDisplayInfo (nextid)) {
slouken@1662
   118
                struct DimensionInfo info;
slouken@0
   119
slouken@1662
   120
                if (GetDisplayInfoData
slouken@1662
   121
                    (h, (char *) &info, sizeof (struct DimensionInfo),
slouken@1662
   122
                     DTAG_DIMS, NULL)) {
slouken@1662
   123
                    int ok = 0;
slouken@0
   124
slouken@1662
   125
                    for (i = 0; i < nmodes; i++) {
slouken@1662
   126
                        if (SDL_modelist[i]->w == (info.Nominal.MaxX + 1)
slouken@1662
   127
                            && SDL_modelist[i]->h == (info.Nominal.MaxY + 1))
slouken@1662
   128
                            ok = 1;
slouken@1662
   129
                    }
slouken@0
   130
slouken@1662
   131
                    if (!ok) {
slouken@1662
   132
                        nmodes++;
slouken@0
   133
slouken@1662
   134
                        SDL_modelist =
slouken@1662
   135
                            (SDL_Rect **) SDL_realloc (SDL_modelist,
slouken@1662
   136
                                                       (nmodes +
slouken@1662
   137
                                                        1) *
slouken@1662
   138
                                                       sizeof (SDL_Rect *));
slouken@1662
   139
                        SDL_modelist[nmodes] = NULL;
slouken@0
   140
slouken@1662
   141
                        if (SDL_modelist) {
slouken@1662
   142
                            SDL_modelist[nmodes - 1] = (SDL_Rect *)
slouken@1662
   143
                                SDL_malloc (sizeof (SDL_Rect));
slouken@0
   144
slouken@1662
   145
                            if (SDL_modelist[nmodes - 1] == NULL)
slouken@1662
   146
                                break;
slouken@0
   147
slouken@1662
   148
                            SDL_modelist[nmodes - 1]->x = 0;
slouken@1662
   149
                            SDL_modelist[nmodes - 1]->y = 0;
slouken@1662
   150
                            SDL_modelist[nmodes - 1]->w =
slouken@1662
   151
                                info.Nominal.MaxX + 1;
slouken@1662
   152
                            SDL_modelist[nmodes - 1]->h =
slouken@1662
   153
                                info.Nominal.MaxY + 1;
slouken@1662
   154
                        }
slouken@1662
   155
                    }
slouken@1662
   156
                }
slouken@1662
   157
            }
slouken@1662
   158
        }
slouken@1662
   159
        nextid = NextDisplayInfo (nextid);
slouken@1662
   160
    }
slouken@0
   161
slouken@0
   162
slouken@1662
   163
    this->hidden->nvisuals = 0;
slouken@1662
   164
    /* Search for the visuals in deepest-first order, so that the first
slouken@1662
   165
       will be the richest one */
slouken@1662
   166
    add_visual (this, 32, TrueColor);
slouken@1662
   167
    add_visual (this, 24, TrueColor);
slouken@1662
   168
    add_visual (this, 16, TrueColor);
slouken@1662
   169
    add_visual (this, 15, TrueColor);
slouken@1662
   170
    add_visual (this, 8, PseudoColor);
slouken@0
   171
slouken@1662
   172
    if (this->hidden->nvisuals == 0) {
slouken@1662
   173
        SDL_SetError ("Found no sufficiently capable CGX visuals");
slouken@1662
   174
        return -1;
slouken@1662
   175
    }
slouken@0
   176
slouken@1662
   177
    if (SDL_modelist == NULL) {
slouken@1662
   178
        SDL_modelist =
slouken@1662
   179
            (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
slouken@0
   180
        i = 0;
slouken@1662
   181
        if (SDL_modelist) {
slouken@1662
   182
            SDL_modelist[i] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
slouken@1662
   183
            if (SDL_modelist[i]) {
slouken@0
   184
                SDL_modelist[i]->x = 0;
slouken@0
   185
                SDL_modelist[i]->y = 0;
slouken@0
   186
                SDL_modelist[i]->w = SDL_Display->Width;
slouken@0
   187
                SDL_modelist[i]->h = SDL_Display->Height;
slouken@0
   188
                ++i;
slouken@0
   189
            }
slouken@0
   190
            SDL_modelist[i] = NULL;
slouken@0
   191
        }
slouken@0
   192
    }
slouken@0
   193
slouken@1662
   194
    D (if (SDL_modelist) {
slouken@1662
   195
       bug ("CGX video mode list: (%ld)\n", nmodes);
slouken@1662
   196
       for (i = 0; SDL_modelist[i]; ++i) {
slouken@1662
   197
       bug ("\t%ld x %ld\n", SDL_modelist[i]->w, SDL_modelist[i]->h);}
slouken@1662
   198
       }
slouken@0
   199
    );
slouken@0
   200
slouken@1662
   201
    D ( {
slouken@1662
   202
       bug ("CGX visuals list: (%ld)\n", this->hidden->nvisuals);
slouken@1662
   203
       for (i = 0; i < this->hidden->nvisuals; i++)
slouken@1662
   204
       bug ("\t%lx - depth: %ld bpp: %ld\n",
slouken@1662
   205
            this->hidden->visuals[i].visual,
slouken@1662
   206
            this->hidden->visuals[i].depth, this->hidden->visuals[i].bpp);}
slouken@0
   207
    );
slouken@0
   208
    return 0;
slouken@0
   209
}
slouken@0
   210
slouken@1662
   211
int
slouken@1662
   212
CGX_SupportedVisual (_THIS, SDL_PixelFormat * format)
slouken@0
   213
{
slouken@0
   214
    int i;
slouken@1662
   215
    for (i = 0; i < this->hidden->nvisuals; i++) {
slouken@1662
   216
        if (this->hidden->visuals[i].depth == format->BitsPerPixel)     // Era bpp
slouken@1662
   217
            return 1;
slouken@1662
   218
    }
slouken@0
   219
    return 0;
slouken@0
   220
}
slouken@0
   221
slouken@1662
   222
SDL_Rect **
slouken@1662
   223
CGX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
slouken@0
   224
{
slouken@1662
   225
    if (CGX_SupportedVisual (this, format)) {
slouken@1662
   226
        if (flags & SDL_FULLSCREEN) {
slouken@1662
   227
            return (SDL_modelist);
slouken@0
   228
        } else {
slouken@1662
   229
            return ((SDL_Rect **) - 1);
slouken@0
   230
        }
slouken@0
   231
    } else {
slouken@1662
   232
        return ((SDL_Rect **) 0);
slouken@0
   233
    }
slouken@0
   234
}
slouken@0
   235
slouken@1662
   236
void
slouken@1662
   237
CGX_FreeVideoModes (_THIS)
slouken@0
   238
{
slouken@0
   239
    int i;
slouken@0
   240
slouken@1662
   241
    if (SDL_modelist) {
slouken@1662
   242
        for (i = 0; SDL_modelist[i]; ++i) {
slouken@1662
   243
            SDL_free (SDL_modelist[i]);
slouken@0
   244
        }
slouken@1662
   245
        SDL_free (SDL_modelist);
slouken@0
   246
        SDL_modelist = NULL;
slouken@0
   247
    }
slouken@0
   248
}
slouken@0
   249
slouken@1662
   250
int
slouken@1662
   251
CGX_ResizeFullScreen (_THIS)
slouken@0
   252
{
slouken@0
   253
    int x, y;
slouken@0
   254
    int real_w, real_h;
slouken@0
   255
slouken@1662
   256
    if (currently_fullscreen) {
slouken@0
   257
/* Per ora non faccio nulla qui */
slouken@0
   258
    }
slouken@1662
   259
    return (1);
slouken@0
   260
}
slouken@0
   261
slouken@1662
   262
void
slouken@1662
   263
_QueueEnterFullScreen (_THIS)
slouken@0
   264
{
slouken@0
   265
}
slouken@0
   266
slouken@1662
   267
int
slouken@1662
   268
CGX_EnterFullScreen (_THIS)
slouken@0
   269
{
slouken@0
   270
    int okay;
slouken@1662
   271
    Uint32 saved_flags;
slouken@0
   272
slouken@0
   273
    okay = 1;
slouken@255
   274
    saved_flags = this->screen->flags;
slouken@255
   275
slouken@1662
   276
    if (!currently_fullscreen) {
slouken@0
   277
        int real_w, real_h;
slouken@0
   278
slouken@0
   279
        /* Map the fullscreen window to blank the screen */
slouken@1662
   280
        get_real_resolution (this, &real_w, &real_h);
slouken@255
   281
slouken@1662
   282
        CGX_DestroyWindow (this, this->screen);
slouken@1662
   283
        set_best_resolution (this, real_w, real_h);
slouken@0
   284
slouken@0
   285
        currently_fullscreen = 1;
slouken@1662
   286
        this->screen->flags = saved_flags;
slouken@0
   287
slouken@1662
   288
        CGX_CreateWindow (this, this->screen, real_w, real_h,
slouken@1662
   289
                          GetCyberMapAttr (SDL_Display->RastPort.BitMap,
slouken@1662
   290
                                           CYBRMATTR_DEPTH),
slouken@1662
   291
                          this->screen->flags);
slouken@0
   292
slouken@0
   293
        /* Set the new resolution */
slouken@1662
   294
        okay = CGX_ResizeFullScreen (this);
slouken@1662
   295
        if (!okay) {
slouken@1662
   296
            CGX_LeaveFullScreen (this);
slouken@0
   297
        }
slouken@1662
   298
        /* Set the colormap */
slouken@0
   299
/*
slouken@0
   300
		if ( SDL_XColorMap ) {
slouken@0
   301
			XInstallColormap(SDL_Display, SDL_XColorMap);
slouken@0
   302
		}
slouken@0
   303
*/
slouken@255
   304
    }
slouken@0
   305
//    CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
slouken@1662
   306
    return (okay);
slouken@0
   307
}
slouken@0
   308
slouken@1662
   309
int
slouken@1662
   310
CGX_LeaveFullScreen (_THIS)
slouken@0
   311
{
slouken@1662
   312
    if (currently_fullscreen) {
slouken@1662
   313
        int width, height;
slouken@1662
   314
        if (SDL_Window) {
slouken@1662
   315
            CloseWindow (SDL_Window);
slouken@1662
   316
            SDL_Window = NULL;
slouken@1662
   317
        }
slouken@1662
   318
        CloseScreen (SDL_Display);
slouken@0
   319
slouken@1662
   320
        GFX_Display = SDL_Display = LockPubScreen (NULL);
slouken@0
   321
slouken@1662
   322
        currently_fullscreen = 0;
slouken@0
   323
slouken@1662
   324
        CGX_CreateWindow (this, this->screen, this->screen->w,
slouken@1662
   325
                          this->screen->h,
slouken@1662
   326
                          GetCyberMapAttr (SDL_Display->RastPort.BitMap,
slouken@1662
   327
                                           CYBRMATTR_DEPTH),
slouken@1662
   328
                          this->screen->flags);
slouken@1662
   329
        CGX_ResizeImage (this, this->screen, 0L);
slouken@0
   330
    }
slouken@0
   331
slouken@1662
   332
    return (0);
slouken@0
   333
}
slouken@1662
   334
slouken@1662
   335
/* vi: set ts=4 sw=4 expandtab: */