src/video/Xext/XME/xme.c
author Ryan C. Gordon
Sun, 29 Oct 2006 02:46:42 +0000
branchSDL-1.2
changeset 3885 a10bddfdc40f
parent 1599 ecba4bbaf9c2
child 4144 904defc0792e
permissions -rw-r--r--
Closing minor memory leak in XME code.
icculus@1242
     1
/*
icculus@1242
     2
 * Copyright 1993-2001 by Xi Graphics, Inc.
icculus@1242
     3
 * All Rights Reserved.
icculus@1242
     4
 *
icculus@1242
     5
 * Please see the LICENSE file accompanying this distribution for licensing 
icculus@1242
     6
 * information. 
icculus@1242
     7
 *
icculus@1242
     8
 * Please send any bug fixes and modifications to src@xig.com.
icculus@1242
     9
 *
icculus@1242
    10
 * $XiGId: xme.c,v 1.2 2001/11/30 21:56:59 jon Exp $
icculus@1242
    11
 *
icculus@1242
    12
 */
icculus@1242
    13
icculus@1242
    14
#define NEED_EVENTS
icculus@1242
    15
#define NEED_REPLIES
icculus@1242
    16
icculus@1599
    17
#include <X11/Xlibint.h>
icculus@1242
    18
#include <X11/Xthreads.h>
icculus@1242
    19
#include <X11/Xmd.h>
icculus@1242
    20
#include <X11/Xproto.h>
icculus@1599
    21
#include "../extensions/Xext.h"
slouken@1361
    22
#include "../extensions/extutil.h"
icculus@1242
    23
icculus@1242
    24
/*****************************************************************************/
icculus@1242
    25
icculus@1242
    26
icculus@1242
    27
#define	XIGMISC_PROTOCOL_NAME 		     "XiG-SUNDRY-NONSTANDARD"
icculus@1242
    28
#define XIGMISC_MAJOR_VERSION	             2
icculus@1242
    29
#define XIGMISC_MINOR_VERSION 	             0
icculus@1242
    30
icculus@1242
    31
#define XiGMiscNumberEvents	             0
icculus@1242
    32
icculus@1242
    33
#define	X_XiGMiscQueryVersion		     0
icculus@1242
    34
#define	X_XiGMiscQueryViews		     1
icculus@1242
    35
#define X_XiGMiscQueryResolutions            2
icculus@1242
    36
#define X_XiGMiscChangeResolution            3
icculus@1242
    37
#define X_XiGMiscFullScreen                  4
icculus@1242
    38
icculus@1242
    39
#define sz_xXiGMiscQueryVersionReq	     8
icculus@1242
    40
#define sz_xXiGMiscQueryViewsReq	     8
icculus@1242
    41
#define sz_xXiGMiscQueryResolutionsReq       8
icculus@1242
    42
#define sz_xXiGMiscChangeResolutionReq       16
icculus@1242
    43
#define sz_xXiGMiscFullScreenReq             16
icculus@1242
    44
icculus@1242
    45
#define sz_xXiGMiscQueryVersionReply	     32
icculus@1242
    46
#define sz_xXiGMiscQueryViewsReply	     32
icculus@1242
    47
#define sz_xXiGMiscQueryResolutionsReply     32
icculus@1242
    48
#define sz_xXiGMiscQueryFullScreenReply      32
icculus@1242
    49
icculus@1242
    50
/*******************************************************************/
icculus@1242
    51
icculus@1242
    52
typedef struct {
icculus@1242
    53
  CARD8         reqType;                /* always codes->major_opcode        */
icculus@1242
    54
  CARD8         xigmiscReqType;         /* always X_XiGMiscQueryVersion      */
icculus@1242
    55
  CARD16        length;
icculus@1242
    56
  CARD16        major;
icculus@1242
    57
  CARD16        minor;
icculus@1242
    58
} xXiGMiscQueryVersionReq;
icculus@1242
    59
icculus@1242
    60
typedef struct {
icculus@1242
    61
  CARD8         reqType;                /* always codes->major_opcode        */
icculus@1242
    62
  CARD8         xigmiscReqType;         /* always X_XiGMiscQueryViews        */
icculus@1242
    63
  CARD16        length;
icculus@1242
    64
  CARD8		screen;
icculus@1242
    65
  CARD8		pad0;
icculus@1242
    66
  CARD16	pad1;
icculus@1242
    67
} xXiGMiscQueryViewsReq;
icculus@1242
    68
icculus@1242
    69
typedef struct {
icculus@1242
    70
  CARD8         reqType;                /* always codes->major_opcode        */
icculus@1242
    71
  CARD8         xigmiscReqType;         /* always X_XiGMiscQueryResolutions  */
icculus@1242
    72
  CARD16        length;
icculus@1242
    73
  CARD8		screen;
icculus@1242
    74
  CARD8		view;
icculus@1242
    75
  CARD16	pad0;
icculus@1242
    76
} xXiGMiscQueryResolutionsReq;
icculus@1242
    77
icculus@1242
    78
typedef struct {
icculus@1242
    79
  CARD8         reqType;                /* always codes->major_opcode        */
icculus@1242
    80
  CARD8         xigmiscReqType;         /* always X_XiGMiscChangeResolution  */
icculus@1242
    81
  CARD16        length;
icculus@1242
    82
  CARD8		screen;
icculus@1242
    83
  CARD8		view;
icculus@1242
    84
  CARD16	pad0;
icculus@1242
    85
  CARD16        width;
icculus@1242
    86
  CARD16        height;
icculus@1242
    87
  INT32         refresh;
icculus@1242
    88
} xXiGMiscChangeResolutionReq;
icculus@1242
    89
icculus@1242
    90
typedef struct {
icculus@1242
    91
  CARD8         reqType;                /* always codes->major_opcode        */
icculus@1242
    92
  CARD8         xigmiscReqType;         /* always X_XiGMiscFullScreen        */
icculus@1242
    93
  CARD16        length;
icculus@1242
    94
  CARD8		screen;
icculus@1242
    95
  CARD8		pad0;
icculus@1242
    96
  CARD16	pad1;
icculus@1242
    97
  CARD32	window;
icculus@1242
    98
  CARD32	cmap;
icculus@1242
    99
} xXiGMiscFullScreenReq;
icculus@1242
   100
icculus@1242
   101
/*******************************************************************/
icculus@1242
   102
icculus@1242
   103
typedef struct {        
icculus@1242
   104
  BYTE          type;                   /* X_Reply                           */
icculus@1242
   105
  CARD8         pad0;
icculus@1242
   106
  CARD16        sequenceNumber;
icculus@1242
   107
  CARD32        length;
icculus@1242
   108
  CARD16        major;
icculus@1242
   109
  CARD16        minor;
icculus@1242
   110
  CARD32        pad1;
icculus@1242
   111
  CARD32        pad2;
icculus@1242
   112
  CARD32        pad3;
icculus@1242
   113
  CARD32        pad4;
icculus@1242
   114
  CARD32        pad5;
icculus@1242
   115
} xXiGMiscQueryVersionReply;
icculus@1242
   116
icculus@1242
   117
typedef struct {        
icculus@1242
   118
  BYTE          type;                   /* X_Reply                           */
icculus@1242
   119
  CARD8         pad0;
icculus@1242
   120
  CARD16        sequenceNumber;
icculus@1242
   121
  CARD32        length;
icculus@1242
   122
  CARD32        nviews;
icculus@1242
   123
  CARD32        pad1;
icculus@1242
   124
  CARD32        pad2;
icculus@1242
   125
  CARD32        pad3;
icculus@1242
   126
  CARD32        pad4;
icculus@1242
   127
  CARD32        pad5;
icculus@1242
   128
} xXiGMiscQueryViewsReply;
icculus@1242
   129
icculus@1242
   130
typedef struct {        
icculus@1242
   131
  BYTE          type;                   /* X_Reply                           */
icculus@1242
   132
  CARD8         pad0;
icculus@1242
   133
  CARD16        sequenceNumber;
icculus@1242
   134
  CARD32        length;
icculus@1242
   135
  CARD16        active;
icculus@1242
   136
  CARD16        nresolutions;
icculus@1242
   137
  CARD32        pad1;
icculus@1242
   138
  CARD32        pad2;
icculus@1242
   139
  CARD32        pad3;
icculus@1242
   140
  CARD32        pad4;
icculus@1242
   141
  CARD32        pad5;
icculus@1242
   142
} xXiGMiscQueryResolutionsReply;
icculus@1242
   143
icculus@1242
   144
typedef struct {        
icculus@1242
   145
  BYTE          type;                   /* X_Reply                           */
icculus@1242
   146
  BOOL          success;
icculus@1242
   147
  CARD16        sequenceNumber;
icculus@1242
   148
  CARD32        length;
icculus@1242
   149
  CARD32        pad1;
icculus@1242
   150
  CARD32        pad2;
icculus@1242
   151
  CARD32        pad3;
icculus@1242
   152
  CARD32        pad4;
icculus@1242
   153
  CARD32        pad5;
icculus@1242
   154
  CARD32        pad6;
icculus@1242
   155
} xXiGMiscFullScreenReply;
icculus@1242
   156
icculus@1242
   157
/*******************************************************************/
icculus@1242
   158
icculus@1242
   159
typedef struct {        
icculus@1242
   160
  INT16		x;
icculus@1242
   161
  INT16		y;
icculus@1242
   162
  CARD16	w;
icculus@1242
   163
  CARD16	h;
icculus@1242
   164
} XiGMiscViewInfo;
icculus@1242
   165
icculus@1242
   166
typedef struct {        
icculus@1242
   167
  CARD16        width;
icculus@1242
   168
  CARD16        height;
icculus@1242
   169
  INT32         refresh;
icculus@1242
   170
} XiGMiscResolutionInfo;
icculus@1242
   171
icculus@1242
   172
/*****************************************************************************/
icculus@1242
   173
icculus@1242
   174
static XExtensionInfo *xigmisc_info = NULL;
icculus@1242
   175
static char *xigmisc_extension_name = XIGMISC_PROTOCOL_NAME;
icculus@1242
   176
icculus@1242
   177
#define XiGMiscCheckExtension(dpy,i,val) \
icculus@1242
   178
  XextCheckExtension (dpy, i, xigmisc_extension_name, val)
icculus@1242
   179
#define XiGMiscSimpleCheckExtension(dpy,i) \
icculus@1242
   180
  XextSimpleCheckExtension (dpy, i, xigmisc_extension_name)
icculus@1242
   181
icculus@1242
   182
#if defined(__STDC__) && !defined(UNIXCPP)
icculus@1242
   183
#define XiGMiscGetReq(name,req,info) GetReq (name, req); \
icculus@1242
   184
        req->reqType = info->codes->major_opcode; \
icculus@1242
   185
        req->xigmiscReqType = X_##name;
icculus@1242
   186
icculus@1242
   187
#define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
icculus@1242
   188
        req->reqType = info->codes->major_opcode; \
icculus@1242
   189
        req->xigmicReqType = X_##name;
icculus@1242
   190
#else
icculus@1242
   191
#define XiGMiscGetReq(name,req,info) GetReq (name, req); \
icculus@1242
   192
        req->reqType = info->codes->major_opcode; \
icculus@1242
   193
        req->xigmiscReqType = X_/**/name;
icculus@1242
   194
#define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
icculus@1242
   195
        req->reqType = info->codes->major_opcode; \
icculus@1242
   196
        req->xigmiscReqType = X_/**/name;
icculus@1242
   197
#endif
icculus@1242
   198
icculus@1242
   199
icculus@1242
   200
icculus@1242
   201
/*
icculus@1242
   202
 * find_display - locate the display info block
icculus@1242
   203
 */
icculus@1242
   204
static int XiGMiscCloseDisplay();
icculus@1242
   205
icculus@1242
   206
static XExtensionHooks xigmisc_extension_hooks = {
icculus@1242
   207
    NULL,                               /* create_gc */
icculus@1242
   208
    NULL,                               /* copy_gc */
icculus@1242
   209
    NULL,                               /* flush_gc */
icculus@1242
   210
    NULL,                               /* free_gc */
icculus@1242
   211
    NULL,                               /* create_font */
icculus@1242
   212
    NULL,                               /* free_font */
icculus@1242
   213
    XiGMiscCloseDisplay,                /* close_display */
icculus@1242
   214
    NULL,                               /* wire_to_event */
icculus@1242
   215
    NULL,                               /* event_to_wire */
icculus@1242
   216
    NULL,                               /* error */
icculus@1242
   217
    NULL,                               /* error_string */
icculus@1242
   218
};
icculus@1242
   219
icculus@1242
   220
icculus@1242
   221
static XEXT_GENERATE_CLOSE_DISPLAY (XiGMiscCloseDisplay, xigmisc_info)
icculus@1242
   222
icculus@1242
   223
static XEXT_GENERATE_FIND_DISPLAY (XiGMiscFindDisplay, xigmisc_info,
icculus@1242
   224
				   xigmisc_extension_name, 
icculus@1242
   225
				   &xigmisc_extension_hooks, XiGMiscNumberEvents, NULL)
icculus@1242
   226
icculus@1242
   227
icculus@1242
   228
/*****************************************************************************/
icculus@1242
   229
icculus@1242
   230
Bool XiGMiscQueryVersion(Display *dpy, int *major, int *minor)
icculus@1242
   231
{
icculus@1242
   232
  int opcode, event, error;
icculus@1242
   233
  xXiGMiscQueryVersionReq *req;
icculus@1242
   234
  xXiGMiscQueryVersionReply rep;
icculus@1242
   235
  XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
icculus@1242
   236
icculus@1575
   237
  if (!XQueryExtension(dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error))
icculus@1242
   238
    return xFalse;
icculus@1242
   239
icculus@1242
   240
  XiGMiscCheckExtension(dpy, info, xFalse);
icculus@1242
   241
icculus@1242
   242
  LockDisplay (dpy);
icculus@1242
   243
  XiGMiscGetReq (XiGMiscQueryVersion, req, info);
icculus@1242
   244
icculus@1242
   245
  req->major = XIGMISC_MAJOR_VERSION;
icculus@1242
   246
  req->minor = XIGMISC_MINOR_VERSION;
icculus@1242
   247
icculus@1575
   248
  if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
icculus@1242
   249
    UnlockDisplay(dpy);
icculus@1242
   250
    SyncHandle();
icculus@1242
   251
    return xFalse;
icculus@1242
   252
  }
icculus@1242
   253
icculus@1242
   254
  *major = rep.major;
icculus@1242
   255
  *minor = rep.minor;
icculus@1242
   256
  UnlockDisplay(dpy);
icculus@1242
   257
  SyncHandle();
icculus@1242
   258
icculus@1242
   259
  return xTrue;
icculus@1242
   260
}
icculus@1242
   261
icculus@1242
   262
int XiGMiscQueryViews(Display *dpy, int screen, XiGMiscViewInfo **pviews)
icculus@1242
   263
{
icculus@1242
   264
  int n, size;
icculus@1242
   265
  XiGMiscViewInfo *views;
icculus@1242
   266
  xXiGMiscQueryViewsReq *req;
icculus@1242
   267
  xXiGMiscQueryViewsReply rep;
icculus@1242
   268
  XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
icculus@1242
   269
  XiGMiscCheckExtension(dpy, info, 0);
icculus@1242
   270
icculus@1242
   271
  LockDisplay (dpy);
icculus@1242
   272
  XiGMiscGetReq (XiGMiscQueryViews, req, info);
icculus@1242
   273
  req->screen = screen;
icculus@1242
   274
icculus@1575
   275
  if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
icculus@1242
   276
    UnlockDisplay(dpy);
icculus@1242
   277
    SyncHandle();
icculus@1242
   278
    return 0;
icculus@1242
   279
  }
icculus@1242
   280
icculus@1242
   281
  n = rep.nviews;
icculus@1242
   282
icculus@1242
   283
  if (n > 0) {
icculus@1242
   284
    size = sizeof(XiGMiscViewInfo) * n;
icculus@1242
   285
    views = (XiGMiscViewInfo*)Xmalloc(size);
icculus@1242
   286
    if (!views) {
icculus@1575
   287
      _XEatData(dpy, (unsigned long)size);
icculus@1242
   288
      UnlockDisplay(dpy);
icculus@1242
   289
      SyncHandle();
icculus@1242
   290
      return 0;
icculus@1242
   291
    }
icculus@1242
   292
icculus@1575
   293
    _XReadPad(dpy, (void*)views, size);
icculus@1242
   294
icculus@1242
   295
    *pviews = views;
icculus@1242
   296
  }
icculus@1242
   297
icculus@1242
   298
  UnlockDisplay(dpy);
icculus@1242
   299
  SyncHandle();
icculus@1242
   300
icculus@1242
   301
  return n;
icculus@1242
   302
}
icculus@1242
   303
icculus@1242
   304
int XiGMiscQueryResolutions(Display *dpy, int screen, int view, int *pactive, XiGMiscResolutionInfo **presolutions)
icculus@1242
   305
{
icculus@1242
   306
  int n, size;
icculus@1242
   307
  XiGMiscResolutionInfo *resolutions;
icculus@1242
   308
  xXiGMiscQueryResolutionsReq *req;
icculus@1242
   309
  xXiGMiscQueryResolutionsReply rep;
icculus@1242
   310
  XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
icculus@1242
   311
  XiGMiscCheckExtension(dpy, info, 0);
icculus@1242
   312
icculus@1242
   313
  LockDisplay (dpy);
icculus@1242
   314
  XiGMiscGetReq (XiGMiscQueryResolutions, req, info);
icculus@1242
   315
  req->screen = screen;
icculus@1242
   316
  req->view   = view;
icculus@1242
   317
icculus@1575
   318
  if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
icculus@1242
   319
    UnlockDisplay(dpy);
icculus@1242
   320
    SyncHandle();
icculus@1242
   321
    return 0;
icculus@1242
   322
  }
icculus@1242
   323
icculus@1242
   324
  n = rep.nresolutions;
icculus@1242
   325
icculus@1242
   326
  if (n > 0) {
icculus@1242
   327
    size = sizeof(XiGMiscResolutionInfo) * n;
icculus@1242
   328
    resolutions = (XiGMiscResolutionInfo*)Xmalloc(size);
icculus@1242
   329
    if (!resolutions) {
icculus@1575
   330
      _XEatData(dpy, (unsigned long)size);
icculus@1242
   331
      UnlockDisplay(dpy);
icculus@1242
   332
      SyncHandle();
icculus@1242
   333
      return 0;
icculus@1242
   334
    }
icculus@1242
   335
icculus@1575
   336
    _XReadPad(dpy, (void*)resolutions, size);
icculus@1242
   337
icculus@1242
   338
    *presolutions = resolutions;
icculus@1242
   339
    *pactive = rep.active;
icculus@1242
   340
  }
icculus@1242
   341
icculus@1242
   342
  UnlockDisplay(dpy);
icculus@1242
   343
  SyncHandle();
icculus@1242
   344
icculus@1242
   345
  return n;
icculus@1242
   346
}
icculus@1242
   347
icculus@1242
   348
void XiGMiscChangeResolution(Display *dpy, int screen, int view, int width, int height, int refresh)
icculus@1242
   349
{
icculus@1242
   350
  xXiGMiscChangeResolutionReq *req;
icculus@1242
   351
  XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
icculus@1242
   352
icculus@1242
   353
  XiGMiscSimpleCheckExtension(dpy, info);
icculus@1242
   354
icculus@1242
   355
  LockDisplay (dpy);
icculus@1242
   356
  XiGMiscGetReq (XiGMiscChangeResolution, req, info);
icculus@1242
   357
  req->screen = screen;
icculus@1242
   358
  req->view = view;
icculus@1242
   359
  req->width = width;
icculus@1242
   360
  req->height = height;
icculus@1242
   361
  req->refresh = refresh;
icculus@1242
   362
icculus@1242
   363
  UnlockDisplay(dpy);
icculus@1242
   364
  SyncHandle();
icculus@1242
   365
}
icculus@1242
   366
icculus@1242
   367
icculus@1242
   368
Bool XiGMiscFullScreen(Display *dpy, int screen, XID window, XID cmap)
icculus@1242
   369
{
icculus@1242
   370
  xXiGMiscFullScreenReq *req;
icculus@1242
   371
  xXiGMiscFullScreenReply rep;
icculus@1242
   372
  XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
icculus@1242
   373
icculus@1242
   374
  XiGMiscCheckExtension(dpy, info, xFalse);
icculus@1242
   375
icculus@1242
   376
  LockDisplay (dpy);
icculus@1242
   377
  XiGMiscGetReq (XiGMiscFullScreen, req, info);
icculus@1242
   378
  req->screen = screen;
icculus@1242
   379
  req->pad0 = 0;
icculus@1242
   380
  req->pad1 = 0;
icculus@1242
   381
  req->window = window;
icculus@1242
   382
  req->cmap = cmap;
icculus@1242
   383
icculus@1575
   384
  if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
icculus@1242
   385
    UnlockDisplay(dpy);
icculus@1242
   386
    SyncHandle();
icculus@1242
   387
    return xFalse;
icculus@1242
   388
  }
icculus@1242
   389
icculus@1242
   390
  UnlockDisplay(dpy);
icculus@1242
   391
  SyncHandle();
icculus@1242
   392
icculus@1242
   393
  return (rep.success ? xTrue : xFalse);
icculus@1242
   394
}
icculus@1242
   395
icculus@3885
   396
icculus@3885
   397
/* SDL addition from Ryan: free memory used by xme. */
icculus@3885
   398
void XiGMiscDestroy(void)
icculus@3885
   399
{
icculus@3885
   400
    if (xigmisc_info) {
icculus@3885
   401
        XextDestroyExtension(xigmisc_info);
icculus@3885
   402
        xigmisc_info = NULL;
icculus@3885
   403
    }
icculus@3885
   404
}
icculus@3885
   405