Skip to content

Latest commit

 

History

History
1323 lines (1193 loc) · 34.1 KB

SDL_dibvideo.c

File metadata and controls

1323 lines (1193 loc) · 34.1 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library 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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
Feb 25, 2006
Feb 25, 2006
24
25
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Sep 29, 2005
Sep 29, 2005
26
Apr 26, 2001
Apr 26, 2001
27
28
29
30
31
/* Not yet in the mingw32 cross-compile headers */
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#endif
Feb 7, 2006
Feb 7, 2006
32
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
33
34
35
36
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
Feb 16, 2009
Feb 16, 2009
37
#include "SDL_gapidibvideo.h"
Apr 26, 2001
Apr 26, 2001
38
#include "SDL_dibvideo.h"
Feb 16, 2006
Feb 16, 2006
39
40
#include "../wincommon/SDL_syswm_c.h"
#include "../wincommon/SDL_sysmouse_c.h"
Apr 26, 2001
Apr 26, 2001
41
#include "SDL_dibevents_c.h"
Feb 16, 2006
Feb 16, 2006
42
#include "../wincommon/SDL_wingl_c.h"
Apr 26, 2001
Apr 26, 2001
43
44
#ifdef _WIN32_WCE
Jan 3, 2008
Jan 3, 2008
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef DM_DISPLAYORIENTATION
#define DM_DISPLAYORIENTATION 0x00800000L
#endif
#ifndef DM_DISPLAYQUERYORIENTATION
#define DM_DISPLAYQUERYORIENTATION 0x01000000L
#endif
#ifndef DMDO_0
#define DMDO_0 0
#endif
#ifndef DMDO_90
#define DMDO_90 1
#endif
#ifndef DMDO_180
#define DMDO_180 2
#endif
#ifndef DMDO_270
#define DMDO_270 4
#endif
Apr 26, 2001
Apr 26, 2001
65
66
#define NO_GETDIBITS
#define NO_GAMMA_SUPPORT
Mar 4, 2006
Mar 4, 2006
67
68
69
70
71
#if _WIN32_WCE < 420
#define NO_CHANGEDISPLAYSETTINGS
#else
#define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0)
#endif
Apr 26, 2001
Apr 26, 2001
72
#endif
Aug 20, 2002
Aug 20, 2002
73
#ifndef WS_MAXIMIZE
Jan 4, 2004
Jan 4, 2004
74
75
76
77
#define WS_MAXIMIZE 0
#endif
#ifndef WS_THICKFRAME
#define WS_THICKFRAME 0
Aug 20, 2002
Aug 20, 2002
78
79
80
81
82
83
84
#endif
#ifndef SWP_NOCOPYBITS
#define SWP_NOCOPYBITS 0
#endif
#ifndef PC_NOCOLLAPSE
#define PC_NOCOLLAPSE 0
#endif
Apr 26, 2001
Apr 26, 2001
85
Mar 4, 2006
Mar 4, 2006
86
87
88
89
90
#ifdef _WIN32_WCE
// defined and used in SDL_sysevents.c
extern HINSTANCE aygshell;
#endif
Apr 26, 2001
Apr 26, 2001
91
92
93
94
95
96
97
/* Initialization/Query functions */
static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int DIB_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors);
static void DIB_CheckGamma(_THIS);
Apr 11, 2002
Apr 11, 2002
98
99
100
101
void DIB_SwapGamma(_THIS);
void DIB_QuitGamma(_THIS);
int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
Apr 26, 2001
Apr 26, 2001
102
103
104
105
106
107
108
109
110
static void DIB_VideoQuit(_THIS);
/* Hardware surface functions */
static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface);
static int DIB_LockHWSurface(_THIS, SDL_Surface *surface);
static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface);
/* Windows message handling functions */
Jul 3, 2007
Jul 3, 2007
111
112
113
static void DIB_GrabStaticColors(HWND window);
static void DIB_ReleaseStaticColors(HWND window);
static void DIB_Activate(_THIS, BOOL active, BOOL minimized);
Apr 26, 2001
Apr 26, 2001
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
static void DIB_RealizePalette(_THIS);
static void DIB_PaletteChanged(_THIS, HWND window);
static void DIB_WinPAINT(_THIS, HDC hdc);
/* helper fn */
static int DIB_SussScreenDepth();
/* DIB driver bootstrap functions */
static int DIB_Available(void)
{
return(1);
}
static void DIB_DeleteDevice(SDL_VideoDevice *device)
{
if ( device ) {
if ( device->hidden ) {
Feb 16, 2009
Feb 16, 2009
132
133
134
if ( device->hidden->dibInfo ) {
SDL_free( device->hidden->dibInfo );
}
Feb 7, 2006
Feb 7, 2006
135
SDL_free(device->hidden);
Apr 26, 2001
Apr 26, 2001
136
137
}
if ( device->gl_data ) {
Feb 7, 2006
Feb 7, 2006
138
SDL_free(device->gl_data);
Apr 26, 2001
Apr 26, 2001
139
}
Feb 7, 2006
Feb 7, 2006
140
SDL_free(device);
Apr 26, 2001
Apr 26, 2001
141
142
143
144
145
146
147
148
}
}
static SDL_VideoDevice *DIB_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
149
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
Apr 26, 2001
Apr 26, 2001
150
if ( device ) {
Feb 7, 2006
Feb 7, 2006
151
SDL_memset(device, 0, (sizeof *device));
Apr 26, 2001
Apr 26, 2001
152
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
153
SDL_malloc((sizeof *device->hidden));
Feb 16, 2009
Feb 16, 2009
154
155
156
157
158
159
160
161
162
163
if(device->hidden){
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
device->hidden->dibInfo = (DibInfo *)SDL_malloc((sizeof(DibInfo)));
if(device->hidden->dibInfo == NULL)
{
SDL_free(device->hidden);
device->hidden = NULL;
}
}
Apr 26, 2001
Apr 26, 2001
164
device->gl_data = (struct SDL_PrivateGLData *)
Feb 7, 2006
Feb 7, 2006
165
SDL_malloc((sizeof *device->gl_data));
Apr 26, 2001
Apr 26, 2001
166
167
168
169
170
171
172
}
if ( (device == NULL) || (device->hidden == NULL) ||
(device->gl_data == NULL) ) {
SDL_OutOfMemory();
DIB_DeleteDevice(device);
return(NULL);
}
Feb 16, 2009
Feb 16, 2009
173
SDL_memset(device->hidden->dibInfo, 0, (sizeof *device->hidden->dibInfo));
Feb 7, 2006
Feb 7, 2006
174
SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
Apr 26, 2001
Apr 26, 2001
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* Set the function pointers */
device->VideoInit = DIB_VideoInit;
device->ListModes = DIB_ListModes;
device->SetVideoMode = DIB_SetVideoMode;
device->UpdateMouse = WIN_UpdateMouse;
device->SetColors = DIB_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = DIB_VideoQuit;
device->AllocHWSurface = DIB_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = DIB_LockHWSurface;
device->UnlockHWSurface = DIB_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = DIB_FreeHWSurface;
device->SetGammaRamp = DIB_SetGammaRamp;
device->GetGammaRamp = DIB_GetGammaRamp;
Feb 16, 2006
Feb 16, 2006
195
#if SDL_VIDEO_OPENGL
Aug 20, 2002
Aug 20, 2002
196
197
198
199
200
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress;
device->GL_GetAttribute = WIN_GL_GetAttribute;
device->GL_MakeCurrent = WIN_GL_MakeCurrent;
device->GL_SwapBuffers = WIN_GL_SwapBuffers;
Apr 26, 2001
Apr 26, 2001
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#endif
device->SetCaption = WIN_SetWMCaption;
device->SetIcon = WIN_SetWMIcon;
device->IconifyWindow = WIN_IconifyWindow;
device->GrabInput = WIN_GrabInput;
device->GetWMInfo = WIN_GetWMInfo;
device->FreeWMCursor = WIN_FreeWMCursor;
device->CreateWMCursor = WIN_CreateWMCursor;
device->ShowWMCursor = WIN_ShowWMCursor;
device->WarpWMCursor = WIN_WarpWMCursor;
device->CheckMouseMode = WIN_CheckMouseMode;
device->InitOSKeymap = DIB_InitOSKeymap;
device->PumpEvents = DIB_PumpEvents;
/* Set up the windows message handling functions */
Jul 3, 2007
Jul 3, 2007
216
WIN_Activate = DIB_Activate;
Apr 26, 2001
Apr 26, 2001
217
218
219
220
221
222
223
224
225
226
227
228
WIN_RealizePalette = DIB_RealizePalette;
WIN_PaletteChanged = DIB_PaletteChanged;
WIN_WinPAINT = DIB_WinPAINT;
HandleMessage = DIB_HandleMessage;
device->free = DIB_DeleteDevice;
/* We're finally ready */
return device;
}
VideoBootStrap WINDIB_bootstrap = {
Sep 29, 2005
Sep 29, 2005
229
"windib", "Win95/98/NT/2000/CE GDI",
Apr 26, 2001
Apr 26, 2001
230
231
232
233
234
235
236
DIB_Available, DIB_CreateDevice
};
static int cmpmodes(const void *va, const void *vb)
{
SDL_Rect *a = *(SDL_Rect **)va;
SDL_Rect *b = *(SDL_Rect **)vb;
Nov 12, 2004
Nov 12, 2004
237
238
239
240
if ( a->w == b->w )
return b->h - a->h;
else
return b->w - a->w;
Apr 26, 2001
Apr 26, 2001
241
242
243
244
245
246
247
248
249
}
static int DIB_AddMode(_THIS, int bpp, int w, int h)
{
SDL_Rect *mode;
int i, index;
int next_mode;
/* Check to see if we already have this mode */
Dec 27, 2007
Dec 27, 2007
250
if ( bpp < 8 || bpp > 32 ) { /* Not supported */
Apr 26, 2001
Apr 26, 2001
251
252
253
254
255
256
257
258
259
260
261
return(0);
}
index = ((bpp+7)/8)-1;
for ( i=0; i<SDL_nummodes[index]; ++i ) {
mode = SDL_modelist[index][i];
if ( (mode->w == w) && (mode->h == h) ) {
return(0);
}
}
/* Set up the new video mode rectangle */
Feb 7, 2006
Feb 7, 2006
262
mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
Apr 26, 2001
Apr 26, 2001
263
264
265
266
267
268
269
270
271
272
273
274
if ( mode == NULL ) {
SDL_OutOfMemory();
return(-1);
}
mode->x = 0;
mode->y = 0;
mode->w = w;
mode->h = h;
/* Allocate the new list of modes, and fill in the new mode */
next_mode = SDL_nummodes[index];
SDL_modelist[index] = (SDL_Rect **)
Feb 7, 2006
Feb 7, 2006
275
SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
Apr 26, 2001
Apr 26, 2001
276
277
278
if ( SDL_modelist[index] == NULL ) {
SDL_OutOfMemory();
SDL_nummodes[index] = 0;
Feb 7, 2006
Feb 7, 2006
279
SDL_free(mode);
Apr 26, 2001
Apr 26, 2001
280
281
282
283
284
285
286
287
288
return(-1);
}
SDL_modelist[index][next_mode] = mode;
SDL_modelist[index][next_mode+1] = NULL;
SDL_nummodes[index]++;
return(0);
}
Jul 3, 2007
Jul 3, 2007
289
static void DIB_CreatePalette(_THIS, int bpp)
Apr 26, 2001
Apr 26, 2001
290
291
292
293
{
/* RJR: March 28, 2000
moved palette creation here from "DIB_VideoInit" */
Jul 3, 2007
Jul 3, 2007
294
295
296
LOGPALETTE *palette;
HDC hdc;
int ncolors;
Apr 26, 2001
Apr 26, 2001
297
Jul 3, 2007
Jul 3, 2007
298
299
300
301
302
303
304
305
306
307
ncolors = (1 << bpp);
palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+
ncolors*sizeof(PALETTEENTRY));
palette->palVersion = 0x300;
palette->palNumEntries = ncolors;
hdc = GetDC(SDL_Window);
GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry);
ReleaseDC(SDL_Window, hdc);
screen_pal = CreatePalette(palette);
screen_logpal = palette;
Apr 26, 2001
Apr 26, 2001
308
309
310
311
}
int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Jun 26, 2007
Jun 26, 2007
312
const char *env = NULL;
Apr 26, 2001
Apr 26, 2001
313
314
315
316
317
318
319
320
321
#ifndef NO_CHANGEDISPLAYSETTINGS
int i;
DEVMODE settings;
#endif
/* Create the window */
if ( DIB_CreateWindow(this) < 0 ) {
return(-1);
}
Mar 14, 2006
Mar 14, 2006
322
Feb 16, 2006
Feb 16, 2006
323
#if !SDL_AUDIO_DISABLED
Apr 26, 2001
Apr 26, 2001
324
DX5_SoundFocus(SDL_Window);
Sep 4, 2001
Sep 4, 2001
325
#endif
Apr 26, 2001
Apr 26, 2001
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/* Determine the screen depth */
vformat->BitsPerPixel = DIB_SussScreenDepth();
switch (vformat->BitsPerPixel) {
case 15:
vformat->Rmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Bmask = 0x0000001f;
vformat->BitsPerPixel = 16;
break;
case 16:
vformat->Rmask = 0x0000f800;
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
break;
case 24:
case 32:
/* GDI defined as 8-8-8 */
vformat->Rmask = 0x00ff0000;
vformat->Gmask = 0x0000ff00;
vformat->Bmask = 0x000000ff;
break;
default:
break;
}
/* See if gamma is supported on this screen */
DIB_CheckGamma(this);
#ifndef NO_CHANGEDISPLAYSETTINGS
Mar 4, 2006
Mar 4, 2006
356
357
358
359
360
361
362
settings.dmSize = sizeof(DEVMODE);
settings.dmDriverExtra = 0;
#ifdef _WIN32_WCE
settings.dmFields = DM_DISPLAYQUERYORIENTATION;
this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL;
#endif
Jan 30, 2006
Jan 30, 2006
363
/* Query for the desktop resolution */
Feb 16, 2009
Feb 16, 2009
364
365
SDL_desktop_mode.dmSize = sizeof(SDL_desktop_mode);
SDL_desktop_mode.dmDriverExtra = 0;
Jan 30, 2006
Jan 30, 2006
366
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
Mar 15, 2006
Mar 15, 2006
367
368
this->info.current_w = SDL_desktop_mode.dmPelsWidth;
this->info.current_h = SDL_desktop_mode.dmPelsHeight;
Jan 30, 2006
Jan 30, 2006
369
Apr 26, 2001
Apr 26, 2001
370
371
372
373
/* Query for the list of available video modes */
for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) {
DIB_AddMode(this, settings.dmBitsPerPel,
settings.dmPelsWidth, settings.dmPelsHeight);
Mar 4, 2006
Mar 4, 2006
374
375
376
377
378
#ifdef _WIN32_WCE
if( this->hidden->supportRotation )
DIB_AddMode(this, settings.dmBitsPerPel,
settings.dmPelsHeight, settings.dmPelsWidth);
#endif
Apr 26, 2001
Apr 26, 2001
379
380
381
382
}
/* Sort the mode lists */
for ( i=0; i<NUM_MODELISTS; ++i ) {
if ( SDL_nummodes[i] > 0 ) {
Feb 7, 2006
Feb 7, 2006
383
SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
Apr 26, 2001
Apr 26, 2001
384
385
}
}
Mar 4, 2006
Mar 4, 2006
386
387
388
389
390
391
392
#else
// WinCE and fullscreen mode:
// We use only vformat->BitsPerPixel that allow SDL to
// emulate other bpp (8, 32) and use triple buffer,
// because SDL surface conversion is much faster than the WinCE one.
// Although it should be tested on devices with graphics accelerator.
May 7, 2006
May 7, 2006
393
DIB_AddMode(this, vformat->BitsPerPixel,
Mar 4, 2006
Mar 4, 2006
394
395
396
GetDeviceCaps(GetDC(NULL), HORZRES),
GetDeviceCaps(GetDC(NULL), VERTRES));
Apr 26, 2001
Apr 26, 2001
397
398
399
400
401
402
#endif /* !NO_CHANGEDISPLAYSETTINGS */
/* Grab an identity palette if we are in a palettized mode */
if ( vformat->BitsPerPixel <= 8 ) {
/* RJR: March 28, 2000
moved palette creation to "DIB_CreatePalette" */
Jul 3, 2007
Jul 3, 2007
403
DIB_CreatePalette(this, vformat->BitsPerPixel);
Apr 26, 2001
Apr 26, 2001
404
405
406
407
408
}
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
Mar 4, 2006
Mar 4, 2006
409
410
411
412
#ifdef _WIN32_WCE
this->hidden->origRotation = -1;
#endif
Jun 26, 2007
Jun 26, 2007
413
414
/* Allow environment override of screensaver disable. */
env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
Feb 29, 2008
Feb 29, 2008
415
416
417
418
419
420
421
422
423
if ( env ) {
allow_screensaver = SDL_atoi(env);
} else {
#ifdef SDL_VIDEO_DISABLE_SCREENSAVER
allow_screensaver = 0;
#else
allow_screensaver = 1;
#endif
}
Jun 26, 2007
Jun 26, 2007
424
Apr 26, 2001
Apr 26, 2001
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/* We're done! */
return(0);
}
/* We support any format at any dimension */
SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
} else {
return((SDL_Rect **)-1);
}
}
/*
Helper fn to work out which screen depth windows is currently using.
15 bit mode is considered 555 format, 16 bit is 565.
returns 0 for unknown mode.
(Derived from code in sept 1999 Windows Developer Journal
http://www.wdj.com/code/archive.html)
*/
static int DIB_SussScreenDepth()
{
#ifdef NO_GETDIBITS
int depth;
HDC hdc;
hdc = GetDC(SDL_Window);
depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
ReleaseDC(SDL_Window, hdc);
return(depth);
#else
Jun 24, 2006
Jun 24, 2006
458
int depth;
Apr 26, 2001
Apr 26, 2001
459
460
461
462
463
464
465
466
467
int dib_size;
LPBITMAPINFOHEADER dib_hdr;
HDC hdc;
HBITMAP hbm;
/* Allocate enough space for a DIB header plus palette (for
* 8-bit modes) or bitfields (for 16- and 32-bit modes)
*/
dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
Feb 7, 2006
Feb 7, 2006
468
469
dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size);
SDL_memset(dib_hdr, 0, dib_size);
Apr 26, 2001
Apr 26, 2001
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
dib_hdr->biSize = sizeof(BITMAPINFOHEADER);
/* Get a device-dependent bitmap that's compatible with the
screen.
*/
hdc = GetDC(NULL);
hbm = CreateCompatibleBitmap( hdc, 1, 1 );
/* Convert the DDB to a DIB. We need to call GetDIBits twice:
* the first call just fills in the BITMAPINFOHEADER; the
* second fills in the bitfields or palette.
*/
GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS);
GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS);
DeleteObject(hbm);
ReleaseDC(NULL, hdc);
Jun 24, 2006
Jun 24, 2006
487
depth = 0;
Apr 26, 2001
Apr 26, 2001
488
489
switch( dib_hdr->biBitCount )
{
Jun 24, 2006
Jun 24, 2006
490
491
492
case 8: depth = 8; break;
case 24: depth = 24; break;
case 32: depth = 32; break;
Apr 26, 2001
Apr 26, 2001
493
494
495
496
case 16:
if( dib_hdr->biCompression == BI_BITFIELDS ) {
/* check the red mask */
switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) {
Jun 24, 2006
Jun 24, 2006
497
498
case 0xf800: depth = 16; break; /* 565 */
case 0x7c00: depth = 15; break; /* 555 */
Apr 26, 2001
Apr 26, 2001
499
500
501
}
}
}
Jun 24, 2006
Jun 24, 2006
502
503
SDL_free(dib_hdr);
return depth;
Apr 26, 2001
Apr 26, 2001
504
505
506
507
508
509
510
511
512
513
514
#endif /* NO_GETDIBITS */
}
/* Various screen update functions available */
static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
SDL_Surface *video;
Jul 20, 2007
Jul 20, 2007
515
int prev_w, prev_h;
Apr 26, 2001
Apr 26, 2001
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
Uint32 prev_flags;
DWORD style;
const DWORD directstyle =
(WS_POPUP);
const DWORD windowstyle =
(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
const DWORD resizestyle =
(WS_THICKFRAME|WS_MAXIMIZEBOX);
int binfo_size;
BITMAPINFO *binfo;
HDC hdc;
RECT bounds;
int x, y;
Uint32 Rmask, Gmask, Bmask;
Mar 12, 2008
Mar 12, 2008
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
* Special case for OpenGL windows...since the app needs to call
* SDL_SetVideoMode() in response to resize events to continue to
* function, but WGL handles the GL context details behind the scenes,
* there's no sense in tearing the context down just to rebuild it
* to what it already was...tearing it down sacrifices your GL state
* and uploaded textures. So if we're requesting the same video mode
* attributes and the width/height matches the physical window, just
* return immediately.
*/
if ( (SDL_Window != NULL) &&
(current != NULL) &&
(current->flags == flags) &&
(current->format->BitsPerPixel == bpp) &&
((flags & SDL_FULLSCREEN) == 0) ) { /* probably not safe for fs */
int curwidth, curheight;
RECT size;
/* Get the current position of our window */
GetClientRect(SDL_Window, &size);
curwidth = (size.right - size.left);
curheight = (size.bottom - size.top);
if ((width == curwidth) && (height == curheight)) {
current->w = width;
current->h = height;
return current; /* we're already good to go. */
}
}
Dec 28, 2007
Dec 28, 2007
561
562
prev_flags = current->flags;
Apr 26, 2001
Apr 26, 2001
563
564
565
566
/* Clean up any GL context that may be hanging around */
if ( current->flags & SDL_OPENGL ) {
WIN_GL_ShutDown(this);
}
Jan 29, 2006
Jan 29, 2006
567
SDL_resizing = 1;
Apr 26, 2001
Apr 26, 2001
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/* Recalculate the bitmasks if necessary */
if ( bpp == current->format->BitsPerPixel ) {
video = current;
} else {
switch (bpp) {
case 15:
case 16:
if ( DIB_SussScreenDepth() == 15 ) {
/* 5-5-5 */
Rmask = 0x00007c00;
Gmask = 0x000003e0;
Bmask = 0x0000001f;
} else {
/* 5-6-5 */
Rmask = 0x0000f800;
Gmask = 0x000007e0;
Bmask = 0x0000001f;
}
break;
case 24:
case 32:
/* GDI defined as 8-8-8 */
Rmask = 0x00ff0000;
Gmask = 0x0000ff00;
Bmask = 0x000000ff;
break;
default:
Rmask = 0x00000000;
Gmask = 0x00000000;
Bmask = 0x00000000;
break;
}
video = SDL_CreateRGBSurface(SDL_SWSURFACE,
0, 0, bpp, Rmask, Gmask, Bmask, 0);
if ( video == NULL ) {
SDL_OutOfMemory();
return(NULL);
}
}
/* Fill in part of the video surface */
Jul 20, 2007
Jul 20, 2007
610
611
prev_w = video->w;
prev_h = video->h;
Apr 26, 2001
Apr 26, 2001
612
613
614
615
616
video->flags = 0; /* Clear flags */
video->w = width;
video->h = height;
video->pitch = SDL_CalculatePitch(video);
Sep 29, 2005
Sep 29, 2005
617
618
619
620
621
622
623
624
625
/* Small fix for WinCE/Win32 - when activating window
SDL_VideoSurface is equal to zero, so activating code
is not called properly for fullscreen windows because
macros WINDIB_FULLSCREEN uses SDL_VideoSurface
*/
SDL_VideoSurface = video;
#if defined(_WIN32_WCE)
if ( flags & SDL_FULLSCREEN )
Oct 6, 2002
Oct 6, 2002
626
627
video->flags |= SDL_FULLSCREEN;
#endif
Sep 29, 2005
Sep 29, 2005
628
Apr 26, 2001
Apr 26, 2001
629
630
631
632
#ifndef NO_CHANGEDISPLAYSETTINGS
/* Set fullscreen mode if appropriate */
if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
DEVMODE settings;
Jan 30, 2006
Jan 30, 2006
633
BOOL changed;
Apr 26, 2001
Apr 26, 2001
634
Feb 7, 2006
Feb 7, 2006
635
SDL_memset(&settings, 0, sizeof(DEVMODE));
Apr 26, 2001
Apr 26, 2001
636
settings.dmSize = sizeof(DEVMODE);
Mar 4, 2006
Mar 4, 2006
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#ifdef _WIN32_WCE
// try to rotate screen to fit requested resolution
if( this->hidden->supportRotation )
{
DWORD rotation;
// ask current mode
settings.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
rotation = settings.dmDisplayOrientation;
if( (width > GetDeviceCaps(GetDC(NULL), HORZRES))
&& (height < GetDeviceCaps(GetDC(NULL), VERTRES)))
{
switch( rotation )
{
case DMDO_0:
settings.dmDisplayOrientation = DMDO_90;
break;
case DMDO_270:
settings.dmDisplayOrientation = DMDO_180;
break;
}
if( settings.dmDisplayOrientation != rotation )
{
// go to landscape
this->hidden->origRotation = rotation;
ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
}
}
if( (width < GetDeviceCaps(GetDC(NULL), HORZRES))
&& (height > GetDeviceCaps(GetDC(NULL), VERTRES)))
{
switch( rotation )
{
case DMDO_90:
settings.dmDisplayOrientation = DMDO_0;
break;
case DMDO_180:
settings.dmDisplayOrientation = DMDO_270;
break;
}
if( settings.dmDisplayOrientation != rotation )
{
// go to portrait
this->hidden->origRotation = rotation;
ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
}
}
}
#endif
#ifndef _WIN32_WCE
Apr 26, 2001
Apr 26, 2001
692
693
694
695
settings.dmBitsPerPel = video->format->BitsPerPixel;
settings.dmPelsWidth = width;
settings.dmPelsHeight = height;
settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
Feb 6, 2006
Feb 6, 2006
696
697
if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&
height <= (int)SDL_desktop_mode.dmPelsHeight ) {
Jan 30, 2006
Jan 30, 2006
698
699
700
701
702
703
704
705
settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
settings.dmFields |= DM_DISPLAYFREQUENCY;
}
changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) {
settings.dmFields &= ~DM_DISPLAYFREQUENCY;
changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
}
Mar 4, 2006
Mar 4, 2006
706
707
708
#else
changed = 1;
#endif
Jan 30, 2006
Jan 30, 2006
709
if ( changed ) {
Apr 26, 2001
Apr 26, 2001
710
video->flags |= SDL_FULLSCREEN;
Mar 10, 2002
Mar 10, 2002
711
SDL_fullscreen_mode = settings;
Apr 26, 2001
Apr 26, 2001
712
}
Mar 4, 2006
Mar 4, 2006
713
Apr 26, 2001
Apr 26, 2001
714
715
716
}
#endif /* !NO_CHANGEDISPLAYSETTINGS */
Jun 7, 2001
Jun 7, 2001
717
/* Reset the palette and create a new one if necessary */
Jul 16, 2007
Jul 16, 2007
718
719
720
721
if ( grab_palette ) {
DIB_ReleaseStaticColors(SDL_Window);
grab_palette = FALSE;
}
Jun 7, 2001
Jun 7, 2001
722
723
724
725
726
727
if ( screen_pal != NULL ) {
/* RJR: March 28, 2000
delete identity palette if switching from a palettized mode */
DeleteObject(screen_pal);
screen_pal = NULL;
}
Jul 3, 2007
Jul 3, 2007
728
729
730
731
if ( screen_logpal != NULL ) {
SDL_free(screen_logpal);
screen_logpal = NULL;
}
Jul 16, 2007
Jul 16, 2007
732
Jun 7, 2001
Jun 7, 2001
733
734
735
736
if ( bpp <= 8 )
{
/* RJR: March 28, 2000
create identity palette switching to a palettized mode */
Jul 3, 2007
Jul 3, 2007
737
DIB_CreatePalette(this, bpp);
Jun 7, 2001
Jun 7, 2001
738
739
}
Mar 7, 2006
Mar 7, 2006
740
style = GetWindowLong(SDL_Window, GWL_STYLE);
Apr 26, 2001
Apr 26, 2001
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
style &= ~(resizestyle|WS_MAXIMIZE);
if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
style &= ~windowstyle;
style |= directstyle;
} else {
#ifndef NO_CHANGEDISPLAYSETTINGS
if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
ChangeDisplaySettings(NULL, 0);
}
#endif
if ( flags & SDL_NOFRAME ) {
style &= ~windowstyle;
style |= directstyle;
video->flags |= SDL_NOFRAME;
} else {
style &= ~directstyle;
style |= windowstyle;
if ( flags & SDL_RESIZABLE ) {
style |= resizestyle;
video->flags |= SDL_RESIZABLE;
}
}
Feb 16, 2009
Feb 16, 2009
763
#if WS_MAXIMIZE && !defined(_WIN32_WCE)
Apr 26, 2001
Apr 26, 2001
764
if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
May 23, 2001
May 23, 2001
765
#endif
Apr 26, 2001
Apr 26, 2001
766
}
Aug 9, 2001
Aug 9, 2001
767
Aug 19, 2002
Aug 19, 2002
768
/* DJM: Don't piss of anyone who has setup his own window */
Jan 29, 2006
Jan 29, 2006
769
if ( !SDL_windowid )
Mar 7, 2006
Mar 7, 2006
770
SetWindowLong(SDL_Window, GWL_STYLE, style);
Apr 26, 2001
Apr 26, 2001
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
/* Delete the old bitmap if necessary */
if ( screen_bmp != NULL ) {
DeleteObject(screen_bmp);
}
if ( ! (flags & SDL_OPENGL) ) {
BOOL is16bitmode = (video->format->BytesPerPixel == 2);
/* Suss out the bitmap info header */
binfo_size = sizeof(*binfo);
if( is16bitmode ) {
/* 16bit modes, palette area used for rgb bitmasks */
binfo_size += 3*sizeof(DWORD);
} else if ( video->format->palette ) {
binfo_size += video->format->palette->ncolors *
sizeof(RGBQUAD);
}
Feb 7, 2006
Feb 7, 2006
788
binfo = (BITMAPINFO *)SDL_malloc(binfo_size);
Apr 26, 2001
Apr 26, 2001
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
if ( ! binfo ) {
if ( video != current ) {
SDL_FreeSurface(video);
}
SDL_OutOfMemory();
return(NULL);
}
binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
binfo->bmiHeader.biWidth = video->w;
binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */
binfo->bmiHeader.biPlanes = 1;
binfo->bmiHeader.biSizeImage = video->h * video->pitch;
binfo->bmiHeader.biXPelsPerMeter = 0;
binfo->bmiHeader.biYPelsPerMeter = 0;
binfo->bmiHeader.biClrUsed = 0;
binfo->bmiHeader.biClrImportant = 0;
binfo->bmiHeader.biBitCount = video->format->BitsPerPixel;
if ( is16bitmode ) {
/* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */
binfo->bmiHeader.biCompression = BI_BITFIELDS;
((Uint32*)binfo->bmiColors)[0] = video->format->Rmask;
((Uint32*)binfo->bmiColors)[1] = video->format->Gmask;
((Uint32*)binfo->bmiColors)[2] = video->format->Bmask;
} else {
binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */
if ( video->format->palette ) {
Feb 7, 2006
Feb 7, 2006
817
SDL_memset(binfo->bmiColors, 0,
Apr 26, 2001
Apr 26, 2001
818
819
820
821
822
823
824
825
826
video->format->palette->ncolors*sizeof(RGBQUAD));
}
}
/* Create the offscreen bitmap buffer */
hdc = GetDC(SDL_Window);
screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS,
(void **)(&video->pixels), NULL, 0);
ReleaseDC(SDL_Window, hdc);
Feb 7, 2006
Feb 7, 2006
827
SDL_free(binfo);
Apr 26, 2001
Apr 26, 2001
828
829
830
831
832
833
834
835
836
837
if ( screen_bmp == NULL ) {
if ( video != current ) {
SDL_FreeSurface(video);
}
SDL_SetError("Couldn't create DIB section");
return(NULL);
}
this->UpdateRects = DIB_NormalUpdate;
/* Set video surface flags */
Jul 16, 2007
Jul 16, 2007
838
839
if ( screen_pal && (flags & (SDL_FULLSCREEN|SDL_HWPALETTE)) ) {
grab_palette = TRUE;
Apr 26, 2001
Apr 26, 2001
840
}
Jan 25, 2008
Jan 25, 2008
841
842
843
844
if ( screen_pal ) {
/* BitBlt() maps colors for us */
video->flags |= SDL_HWPALETTE;
}
Apr 26, 2001
Apr 26, 2001
845
}
Mar 4, 2006
Mar 4, 2006
846
#ifndef _WIN32_WCE
Apr 26, 2001
Apr 26, 2001
847
/* Resize the window */
Jan 29, 2006
Jan 29, 2006
848
if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
Mar 4, 2006
Mar 4, 2006
849
850
851
#else
if ( !SDL_windowid ) {
#endif
Aug 19, 2002
Aug 19, 2002
852
HWND top;
Apr 26, 2001
Apr 26, 2001
853
UINT swp_flags;
Jan 29, 2006
Jan 29, 2006
854
855
const char *window = NULL;
const char *center = NULL;
Feb 16, 2004
Feb 16, 2004
856
Jul 20, 2007
Jul 20, 2007
857
if ( video->w != prev_w || video->h != prev_h ) {
Feb 7, 2006
Feb 7, 2006
858
859
window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
center = SDL_getenv("SDL_VIDEO_CENTERED");
Feb 16, 2004
Feb 16, 2004
860
if ( window ) {
Feb 7, 2006
Feb 7, 2006
861
if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {
Feb 16, 2004
Feb 16, 2004
862
863
864
SDL_windowX = x;
SDL_windowY = y;
}
Feb 7, 2006
Feb 7, 2006
865
if ( SDL_strcmp(window, "center") == 0 ) {
Feb 16, 2004
Feb 16, 2004
866
867
868
869
870
center = window;
}
}
}
swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
Apr 26, 2001
Apr 26, 2001
871
Feb 16, 2004
Feb 16, 2004
872
873
874
875
bounds.left = SDL_windowX;
bounds.top = SDL_windowY;
bounds.right = SDL_windowX+video->w;
bounds.bottom = SDL_windowY+video->h;
Sep 23, 2006
Sep 23, 2006
876
#ifndef _WIN32_WCE
Jun 24, 2006
Jun 24, 2006
877
AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), (GetMenu(SDL_Window) != NULL), 0);
Sep 23, 2006
Sep 23, 2006
878
879
880
881
#else
// The bMenu parameter must be FALSE; menu bars are not supported
AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), 0, 0);
#endif
Apr 26, 2001
Apr 26, 2001
882
883
width = bounds.right-bounds.left;
height = bounds.bottom-bounds.top;
Feb 16, 2004
Feb 16, 2004
884
885
886
887
888
889
if ( (flags & SDL_FULLSCREEN) ) {
x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
} else if ( center ) {
x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
Nov 12, 2004
Nov 12, 2004
890
891
892
} else if ( SDL_windowX || SDL_windowY || window ) {
x = bounds.left;
y = bounds.top;
Feb 16, 2004
Feb 16, 2004
893
894
895
896
} else {
x = y = -1;
swp_flags |= SWP_NOMOVE;
}
Aug 19, 2002
Aug 19, 2002
897
898
899
900
901
902
if ( flags & SDL_FULLSCREEN ) {
top = HWND_TOPMOST;
} else {
top = HWND_NOTOPMOST;
}
SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
Jan 29, 2006
Jan 29, 2006
903
904
905
906
if ( !(flags & SDL_FULLSCREEN) ) {
SDL_windowX = SDL_bounds.left;
SDL_windowY = SDL_bounds.top;
}
Apr 26, 2001
Apr 26, 2001
907
908
SetForegroundWindow(SDL_Window);
}
Jan 29, 2006
Jan 29, 2006
909
SDL_resizing = 0;
Apr 26, 2001
Apr 26, 2001
910
911
912
913
914
915
916
917
/* Set up for OpenGL */
if ( flags & SDL_OPENGL ) {
if ( WIN_GL_SetupWindow(this) < 0 ) {
return(NULL);
}
video->flags |= SDL_OPENGL;
}
May 23, 2001
May 23, 2001
918
Mar 14, 2006
Mar 14, 2006
919
920
921
922
923
924
/* JC 14 Mar 2006
Flush the message loop or this can cause big problems later
Especially if the user decides to use dialog boxes or assert()!
*/
WIN_FlushMessageQueue();
Apr 26, 2001
Apr 26, 2001
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
/* We're live! */
return(video);
}
/* We don't actually allow hardware surfaces in the DIB driver */
static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static int DIB_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
{
HDC hdc, mdc;
int i;
hdc = GetDC(SDL_Window);
if ( screen_pal ) {
SelectPalette(hdc, screen_pal, FALSE);
}
mdc = CreateCompatibleDC(hdc);
SelectObject(mdc, screen_bmp);
for ( i=0; i<numrects; ++i ) {
BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
mdc, rects[i].x, rects[i].y, SRCCOPY);
}
DeleteDC(mdc);
ReleaseDC(SDL_Window, hdc);
}
Jul 3, 2007
Jul 3, 2007
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
static int FindPaletteIndex(LOGPALETTE *pal, BYTE r, BYTE g, BYTE b)
{
PALETTEENTRY *entry;
int i;
int nentries = pal->palNumEntries;
for ( i = 0; i < nentries; ++i ) {
entry = &pal->palPalEntry[i];
if ( entry->peRed == r && entry->peGreen == g && entry->peBlue == b ) {
return i;
}
}
return -1;
}
static BOOL CheckPaletteEntry(LOGPALETTE *pal, int index, BYTE r, BYTE g, BYTE b)
{
PALETTEENTRY *entry;
BOOL moved = 0;
entry = &pal->palPalEntry[index];
if ( entry->peRed != r || entry->peGreen != g || entry->peBlue != b ) {
int found = FindPaletteIndex(pal, r, g, b);
if ( found >= 0 ) {
pal->palPalEntry[found] = *entry;
}
entry->peRed = r;
entry->peGreen = g;
entry->peBlue = b;
moved = 1;
}
entry->peFlags = 0;
return moved;
}