Lines Matching refs:surface
35 * Create an empty RGB surface of the appropriate depth
44 SDL_Surface *surface;
53 /* Check to see if we desire the surface in video memory */
77 /* Allocate the surface */
78 surface = (SDL_Surface *)SDL_malloc(sizeof(*surface));
79 if ( surface == NULL ) {
83 surface->flags = SDL_SWSURFACE;
102 surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
103 if ( surface->format == NULL ) {
104 SDL_free(surface);
108 surface->flags |= SDL_SRCALPHA;
110 surface->w = width;
111 surface->h = height;
112 surface->pitch = SDL_CalculatePitch(surface);
113 surface->pixels = NULL;
114 surface->offset = 0;
115 surface->hwdata = NULL;
116 surface->locked = 0;
117 surface->map = NULL;
118 surface->unused1 = 0;
119 SDL_SetClipRect(surface, NULL);
120 SDL_FormatChanged(surface);
124 (video->AllocHWSurface(this, surface) < 0) ) {
125 if ( surface->w && surface->h ) {
126 surface->pixels = SDL_malloc(surface->h*surface->pitch);
127 if ( surface->pixels == NULL ) {
128 SDL_FreeSurface(surface);
133 SDL_memset(surface->pixels, 0, surface->h*surface->pitch);
138 surface->map = SDL_AllocBlitMap();
139 if ( surface->map == NULL ) {
140 SDL_FreeSurface(surface);
144 /* The surface is ready to go */
145 surface->refcount = 1;
149 return(surface);
152 * Create an RGB surface from an existing memory buffer
158 SDL_Surface *surface;
160 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, depth,
162 if ( surface != NULL ) {
163 surface->flags |= SDL_PREALLOC;
164 surface->pixels = pixels;
165 surface->w = width;
166 surface->h = height;
167 surface->pitch = pitch;
168 SDL_SetClipRect(surface, NULL);
170 return(surface);
173 * Set the color key in a blittable surface
175 int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
189 if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
190 (key == surface->format->colorkey) ) {
195 if ( surface->flags & SDL_RLEACCEL ) {
196 SDL_UnRLESurface(surface, 1);
204 surface->flags |= SDL_SRCCOLORKEY;
205 surface->format->colorkey = key;
206 if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
208 (video->SetHWColorKey(this, surface, key) < 0) ) {
209 surface->flags &= ~SDL_HWACCEL;
213 surface->flags |= SDL_RLEACCELOK;
215 surface->flags &= ~SDL_RLEACCELOK;
218 surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
219 surface->format->colorkey = 0;
221 SDL_InvalidateMap(surface->map);
224 /* This function sets the alpha channel of a surface */
225 int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
227 Uint32 oldflags = surface->flags;
228 Uint32 oldalpha = surface->format->alpha;
242 if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&
247 if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
248 SDL_UnRLESurface(surface, 1);
254 surface->flags |= SDL_SRCALPHA;
255 surface->format->alpha = value;
256 if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
258 (video->SetHWAlpha(this, surface, value) < 0) ) {
259 surface->flags &= ~SDL_HWACCEL;
263 surface->flags |= SDL_RLEACCELOK;
265 surface->flags &= ~SDL_RLEACCELOK;
268 surface->flags &= ~SDL_SRCALPHA;
269 surface->format->alpha = SDL_ALPHA_OPAQUE;
273 * per-surface alpha, so no need to invalidate the blit mapping
277 if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
278 || oldflags != surface->flags
280 SDL_InvalidateMap(surface->map);
283 int SDL_SetAlphaChannel(SDL_Surface *surface, Uint8 value)
289 if ( (surface->format->Amask != 0xFF000000) &&
290 (surface->format->Amask != 0x000000FF) ) {
291 SDL_SetError("Unsupported surface alpha mask format");
296 if ( surface->format->Amask == 0xFF000000 ) {
302 if ( surface->format->Amask == 0xFF000000 ) {
309 /* Quickly set the alpha channel of an RGBA or ARGB surface */
310 if ( SDL_MUSTLOCK(surface) ) {
311 if ( SDL_LockSurface(surface) < 0 ) {
315 row = surface->h;
317 col = surface->w;
318 buf = (Uint8 *)surface->pixels + row * surface->pitch + offset;
324 if ( SDL_MUSTLOCK(surface) ) {
325 SDL_UnlockSurface(surface);
366 * Set the clipping rectangle for a blittable surface
368 SDL_bool SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
372 /* Don't do anything if there's no surface to act on */
373 if ( ! surface ) {
377 /* Set up the full surface rectangle */
380 full_rect.w = surface->w;
381 full_rect.h = surface->h;
385 surface->clip_rect = full_rect;
388 return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
390 void SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect)
392 if ( surface && rect ) {
393 *rect = surface->clip_rect;
452 SDL_SetError("SDL_UpperBlit: passed a NULL surface");
460 /* If the destination rectangle is NULL, use the entire dest surface */
466 /* clip the source rectangle to the source surface */
570 SDL_SetError("Fill rect on unsupported surface format");
576 /* If 'dstrect' == NULL, then fill the whole surface */
734 * Lock a surface to directly access the pixels
736 int SDL_LockSurface (SDL_Surface *surface)
738 if ( ! surface->locked ) {
740 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
743 if ( video->LockHWSurface(this, surface) < 0 ) {
747 if ( surface->flags & SDL_RLEACCEL ) {
748 SDL_UnRLESurface(surface, 1);
749 surface->flags |= SDL_RLEACCEL; /* save accel'd state */
752 surface->pixels = (Uint8 *)surface->pixels + surface->offset;
755 /* Increment the surface lock count, for recursive locks */
756 ++surface->locked;
762 * Unlock a previously locked surface
764 void SDL_UnlockSurface (SDL_Surface *surface)
767 if ( ! surface->locked || (--surface->locked > 0) ) {
772 surface->pixels = (Uint8 *)surface->pixels - surface->offset;
775 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) {
778 video->UnlockHWSurface(this, surface);
780 /* Update RLE encoded surface with new data */
781 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
782 surface->flags &= ~SDL_RLEACCEL; /* stop lying */
783 SDL_RLESurface(surface);
789 * Convert a surface into the specified pixel format.
791 SDL_Surface * SDL_ConvertSurface (SDL_Surface *surface,
823 /* Create a new surface with the desired format */
825 surface->w, surface->h, format->BitsPerPixel,
839 /* Save the original surface color key and alpha */
840 surface_flags = surface->flags;
847 colorkey = surface->format->colorkey;
848 SDL_SetColorKey(surface, 0, 0);
854 surface->flags &= ~SDL_SRCALPHA;
856 alpha = surface->format->alpha;
857 SDL_SetAlpha(surface, 0, 0);
864 bounds.w = surface->w;
865 bounds.h = surface->h;
866 SDL_LowerBlit(surface, &bounds, convert, &bounds);
868 /* Clean up the original surface, and update converted surface */
870 SDL_SetClipRect(convert, &surface->clip_rect);
877 SDL_GetRGB(colorkey,surface->format,&keyR,&keyG,&keyB);
881 SDL_SetColorKey(surface, cflags, colorkey);
890 surface->flags |= SDL_SRCALPHA;
892 SDL_SetAlpha(surface, aflags, alpha);
901 * Free a surface created by the above function.
903 void SDL_FreeSurface (SDL_Surface *surface)
905 /* Free anything that's not NULL, and not the screen surface */
906 if ((surface == NULL) ||
908 ((surface == SDL_ShadowSurface)||(surface == SDL_VideoSurface)))) {
911 if ( --surface->refcount > 0 ) {
914 while ( surface->locked > 0 ) {
915 SDL_UnlockSurface(surface);
917 if ( (surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
918 SDL_UnRLESurface(surface, 0);
920 if ( surface->format ) {
921 SDL_FreeFormat(surface->format);
922 surface->format = NULL;
924 if ( surface->map != NULL ) {
925 SDL_FreeBlitMap(surface->map);
926 surface->map = NULL;
928 if ( surface->hwdata ) {
931 video->FreeHWSurface(this, surface);
933 if ( surface->pixels &&
934 ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) {
935 SDL_free(surface->pixels);
937 SDL_free(surface);