comparison src/video/SDL_blit.c @ 526:4314a501d7be

Fixed a crash blitting RLE surfaces to RLE surfaces
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Oct 2002 07:56:36 +0000
parents c97c1d3b3b5c
children 5bb080d35049
comparison
equal deleted inserted replaced
525:f55cdaec12b9 526:4314a501d7be
48 /* Everything is okay at the beginning... */ 48 /* Everything is okay at the beginning... */
49 okay = 1; 49 okay = 1;
50 50
51 /* Lock the destination if it's in hardware */ 51 /* Lock the destination if it's in hardware */
52 dst_locked = 0; 52 dst_locked = 0;
53 if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 53 if ( SDL_MUSTLOCK(dst) ) {
54 SDL_VideoDevice *video = current_video; 54 if ( SDL_LockSurface(dst) < 0 ) {
55 SDL_VideoDevice *this = current_video;
56 if ( video->LockHWSurface(this, dst) < 0 ) {
57 okay = 0; 55 okay = 0;
58 } else { 56 } else {
59 dst_locked = 1; 57 dst_locked = 1;
60 } 58 }
61 } 59 }
62 /* Lock the source if it's in hardware */ 60 /* Lock the source if it's in hardware */
63 src_locked = 0; 61 src_locked = 0;
64 if ( src->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 62 if ( SDL_MUSTLOCK(src) ) {
65 SDL_VideoDevice *video = current_video; 63 if ( SDL_LockSurface(src) < 0 ) {
66 SDL_VideoDevice *this = current_video;
67 if ( video->LockHWSurface(this, src) < 0 ) {
68 okay = 0; 64 okay = 0;
69 } else { 65 } else {
70 src_locked = 1; 66 src_locked = 1;
71 } 67 }
72 }
73
74 /* Unencode the destination if it's RLE encoded */
75 if ( dst->flags & SDL_RLEACCEL ) {
76 SDL_UnRLESurface(dst, 1);
77 dst->flags |= SDL_RLEACCEL; /* save accel'd state */
78 } 68 }
79 69
80 /* Set up source and destination buffer pointers, and BLIT! */ 70 /* Set up source and destination buffer pointers, and BLIT! */
81 if ( okay && srcrect->w && srcrect->h ) { 71 if ( okay && srcrect->w && srcrect->h ) {
82 SDL_BlitInfo info; 72 SDL_BlitInfo info;
83 SDL_loblit RunBlit; 73 SDL_loblit RunBlit;
84 74
85 /* Set up the blit information */ 75 /* Set up the blit information */
86 info.s_pixels = (Uint8 *)src->pixels + src->offset + 76 info.s_pixels = (Uint8 *)src->pixels +
87 (Uint16)srcrect->y*src->pitch + 77 (Uint16)srcrect->y*src->pitch +
88 (Uint16)srcrect->x*src->format->BytesPerPixel; 78 (Uint16)srcrect->x*src->format->BytesPerPixel;
89 info.s_width = srcrect->w; 79 info.s_width = srcrect->w;
90 info.s_height = srcrect->h; 80 info.s_height = srcrect->h;
91 info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; 81 info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel;
92 info.d_pixels = (Uint8 *)dst->pixels + dst->offset + 82 info.d_pixels = (Uint8 *)dst->pixels +
93 (Uint16)dstrect->y*dst->pitch + 83 (Uint16)dstrect->y*dst->pitch +
94 (Uint16)dstrect->x*dst->format->BytesPerPixel; 84 (Uint16)dstrect->x*dst->format->BytesPerPixel;
95 info.d_width = dstrect->w; 85 info.d_width = dstrect->w;
96 info.d_height = dstrect->h; 86 info.d_height = dstrect->h;
97 info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel; 87 info.d_skip=dst->pitch-info.d_width*dst->format->BytesPerPixel;
103 93
104 /* Run the actual software blit */ 94 /* Run the actual software blit */
105 RunBlit(&info); 95 RunBlit(&info);
106 } 96 }
107 97
108 /* Re-encode the destination if it's RLE encoded */
109 if ( dst->flags & SDL_RLEACCEL ) {
110 dst->flags &= ~SDL_RLEACCEL; /* stop lying */
111 SDL_RLESurface(dst);
112 }
113
114 /* We need to unlock the surfaces if they're locked */ 98 /* We need to unlock the surfaces if they're locked */
115 if ( dst_locked ) { 99 if ( dst_locked ) {
116 SDL_VideoDevice *video = current_video; 100 SDL_UnlockSurface(dst);
117 SDL_VideoDevice *this = current_video;
118 video->UnlockHWSurface(this, dst);
119 } 101 }
120 if ( src_locked ) { 102 if ( src_locked ) {
121 SDL_VideoDevice *video = current_video; 103 SDL_UnlockSurface(src);
122 SDL_VideoDevice *this = current_video;
123 video->UnlockHWSurface(this, src);
124 } 104 }
125 /* Blit is done! */ 105 /* Blit is done! */
126 return(okay ? 0 : -1); 106 return(okay ? 0 : -1);
127 } 107 }
128 108