comparison libvo/vo_sdl.c @ 36523:beef55a708b5

vo_sdl: some minor code simplifications.
author reimar
date Sat, 18 Jan 2014 23:08:34 +0000
parents c9e8812156f4
children f42155eac256
comparison
equal deleted inserted replaced
36522:c9e8812156f4 36523:beef55a708b5
96 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \ 96 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \
97 return x; \ 97 return x; \
98 } 98 }
99 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay); 99 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay);
100 100
101 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \ 101 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf) && SDL_LockSurface (srf)) { \
102 if(SDL_LockSurface (srf)) { \
103 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \ 102 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \
104 return x; \ 103 return x; \
105 } \
106 } 104 }
107 105
108 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \ 106 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \
109 SDL_UnlockSurface (srf); 107 SDL_UnlockSurface (srf);
110 #else 108 #else
239 237
240 if(priv->osd_has_changed) { 238 if(priv->osd_has_changed) {
241 /* OSD did change. Store a bounding box of everything drawn into the OSD */ 239 /* OSD did change. Store a bounding box of everything drawn into the OSD */
242 if(priv->y >= y0) { 240 if(priv->y >= y0) {
243 /* Make sure we don't mark part of the frame area dirty */ 241 /* Make sure we don't mark part of the frame area dirty */
244 if(h + y0 > priv->y) 242 expand_rect(&priv->dirty_off_frame[0], x0, y0, w, FFMIN(priv->y - y0, h));
245 expand_rect(&priv->dirty_off_frame[0], x0, y0, w, priv->y - y0);
246 else
247 expand_rect(&priv->dirty_off_frame[0], x0, y0, w, h);
248 } 243 }
249 else if(priv->y + priv->height <= y0 + h) { 244 else if(priv->y + priv->height <= y0 + h) {
250 /* Make sure we don't mark part of the frame area dirty */ 245 /* Make sure we don't mark part of the frame area dirty */
251 if(y0 < priv->y + priv->height) 246 int offset = FFMAX(0, priv->y + priv->height - y0);
252 expand_rect(&priv->dirty_off_frame[1], x0, 247 expand_rect(&priv->dirty_off_frame[1], x0, y0 + offset, w, h - offset);
253 priv->y + priv->height,
254 w, h - ((priv->y + priv->height) - y0));
255 else
256 expand_rect(&priv->dirty_off_frame[1], x0, y0, w, h);
257 } 248 }
258 } 249 }
259 else { /* OSD contents didn't change only draw parts that was erased by the frame */ 250 else { /* OSD contents didn't change only draw parts that was erased by the frame */
260 if(priv->y >= y0) { 251 if(priv->y >= y0) {
261 src = src + (priv->y - y0) * stride; 252 src += (priv->y - y0) * stride;
262 srca = srca + (priv->y - y0) * stride; 253 srca += (priv->y - y0) * stride;
263 h -= priv->y - y0; 254 h -= priv->y - y0;
264 y0 = priv->y; 255 y0 = priv->y;
265 } 256 }
266 257
267 if(priv->y + priv->height <= y0 + h) 258 if(priv->y + priv->height <= y0 + h)
281 case IMGFMT_IYUV: 272 case IMGFMT_IYUV:
282 draw(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]); 273 draw(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]);
283 break; 274 break;
284 275
285 default: 276 default:
286 if(priv->dblit) { 277 {
287 draw(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); 278 SDL_Surface *sf = priv->dblit ? priv->surface : priv->rgbsurface;
288 } 279 draw(w,h,src,srca,stride,((uint8_t *)sf->pixels)+y0*sf->pitch+x0,sf->pitch);
289 else {
290 draw(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch);
291 } 280 }
292 } 281 }
293 } 282 }
294 283
295 284
518 } 507 }
519 508
520 aspect_save_screenres(screen_surface_w, screen_surface_h); 509 aspect_save_screenres(screen_surface_w, screen_surface_h);
521 510
522 /* calculate new video size/aspect */ 511 /* calculate new video size/aspect */
523 if(priv->mode == YUV) { 512 if(priv->mode == YUV && priv->fulltype&VOFLAG_FULLSCREEN)
524 if(priv->fulltype&VOFLAG_FULLSCREEN)
525 aspect(&priv->dstwidth, &priv->dstheight, A_ZOOM); 513 aspect(&priv->dstwidth, &priv->dstheight, A_ZOOM);
526 }
527 514
528 /* try to change to given fullscreenmode */ 515 /* try to change to given fullscreenmode */
529 vo_dwidth = priv->dstwidth; 516 vo_dwidth = priv->dstwidth;
530 vo_dheight = screen_surface_h; 517 vo_dheight = screen_surface_h;
531 newsurface = sdl_set_mode(priv->bpp, priv->sdlfullflags); 518 newsurface = sdl_set_mode(priv->bpp, priv->sdlfullflags);
851 case IMGFMT_BGR16: 838 case IMGFMT_BGR16:
852 case IMGFMT_RGB24: 839 case IMGFMT_RGB24:
853 case IMGFMT_BGR24: 840 case IMGFMT_BGR24:
854 case IMGFMT_RGB32: 841 case IMGFMT_RGB32:
855 case IMGFMT_BGR32: 842 case IMGFMT_BGR32:
856 if(priv->dblit) { 843 {
857 SDL_SRF_LOCK(priv->surface, -1) 844 SDL_Surface *sf = priv->dblit ? priv->surface : priv->rgbsurface;
858 dst = (uint8_t *) priv->surface->pixels + priv->y*priv->surface->pitch; 845 SDL_SRF_LOCK(sf, -1)
846 dst = (uint8_t *)sf->pixels + priv->y*sf->pitch;
859 if (priv->flip) { 847 if (priv->flip) {
860 mysrc += (priv->height - 1) * srcstride; 848 mysrc += (priv->height - 1) * srcstride;
861 srcstride = -srcstride; 849 srcstride = -srcstride;
862 } 850 }
863 memcpy_pic(dst, mysrc, priv->stridePlaneRGB, priv->height, 851 memcpy_pic(dst, mysrc, priv->stridePlaneRGB, priv->height,
864 priv->surface->pitch, srcstride); 852 sf->pitch, srcstride);
865 SDL_SRF_UNLOCK(priv->surface) 853 SDL_SRF_UNLOCK(sf)
866 } else {
867 SDL_SRF_LOCK(priv->rgbsurface, -1)
868 dst = (uint8_t *) priv->rgbsurface->pixels + priv->y*priv->rgbsurface->pitch;
869 if (priv->flip) {
870 mysrc += (priv->height - 1) * srcstride;
871 srcstride = -srcstride;
872 }
873 memcpy_pic(dst, mysrc, priv->stridePlaneRGB, priv->height,
874 priv->rgbsurface->pitch, srcstride);
875 SDL_SRF_UNLOCK(priv->rgbsurface)
876 } 854 }
877 break; 855 break;
878 856
879 } 857 }
880 858
1079 case IMGFMT_RGB24: 1057 case IMGFMT_RGB24:
1080 case IMGFMT_BGR24: 1058 case IMGFMT_BGR24:
1081 case IMGFMT_RGB32: 1059 case IMGFMT_RGB32:
1082 case IMGFMT_BGR32: 1060 case IMGFMT_BGR32:
1083 { 1061 {
1062 SDL_Surface *sf = priv->dblit ? priv->surface : priv->rgbsurface;
1084 SDL_Rect rect; 1063 SDL_Rect rect;
1085 rect.w = w; rect.h = h; 1064 rect.w = w; rect.h = h;
1086 rect.x = x; rect.y = y; 1065 rect.x = x; rect.y = y;
1087 1066
1088 if(priv->dblit) { 1067 SDL_SRF_LOCK(sf, (void) 0)
1089 SDL_SRF_LOCK(priv->surface, (void) 0) 1068 SDL_FillRect(sf, &rect, 0);
1090 SDL_FillRect(priv->surface, &rect, 0); 1069 SDL_SRF_UNLOCK(sf)
1091 SDL_SRF_UNLOCK(priv->surface)
1092 }
1093 else {
1094 SDL_SRF_LOCK(priv->rgbsurface, (void) 0)
1095 SDL_FillRect(priv->rgbsurface, &rect, 0);
1096 SDL_SRF_UNLOCK(priv->rgbsurface)
1097 }
1098 break; 1070 break;
1099 } 1071 }
1100 } 1072 }
1101 } 1073 }
1102 1074
1123 1095
1124 /* update osd/subtitles */ 1096 /* update osd/subtitles */
1125 if(priv->mode == YUV) 1097 if(priv->mode == YUV)
1126 vo_draw_text(priv->overlay->w, priv->overlay->h, draw_alpha); 1098 vo_draw_text(priv->overlay->w, priv->overlay->h, draw_alpha);
1127 else { 1099 else {
1128 if(priv->dblit) 1100 SDL_Surface *sf = priv->dblit ? priv->surface : priv->rgbsurface;
1129 vo_draw_text(priv->surface->w, priv->surface->h, draw_alpha); 1101 vo_draw_text(sf->w, sf->h, draw_alpha);
1130 else
1131 vo_draw_text(priv->rgbsurface->w, priv->rgbsurface->h, draw_alpha);
1132 } 1102 }
1133 } 1103 }
1134 1104
1135 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch' 1105 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1136 * are given in bytes. 4 bytes at a time. 1106 * are given in bytes. 4 bytes at a time.
1336 FFSWAP(void *, mpi->planes[1], mpi->planes[2]); 1306 FFSWAP(void *, mpi->planes[1], mpi->planes[2]);
1337 FFSWAP(int, mpi->stride[1], mpi->stride[2]); 1307 FFSWAP(int, mpi->stride[1], mpi->stride[2]);
1338 } 1308 }
1339 } 1309 }
1340 else if(IMGFMT_IS_RGB(priv->format) || IMGFMT_IS_BGR(priv->format)) { 1310 else if(IMGFMT_IS_RGB(priv->format) || IMGFMT_IS_BGR(priv->format)) {
1341 if(priv->dblit) { 1311 SDL_Surface *sf = priv->dblit ? priv->surface : priv->rgbsurface;
1342 if(mpi->type == MP_IMGTYPE_STATIC && (priv->surface->flags & SDL_DOUBLEBUF)) 1312 if(priv->dblit && mpi->type == MP_IMGTYPE_STATIC && (priv->surface->flags & SDL_DOUBLEBUF))
1343 return VO_FALSE; 1313 return VO_FALSE;
1344 1314
1345 mpi->planes[0] = (uint8_t *)priv->surface->pixels + priv->y*priv->surface->pitch; 1315 mpi->planes[0] = (uint8_t *)sf->pixels + priv->y*sf->pitch;
1346 mpi->stride[0] = priv->surface->pitch; 1316 mpi->stride[0] = sf->pitch;
1347 }
1348 else {
1349 mpi->planes[0] = (uint8_t *)priv->rgbsurface->pixels + priv->y*priv->rgbsurface->pitch;
1350 mpi->stride[0] = priv->rgbsurface->pitch;
1351 }
1352 } 1317 }
1353 else { 1318 else {
1354 mpi->planes[0] = priv->overlay->pixels[0] + priv->y*priv->overlay->pitches[0]; 1319 mpi->planes[0] = priv->overlay->pixels[0] + priv->y*priv->overlay->pitches[0];
1355 mpi->stride[0] = priv->overlay->pitches[0]; 1320 mpi->stride[0] = priv->overlay->pitches[0];
1356 } 1321 }