28 |
28 |
29 #include "video/SDL_sysvideo.h" |
29 #include "video/SDL_sysvideo.h" |
30 #include "video/SDL_pixels_c.h" |
30 #include "video/SDL_pixels_c.h" |
31 #include "video/SDL_yuv_sw_c.h" |
31 #include "video/SDL_yuv_sw_c.h" |
32 |
32 |
33 static SDL_WindowID SDL_VideoWindow = 0; |
33 static SDL_Window *SDL_VideoWindow = NULL; |
34 static SDL_RendererInfo SDL_VideoRendererInfo; |
34 static SDL_RendererInfo SDL_VideoRendererInfo; |
35 static SDL_TextureID SDL_VideoTexture = 0; |
35 static SDL_Texture *SDL_VideoTexture = NULL; |
36 static SDL_Surface *SDL_VideoSurface = NULL; |
36 static SDL_Surface *SDL_VideoSurface = NULL; |
37 static SDL_Surface *SDL_ShadowSurface = NULL; |
37 static SDL_Surface *SDL_ShadowSurface = NULL; |
38 static SDL_Surface *SDL_PublicSurface = NULL; |
38 static SDL_Surface *SDL_PublicSurface = NULL; |
39 static SDL_GLContext *SDL_VideoContext = NULL; |
39 static SDL_GLContext *SDL_VideoContext = NULL; |
40 static Uint32 SDL_VideoFlags = 0; |
40 static Uint32 SDL_VideoFlags = 0; |
292 button = SDL_BUTTON_WHEELUP; |
292 button = SDL_BUTTON_WHEELUP; |
293 } else { |
293 } else { |
294 button = SDL_BUTTON_WHEELDOWN; |
294 button = SDL_BUTTON_WHEELDOWN; |
295 } |
295 } |
296 |
296 |
297 fake.button.which = event->wheel.windowID; |
297 fake.button.which = event->wheel.which; |
298 fake.button.button = button; |
298 fake.button.button = button; |
299 fake.button.x = x; |
299 fake.button.x = x; |
300 fake.button.y = y; |
300 fake.button.y = y; |
301 fake.button.windowID = event->wheel.windowID; |
301 fake.button.windowID = event->wheel.windowID; |
302 |
302 |
355 *y = (mode.h - h) / 2; |
355 *y = (mode.h - h) / 2; |
356 } |
356 } |
357 } |
357 } |
358 |
358 |
359 static SDL_Surface * |
359 static SDL_Surface * |
360 CreateVideoSurface(SDL_TextureID textureID) |
360 CreateVideoSurface(SDL_Texture * texture) |
361 { |
361 { |
362 SDL_Surface *surface; |
362 SDL_Surface *surface; |
363 Uint32 format; |
363 Uint32 format; |
364 int w, h; |
364 int w, h; |
365 int bpp; |
365 int bpp; |
366 Uint32 Rmask, Gmask, Bmask, Amask; |
366 Uint32 Rmask, Gmask, Bmask, Amask; |
367 void *pixels; |
367 void *pixels; |
368 int pitch; |
368 int pitch; |
369 |
369 |
370 if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) { |
370 if (SDL_QueryTexture(texture, &format, NULL, &w, &h) < 0) { |
371 return NULL; |
371 return NULL; |
372 } |
372 } |
373 |
373 |
374 if (!SDL_PixelFormatEnumToMasks |
374 if (!SDL_PixelFormatEnumToMasks |
375 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
375 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
376 SDL_SetError("Unknown texture format"); |
376 SDL_SetError("Unknown texture format"); |
377 return NULL; |
377 return NULL; |
378 } |
378 } |
379 |
379 |
380 if (SDL_QueryTexturePixels(textureID, &pixels, &pitch) == 0) { |
380 if (SDL_QueryTexturePixels(texture, &pixels, &pitch) == 0) { |
381 surface = |
381 surface = |
382 SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask, |
382 SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask, |
383 Bmask, Amask); |
383 Bmask, Amask); |
384 } else { |
384 } else { |
385 surface = |
385 surface = |
1502 Uint16 pitches[3]; |
1502 Uint16 pitches[3]; |
1503 Uint8 *planes[3]; |
1503 Uint8 *planes[3]; |
1504 |
1504 |
1505 SDL_SW_YUVTexture *sw; |
1505 SDL_SW_YUVTexture *sw; |
1506 |
1506 |
1507 SDL_TextureID textureID; |
1507 SDL_Texture *texture; |
1508 Uint32 texture_format; |
1508 Uint32 texture_format; |
1509 }; |
1509 }; |
1510 |
1510 |
1511 SDL_Overlay * |
1511 SDL_Overlay * |
1512 SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) |
1512 SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) |
1583 case SDL_YVYU_OVERLAY: |
1583 case SDL_YVYU_OVERLAY: |
1584 overlay->pitches[0] = overlay->w * 2; |
1584 overlay->pitches[0] = overlay->w * 2; |
1585 break; |
1585 break; |
1586 } |
1586 } |
1587 |
1587 |
1588 overlay->hwdata->textureID = |
1588 overlay->hwdata->texture = |
1589 SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h); |
1589 SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h); |
1590 if (overlay->hwdata->textureID) { |
1590 if (overlay->hwdata->texture) { |
1591 overlay->hwdata->sw = NULL; |
1591 overlay->hwdata->sw = NULL; |
1592 } else { |
1592 } else { |
1593 SDL_DisplayMode current_mode; |
1593 SDL_DisplayMode current_mode; |
1594 |
1594 |
1595 overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h); |
1595 overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h); |
1599 } |
1599 } |
1600 |
1600 |
1601 /* Create a supported RGB format texture for display */ |
1601 /* Create a supported RGB format texture for display */ |
1602 SDL_GetCurrentDisplayMode(¤t_mode); |
1602 SDL_GetCurrentDisplayMode(¤t_mode); |
1603 texture_format = current_mode.format; |
1603 texture_format = current_mode.format; |
1604 overlay->hwdata->textureID = |
1604 overlay->hwdata->texture = |
1605 SDL_CreateTexture(texture_format, |
1605 SDL_CreateTexture(texture_format, |
1606 SDL_TEXTUREACCESS_STREAMING, w, h); |
1606 SDL_TEXTUREACCESS_STREAMING, w, h); |
1607 } |
1607 } |
1608 if (!overlay->hwdata->textureID) { |
1608 if (!overlay->hwdata->texture) { |
1609 SDL_FreeYUVOverlay(overlay); |
1609 SDL_FreeYUVOverlay(overlay); |
1610 return NULL; |
1610 return NULL; |
1611 } |
1611 } |
1612 overlay->hwdata->texture_format = texture_format; |
1612 overlay->hwdata->texture_format = texture_format; |
1613 |
1613 |
1664 } |
1664 } |
1665 if (overlay->hwdata->sw) { |
1665 if (overlay->hwdata->sw) { |
1666 void *pixels; |
1666 void *pixels; |
1667 int pitch; |
1667 int pitch; |
1668 if (SDL_LockTexture |
1668 if (SDL_LockTexture |
1669 (overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) == 0) { |
1669 (overlay->hwdata->texture, NULL, 1, &pixels, &pitch) == 0) { |
1670 SDL_Rect srcrect; |
1670 SDL_Rect srcrect; |
1671 |
1671 |
1672 srcrect.x = 0; |
1672 srcrect.x = 0; |
1673 srcrect.y = 0; |
1673 srcrect.y = 0; |
1674 srcrect.w = overlay->w; |
1674 srcrect.w = overlay->w; |
1675 srcrect.h = overlay->h; |
1675 srcrect.h = overlay->h; |
1676 SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect, |
1676 SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect, |
1677 overlay->hwdata->texture_format, |
1677 overlay->hwdata->texture_format, |
1678 overlay->w, overlay->h, pixels, pitch); |
1678 overlay->w, overlay->h, pixels, pitch); |
1679 SDL_UnlockTexture(overlay->hwdata->textureID); |
1679 SDL_UnlockTexture(overlay->hwdata->texture); |
1680 } |
1680 } |
1681 } else { |
1681 } else { |
1682 SDL_UnlockTexture(overlay->hwdata->textureID); |
1682 SDL_UnlockTexture(overlay->hwdata->texture); |
1683 } |
1683 } |
1684 } |
1684 } |
1685 |
1685 |
1686 int |
1686 int |
1687 SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) |
1687 SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect) |
1688 { |
1688 { |
1689 if (!overlay || !dstrect) { |
1689 if (!overlay || !dstrect) { |
1690 SDL_SetError("Passed a NULL overlay or dstrect"); |
1690 SDL_SetError("Passed a NULL overlay or dstrect"); |
1691 return -1; |
1691 return -1; |
1692 } |
1692 } |
1693 if (SDL_RenderCopy(overlay->hwdata->textureID, NULL, dstrect) < 0) { |
1693 if (SDL_RenderCopy(overlay->hwdata->texture, NULL, dstrect) < 0) { |
1694 return -1; |
1694 return -1; |
1695 } |
1695 } |
1696 SDL_RenderPresent(); |
1696 SDL_RenderPresent(); |
1697 return 0; |
1697 return 0; |
1698 } |
1698 } |