Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fb3dfx.c @ 1287:15a89a0c52bf
Date: Tue, 15 Feb 2005 21:28:48 +0900 (JST)
From: "Michael Leonhard"
Subject: [SDL] resize bug on Win32 and patch
This is my first post to this mailing list. In this email I will detail a
bug in the behavior of resizable SDL windows on Win32. Then I will
explain the solution and provide a patch.
Symptoms:
Under Windows, an SDL display created with the SDL_RESIZABLE flag exhibits
quirky behavior when being maximized. The window is resized to the proper
size, but it is shifted upwards about half the height of the title bar.
Similarly, a window whose origin is above the top of the screen will
spontaneously move its upper-left origin upon being resized. After two
such resize-induced moves, the title bar will be entirely off the top edge
of the screen. Subsequently, when the mouse is clicked and released on
the window border, the window will shrink its height spontaneously. This
height shrinkage occurs even if the user did not resize the border.
To observe this curious situation, please invoke:
SDL-1.2.8/test/testwm.exe -resize
Cause:
A pair of integers, SDL_windowX and SDL_windowY, are defined in
video/wincommon/SDL_sysevents.c. They are used by the DirectX video
driver and the DIB video driver:
video/windx5/SDL_dx5video.c
video/windib/SDL_dibvideo.c
As I understand the source code, the primary use of these variables is to
create a rectangle that represents the surface area in CLIENT SPACE.
Client space refers to a coordinate system that originates at the upper
left corner of a Win32 Window's drawable area. This is just inside the
window border and title bar. This client space rectangle, called bounds,
is subsequently converted to screen space with a call to
AdjustWindowRectEx. The problem is found in SDL's handling of the
WM_WINDOWPOSCHANGED message. According to MSDN,
"The WM_WINDOWPOSCHANGED message is sent to a window whose
size, position, or place in the Z order has changed as a
result of a call to the SetWindowPos function or another
window-management function."
I have confirmed that this message is indeed being sent to the SDL window
when the mouse is clicked on the window border, even if the window border
is not dragged.
In video/wincommon/SDL_sysevents.c, on line 464, in response to the
WM_WINDOWPOSCHANGED message, the (potentially) new client rectangle is
obtained. This rectangle is translated into screen coordinates and THEN
assigned to the SDL_windowX and Y variables. Thus screen coordinates are
being assigned to client coordinate variables. Once this is understood,
the solution is apparent: assign SDL_windowX and Y before translating the
rectangle to screen coordinates. This is accomplished by the following
patch.
-Mike_L
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 08:50:06 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
109
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include "SDL_types.h" | |
29 #include "SDL_video.h" | |
30 #include "SDL_blit.h" | |
31 #include "SDL_fb3dfx.h" | |
32 #include "3dfx_mmio.h" | |
33 | |
34 | |
35 /* Wait for vertical retrace */ | |
36 static void WaitVBL(_THIS) | |
37 { | |
38 /* find start of retrace */ | |
39 tdfx_waitidle(); | |
40 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE ) | |
41 ; | |
42 /* wait until we're past the start */ | |
43 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0 ) | |
44 ; | |
45 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
46 static void WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
47 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
48 tdfx_waitidle(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
49 } |
0 | 50 |
51 /* Sets video mem colorkey and accelerated blit function */ | |
52 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key) | |
53 { | |
54 return(0); | |
55 } | |
56 | |
57 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color) | |
58 { | |
59 int bpp; | |
60 char *dst_base; | |
61 Uint32 format; | |
62 int dstX, dstY; | |
63 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
64 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
65 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
66 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
67 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
68 |
0 | 69 /* Set the destination pixel format */ |
70 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
71 bpp = dst->format->BitsPerPixel; | |
72 format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
73 | |
74 /* Calculate source and destination base coordinates */ | |
75 dstX = rect->x; | |
76 dstY = rect->y; | |
77 | |
78 /* Execute the fill command */ | |
79 tdfx_wait(6); | |
80 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
81 tdfx_out32(DSTFORMAT, format); | |
82 tdfx_out32(COLORFORE, color); | |
83 tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT); | |
84 tdfx_out32(DSTSIZE, rect->w | (rect->h << 16)); | |
85 tdfx_out32(LAUNCH_2D, dstX | (dstY << 16)); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
86 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
87 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
89 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
90 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
91 } |
0 | 92 return(0); |
93 } | |
94 | |
95 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
96 SDL_Surface *dst, SDL_Rect *dstrect) | |
97 { | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
98 SDL_VideoDevice *this = current_video; |
0 | 99 int bpp; |
100 Uint32 src_format; | |
101 Uint32 dst_format; | |
102 char *src_base; | |
103 char *dst_base; | |
104 int srcX, srcY; | |
105 int dstX, dstY; | |
106 Uint32 blitop; | |
107 Uint32 use_colorkey; | |
108 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
109 /* Don't blit to the display surface when switched away */ |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
110 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
111 SDL_mutexP(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
112 } |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
113 |
0 | 114 /* Set the source and destination pixel format */ |
115 src_base = (char *)((char *)src->pixels - mapped_mem); | |
116 bpp = src->format->BitsPerPixel; | |
117 src_format = src->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
118 dst_base = (char *)((char *)dst->pixels - mapped_mem); | |
119 bpp = dst->format->BitsPerPixel; | |
120 dst_format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13); | |
121 | |
122 srcX = srcrect->x; | |
123 srcY = srcrect->y; | |
124 dstX = dstrect->x; | |
125 dstY = dstrect->y; | |
126 | |
127 /* Assemble the blit operation */ | |
128 blitop = COMMAND_2D_BITBLT | (0xCC << 24); | |
129 if ( srcX <= dstX ) { | |
130 blitop |= BIT(14); | |
131 srcX += (dstrect->w - 1); | |
132 dstX += (dstrect->w - 1); | |
133 } | |
134 if ( srcY <= dstY ) { | |
135 blitop |= BIT(15); | |
136 srcY += (dstrect->h - 1); | |
137 dstY += (dstrect->h - 1); | |
138 } | |
139 | |
140 /* Perform the blit! */ | |
141 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
142 tdfx_wait(3); | |
143 tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey); | |
144 tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey); | |
145 tdfx_out32(ROP_2D, 0xAA00); | |
146 use_colorkey = 1; | |
147 } else { | |
148 use_colorkey = 0; | |
149 } | |
150 tdfx_wait(9); | |
151 tdfx_out32(SRCBASE, (Uint32)src_base); | |
152 tdfx_out32(SRCFORMAT, src_format); | |
153 tdfx_out32(DSTBASE, (Uint32)dst_base); | |
154 tdfx_out32(DSTFORMAT, src_format); | |
155 tdfx_out32(COMMAND_2D, blitop); | |
156 tdfx_out32(COMMANDEXTRA_2D, use_colorkey); | |
157 tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16)); | |
158 tdfx_out32(DSTXY, dstX | (dstY << 16)); | |
159 tdfx_out32(LAUNCH_2D, srcX | (srcY << 16)); | |
160 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 FB_AddBusySurface(src); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 FB_AddBusySurface(dst); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
164 if ( dst == this->screen ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
165 SDL_mutexV(hw_lock); |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
106
diff
changeset
|
166 } |
0 | 167 return(0); |
168 } | |
169 | |
170 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | |
171 { | |
172 int accelerated; | |
173 | |
174 /* Set initial acceleration on */ | |
175 src->flags |= SDL_HWACCEL; | |
176 | |
177 /* Set the surface attributes */ | |
178 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { | |
179 if ( ! this->info.blit_hw_A ) { | |
180 src->flags &= ~SDL_HWACCEL; | |
181 } | |
182 } | |
183 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) { | |
184 if ( ! this->info.blit_hw_CC ) { | |
185 src->flags &= ~SDL_HWACCEL; | |
186 } | |
187 } | |
188 | |
189 /* Check to see if final surface blit is accelerated */ | |
190 accelerated = !!(src->flags & SDL_HWACCEL); | |
191 if ( accelerated ) { | |
192 src->map->hw_blit = HWAccelBlit; | |
193 } | |
194 return(accelerated); | |
195 } | |
196 | |
197 void FB_3DfxAccel(_THIS, __u32 card) | |
198 { | |
199 /* We have hardware accelerated surface functions */ | |
200 this->CheckHWBlit = CheckHWBlit; | |
201 wait_vbl = WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
202 wait_idle = WaitIdle; |
0 | 203 |
204 /* Reset the 3Dfx controller */ | |
205 tdfx_out32(BRESERROR0, 0); | |
206 tdfx_out32(BRESERROR1, 0); | |
207 | |
208 /* The 3Dfx has an accelerated color fill */ | |
209 this->info.blit_fill = 1; | |
210 this->FillHWRect = FillHWRect; | |
211 | |
212 /* The 3Dfx has accelerated normal and colorkey blits */ | |
213 this->info.blit_hw = 1; | |
214 this->info.blit_hw_CC = 1; | |
215 this->SetHWColorKey = SetHWColorKey; | |
216 } |