Mercurial > sdl-ios-xcode
annotate src/video/SDL_blit.c @ 4139:568c9b3c0167 SDL-1.2
* Added configure option --enable-screensaver, to allow enabling the screensaver by default.
* Use XResetScreenSaver() instead of disabling screensaver entirely.
Full discussion summary from Erik on the SDL mailing list:
Current behaviour
=================
SDL changes the user's display power management settings without
permission from the user and without telling the user.
The interface that it uses to do so is DPMSDisable/DPMSEnable, which
should only ever be used by configuration utilities like KControl, never
by normal application programs, let alone by the libraries that they
use. Using an interface that is not at all intended for what SDL tries
to achieve means that it will not work as it should. Firstly, the power
management is completely disabled during the whole lifetime of the SDL
program, not only when it should be. Secondly, it makes SDL
non-reentrant, meaning that things will break when multiple SDL programs
are clients of the same X server simultaneously. Thirdly, no cleanup
mechanism ensures that the setting is restored if the client does not do
that (for example if it crashes).
In addition to that, this interface is broken on xorg,
[http://bugs.freedesktop.org/show_bug.cgi?id=13962], so what SDL tries
to do does not work at all on that implementation of the X Window
System. (The reason that the DPMSEnable works in KControl is that it
calls DPMSSetTimeout immediately after,
[http://websvn.kde.org/tags/KDE/3.5.9/kdebase/kcontrol/energy/energy.cpp?annotate=774532#l343]).
The problems that the current behaviour causes
==============================================
1. Information leak. When the user is away, someone might see what the
user has on the display when the user counts on the screensaver
preventing this. This does not even require physical access to the
workstation, it is enough to see it from a distance.
2. Draining battery. An SDL program that runs on a laptop will quickly
drain the battery while the user is away. The system will soon shut down
and require recharging before being usable again, while it should in
fact have consumed very little energy if the user's settings would have
been obeyed.
3. Wasting energy. Even if battery issues are not considered, energy as
such is wasted.
4. Display wear. The display may be worn out.
The problems that the current behaviour tries to solve
======================================================
1. Preventing screensaver while playing movies.
Many SDL applications are media players. They have reasons to prevent
screensavers from being activated while a movie is being played. When a
user clicks on the play button it can be interpreted as saying "play
this movie, but do not turn off the display while playing it, because I
will watch it even though I do not interact with the system".
2. Preventing screensaver when some input bypasses X.
Sometimes SDL uses input from another source than the X server, so
that the X server is bypassed. This obviously breaks the screensaver
handling. SDL tries to work around that.
3. Preventing screensaver when all input bypasses X.
There is something called Direct Graphics Access mode, where a
program takes control of both the display and the input devices from the
X server. This obviously means that the X server can not handle the
screensaver alone, since screensaver handling depends on input handling.
SDL does not do what it should to help the X server to handle the
screensaver. Nor does SDL take care of screeensaver handling itself. SDL
simply disables the screensaver completely.
How the problems should be solved
=================================
The correct way for an application program to prevent the screensaver
under X is to call XResetScreenSaver. This was recently discovered and
implemented by the mplayer developers,
[http://svn.mplayerhq.hu/mplayer?view=rev&revision=25637]. SDL needs to
wrap this in an API call (SDL_ResetScreenSaver) and implement it for the
other video targets (if they do not have a corresponding call, SDL
should do what it takes on that particular target, for example sending
fake key events).
1. When a movie is played, the player should reset the screensaver when
the animation is advanced to a new frame. The same applies to anything
similar, like slideshows.
2. When the X server is handling input, it must handle all input
(keyboards, mice, gamepads, ...). This is necessary, not only to be able
to handle the screensaver, but also so that it can send the events to
the correct (the currently active) client. If there is an input device
that the X server can not handle for some reason (such as lack of Plug
and Play capability), the program that handles the device as a
workaround must simulate what would happen if the X server would have
handled the device, by calling XResetScreenSaver when input is received
from the device.
3. When the X server is not handling the input, it depends on the
program that does to call XResetScreenSaver whenever an input event
occurs. Alternatively the program must handle the screensaver countdown
internally and call XActivateScreenSaver.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 29 Feb 2008 13:55:44 +0000 |
parents | 6832b00d3594 |
children | a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1196
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #include "SDL_video.h" | |
25 #include "SDL_sysvideo.h" | |
26 #include "SDL_blit.h" | |
27 #include "SDL_RLEaccel_c.h" | |
28 #include "SDL_pixels_c.h" | |
29 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
30 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && SDL_ASSEMBLY_ROUTINES |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
31 #define MMX_ASMBLIT |
3909
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
32 #if (__GNUC__ > 2) /* SSE instructions aren't in GCC 2. */ |
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
33 #define SSE_ASMBLIT |
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
34 #endif |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
35 #endif |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
36 |
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
37 #if defined(MMX_ASMBLIT) |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
38 #include "SDL_cpuinfo.h" |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
39 #include "mmx.h" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
40 #endif |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
41 |
0 | 42 /* The general purpose software blit routine */ |
43 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, | |
44 SDL_Surface *dst, SDL_Rect *dstrect) | |
45 { | |
46 int okay; | |
47 int src_locked; | |
48 int dst_locked; | |
49 | |
50 /* Everything is okay at the beginning... */ | |
51 okay = 1; | |
52 | |
53 /* Lock the destination if it's in hardware */ | |
54 dst_locked = 0; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
55 if ( SDL_MUSTLOCK(dst) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
56 if ( SDL_LockSurface(dst) < 0 ) { |
0 | 57 okay = 0; |
58 } else { | |
59 dst_locked = 1; | |
60 } | |
61 } | |
62 /* Lock the source if it's in hardware */ | |
63 src_locked = 0; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
64 if ( SDL_MUSTLOCK(src) ) { |
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
65 if ( SDL_LockSurface(src) < 0 ) { |
0 | 66 okay = 0; |
67 } else { | |
68 src_locked = 1; | |
69 } | |
70 } | |
71 | |
72 /* Set up source and destination buffer pointers, and BLIT! */ | |
73 if ( okay && srcrect->w && srcrect->h ) { | |
74 SDL_BlitInfo info; | |
75 SDL_loblit RunBlit; | |
76 | |
77 /* Set up the blit information */ | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
78 info.s_pixels = (Uint8 *)src->pixels + |
0 | 79 (Uint16)srcrect->y*src->pitch + |
80 (Uint16)srcrect->x*src->format->BytesPerPixel; | |
81 info.s_width = srcrect->w; | |
82 info.s_height = srcrect->h; | |
83 info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
84 info.d_pixels = (Uint8 *)dst->pixels + |
0 | 85 (Uint16)dstrect->y*dst->pitch + |
86 (Uint16)dstrect->x*dst->format->BytesPerPixel; | |
87 info.d_width = dstrect->w; | |
88 info.d_height = dstrect->h; | |
89 info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel; | |
90 info.aux_data = src->map->sw_data->aux_data; | |
91 info.src = src->format; | |
92 info.table = src->map->table; | |
93 info.dst = dst->format; | |
94 RunBlit = src->map->sw_data->blit; | |
95 | |
96 /* Run the actual software blit */ | |
97 RunBlit(&info); | |
98 } | |
99 | |
100 /* We need to unlock the surfaces if they're locked */ | |
101 if ( dst_locked ) { | |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
102 SDL_UnlockSurface(dst); |
310
c97c1d3b3b5c
Blit bug fix from John Popplewell
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
103 } |
0 | 104 if ( src_locked ) { |
526
4314a501d7be
Fixed a crash blitting RLE surfaces to RLE surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
310
diff
changeset
|
105 SDL_UnlockSurface(src); |
0 | 106 } |
107 /* Blit is done! */ | |
108 return(okay ? 0 : -1); | |
109 } | |
110 | |
880
9ef41050100c
Date: Tue, 30 Mar 2004 21:26:47 -0600
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
111 #ifdef MMX_ASMBLIT |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1052
diff
changeset
|
112 static __inline__ void SDL_memcpyMMX(Uint8 *to, const Uint8 *from, int len) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
113 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
114 int i; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
115 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
116 for(i=0; i<len/8; i++) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
117 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
118 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
119 " movq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
120 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
121 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
122 to+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
123 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
124 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
125 SDL_memcpy(to, from, len&7); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
126 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
127 |
3909
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
128 #ifdef SSE_ASMBLIT |
1196
b81f54c3963f
Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents:
1052
diff
changeset
|
129 static __inline__ void SDL_memcpySSE(Uint8 *to, const Uint8 *from, int len) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
130 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
131 int i; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
132 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
133 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
134 " prefetchnta (%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
135 " prefetchnta 64(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
136 " prefetchnta 128(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
137 " prefetchnta 192(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
138 : : "r" (from) ); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
139 |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
140 for(i=0; i<len/8; i++) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
141 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
142 " prefetchnta 256(%0)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
143 " movq (%0), %%mm0\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
144 " movntq %%mm0, (%1)\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
145 : : "r" (from), "r" (to) : "memory"); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
146 from+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
147 to+=8; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
148 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
149 if (len&7) |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
150 SDL_memcpy(to, from, len&7); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
151 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
152 #endif |
3909
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
153 #endif |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
154 |
0 | 155 static void SDL_BlitCopy(SDL_BlitInfo *info) |
156 { | |
157 Uint8 *src, *dst; | |
158 int w, h; | |
159 int srcskip, dstskip; | |
160 | |
161 w = info->d_width*info->dst->BytesPerPixel; | |
162 h = info->d_height; | |
163 src = info->s_pixels; | |
164 dst = info->d_pixels; | |
165 srcskip = w+info->s_skip; | |
166 dstskip = w+info->d_skip; | |
3909
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
167 |
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
168 #ifdef SSE_ASMBLIT |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
169 if(SDL_HasSSE()) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
170 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
171 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
172 SDL_memcpySSE(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
173 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
174 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
175 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
176 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
177 " emms\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
178 ::); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
179 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
180 else |
3909
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
181 #endif |
6832b00d3594
Patched to compile on BeOS and old, old GCC releases.
Ryan C. Gordon <icculus@icculus.org>
parents:
1402
diff
changeset
|
182 #ifdef MMX_ASMBLIT |
739
22dbf364c017
Added SDL_HasMMX(), SDL_Has3DNow(), SDL_HasSSE() in SDL_cpuinfo.h
Sam Lantinga <slouken@libsdl.org>
parents:
697
diff
changeset
|
183 if(SDL_HasMMX()) |
689
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
184 { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
185 while ( h-- ) { |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
186 SDL_memcpyMMX(dst, src, w); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
187 src += srcskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
188 dst += dstskip; |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
189 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
190 __asm__ __volatile__ ( |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
191 " emms\n" |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
192 ::); |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
193 } |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
194 else |
5bb080d35049
Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
195 #endif |
0 | 196 while ( h-- ) { |
197 SDL_memcpy(dst, src, w); | |
198 src += srcskip; | |
199 dst += dstskip; | |
200 } | |
201 } | |
202 | |
203 static void SDL_BlitCopyOverlap(SDL_BlitInfo *info) | |
204 { | |
205 Uint8 *src, *dst; | |
206 int w, h; | |
207 int srcskip, dstskip; | |
208 | |
209 w = info->d_width*info->dst->BytesPerPixel; | |
210 h = info->d_height; | |
211 src = info->s_pixels; | |
212 dst = info->d_pixels; | |
213 srcskip = w+info->s_skip; | |
214 dstskip = w+info->d_skip; | |
215 if ( dst < src ) { | |
216 while ( h-- ) { | |
217 SDL_memcpy(dst, src, w); | |
218 src += srcskip; | |
219 dst += dstskip; | |
220 } | |
221 } else { | |
222 src += ((h-1) * srcskip); | |
223 dst += ((h-1) * dstskip); | |
224 while ( h-- ) { | |
225 SDL_revcpy(dst, src, w); | |
226 src -= srcskip; | |
227 dst -= dstskip; | |
228 } | |
229 } | |
230 } | |
231 | |
232 /* Figure out which of many blit routines to set up on a surface */ | |
233 int SDL_CalculateBlit(SDL_Surface *surface) | |
234 { | |
235 int blit_index; | |
236 | |
237 /* Clean everything out to start */ | |
238 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { | |
239 SDL_UnRLESurface(surface, 1); | |
240 } | |
241 surface->map->sw_blit = NULL; | |
242 | |
243 /* Figure out if an accelerated hardware blit is possible */ | |
244 surface->flags &= ~SDL_HWACCEL; | |
245 if ( surface->map->identity ) { | |
246 int hw_blit_ok; | |
247 | |
248 if ( (surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { | |
249 /* We only support accelerated blitting to hardware */ | |
250 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
251 hw_blit_ok = current_video->info.blit_hw; | |
252 } else { | |
253 hw_blit_ok = 0; | |
254 } | |
255 if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { | |
256 hw_blit_ok = current_video->info.blit_hw_CC; | |
257 } | |
258 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
259 hw_blit_ok = current_video->info.blit_hw_A; | |
260 } | |
261 } else { | |
262 /* We only support accelerated blitting to hardware */ | |
263 if ( surface->map->dst->flags & SDL_HWSURFACE ) { | |
264 hw_blit_ok = current_video->info.blit_sw; | |
265 } else { | |
266 hw_blit_ok = 0; | |
267 } | |
268 if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) { | |
269 hw_blit_ok = current_video->info.blit_sw_CC; | |
270 } | |
271 if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) { | |
272 hw_blit_ok = current_video->info.blit_sw_A; | |
273 } | |
274 } | |
275 if ( hw_blit_ok ) { | |
276 SDL_VideoDevice *video = current_video; | |
277 SDL_VideoDevice *this = current_video; | |
278 video->CheckHWBlit(this, surface, surface->map->dst); | |
279 } | |
280 } | |
1052
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
281 |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
282 /* if an alpha pixel format is specified, we can accelerate alpha blits */ |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
283 if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )&&(current_video->displayformatalphapixel)) |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
284 { |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
285 if ( (surface->flags & SDL_SRCALPHA) ) |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
286 if ( current_video->info.blit_hw_A ) { |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
287 SDL_VideoDevice *video = current_video; |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
288 SDL_VideoDevice *this = current_video; |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
289 video->CheckHWBlit(this, surface, surface->map->dst); |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
290 } |
68f607298ca9
Some work on using accelerated alpha blits with hardware surfaces.
Ryan C. Gordon <icculus@icculus.org>
parents:
882
diff
changeset
|
291 } |
0 | 292 |
293 /* Get the blit function index, based on surface mode */ | |
294 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ | |
295 blit_index = 0; | |
296 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; | |
297 if ( surface->flags & SDL_SRCALPHA | |
298 && (surface->format->alpha != SDL_ALPHA_OPAQUE | |
299 || surface->format->Amask) ) { | |
300 blit_index |= 2; | |
301 } | |
302 | |
303 /* Check for special "identity" case -- copy blit */ | |
304 if ( surface->map->identity && blit_index == 0 ) { | |
305 surface->map->sw_data->blit = SDL_BlitCopy; | |
306 | |
307 /* Handle overlapping blits on the same surface */ | |
308 if ( surface == surface->map->dst ) { | |
309 surface->map->sw_data->blit = SDL_BlitCopyOverlap; | |
310 } | |
311 } else { | |
312 if ( surface->format->BitsPerPixel < 8 ) { | |
313 surface->map->sw_data->blit = | |
314 SDL_CalculateBlit0(surface, blit_index); | |
315 } else { | |
316 switch ( surface->format->BytesPerPixel ) { | |
317 case 1: | |
318 surface->map->sw_data->blit = | |
319 SDL_CalculateBlit1(surface, blit_index); | |
320 break; | |
321 case 2: | |
322 case 3: | |
323 case 4: | |
324 surface->map->sw_data->blit = | |
325 SDL_CalculateBlitN(surface, blit_index); | |
326 break; | |
327 default: | |
328 surface->map->sw_data->blit = NULL; | |
329 break; | |
330 } | |
331 } | |
332 } | |
333 /* Make sure we have a blit function */ | |
334 if ( surface->map->sw_data->blit == NULL ) { | |
335 SDL_InvalidateMap(surface->map); | |
336 SDL_SetError("Blit combination not supported"); | |
337 return(-1); | |
338 } | |
339 | |
340 /* Choose software blitting function */ | |
341 if(surface->flags & SDL_RLEACCELOK | |
342 && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) { | |
343 | |
344 if(surface->map->identity | |
345 && (blit_index == 1 | |
346 || (blit_index == 3 && !surface->format->Amask))) { | |
347 if ( SDL_RLESurface(surface) == 0 ) | |
348 surface->map->sw_blit = SDL_RLEBlit; | |
349 } else if(blit_index == 2 && surface->format->Amask) { | |
350 if ( SDL_RLESurface(surface) == 0 ) | |
351 surface->map->sw_blit = SDL_RLEAlphaBlit; | |
352 } | |
353 } | |
354 | |
355 if ( surface->map->sw_blit == NULL ) { | |
356 surface->map->sw_blit = SDL_SoftBlit; | |
357 } | |
358 return(0); | |
359 } | |
360 |