Mercurial > sdl-ios-xcode
annotate src/video/SDL_surface.c @ 1672:8e754b82cecc SDL-1.3
Updated SDL_Surface code for software-only access, fixed some build errors
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 09 Jun 2006 07:06:12 +0000 |
parents | eef792d31de8 |
children | 90bf530ced8e |
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:
1251
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:
1251
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:
1251
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:
1251
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:
1251
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:
1251
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:
1251
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:
130
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:
1358
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 #include "SDL_video.h" | |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
25 #include "SDL_compat.h" |
0 | 26 #include "SDL_sysvideo.h" |
27 #include "SDL_blit.h" | |
28 #include "SDL_RLEaccel_c.h" | |
29 #include "SDL_pixels_c.h" | |
30 #include "SDL_leaks.h" | |
31 | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1155
diff
changeset
|
32 |
0 | 33 /* Public routines */ |
34 /* | |
35 * Create an empty RGB surface of the appropriate depth | |
36 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
37 SDL_Surface * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
38 SDL_CreateRGBSurface(Uint32 flags, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
39 int width, int height, int depth, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
40 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
0 | 41 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
42 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
43 SDL_Surface *screen; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
44 SDL_Surface *surface; |
0 | 45 |
1670 | 46 /* FIXME!! */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
47 /* Make sure the size requested doesn't overflow our datatypes */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
48 /* Next time I write a library like SDL, I'll use int for size. :) */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
49 if (width >= 16384 || height >= 65536) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
50 SDL_SetError("Width or height is too large"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
51 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
52 } |
940
bb1588ebe47b
Date: Sat, 10 Jul 2004 21:02:33 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
915
diff
changeset
|
53 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
54 /* Allocate the surface */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
55 surface = (SDL_Surface *) SDL_malloc(sizeof(*surface)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
56 if (surface == NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
57 SDL_OutOfMemory(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
58 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
59 } |
1670 | 60 surface->flags = 0; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
61 surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
62 if (surface->format == NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
63 SDL_free(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
64 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
65 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
66 if (Amask) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
67 surface->flags |= SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
68 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
69 surface->w = width; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
70 surface->h = height; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
71 surface->pitch = SDL_CalculatePitch(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
72 surface->pixels = NULL; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
73 surface->locked = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
74 surface->map = NULL; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
75 SDL_SetClipRect(surface, NULL); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
76 SDL_FormatChanged(surface); |
0 | 77 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
78 /* Get the pixels */ |
1670 | 79 if (surface->w && surface->h) { |
80 surface->pixels = SDL_malloc(surface->h * surface->pitch); | |
81 if (surface->pixels == NULL) { | |
82 SDL_FreeSurface(surface); | |
83 SDL_OutOfMemory(); | |
84 return NULL; | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
85 } |
1670 | 86 /* This is important for bitmaps */ |
87 SDL_memset(surface->pixels, 0, surface->h * surface->pitch); | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
88 } |
0 | 89 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
90 /* Allocate an empty mapping */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
91 surface->map = SDL_AllocBlitMap(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
92 if (surface->map == NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
93 SDL_FreeSurface(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
94 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
95 } |
0 | 96 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
97 /* The surface is ready to go */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
98 surface->refcount = 1; |
0 | 99 #ifdef CHECK_LEAKS |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
100 ++surfaces_allocated; |
0 | 101 #endif |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
102 return (surface); |
0 | 103 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
104 |
0 | 105 /* |
106 * Create an RGB surface from an existing memory buffer | |
107 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
108 SDL_Surface * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
109 SDL_CreateRGBSurfaceFrom(void *pixels, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
110 int width, int height, int depth, int pitch, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
111 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
112 Uint32 Amask) |
0 | 113 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
114 SDL_Surface *surface; |
0 | 115 |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
116 surface = |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
117 SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
118 if (surface != NULL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
119 surface->flags |= SDL_PREALLOC; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
120 surface->pixels = pixels; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
121 surface->w = width; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
122 surface->h = height; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
123 surface->pitch = pitch; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
124 SDL_SetClipRect(surface, NULL); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
125 } |
1670 | 126 return surface; |
127 } | |
128 | |
129 SDL_Surface * | |
130 SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID) | |
131 { | |
132 SDL_Surface *surface; | |
133 Uint32 format; | |
134 int w, h; | |
135 int bpp; | |
136 Uint32 Rmask, Gmask, Bmask, Amask; | |
137 | |
138 if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) { | |
139 return NULL; | |
140 } | |
141 | |
142 if (!SDL_PixelFormatEnumToMasks | |
143 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
144 SDL_SetError("Unknown texture format"); | |
145 return NULL; | |
146 } | |
147 | |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
148 surface = SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask); |
1670 | 149 if (surface != NULL) { |
150 surface->flags |= (SDL_HWSURFACE | SDL_PREALLOC); | |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
151 surface->w = w; |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
152 surface->h = h; |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
153 surface->lock_data = (void *) textureID; |
1670 | 154 SDL_SetClipRect(surface, NULL); |
155 } | |
156 return surface; | |
157 } | |
158 | |
159 /* | |
160 * Set the palette in a blittable surface | |
161 */ | |
162 int | |
163 SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor, | |
164 int ncolors) | |
165 { | |
166 SDL_Palette *pal; | |
167 int gotall; | |
168 int palsize; | |
169 | |
170 /* Verify the parameters */ | |
171 pal = surface->format->palette; | |
172 if (!pal) { | |
173 return 0; /* not a palettized surface */ | |
174 } | |
175 gotall = 1; | |
176 palsize = 1 << surface->format->BitsPerPixel; | |
177 if (ncolors > (palsize - firstcolor)) { | |
178 ncolors = (palsize - firstcolor); | |
179 gotall = 0; | |
180 } | |
181 | |
182 if (colors != (pal->colors + firstcolor)) { | |
183 SDL_memcpy(pal->colors + firstcolor, colors, | |
184 ncolors * sizeof(*colors)); | |
185 } | |
186 SDL_FormatChanged(surface); | |
187 | |
188 if (surface->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) { | |
189 gotall &= SDL_SetScreenColors(surface, colors, firstcolor, ncolors); | |
190 } | |
191 return gotall; | |
0 | 192 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
193 |
0 | 194 /* |
195 * Set the color key in a blittable surface | |
196 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
197 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
198 SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key) |
0 | 199 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
200 /* Sanity check the flag as it gets passed in */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
201 if (flag & SDL_SRCCOLORKEY) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
202 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
203 flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
204 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
205 flag = SDL_SRCCOLORKEY; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
206 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
207 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
208 flag = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
209 } |
0 | 210 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
211 /* Optimize away operations that don't change anything */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
212 if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) && |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
213 (key == surface->format->colorkey)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
214 return (0); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
215 } |
0 | 216 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
217 /* UnRLE surfaces before we change the colorkey */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
218 if (surface->flags & SDL_RLEACCEL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
219 SDL_UnRLESurface(surface, 1); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
220 } |
0 | 221 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
222 if (flag) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
223 surface->flags |= SDL_SRCCOLORKEY; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
224 surface->format->colorkey = key; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
225 if (flag & SDL_RLEACCELOK) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
226 surface->flags |= SDL_RLEACCELOK; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
227 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
228 surface->flags &= ~SDL_RLEACCELOK; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
229 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
230 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
231 surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
232 surface->format->colorkey = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
233 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
234 SDL_InvalidateMap(surface->map); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
235 return (0); |
0 | 236 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
237 |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
238 /* This function sets the alpha channel of a surface */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
239 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
240 SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value) |
0 | 241 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
242 Uint32 oldflags = surface->flags; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
243 Uint32 oldalpha = surface->format->alpha; |
0 | 244 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
245 /* Sanity check the flag as it gets passed in */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
246 if (flag & SDL_SRCALPHA) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
247 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
248 flag = (SDL_SRCALPHA | SDL_RLEACCELOK); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
249 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
250 flag = SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
251 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
252 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
253 flag = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
254 } |
0 | 255 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
256 /* Optimize away operations that don't change anything */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
257 if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) && |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
258 (!flag || value == oldalpha)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
259 return (0); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
260 } |
0 | 261 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
262 if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL)) |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
263 SDL_UnRLESurface(surface, 1); |
0 | 264 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
265 if (flag) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
266 surface->flags |= SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
267 surface->format->alpha = value; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
268 if (flag & SDL_RLEACCELOK) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
269 surface->flags |= SDL_RLEACCELOK; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
270 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
271 surface->flags &= ~SDL_RLEACCELOK; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
272 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
273 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
274 surface->flags &= ~SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
275 surface->format->alpha = SDL_ALPHA_OPAQUE; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
276 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
277 /* |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
278 * The representation for software surfaces is independent of |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
279 * per-surface alpha, so no need to invalidate the blit mapping |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
280 * if just the alpha value was changed. (If either is 255, we still |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
281 * need to invalidate.) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
282 */ |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
283 if (oldflags != surface->flags |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
284 || (((oldalpha + 1) ^ (value + 1)) & 0x100)) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
285 SDL_InvalidateMap(surface->map); |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
286 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
287 return (0); |
0 | 288 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
289 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
290 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
291 SDL_SetAlphaChannel(SDL_Surface * surface, Uint8 value) |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
292 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
293 int row, col; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
294 int offset; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
295 Uint8 *buf; |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
296 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
297 if ((surface->format->Amask != 0xFF000000) && |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
298 (surface->format->Amask != 0x000000FF)) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
299 SDL_SetError("Unsupported surface alpha mask format"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
300 return -1; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
301 } |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
302 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
303 if (surface->format->Amask == 0xFF000000) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
304 offset = 3; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
305 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
306 offset = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
307 } |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
308 #else |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
309 if (surface->format->Amask == 0xFF000000) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
310 offset = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
311 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
312 offset = 3; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
313 } |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
314 #endif /* Byte ordering */ |
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
315 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
316 /* Quickly set the alpha channel of an RGBA or ARGB surface */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
317 if (SDL_MUSTLOCK(surface)) { |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
318 if (SDL_LockSurface(surface) < 0) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
319 return -1; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
320 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
321 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
322 row = surface->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
323 while (row--) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
324 col = surface->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
325 buf = (Uint8 *) surface->pixels + row * surface->pitch + offset; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
326 while (col--) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
327 *buf = value; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
328 buf += 4; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
329 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
330 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
331 if (SDL_MUSTLOCK(surface)) { |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
332 SDL_UnlockSurface(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
333 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
334 return 0; |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
335 } |
0 | 336 |
337 /* | |
338 * A function to calculate the intersection of two rectangles: | |
339 * return true if the rectangles intersect, false otherwise | |
340 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
341 static __inline__ SDL_bool |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
342 SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
343 SDL_Rect * intersection) |
0 | 344 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
345 int Amin, Amax, Bmin, Bmax; |
0 | 346 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
347 /* Horizontal intersection */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
348 Amin = A->x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
349 Amax = Amin + A->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
350 Bmin = B->x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
351 Bmax = Bmin + B->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
352 if (Bmin > Amin) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
353 Amin = Bmin; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
354 intersection->x = Amin; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
355 if (Bmax < Amax) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
356 Amax = Bmax; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
357 intersection->w = Amax - Amin > 0 ? Amax - Amin : 0; |
0 | 358 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
359 /* Vertical intersection */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
360 Amin = A->y; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
361 Amax = Amin + A->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
362 Bmin = B->y; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
363 Bmax = Bmin + B->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
364 if (Bmin > Amin) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
365 Amin = Bmin; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
366 intersection->y = Amin; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
367 if (Bmax < Amax) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
368 Amax = Bmax; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
369 intersection->h = Amax - Amin > 0 ? Amax - Amin : 0; |
0 | 370 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
371 return (intersection->w && intersection->h); |
0 | 372 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
373 |
0 | 374 /* |
375 * Set the clipping rectangle for a blittable surface | |
376 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
377 SDL_bool |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
378 SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect) |
0 | 379 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
380 SDL_Rect full_rect; |
0 | 381 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
382 /* Don't do anything if there's no surface to act on */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
383 if (!surface) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
384 return SDL_FALSE; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
385 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
386 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
387 /* Set up the full surface rectangle */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
388 full_rect.x = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
389 full_rect.y = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
390 full_rect.w = surface->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
391 full_rect.h = surface->h; |
0 | 392 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
393 /* Set the clipping rectangle */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
394 if (!rect) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
395 surface->clip_rect = full_rect; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
396 return 1; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
397 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
398 return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
399 } |
0 | 400 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
401 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
402 SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect) |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
403 { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
404 if (surface && rect) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
405 *rect = surface->clip_rect; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
406 } |
0 | 407 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
408 |
0 | 409 /* |
410 * Set up a blit between two surfaces -- split into three parts: | |
411 * The upper part, SDL_UpperBlit(), performs clipping and rectangle | |
412 * verification. The lower part is a pointer to a low level | |
413 * accelerated blitting function. | |
414 * | |
415 * These parts are separated out and each used internally by this | |
416 * library in the optimimum places. They are exported so that if | |
417 * you know exactly what you are doing, you can optimize your code | |
418 * by calling the one(s) you need. | |
419 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
420 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
421 SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
422 SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 423 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
424 /* Check to make sure the blit mapping is valid */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
425 if ((src->map->dst != dst) || |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
426 (src->map->dst->format_version != src->map->format_version)) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
427 if (SDL_MapSurface(src, dst) < 0) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
428 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
429 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
430 } |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
431 return (src->map->sw_blit(src, srcrect, dst, dstrect)); |
0 | 432 } |
433 | |
434 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
435 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
436 SDL_UpperBlit(SDL_Surface * src, SDL_Rect * srcrect, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
437 SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 438 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
439 SDL_Rect fulldst; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
440 int srcx, srcy, w, h; |
0 | 441 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
442 /* Make sure the surfaces aren't locked */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
443 if (!src || !dst) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
444 SDL_SetError("SDL_UpperBlit: passed a NULL surface"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
445 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
446 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
447 if (src->locked || dst->locked) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
448 SDL_SetError("Surfaces must not be locked during blit"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
449 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
450 } |
0 | 451 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
452 /* If the destination rectangle is NULL, use the entire dest surface */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
453 if (dstrect == NULL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
454 fulldst.x = fulldst.y = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
455 dstrect = &fulldst; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
456 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
457 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
458 /* clip the source rectangle to the source surface */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
459 if (srcrect) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
460 int maxw, maxh; |
0 | 461 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
462 srcx = srcrect->x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
463 w = srcrect->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
464 if (srcx < 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
465 w += srcx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
466 dstrect->x -= srcx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
467 srcx = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
468 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
469 maxw = src->w - srcx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
470 if (maxw < w) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
471 w = maxw; |
0 | 472 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
473 srcy = srcrect->y; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
474 h = srcrect->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
475 if (srcy < 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
476 h += srcy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
477 dstrect->y -= srcy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
478 srcy = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
479 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
480 maxh = src->h - srcy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
481 if (maxh < h) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
482 h = maxh; |
0 | 483 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
484 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
485 srcx = srcy = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
486 w = src->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
487 h = src->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
488 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
489 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
490 /* clip the destination rectangle against the clip rectangle */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
491 { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
492 SDL_Rect *clip = &dst->clip_rect; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
493 int dx, dy; |
0 | 494 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
495 dx = clip->x - dstrect->x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
496 if (dx > 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
497 w -= dx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
498 dstrect->x += dx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
499 srcx += dx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
500 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
501 dx = dstrect->x + w - clip->x - clip->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
502 if (dx > 0) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
503 w -= dx; |
0 | 504 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
505 dy = clip->y - dstrect->y; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
506 if (dy > 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
507 h -= dy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
508 dstrect->y += dy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
509 srcy += dy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
510 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
511 dy = dstrect->y + h - clip->y - clip->h; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
512 if (dy > 0) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
513 h -= dy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
514 } |
0 | 515 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
516 if (w > 0 && h > 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
517 SDL_Rect sr; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
518 sr.x = srcx; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
519 sr.y = srcy; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
520 sr.w = dstrect->w = w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
521 sr.h = dstrect->h = h; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
522 return SDL_LowerBlit(src, &sr, dst, dstrect); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
523 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
524 dstrect->w = dstrect->h = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
525 return 0; |
0 | 526 } |
527 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
528 static int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
529 SDL_FillRect1(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) |
532
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
530 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
531 /* FIXME: We have to worry about packing order.. *sigh* */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
532 SDL_SetError("1-bpp rect fill not yet implemented"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
533 return -1; |
532
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
534 } |
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
535 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
536 static int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
537 SDL_FillRect4(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) |
532
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
538 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
539 /* FIXME: We have to worry about packing order.. *sigh* */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
540 SDL_SetError("4-bpp rect fill not yet implemented"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
541 return -1; |
532
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
542 } |
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
543 |
0 | 544 /* |
545 * This function performs a fast fill of the given rectangle with 'color' | |
546 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
547 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
548 SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) |
0 | 549 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
550 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
551 int x, y; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
552 Uint8 *row; |
0 | 553 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
554 /* This function doesn't work on surfaces < 8 bpp */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
555 if (dst->format->BitsPerPixel < 8) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
556 switch (dst->format->BitsPerPixel) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
557 case 1: |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
558 return SDL_FillRect1(dst, dstrect, color); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
559 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
560 case 4: |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
561 return SDL_FillRect4(dst, dstrect, color); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
562 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
563 default: |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
564 SDL_SetError("Fill rect on unsupported surface format"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
565 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
566 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
567 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
568 } |
532
058d47b7a3b4
Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents:
526
diff
changeset
|
569 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
570 /* If 'dstrect' == NULL, then fill the whole surface */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
571 if (dstrect) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
572 /* Perform clipping */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
573 if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
574 return (0); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
575 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
576 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
577 dstrect = &dst->clip_rect; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
578 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
579 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
580 /* Perform software fill */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
581 if (SDL_LockSurface(dst) != 0) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
582 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
583 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
584 row = (Uint8 *) dst->pixels + dstrect->y * dst->pitch + |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
585 dstrect->x * dst->format->BytesPerPixel; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
586 if (dst->format->palette || (color == 0)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
587 x = dstrect->w * dst->format->BytesPerPixel; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
588 if (!color && !((uintptr_t) row & 3) && !(x & 3) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
589 && !(dst->pitch & 3)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
590 int n = x >> 2; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
591 for (y = dstrect->h; y; --y) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
592 SDL_memset4(row, 0, n); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
593 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
594 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
595 } else { |
0 | 596 #ifdef __powerpc__ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
597 /* |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
598 * SDL_memset() on PPC (both glibc and codewarrior) uses |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
599 * the dcbz (Data Cache Block Zero) instruction, which |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
600 * causes an alignment exception if the destination is |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
601 * uncachable, so only use it on software surfaces |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
602 */ |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
603 if (dst->flags & SDL_HWSURFACE) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
604 if (dstrect->w >= 8) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
605 /* |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
606 * 64-bit stores are probably most |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
607 * efficient to uncached video memory |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
608 */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
609 double fill; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
610 SDL_memset(&fill, color, (sizeof fill)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
611 for (y = dstrect->h; y; y--) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
612 Uint8 *d = row; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
613 unsigned n = x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
614 unsigned nn; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
615 Uint8 c = color; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
616 double f = fill; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
617 while ((unsigned long) d & (sizeof(double) - 1)) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
618 *d++ = c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
619 n--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
620 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
621 nn = n / (sizeof(double) * 4); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
622 while (nn) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
623 ((double *) d)[0] = f; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
624 ((double *) d)[1] = f; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
625 ((double *) d)[2] = f; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
626 ((double *) d)[3] = f; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
627 d += 4 * sizeof(double); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
628 nn--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
629 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
630 n &= ~(sizeof(double) * 4 - 1); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
631 nn = n / sizeof(double); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
632 while (nn) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
633 *(double *) d = f; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
634 d += sizeof(double); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
635 nn--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
636 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
637 n &= ~(sizeof(double) - 1); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
638 while (n) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
639 *d++ = c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
640 n--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
641 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
642 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
643 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
644 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
645 /* narrow boxes */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
646 for (y = dstrect->h; y; y--) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
647 Uint8 *d = row; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
648 Uint8 c = color; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
649 int n = x; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
650 while (n) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
651 *d++ = c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
652 n--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
653 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
654 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
655 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
656 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
657 } else |
0 | 658 #endif /* __powerpc__ */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
659 { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
660 for (y = dstrect->h; y; y--) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
661 SDL_memset(row, color, x); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
662 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
663 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
664 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
665 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
666 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
667 switch (dst->format->BytesPerPixel) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
668 case 2: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
669 for (y = dstrect->h; y; --y) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
670 Uint16 *pixels = (Uint16 *) row; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
671 Uint16 c = (Uint16) color; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
672 Uint32 cc = (Uint32) c << 16 | c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
673 int n = dstrect->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
674 if ((uintptr_t) pixels & 3) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
675 *pixels++ = c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
676 n--; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
677 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
678 if (n >> 1) |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
679 SDL_memset4(pixels, cc, n >> 1); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
680 if (n & 1) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
681 pixels[n - 1] = c; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
682 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
683 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
684 break; |
0 | 685 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
686 case 3: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
687 #if SDL_BYTEORDER == SDL_BIG_ENDIAN |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
688 color <<= 8; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
689 #endif |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
690 for (y = dstrect->h; y; --y) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
691 Uint8 *pixels = row; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
692 for (x = dstrect->w; x; --x) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
693 SDL_memcpy(pixels, &color, 3); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
694 pixels += 3; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
695 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
696 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
697 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
698 break; |
0 | 699 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
700 case 4: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
701 for (y = dstrect->h; y; --y) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
702 SDL_memset4(row, color, dstrect->w); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
703 row += dst->pitch; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
704 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
705 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
706 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
707 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
708 SDL_UnlockSurface(dst); |
0 | 709 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
710 /* We're done! */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
711 return (0); |
0 | 712 } |
713 | |
714 /* | |
715 * Lock a surface to directly access the pixels | |
716 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
717 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
718 SDL_LockSurface(SDL_Surface * surface) |
0 | 719 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
720 if (!surface->locked) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
721 /* Perform the lock */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
722 if (surface->flags & SDL_HWSURFACE) { |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
723 if (SDL_LockTexture |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
724 ((SDL_TextureID) surface->lock_data, NULL, 1, |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
725 &surface->pixels, &surface->pitch) < 0) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
726 return (-1); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
727 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
728 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
729 if (surface->flags & SDL_RLEACCEL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
730 SDL_UnRLESurface(surface, 1); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
731 surface->flags |= SDL_RLEACCEL; /* save accel'd state */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
732 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
733 } |
0 | 734 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
735 /* Increment the surface lock count, for recursive locks */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
736 ++surface->locked; |
0 | 737 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
738 /* Ready to go.. */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
739 return (0); |
0 | 740 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
741 |
0 | 742 /* |
743 * Unlock a previously locked surface | |
744 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
745 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
746 SDL_UnlockSurface(SDL_Surface * surface) |
0 | 747 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
748 /* Only perform an unlock if we are locked */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
749 if (!surface->locked || (--surface->locked > 0)) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
750 return; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
751 } |
0 | 752 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
753 /* Unlock hardware or accelerated surfaces */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
754 if (surface->flags & SDL_HWSURFACE) { |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
755 SDL_UnlockTexture((SDL_TextureID) surface->lock_data); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
756 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
757 /* Update RLE encoded surface with new data */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
758 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
759 surface->flags &= ~SDL_RLEACCEL; /* stop lying */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
760 SDL_RLESurface(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
761 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
762 } |
0 | 763 } |
764 | |
765 /* | |
766 * Convert a surface into the specified pixel format. | |
767 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
768 SDL_Surface * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
769 SDL_ConvertSurface(SDL_Surface * surface, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
770 SDL_PixelFormat * format, Uint32 flags) |
0 | 771 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
772 SDL_Surface *convert; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
773 Uint32 colorkey = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
774 Uint8 alpha = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
775 Uint32 surface_flags; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
776 SDL_Rect bounds; |
0 | 777 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
778 /* Check for empty destination palette! (results in empty image) */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
779 if (format->palette != NULL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
780 int i; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
781 for (i = 0; i < format->palette->ncolors; ++i) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
782 if ((format->palette->colors[i].r != 0) || |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
783 (format->palette->colors[i].g != 0) || |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
784 (format->palette->colors[i].b != 0)) |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
785 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
786 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
787 if (i == format->palette->ncolors) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
788 SDL_SetError("Empty destination palette"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
789 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
790 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
791 } |
0 | 792 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
793 /* Create a new surface with the desired format */ |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
794 convert = SDL_CreateRGBSurface(flags, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
795 surface->w, surface->h, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
796 format->BitsPerPixel, format->Rmask, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
797 format->Gmask, format->Bmask, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
798 format->Amask); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
799 if (convert == NULL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
800 return (NULL); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
801 } |
0 | 802 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
803 /* Copy the palette if any */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
804 if (format->palette && convert->format->palette) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
805 SDL_memcpy(convert->format->palette->colors, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
806 format->palette->colors, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
807 format->palette->ncolors * sizeof(SDL_Color)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
808 convert->format->palette->ncolors = format->palette->ncolors; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
809 } |
0 | 810 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
811 /* Save the original surface color key and alpha */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
812 surface_flags = surface->flags; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
813 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
814 /* Convert colourkeyed surfaces to RGBA if requested */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
815 if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
816 surface_flags &= ~SDL_SRCCOLORKEY; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
817 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
818 colorkey = surface->format->colorkey; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
819 SDL_SetColorKey(surface, 0, 0); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
820 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
821 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
822 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
823 /* Copy over the alpha channel to RGBA if requested */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
824 if (format->Amask) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
825 surface->flags &= ~SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
826 } else { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
827 alpha = surface->format->alpha; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
828 SDL_SetAlpha(surface, 0, 0); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
829 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
830 } |
0 | 831 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
832 /* Copy over the image data */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
833 bounds.x = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
834 bounds.y = 0; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
835 bounds.w = surface->w; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
836 bounds.h = surface->h; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
837 SDL_LowerBlit(surface, &bounds, convert, &bounds); |
0 | 838 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
839 /* Clean up the original surface, and update converted surface */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
840 if (convert != NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
841 SDL_SetClipRect(convert, &surface->clip_rect); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
842 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
843 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
844 Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
845 if (convert != NULL) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
846 Uint8 keyR, keyG, keyB; |
0 | 847 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
848 SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
849 SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK), |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
850 SDL_MapRGB(convert->format, keyR, keyG, keyB)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
851 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
852 SDL_SetColorKey(surface, cflags, colorkey); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
853 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
854 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
855 Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
856 if (convert != NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
857 SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
858 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
859 if (format->Amask) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
860 surface->flags |= SDL_SRCALPHA; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
861 } else { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
862 SDL_SetAlpha(surface, aflags, alpha); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
863 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
864 } |
0 | 865 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
866 /* We're ready to go! */ |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
867 return (convert); |
0 | 868 } |
869 | |
870 /* | |
871 * Free a surface created by the above function. | |
872 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
873 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
874 SDL_FreeSurface(SDL_Surface * surface) |
0 | 875 { |
1666
6e7ec5cb83c3
The dummy video driver compiles. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
876 if (surface == NULL) { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
877 return; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
878 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
879 if (--surface->refcount > 0) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
880 return; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
881 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
882 while (surface->locked > 0) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
883 SDL_UnlockSurface(surface); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
884 } |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
885 if (surface->flags & SDL_RLEACCEL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
886 SDL_UnRLESurface(surface, 0); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
887 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
888 if (surface->format) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
889 SDL_FreeFormat(surface->format); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
890 surface->format = NULL; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
891 } |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
892 if (surface->map != NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
893 SDL_FreeBlitMap(surface->map); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
894 surface->map = NULL; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
895 } |
1672
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
896 /* Should we destroy the texture too? |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
897 if (surface->flags & SDL_HWSURFACE) { |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
898 SDL_DestroyTexture((SDL_TextureID)surface->lock_data); |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
899 } |
8e754b82cecc
Updated SDL_Surface code for software-only access, fixed some build errors
Sam Lantinga <slouken@libsdl.org>
parents:
1670
diff
changeset
|
900 */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
901 if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
902 SDL_free(surface->pixels); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
903 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1666
diff
changeset
|
904 SDL_free(surface); |
0 | 905 #ifdef CHECK_LEAKS |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
906 --surfaces_allocated; |
0 | 907 #endif |
908 } | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
909 |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
910 /* vi: set ts=4 sw=4 expandtab: */ |