1 /*  RetroArch - A frontend for libretro.
2  *  Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  *  Copyright (C) 2011-2017 - Daniel De Matteis
4  *  Copyright (C) 2011-2017 - Higor Euripedes
5  *
6  *  RetroArch is free software: you can redistribute it and/or modify it under the terms
7  *  of the GNU General Public License as published by the Free Software Found-
8  *  ation, either version 3 of the License, or (at your option) any later version.
9  *
10  *  RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  *  PURPOSE.  See the GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along with RetroArch.
15  *  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include <retro_inline.h>
22 #include <gfx/scaler/scaler.h>
23 
24 #ifdef HAVE_CONFIG_H
25 #include "../../config.h"
26 #endif
27 
28 #ifdef HAVE_X11
29 #include "../common/x11_common.h"
30 #endif
31 
32 #ifdef HAVE_MENU
33 #include "../../menu/menu_driver.h"
34 #endif
35 
36 #include "SDL.h"
37 #include "SDL_syswm.h"
38 #include "../common/sdl2_common.h"
39 
40 #include "../font_driver.h"
41 
42 #include "../../configuration.h"
43 #include "../../retroarch.h"
44 #include "../../verbosity.h"
45 
46 static void sdl2_gfx_free(void *data);
47 
sdl_tex_zero(sdl2_tex_t * t)48 static INLINE void sdl_tex_zero(sdl2_tex_t *t)
49 {
50    if (t->tex)
51       SDL_DestroyTexture(t->tex);
52 
53    t->tex = NULL;
54    t->w = t->h = t->pitch = 0;
55 }
56 
sdl2_init_font(sdl2_video_t * vid,const char * font_path,unsigned font_size)57 static void sdl2_init_font(sdl2_video_t *vid, const char *font_path,
58       unsigned font_size)
59 {
60    int i, r, g, b;
61    SDL_Color colors[256];
62    SDL_Surface               *tmp = NULL;
63    SDL_Palette               *pal = NULL;
64    const struct font_atlas *atlas = NULL;
65    settings_t           *settings = config_get_ptr();
66    bool video_font_enable         = settings->bools.video_font_enable;
67    float msg_color_r              = settings->floats.video_msg_color_r;
68    float msg_color_g              = settings->floats.video_msg_color_g;
69    float msg_color_b              = settings->floats.video_msg_color_b;
70 
71    if (!video_font_enable)
72       return;
73 
74    if (!font_renderer_create_default(
75             &vid->font_driver, &vid->font_data,
76             *font_path ? font_path : NULL, font_size))
77    {
78       RARCH_WARN("[SDL]: Could not initialize fonts.\n");
79       return;
80    }
81 
82    r           = msg_color_r * 255;
83    g           = msg_color_g * 255;
84    b           = msg_color_b * 255;
85 
86    r           = (r < 0) ? 0 : (r > 255 ? 255 : r);
87    g           = (g < 0) ? 0 : (g > 255 ? 255 : g);
88    b           = (b < 0) ? 0 : (b > 255 ? 255 : b);
89 
90    vid->font_r = r;
91    vid->font_g = g;
92    vid->font_b = b;
93 
94    atlas       = vid->font_driver->get_atlas(vid->font_data);
95 
96    tmp         = SDL_CreateRGBSurfaceFrom(
97          atlas->buffer, atlas->width,
98          atlas->height, 8, atlas->width,
99          0, 0, 0, 0);
100 
101    for (i = 0; i < 256; ++i)
102    {
103       colors[i].r = colors[i].g = colors[i].b = i;
104       colors[i].a = 255;
105    }
106 
107    pal = SDL_AllocPalette(256);
108    SDL_SetPaletteColors(pal, colors, 0, 256);
109    SDL_SetSurfacePalette(tmp, pal);
110    SDL_SetColorKey(tmp, SDL_TRUE, 0);
111 
112    vid->font.tex  = SDL_CreateTextureFromSurface(vid->renderer, tmp);
113 
114    if (vid->font.tex)
115    {
116       vid->font.w      = atlas->width;
117       vid->font.h      = atlas->height;
118       vid->font.active = true;
119 
120       SDL_SetTextureBlendMode(vid->font.tex, SDL_BLENDMODE_ADD);
121    }
122    else
123       RARCH_WARN("[SDL]: Failed to initialize font texture: %s\n", SDL_GetError());
124 
125    SDL_FreePalette(pal);
126    SDL_FreeSurface(tmp);
127 }
128 
sdl2_render_msg(sdl2_video_t * vid,const char * msg)129 static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
130 {
131    int delta_x          = 0;
132    int delta_y          = 0;
133    unsigned      width  = vid->vp.width;
134    unsigned      height = vid->vp.height;
135    settings_t *settings = config_get_ptr();
136    float msg_pos_x      = settings->floats.video_msg_pos_x;
137    float msg_pos_y      = settings->floats.video_msg_pos_y;
138    int x                = msg_pos_x * width;
139    int y                = (1.0f - msg_pos_y) * height;
140 
141    if (!vid->font_data)
142       return;
143 
144    SDL_SetTextureColorMod(vid->font.tex,
145          vid->font_r, vid->font_g, vid->font_b);
146 
147    for (; *msg; msg++)
148    {
149       SDL_Rect src_rect, dst_rect;
150       int off_x, off_y, tex_x, tex_y;
151       const struct font_glyph *gly =
152          vid->font_driver->get_glyph(vid->font_data, (uint8_t)*msg);
153 
154       if (!gly)
155          gly = vid->font_driver->get_glyph(vid->font_data, '?');
156 
157       if (!gly)
158          continue;
159 
160       off_x      = gly->draw_offset_x;
161       off_y      = gly->draw_offset_y;
162       tex_x      = gly->atlas_offset_x;
163       tex_y      = gly->atlas_offset_y;
164 
165       src_rect.x = tex_x;
166       src_rect.y = tex_y;
167       src_rect.w = (int)gly->width;
168       src_rect.h = (int)gly->height;
169 
170       dst_rect.x = x + delta_x + off_x;
171       dst_rect.y = y + delta_y + off_y;
172       dst_rect.w = (int)gly->width;
173       dst_rect.h = (int)gly->height;
174 
175       SDL_RenderCopyEx(vid->renderer, vid->font.tex,
176             &src_rect, &dst_rect, 0, NULL, SDL_FLIP_NONE);
177 
178       delta_x += gly->advance_x;
179       delta_y -= gly->advance_y;
180    }
181 }
182 
sdl2_init_renderer(sdl2_video_t * vid)183 static void sdl2_init_renderer(sdl2_video_t *vid)
184 {
185    unsigned flags = SDL_RENDERER_ACCELERATED;
186 
187    if (vid->video.vsync)
188       flags |= SDL_RENDERER_PRESENTVSYNC;
189 
190    SDL_ClearHints();
191    SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC,
192                            vid->video.vsync ? "1" : "0", SDL_HINT_OVERRIDE);
193    vid->renderer = SDL_CreateRenderer(vid->window, -1, flags);
194 
195    if (!vid->renderer)
196    {
197       RARCH_ERR("[SDL2]: Failed to initialize renderer: %s", SDL_GetError());
198       return;
199    }
200 
201    SDL_SetRenderDrawColor(vid->renderer, 0, 0, 0, 255);
202 }
203 
sdl_refresh_renderer(sdl2_video_t * vid)204 static void sdl_refresh_renderer(sdl2_video_t *vid)
205 {
206    SDL_Rect r;
207 
208    SDL_RenderClear(vid->renderer);
209 
210    r.x      = vid->vp.x;
211    r.y      = vid->vp.y;
212    r.w      = (int)vid->vp.width;
213    r.h      = (int)vid->vp.height;
214 
215    SDL_RenderSetViewport(vid->renderer, &r);
216 
217    /* breaks int scaling */
218 #if 0
219    SDL_RenderSetLogicalSize(vid->renderer, vid->vp.width, vid->vp.height);
220 #endif
221 }
222 
sdl_refresh_viewport(sdl2_video_t * vid)223 static void sdl_refresh_viewport(sdl2_video_t *vid)
224 {
225    int win_w, win_h;
226    settings_t *settings      = config_get_ptr();
227    bool video_scale_integer  = settings->bools.video_scale_integer;
228    unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
229 
230    SDL_GetWindowSize(vid->window, &win_w, &win_h);
231 
232    vid->vp.x           = 0;
233    vid->vp.y           = 0;
234    vid->vp.width       = win_w;
235    vid->vp.height      = win_h;
236    vid->vp.full_width  = win_w;
237    vid->vp.full_height = win_h;
238 
239    if (video_scale_integer)
240       video_viewport_get_scaled_integer(&vid->vp,
241             win_w, win_h, video_driver_get_aspect_ratio(),
242             vid->video.force_aspect);
243    else if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
244    {
245       const struct video_viewport *custom =
246          (const struct video_viewport*)video_viewport_get_custom();
247 
248       vid->vp.x = custom->x;
249       vid->vp.y = custom->y;
250       vid->vp.width  = custom->width;
251       vid->vp.height = custom->height;
252    }
253    else if (vid->video.force_aspect)
254    {
255       float delta;
256       float device_aspect  = (float)win_w / win_h;
257       float desired_aspect = video_driver_get_aspect_ratio();
258 
259       if (fabsf(device_aspect - desired_aspect) < 0.0001f)
260       {
261          /* If the aspect ratios of screen and desired aspect ratio are
262              * sufficiently equal (floating point stuff), assume they are
263              * actually equal. */
264       }
265       else if (device_aspect > desired_aspect)
266       {
267          delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
268          vid->vp.x     = (int)roundf(win_w * (0.5f - delta));
269          vid->vp.width = (unsigned)roundf(2.0f * win_w * delta);
270       }
271       else
272       {
273          delta  = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
274          vid->vp.y      = (int)roundf(win_h * (0.5f - delta));
275          vid->vp.height = (unsigned)roundf(2.0f * win_h * delta);
276       }
277    }
278 
279    vid->should_resize = false;
280 
281    sdl_refresh_renderer(vid);
282 }
283 
sdl_refresh_input_size(sdl2_video_t * vid,bool menu,bool rgb32,unsigned width,unsigned height,unsigned pitch)284 static void sdl_refresh_input_size(sdl2_video_t *vid, bool menu, bool rgb32,
285       unsigned width, unsigned height, unsigned pitch)
286 {
287    sdl2_tex_t *target = menu ? &vid->menu : &vid->frame;
288 
289    if (!target->tex || target->w != width || target->h != height
290        || target->rgb32 != rgb32 || target->pitch != pitch)
291    {
292       unsigned format;
293 
294       sdl_tex_zero(target);
295 
296       if (menu)
297          format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGBA4444;
298       else /* this assumes the frontend will convert 0RGB1555 to RGB565 */
299          format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGB565;
300 
301       SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
302                               (vid->video.smooth || menu) ? "linear" : "nearest",
303                               SDL_HINT_OVERRIDE);
304 
305       target->tex = SDL_CreateTexture(vid->renderer, format,
306                                       SDL_TEXTUREACCESS_STREAMING, width, height);
307 
308       if (!target->tex)
309       {
310          RARCH_ERR("[SDL2]: Failed to create %s texture: %s\n", menu ? "menu" : "main",
311                    SDL_GetError());
312          return;
313       }
314 
315       if (menu)
316          SDL_SetTextureBlendMode(target->tex, SDL_BLENDMODE_BLEND);
317 
318       target->w = width;
319       target->h = height;
320       target->pitch = pitch;
321       target->rgb32 = rgb32;
322 
323       /* If target is menu, do not override 'active'
324        * state (this should only be set by
325        * sdl2_poke_texture_enable()) */
326       if (!menu)
327          target->active = true;
328    }
329 }
330 
sdl2_gfx_init(const video_info_t * video,input_driver_t ** input,void ** input_data)331 static void *sdl2_gfx_init(const video_info_t *video,
332       input_driver_t **input, void **input_data)
333 {
334    int i;
335    unsigned flags;
336    sdl2_video_t *vid            = NULL;
337    uint32_t sdl_subsystem_flags = SDL_WasInit(0);
338    settings_t *settings         = config_get_ptr();
339 #if defined(HAVE_X11) || defined(HAVE_WAYLAND)
340    const char *video_driver     = NULL;
341 #endif
342 
343 #ifdef HAVE_X11
344    XInitThreads();
345 #endif
346 
347    /* Initialise graphics subsystem, if required */
348    if (sdl_subsystem_flags == 0)
349    {
350       if (SDL_Init(SDL_INIT_VIDEO) < 0)
351          return NULL;
352    }
353    else if ((sdl_subsystem_flags & SDL_INIT_VIDEO) == 0)
354    {
355       if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
356          return NULL;
357    }
358 
359    vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
360    if (!vid)
361       return NULL;
362 
363    RARCH_LOG("[SDL2]: Available renderers (change with $SDL_RENDER_DRIVER):\n");
364    for (i = 0; i < SDL_GetNumRenderDrivers(); ++i)
365    {
366       SDL_RendererInfo renderer;
367       if (SDL_GetRenderDriverInfo(i, &renderer) == 0)
368          RARCH_LOG("\t%s\n", renderer.name);
369    }
370 
371    RARCH_LOG("[SDL2]: Available displays:\n");
372    for (i = 0; i < SDL_GetNumVideoDisplays(); ++i)
373    {
374       SDL_DisplayMode mode;
375 
376       if (SDL_GetCurrentDisplayMode(i, &mode) < 0)
377          RARCH_LOG("\tDisplay #%i mode: unknown.\n", i);
378       else
379          RARCH_LOG("\tDisplay #%i mode: %ix%i@%ihz.\n", i, mode.w, mode.h,
380                    mode.refresh_rate);
381    }
382 
383    if (!video->fullscreen)
384       RARCH_LOG("[SDL]: Creating window @ %ux%u\n", video->width, video->height);
385 
386    if (video->fullscreen)
387       flags = settings->bools.video_windowed_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
388    else
389       flags = SDL_WINDOW_RESIZABLE;
390 
391    vid->window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
392                                   video->width, video->height, flags);
393 
394    if (!vid->window)
395    {
396       RARCH_ERR("[SDL2]: Failed to init SDL window: %s\n", SDL_GetError());
397       goto error;
398    }
399 
400    vid->video         = *video;
401    vid->video.smooth  = video->smooth;
402    vid->should_resize = true;
403 
404    sdl_tex_zero(&vid->frame);
405    sdl_tex_zero(&vid->menu);
406 
407    if (video->fullscreen)
408       SDL_ShowCursor(SDL_DISABLE);
409 
410    sdl2_init_renderer(vid);
411    sdl2_init_font(vid,
412          settings->paths.path_font,
413          settings->floats.video_font_size);
414 
415 #if defined(_WIN32)
416    sdl2_set_handles(vid->window, RARCH_DISPLAY_WIN32);
417 #elif defined(HAVE_COCOA)
418    sdl2_set_handles(vid->window, RARCH_DISPLAY_OSX);
419 #else
420 #if defined(HAVE_X11) || defined(HAVE_WAYLAND)
421    video_driver = SDL_GetCurrentVideoDriver();
422 #endif
423 #ifdef HAVE_X11
424    if (strcmp(video_driver, "x11") == 0)
425       sdl2_set_handles(vid->window, RARCH_DISPLAY_X11);
426    else
427 #endif
428 #ifdef HAVE_WAYLAND
429    if (strcmp(video_driver, "wayland") == 0)
430       sdl2_set_handles(vid->window, RARCH_DISPLAY_WAYLAND);
431    else
432 #endif
433       sdl2_set_handles(vid->window, RARCH_DISPLAY_NONE);
434 #endif
435 
436    sdl_refresh_viewport(vid);
437 
438    *input      = NULL;
439    *input_data = NULL;
440 
441    return vid;
442 
443 error:
444    sdl2_gfx_free(vid);
445    return NULL;
446 }
447 
check_window(sdl2_video_t * vid)448 static void check_window(sdl2_video_t *vid)
449 {
450    SDL_Event event;
451 
452    SDL_PumpEvents();
453    while (SDL_PeepEvents(&event, 1,
454             SDL_GETEVENT, SDL_QUIT, SDL_WINDOWEVENT) > 0)
455    {
456       switch (event.type)
457       {
458          case SDL_QUIT:
459             vid->quitting = true;
460             break;
461 
462          case SDL_WINDOWEVENT:
463             if (event.window.event == SDL_WINDOWEVENT_RESIZED)
464                vid->should_resize = true;
465             break;
466 
467          default:
468             break;
469       }
470    }
471 }
472 
sdl2_gfx_frame(void * data,const void * frame,unsigned width,unsigned height,uint64_t frame_count,unsigned pitch,const char * msg,video_frame_info_t * video_info)473 static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width,
474       unsigned height, uint64_t frame_count,
475       unsigned pitch, const char *msg, video_frame_info_t *video_info)
476 {
477    char title[128];
478    sdl2_video_t *vid     = (sdl2_video_t*)data;
479 #ifdef HAVE_MENU
480    bool menu_is_alive    = video_info->menu_is_alive;
481 #endif
482 
483    if (vid->should_resize)
484       sdl_refresh_viewport(vid);
485 
486    if (frame)
487    {
488       SDL_RenderClear(vid->renderer);
489       sdl_refresh_input_size(vid, false, vid->video.rgb32, width, height, pitch);
490       SDL_UpdateTexture(vid->frame.tex, NULL, frame, pitch);
491    }
492 
493    SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE);
494 
495 #ifdef HAVE_MENU
496    menu_driver_frame(menu_is_alive, video_info);
497 #endif
498 
499    if (vid->menu.active)
500       SDL_RenderCopy(vid->renderer, vid->menu.tex, NULL, NULL);
501 
502    if (msg)
503       sdl2_render_msg(vid, msg);
504 
505    SDL_RenderPresent(vid->renderer);
506 
507    title[0] = '\0';
508 
509    video_driver_get_window_title(title, sizeof(title));
510 
511    if (title[0])
512       SDL_SetWindowTitle((SDL_Window*)video_driver_display_userdata_get(), title);
513 
514    return true;
515 }
516 
sdl2_gfx_set_nonblock_state(void * data,bool toggle,bool adaptive_vsync_enabled,unsigned swap_interval)517 static void sdl2_gfx_set_nonblock_state(void *data, bool toggle,
518       bool adaptive_vsync_enabled, unsigned swap_interval)
519 {
520    sdl2_video_t *vid = (sdl2_video_t*)data;
521 
522    vid->video.vsync  = !toggle;
523    sdl_refresh_renderer(vid);
524 }
525 
sdl2_gfx_alive(void * data)526 static bool sdl2_gfx_alive(void *data)
527 {
528    sdl2_video_t *vid = (sdl2_video_t*)data;
529    check_window(vid);
530    return !vid->quitting;
531 }
532 
sdl2_gfx_focus(void * data)533 static bool sdl2_gfx_focus(void *data)
534 {
535    sdl2_video_t *vid = (sdl2_video_t*)data;
536    unsigned flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
537    return (SDL_GetWindowFlags(vid->window) & flags) == flags;
538 }
539 
sdl2_gfx_suppress_screensaver(void * data,bool enable)540 static bool sdl2_gfx_suppress_screensaver(void *data, bool enable)
541 {
542    (void)data;
543    (void)enable;
544 
545    if (video_driver_display_type_get() == RARCH_DISPLAY_X11)
546    {
547 #ifdef HAVE_X11
548       x11_suspend_screensaver(video_driver_window_get(), enable);
549 #endif
550       return true;
551    }
552 
553    return false;
554 }
555 
sdl2_gfx_has_windowed(void * data)556 static bool sdl2_gfx_has_windowed(void *data)
557 {
558    (void)data;
559 
560    /* TODO - implement */
561 
562    return true;
563 }
564 
sdl2_gfx_free(void * data)565 static void sdl2_gfx_free(void *data)
566 {
567    sdl2_video_t *vid = (sdl2_video_t*)data;
568    if (!vid)
569       return;
570 
571    if (vid->renderer)
572       SDL_DestroyRenderer(vid->renderer);
573 
574    if (vid->window)
575       SDL_DestroyWindow(vid->window);
576 
577    if (vid->font_data)
578       vid->font_driver->free(vid->font_data);
579 
580    free(vid);
581 }
582 
sdl2_gfx_set_rotation(void * data,unsigned rotation)583 static void sdl2_gfx_set_rotation(void *data, unsigned rotation)
584 {
585    sdl2_video_t *vid = (sdl2_video_t*)data;
586 
587    if (vid)
588       vid->rotation = 270 * rotation;
589 }
590 
sdl2_gfx_viewport_info(void * data,struct video_viewport * vp)591 static void sdl2_gfx_viewport_info(void *data, struct video_viewport *vp)
592 {
593    sdl2_video_t *vid = (sdl2_video_t*)data;
594    *vp = vid->vp;
595 }
596 
sdl2_gfx_read_viewport(void * data,uint8_t * buffer,bool is_idle)597 static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle)
598 {
599    SDL_Surface *surf = NULL, *bgr24 = NULL;
600    sdl2_video_t *vid = (sdl2_video_t*)data;
601 
602    if (!is_idle)
603       video_driver_cached_frame();
604 
605    surf  = SDL_GetWindowSurface(vid->window);
606    bgr24 = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_BGR24, 0);
607 
608    if (!bgr24)
609    {
610       RARCH_WARN("Failed to convert viewport data to BGR24: %s", SDL_GetError());
611       return false;
612    }
613 
614    memcpy(buffer, bgr24->pixels, bgr24->h * bgr24->pitch);
615 
616    return true;
617 }
618 
sdl2_poke_set_filtering(void * data,unsigned index,bool smooth,bool ctx_scaling)619 static void sdl2_poke_set_filtering(void *data, unsigned index, bool smooth, bool ctx_scaling)
620 {
621    sdl2_video_t *vid = (sdl2_video_t*)data;
622    vid->video.smooth = smooth;
623 
624    sdl_tex_zero(&vid->frame);
625 }
626 
sdl2_poke_set_aspect_ratio(void * data,unsigned aspect_ratio_idx)627 static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
628 {
629    sdl2_video_t *vid    = (sdl2_video_t*)data;
630 
631    /* FIXME: Why is vid NULL here when starting content? */
632    if (!vid)
633       return;
634 
635    vid->video.force_aspect = true;
636    vid->should_resize      = true;
637 }
638 
sdl2_poke_apply_state_changes(void * data)639 static void sdl2_poke_apply_state_changes(void *data)
640 {
641    sdl2_video_t *vid = (sdl2_video_t*)data;
642    vid->should_resize = true;
643 }
644 
sdl2_poke_set_texture_frame(void * data,const void * frame,bool rgb32,unsigned width,unsigned height,float alpha)645 static void sdl2_poke_set_texture_frame(void *data,
646       const void *frame, bool rgb32,
647       unsigned width, unsigned height, float alpha)
648 {
649    if (frame)
650    {
651       sdl2_video_t *vid = (sdl2_video_t*)data;
652 
653       sdl_refresh_input_size(vid, true, rgb32, width, height,
654             width * (rgb32 ? 4 : 2));
655 
656       SDL_UpdateTexture(vid->menu.tex, NULL, frame, vid->menu.pitch);
657    }
658 }
659 
sdl2_poke_texture_enable(void * data,bool enable,bool full_screen)660 static void sdl2_poke_texture_enable(void *data,
661       bool enable, bool full_screen)
662 {
663    sdl2_video_t *vid   = (sdl2_video_t*)data;
664 
665    if (!vid)
666       return;
667 
668    vid->menu.active = enable;
669 }
670 
sdl2_poke_set_osd_msg(void * data,const char * msg,const void * params,void * font)671 static void sdl2_poke_set_osd_msg(void *data,
672       const char *msg,
673       const void *params, void *font)
674 {
675    sdl2_video_t *vid = (sdl2_video_t*)data;
676    sdl2_render_msg(vid, msg);
677 }
678 
sdl2_show_mouse(void * data,bool state)679 static void sdl2_show_mouse(void *data, bool state) { SDL_ShowCursor(state); }
sdl2_grab_mouse_toggle(void * data)680 static void sdl2_grab_mouse_toggle(void *data)
681 {
682    sdl2_video_t *vid = (sdl2_video_t*)data;
683    SDL_SetWindowGrab(vid->window, SDL_GetWindowGrab(vid->window));
684 }
sdl2_get_flags(void * data)685 static uint32_t sdl2_get_flags(void *data) { return 0; }
686 
687 static video_poke_interface_t sdl2_video_poke_interface = {
688    sdl2_get_flags,
689    NULL,
690    NULL,
691    NULL,
692    NULL, /* get_refresh_rate */
693    sdl2_poke_set_filtering,
694    NULL, /* get_video_output_size */
695    NULL, /* get_video_output_prev */
696    NULL, /* get_video_output_next */
697    NULL, /* get_current_framebuffer */
698    NULL, /* get_proc_address */
699    sdl2_poke_set_aspect_ratio,
700    sdl2_poke_apply_state_changes,
701    sdl2_poke_set_texture_frame,
702    sdl2_poke_texture_enable,
703    sdl2_poke_set_osd_msg,
704    sdl2_show_mouse,
705    sdl2_grab_mouse_toggle,
706    NULL,                         /* get_current_shader */
707    NULL,                         /* get_current_software_framebuffer */
708    NULL                          /* get_hw_render_interface */
709 };
710 
sdl2_gfx_poke_interface(void * data,const video_poke_interface_t ** iface)711 static void sdl2_gfx_poke_interface(void *data, const video_poke_interface_t **iface)
712 {
713    (void)data;
714    *iface = &sdl2_video_poke_interface;
715 }
716 
sdl2_gfx_set_shader(void * data,enum rarch_shader_type type,const char * path)717 static bool sdl2_gfx_set_shader(void *data,
718       enum rarch_shader_type type, const char *path)
719 {
720    (void)data;
721    (void)type;
722    (void)path;
723 
724    return false;
725 }
726 
727 video_driver_t video_sdl2 = {
728    sdl2_gfx_init,
729    sdl2_gfx_frame,
730    sdl2_gfx_set_nonblock_state,
731    sdl2_gfx_alive,
732    sdl2_gfx_focus,
733    sdl2_gfx_suppress_screensaver,
734    sdl2_gfx_has_windowed,
735    sdl2_gfx_set_shader,
736    sdl2_gfx_free,
737    "sdl2",
738 
739    NULL,
740    sdl2_gfx_set_rotation,
741    sdl2_gfx_viewport_info,
742    sdl2_gfx_read_viewport,
743    NULL, /* read_frame_raw */
744 #ifdef HAVE_OVERLAY
745     NULL,
746 #endif
747 #ifdef HAVE_VIDEO_LAYOUT
748   NULL,
749 #endif
750     sdl2_gfx_poke_interface
751 };
752