forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfx_display.c
1922 lines (1664 loc) · 58.6 KB
/
gfx_display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "gfx_display.h"
#include "gfx_animation.h"
#include "video_coord_array.h"
#include "../configuration.h"
#include "../verbosity.h"
#define PARTICLES_COUNT 100
/* Number of pixels corner-to-corner on a 1080p
* display:
* > sqrt((1920 * 1920) + (1080 * 1080))
* Note: This is a double, so no suffix */
#define DIAGONAL_PIXELS_1080P 2202.90717008229831581901
/* Standard reference DPI value, used when determining
* DPI-aware scaling factors */
#define REFERENCE_DPI 96.0f
/* 'OZONE_SIDEBAR_WIDTH' must be kept in sync
* with Ozone driver metrics */
#define OZONE_SIDEBAR_WIDTH 408
static float osk_dark[16] = {
0.00, 0.00, 0.00, 0.85,
0.00, 0.00, 0.00, 0.85,
0.00, 0.00, 0.00, 0.85,
0.00, 0.00, 0.00, 0.85,
};
/* TODO/FIXME - global that gets referenced outside,
* needs to be refactored */
uintptr_t gfx_display_white_texture;
struct gfx_display
{
bool has_windowed;
bool msg_force;
bool framebuf_dirty;
/* Width, height and pitch of the display framebuffer */
unsigned framebuf_width;
unsigned framebuf_height;
size_t framebuf_pitch;
/* Height of the display header */
unsigned header_height;
enum menu_driver_id_type menu_driver_id;
video_coord_array_t dispca;
};
typedef struct gfx_display gfx_display_t;
static gfx_display_t dispgfx;
static gfx_display_t *disp_get_ptr(void)
{
return &dispgfx;
}
static void *gfx_display_null_get_default_mvp(void *data) { return NULL; }
static void gfx_display_null_blend_begin(void *data) { }
static void gfx_display_null_blend_end(void *data) { }
static void gfx_display_null_draw(gfx_display_ctx_draw_t *draw,
void *data, unsigned width, unsigned height) { }
static void gfx_display_null_draw_pipeline(gfx_display_ctx_draw_t *draw,
void *data, unsigned width, unsigned height) { }
static void gfx_display_null_viewport(gfx_display_ctx_draw_t *draw, void *data) { }
static void gfx_display_null_restore_clear_color(void) { }
static void gfx_display_null_clear_color(gfx_display_ctx_clearcolor_t *clearcolor, void *data) { }
static bool gfx_display_null_font_init_first(
void **font_handle, void *video_data,
const char *font_path, float font_size,
bool is_threaded)
{
font_data_t **handle = (font_data_t**)font_handle;
if ((*handle = font_driver_init_first(video_data,
font_path, font_size, true,
is_threaded,
FONT_DRIVER_RENDER_DONT_CARE)))
return true;
return false;
}
static const float *gfx_display_null_get_default_vertices(void)
{
static float dummy[16] = {0.0f};
return &dummy[0];
}
static const float *gfx_display_null_get_default_tex_coords(void)
{
static float dummy[16] = {0.0f};
return &dummy[0];
}
gfx_display_ctx_driver_t gfx_display_ctx_null = {
gfx_display_null_draw,
gfx_display_null_draw_pipeline,
gfx_display_null_viewport,
gfx_display_null_blend_begin,
gfx_display_null_blend_end,
gfx_display_null_restore_clear_color,
gfx_display_null_clear_color,
gfx_display_null_get_default_mvp,
gfx_display_null_get_default_vertices,
gfx_display_null_get_default_tex_coords,
gfx_display_null_font_init_first,
GFX_VIDEO_DRIVER_GENERIC,
"null",
false,
NULL,
NULL
};
/* Menu display drivers */
static gfx_display_ctx_driver_t *gfx_display_ctx_drivers[] = {
#ifdef HAVE_D3D8
&gfx_display_ctx_d3d8,
#endif
#ifdef HAVE_D3D9
&gfx_display_ctx_d3d9,
#endif
#ifdef HAVE_D3D10
&gfx_display_ctx_d3d10,
#endif
#ifdef HAVE_D3D11
&gfx_display_ctx_d3d11,
#endif
#ifdef HAVE_D3D12
&gfx_display_ctx_d3d12,
#endif
#ifdef HAVE_OPENGL
&gfx_display_ctx_gl,
#endif
#ifdef HAVE_OPENGL1
&gfx_display_ctx_gl1,
#endif
#ifdef HAVE_OPENGL_CORE
&gfx_display_ctx_gl_core,
#endif
#ifdef HAVE_VULKAN
&gfx_display_ctx_vulkan,
#endif
#ifdef HAVE_METAL
&gfx_display_ctx_metal,
#endif
#ifdef HAVE_VITA2D
&gfx_display_ctx_vita2d,
#endif
#ifdef _3DS
&gfx_display_ctx_ctr,
#endif
#ifdef WIIU
&gfx_display_ctx_wiiu,
#endif
#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
#ifdef HAVE_GDI
&gfx_display_ctx_gdi,
#endif
#endif
&gfx_display_ctx_null,
NULL,
};
static gfx_display_ctx_driver_t *dispctx = NULL;
static INLINE float gfx_display_scalef(float val,
float oldmin, float oldmax, float newmin, float newmax)
{
return (((val - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
}
static INLINE float gfx_display_randf(float min, float max)
{
return (rand() * ((max - min) / RAND_MAX)) + min;
}
void gfx_display_set_driver_id(enum menu_driver_id_type type)
{
gfx_display_t *p_disp = disp_get_ptr();
p_disp->menu_driver_id = type;
}
enum menu_driver_id_type gfx_display_get_driver_id(void)
{
gfx_display_t *p_disp = disp_get_ptr();
return p_disp->menu_driver_id;
}
static float gfx_display_get_adjusted_scale_internal(
float base_scale, float scale_factor, unsigned width)
{
gfx_display_t *p_disp = disp_get_ptr();
/* Apply user-set scaling factor */
float adjusted_scale = base_scale * scale_factor;
#ifdef HAVE_OZONE
/* Ozone has a capped scale factor */
if (p_disp->menu_driver_id == MENU_DRIVER_ID_OZONE)
{
float new_width = (float)width * 0.3333333f;
adjusted_scale =
(((float)OZONE_SIDEBAR_WIDTH * adjusted_scale)
> new_width
? (new_width / (float)OZONE_SIDEBAR_WIDTH)
: adjusted_scale);
}
#endif
/* Ensure final scale is 'sane' */
return (adjusted_scale > 0.0001f) ? adjusted_scale : 1.0f;
}
float gfx_display_get_dpi_scale_internal(unsigned width, unsigned height)
{
float dpi;
float diagonal_pixels;
float pixel_scale;
static unsigned last_width = 0;
static unsigned last_height = 0;
static float scale = 0.0f;
static bool scale_cached = false;
gfx_ctx_metrics_t metrics;
if (scale_cached &&
(width == last_width) &&
(height == last_height))
return scale;
/* Determine the diagonal 'size' of the display
* (or window) in terms of pixels */
diagonal_pixels = (float)sqrt(
(double)((width * width) + (height * height)));
/* TODO/FIXME: On Mac, calling video_context_driver_get_metrics()
* here causes RetroArch to crash (EXC_BAD_ACCESS). This is
* unfortunate, and needs to be fixed at the gfx context driver
* level. Until this is done, all we can do is fallback to using
* the old legacy 'magic number' scaling on Mac platforms. */
#if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL)
if (true)
{
scale = (diagonal_pixels / 6.5f) / 212.0f;
scale_cached = true;
last_width = width;
last_height = height;
return scale;
}
#endif
/* Get pixel scale relative to baseline 1080p display */
pixel_scale = diagonal_pixels / DIAGONAL_PIXELS_1080P;
/* Attempt to get display DPI */
metrics.type = DISPLAY_METRIC_DPI;
metrics.value = &dpi;
if (video_context_driver_get_metrics(&metrics) && (dpi > 0.0f))
{
float display_size;
float dpi_scale;
#if defined(ANDROID) || defined(HAVE_COCOATOUCH)
/* Android/iOS devices tell complete lies when
* reporting DPI values. From the Android devices
* I've had access to, the DPI is generally
* overestimated by 17%. All we can do is apply
* a blind correction factor... */
dpi = dpi * 0.83f;
#endif
/* Note: If we are running in windowed mode, this
* 'display size' is actually the window size - which
* kinda makes a mess of everything. Since we cannot
* get fullscreen resolution when running in windowed
* mode, there is nothing we can do about this. So just
* treat the window as a display, and hope for the best... */
display_size = diagonal_pixels / dpi;
dpi_scale = dpi / REFERENCE_DPI;
/* Note: We have tried leveraging every possible metric
* (and numerous studies on TV/monitor/mobile device
* usage habits) to determine an appropriate auto scaling
* factor. *None of these 'smart'/technical methods work
* consistently in the real world* - there is simply too
* much variance.
* So instead we have implemented a very fuzzy/loose
* method which is crude as can be, but actually has
* some semblance of usability... */
if (display_size > 24.0f)
{
/* DPI scaling fails miserably when using large
* displays. Having a UI element that's 1 inch high
* on all screens might seem like a good idea - until
* you realise that a HTPC user is probably sitting
* several metres from their TV, which makes something
* 1 inch high virtually invisible.
* So we make some assumptions:
* - Normal size displays <= 24 inches are probably
* PC monitors, with an eye-to-screen distance of
* 1 arm length. Under these conditions, fixed size
* (DPI scaled) UI elements should be visible for most
* users
* - Large displays > 24 inches start to encroach on
* TV territory. Once we start working with TVs, we
* have to consider users sitting on a couch - and
* in this situation, we fall back to the age-old
* standard of UI elements occupying a fixed fraction
* of the display size (i.e. just look at the menu of
* any console system for the past decade)
* - 24 -> 32 inches is a grey area, where the display
* might be a monitor or a TV. Above 32 inches, a TV
* is almost a certainty. So we simply lerp between
* dpi scaling and pixel scaling as the display size
* increases from 24 to 32 */
float fraction = (display_size > 32.0f) ? 32.0f : display_size;
fraction = fraction - 24.0f;
fraction = fraction / (32.0f - 24.0f);
scale = ((1.0f - fraction) * dpi_scale) + (fraction * pixel_scale);
}
else if (display_size < 12.0f)
{
/* DPI scaling also fails when using very small
* displays - i.e. mobile devices (tablets/phones).
* That 1 inch UI element is going to look pretty
* dumb on a 5 inch screen in landscape orientation...
* We're essentially in the opposite situation to the
* TV case above, and it turns out that a similar
* solution provides relief: as screen size reduces
* from 12 inches to zero, we lerp from dpi scaling
* to pixel scaling */
float fraction = display_size / 12.0f;
scale = ((1.0f - fraction) * pixel_scale) + (fraction * dpi_scale);
}
else
scale = dpi_scale;
}
/* If DPI retrieval is unsupported, all we can do
* is use the raw pixel scale */
else
scale = pixel_scale;
scale_cached = true;
last_width = width;
last_height = height;
return scale;
}
float gfx_display_get_dpi_scale(unsigned width, unsigned height)
{
static unsigned last_width = 0;
static unsigned last_height = 0;
static float scale = 0.0f;
static bool scale_cached = false;
bool scale_updated = false;
static float last_menu_scale_factor = 0.0f;
static enum menu_driver_id_type last_menu_driver_id = MENU_DRIVER_ID_UNKNOWN;
static float adjusted_scale = 1.0f;
settings_t *settings = config_get_ptr();
float menu_scale_factor = settings->floats.menu_scale_factor;
gfx_display_t *p_disp = disp_get_ptr();
/* Scale is based on display metrics - these are a fixed
* hardware property. To minimise performance overheads
* we therefore only call video_context_driver_get_metrics()
* on first run, or when the current video resolution changes */
if (!scale_cached ||
(width != last_width) ||
(height != last_height))
{
scale = gfx_display_get_dpi_scale_internal(width, height);
scale_cached = true;
scale_updated = true;
last_width = width;
last_height = height;
}
/* Adjusted scale calculation may also be slow, so
* only update if something changes */
if (scale_updated ||
(menu_scale_factor != last_menu_scale_factor) ||
(p_disp->menu_driver_id != last_menu_driver_id))
{
adjusted_scale = gfx_display_get_adjusted_scale_internal(
scale, menu_scale_factor, width);
last_menu_scale_factor = menu_scale_factor;
last_menu_driver_id = p_disp->menu_driver_id;
}
return adjusted_scale;
}
float gfx_display_get_widget_dpi_scale(
unsigned width, unsigned height, bool fullscreen)
{
static unsigned last_width = 0;
static unsigned last_height = 0;
static float scale = 0.0f;
static bool scale_cached = false;
bool scale_updated = false;
static float last_menu_scale_factor = 0.0f;
static enum menu_driver_id_type last_menu_driver_id = MENU_DRIVER_ID_UNKNOWN;
static float adjusted_scale = 1.0f;
settings_t *settings = config_get_ptr();
bool gfx_widget_scale_auto = settings->bools.menu_widget_scale_auto;
float _menu_scale_factor = settings->floats.menu_scale_factor;
#if (defined(RARCH_CONSOLE) || defined(RARCH_MOBILE))
float menu_widget_scale_factor = settings->floats.menu_widget_scale_factor;
#else
float menu_widget_scale_factor_fullscreen = settings->floats.menu_widget_scale_factor;
float menu_widget_scale_factor_windowed = settings->floats.menu_widget_scale_factor_windowed;
float menu_widget_scale_factor = fullscreen ?
menu_widget_scale_factor_fullscreen : menu_widget_scale_factor_windowed;
#endif
gfx_display_t *p_disp = disp_get_ptr();
/* When using RGUI, _menu_scale_factor
* is ignored
* > If we are not using a widget scale factor override,
* just set menu_scale_factor to 1.0 */
float menu_scale_factor =
gfx_widget_scale_auto ?
((p_disp->menu_driver_id == MENU_DRIVER_ID_RGUI) ?
1.0f : _menu_scale_factor) :
menu_widget_scale_factor;
/* Scale is based on display metrics - these are a fixed
* hardware property. To minimise performance overheads
* we therefore only call video_context_driver_get_metrics()
* on first run, or when the current video resolution changes */
if (!scale_cached ||
(width != last_width) ||
(height != last_height))
{
scale = gfx_display_get_dpi_scale_internal(width, height);
scale_cached = true;
scale_updated = true;
last_width = width;
last_height = height;
}
/* Adjusted scale calculation may also be slow, so
* only update if something changes */
if (scale_updated ||
(menu_scale_factor != last_menu_scale_factor) ||
(p_disp->menu_driver_id != last_menu_driver_id))
{
adjusted_scale = gfx_display_get_adjusted_scale_internal(
scale, menu_scale_factor, width);
last_menu_scale_factor = menu_scale_factor;
last_menu_driver_id = p_disp->menu_driver_id;
}
return adjusted_scale;
}
float gfx_display_get_widget_pixel_scale(
unsigned width, unsigned height, bool fullscreen)
{
static unsigned last_width = 0;
static unsigned last_height = 0;
static float scale = 0.0f;
static bool scale_cached = false;
bool scale_updated = false;
static float last_menu_scale_factor = 0.0f;
static enum menu_driver_id_type last_menu_driver_id = MENU_DRIVER_ID_UNKNOWN;
static float adjusted_scale = 1.0f;
settings_t *settings = config_get_ptr();
bool gfx_widget_scale_auto = settings->bools.menu_widget_scale_auto;
float _menu_scale_factor = settings->floats.menu_scale_factor;
#if (defined(RARCH_CONSOLE) || defined(RARCH_MOBILE))
float menu_widget_scale_factor = settings->floats.menu_widget_scale_factor;
#else
float menu_widget_scale_factor_fullscreen = settings->floats.menu_widget_scale_factor;
float menu_widget_scale_factor_windowed = settings->floats.menu_widget_scale_factor_windowed;
float menu_widget_scale_factor = fullscreen ?
menu_widget_scale_factor_fullscreen : menu_widget_scale_factor_windowed;
#endif
gfx_display_t *p_disp = disp_get_ptr();
/* When using RGUI, _menu_scale_factor is ignored
* > If we are not using a widget scale factor override,
* just set menu_scale_factor to 1.0 */
float menu_scale_factor =
gfx_widget_scale_auto ?
((p_disp->menu_driver_id == MENU_DRIVER_ID_RGUI) ?
1.0f : _menu_scale_factor) :
menu_widget_scale_factor;
/* We need to perform a square root here, which
* can be slow on some platforms (not *slow*, but
* it involves enough work that it's worth trying
* to optimise). We therefore cache the pixel scale,
* and only update on first run or when the video
* size changes */
if (!scale_cached ||
(width != last_width) ||
(height != last_height))
{
/* Baseline reference is a 1080p display */
scale = (float)(
sqrt((double)((width * width) + (height * height))) /
DIAGONAL_PIXELS_1080P);
scale_cached = true;
scale_updated = true;
last_width = width;
last_height = height;
}
/* Adjusted scale calculation may also be slow, so
* only update if something changes */
if (scale_updated ||
(menu_scale_factor != last_menu_scale_factor) ||
(p_disp->menu_driver_id != last_menu_driver_id))
{
adjusted_scale = gfx_display_get_adjusted_scale_internal(
scale, menu_scale_factor, width);
last_menu_scale_factor = menu_scale_factor;
last_menu_driver_id = p_disp->menu_driver_id;
}
return adjusted_scale;
}
/* Check if the current menu driver is compatible
* with your video driver. */
static bool gfx_display_check_compatibility(
enum gfx_display_driver_type type,
bool video_is_threaded)
{
const char *video_driver = video_driver_get_ident();
switch (type)
{
case GFX_VIDEO_DRIVER_GENERIC:
return true;
case GFX_VIDEO_DRIVER_OPENGL:
if (string_is_equal(video_driver, "gl"))
return true;
break;
case GFX_VIDEO_DRIVER_OPENGL1:
if (string_is_equal(video_driver, "gl1"))
return true;
break;
case GFX_VIDEO_DRIVER_OPENGL_CORE:
if (string_is_equal(video_driver, "glcore"))
return true;
break;
case GFX_VIDEO_DRIVER_VULKAN:
if (string_is_equal(video_driver, "vulkan"))
return true;
break;
case GFX_VIDEO_DRIVER_METAL:
if (string_is_equal(video_driver, "metal"))
return true;
break;
case GFX_VIDEO_DRIVER_DIRECT3D8:
if (string_is_equal(video_driver, "d3d8"))
return true;
break;
case GFX_VIDEO_DRIVER_DIRECT3D9:
if (string_is_equal(video_driver, "d3d9"))
return true;
break;
case GFX_VIDEO_DRIVER_DIRECT3D10:
if (string_is_equal(video_driver, "d3d10"))
return true;
break;
case GFX_VIDEO_DRIVER_DIRECT3D11:
if (string_is_equal(video_driver, "d3d11"))
return true;
break;
case GFX_VIDEO_DRIVER_DIRECT3D12:
if (string_is_equal(video_driver, "d3d12"))
return true;
break;
case GFX_VIDEO_DRIVER_VITA2D:
if (string_is_equal(video_driver, "vita2d"))
return true;
break;
case GFX_VIDEO_DRIVER_CTR:
if (string_is_equal(video_driver, "ctr"))
return true;
break;
case GFX_VIDEO_DRIVER_WIIU:
if (string_is_equal(video_driver, "gx2"))
return true;
break;
case GFX_VIDEO_DRIVER_GDI:
if (string_is_equal(video_driver, "gdi"))
return true;
break;
case GFX_VIDEO_DRIVER_SWITCH:
if (string_is_equal(video_driver, "switch"))
return true;
break;
}
return false;
}
video_coord_array_t *gfx_display_get_coords_array(void)
{
gfx_display_t *p_disp = disp_get_ptr();
return &p_disp->dispca;
}
/* Reset the display's coordinate array vertices.
* NOTE: Not every display driver uses this. */
void gfx_display_coords_array_reset(void)
{
video_coord_array_t *p_dispca = gfx_display_get_coords_array();
p_dispca->coords.vertices = 0;
}
/* Begin blending operation */
void gfx_display_blend_begin(void *data)
{
if (dispctx && dispctx->blend_begin)
dispctx->blend_begin(data);
}
/* End blending operation */
void gfx_display_blend_end(void *data)
{
if (dispctx && dispctx->blend_end)
dispctx->blend_end(data);
}
/* Begin scissoring operation */
void gfx_display_scissor_begin(void *userdata,
unsigned video_width,
unsigned video_height,
int x, int y, unsigned width, unsigned height)
{
if (dispctx && dispctx->scissor_begin)
{
if (y < 0)
{
if (height < (unsigned)(-y))
height = 0;
else
height += y;
y = 0;
}
if (x < 0)
{
if (width < (unsigned)(-x))
width = 0;
else
width += x;
x = 0;
}
if (y >= (int)video_height)
{
height = 0;
y = 0;
}
if (x >= (int)video_width)
{
width = 0;
x = 0;
}
if ((y + height) > video_height)
height = video_height - y;
if ((x + width) > video_width)
width = video_width - x;
dispctx->scissor_begin(userdata,
video_width, video_height,
x, y, width, height);
}
}
/* End scissoring operation */
void gfx_display_scissor_end(
void *userdata,
unsigned video_width,
unsigned video_height
)
{
if (dispctx && dispctx->scissor_end)
dispctx->scissor_end(userdata,
video_width, video_height);
}
font_data_t *gfx_display_font_file(
char* fontpath, float menu_font_size, bool is_threaded)
{
font_data_t *font_data = NULL;
float font_size = menu_font_size;
if (!dispctx)
return NULL;
/* Font size must be at least 2, or font_init_first()
* will generate a heap-buffer-overflow when using
* many font drivers */
font_size = (font_size > 2.0f) ? font_size : 2.0f;
if (!dispctx->font_init_first((void**)&font_data,
video_driver_get_ptr(false),
fontpath, font_size, is_threaded))
return NULL;
return font_data;
}
bool gfx_display_restore_clear_color(void)
{
if (!dispctx || !dispctx->restore_clear_color)
return false;
dispctx->restore_clear_color();
return true;
}
/* TODO/FIXME - this is no longer used - consider getting rid of it */
void gfx_display_clear_color(gfx_display_ctx_clearcolor_t *color, void *data)
{
if (dispctx && dispctx->clear_color)
dispctx->clear_color(color, data);
}
void gfx_display_draw(gfx_display_ctx_draw_t *draw,
void *data,
unsigned video_width,
unsigned video_height)
{
if (!dispctx || !draw || !dispctx->draw)
return;
if (draw->height <= 0)
return;
if (draw->width <= 0)
return;
dispctx->draw(draw, data, video_width, video_height);
}
void gfx_display_draw_blend(
gfx_display_ctx_draw_t *draw,
void *data,
unsigned video_width,
unsigned video_height)
{
if (!dispctx || !draw || !dispctx->draw)
return;
if (draw->height <= 0)
return;
if (draw->width <= 0)
return;
gfx_display_blend_begin(data);
dispctx->draw(draw, data, video_width, video_height);
gfx_display_blend_end(data);
}
void gfx_display_draw_pipeline(
gfx_display_ctx_draw_t *draw,
void *userdata,
unsigned video_width,
unsigned video_height)
{
if (dispctx && draw && dispctx->draw_pipeline)
dispctx->draw_pipeline(draw, userdata,
video_width, video_height);
}
void gfx_display_draw_bg(gfx_display_ctx_draw_t *draw,
void *userdata, bool add_opacity_to_wallpaper,
float override_opacity)
{
static struct video_coords coords;
const float *new_vertex = NULL;
const float *new_tex_coord = NULL;
if (!dispctx || !draw)
return;
new_vertex = draw->vertex;
new_tex_coord = draw->tex_coord;
if (!new_vertex)
new_vertex = dispctx->get_default_vertices();
if (!new_tex_coord)
new_tex_coord = dispctx->get_default_tex_coords();
coords.vertices = (unsigned)draw->vertex_count;
coords.vertex = new_vertex;
coords.tex_coord = new_tex_coord;
coords.lut_tex_coord = new_tex_coord;
coords.color = (const float*)draw->color;
draw->coords = &coords;
draw->scale_factor = 1.0f;
draw->rotation = 0.0f;
if (draw->texture)
add_opacity_to_wallpaper = true;
if (add_opacity_to_wallpaper)
gfx_display_set_alpha(draw->color, override_opacity);
if (!draw->texture)
draw->texture = gfx_display_white_texture;
if (dispctx && dispctx->get_default_mvp)
draw->matrix_data = (math_matrix_4x4*)dispctx->get_default_mvp(
userdata);
}
void gfx_display_draw_gradient(
gfx_display_ctx_draw_t *draw,
void *userdata,
unsigned video_width,
unsigned video_height,
float menu_wallpaper_opacity
)
{
draw->texture = 0;
draw->x = 0;
draw->y = 0;
gfx_display_draw_bg(draw, userdata, false,
menu_wallpaper_opacity);
gfx_display_draw(draw, userdata,
video_width, video_height);
}
void gfx_display_draw_quad(
void *data,
unsigned video_width,
unsigned video_height,
int x, int y, unsigned w, unsigned h,
unsigned width, unsigned height,
float *color)
{
gfx_display_ctx_draw_t draw;
struct video_coords coords;
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = color;
if (dispctx && dispctx->blend_begin)
dispctx->blend_begin(data);
draw.x = x;
draw.y = (int)height - y - (int)h;
draw.width = w;
draw.height = h;
draw.coords = &coords;
draw.matrix_data = NULL;
draw.texture = gfx_display_white_texture;
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
draw.pipeline.id = 0;
draw.scale_factor = 1.0f;
draw.rotation = 0.0f;
gfx_display_draw(&draw, data,
video_width, video_height);
if (dispctx && dispctx->blend_end)
dispctx->blend_end(data);
}
void gfx_display_draw_polygon(
void *userdata,
unsigned video_width,
unsigned video_height,
int x1, int y1,
int x2, int y2,
int x3, int y3,
int x4, int y4,
unsigned width, unsigned height,
float *color)
{
gfx_display_ctx_draw_t draw;
struct video_coords coords;
float vertex[8];
vertex[0] = x1 / (float)width;
vertex[1] = y1 / (float)height;
vertex[2] = x2 / (float)width;
vertex[3] = y2 / (float)height;
vertex[4] = x3 / (float)width;
vertex[5] = y3 / (float)height;
vertex[6] = x4 / (float)width;
vertex[7] = y4 / (float)height;
coords.vertices = 4;
coords.vertex = &vertex[0];
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = color;
if (dispctx && dispctx->blend_begin)
dispctx->blend_begin(userdata);
draw.x = 0;
draw.y = 0;
draw.width = width;
draw.height = height;
draw.coords = &coords;
draw.matrix_data = NULL;
draw.texture = gfx_display_white_texture;
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
draw.pipeline.id = 0;
draw.scale_factor = 1.0f;
draw.rotation = 0.0f;
gfx_display_draw(&draw, userdata,
video_width, video_height);
if (dispctx && dispctx->blend_end)
dispctx->blend_end(userdata);
}
void gfx_display_draw_texture(
void *userdata,
unsigned video_width,
unsigned video_height,
int x, int y, unsigned w, unsigned h,
unsigned width, unsigned height,
float *color, uintptr_t texture)
{
gfx_display_ctx_draw_t draw;
gfx_display_ctx_rotate_draw_t rotate_draw;
struct video_coords coords;
math_matrix_4x4 mymat;
rotate_draw.matrix = &mymat;
rotate_draw.rotation = 0.0;
rotate_draw.scale_x = 1.0;
rotate_draw.scale_y = 1.0;
rotate_draw.scale_z = 1;
rotate_draw.scale_enable = true;
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
draw.width = w;
draw.height = h;
draw.coords = &coords;
draw.matrix_data = &mymat;
draw.prim_type = GFX_DISPLAY_PRIM_TRIANGLESTRIP;
draw.pipeline.id = 0;
coords.color = (const float*)color;
gfx_display_rotate_z(&rotate_draw, userdata);
draw.texture = texture;
draw.x = x;
draw.y = height - y;
gfx_display_draw(&draw, userdata,
video_width, video_height);
}
/* Draw the texture split into 9 sections, without scaling the corners.
* The middle sections will only scale in the X axis, and the side
* sections will only scale in the Y axis. */
void gfx_display_draw_texture_slice(
void *userdata,
unsigned video_width,
unsigned video_height,
int x, int y, unsigned w, unsigned h,
unsigned new_w, unsigned new_h,
unsigned width, unsigned height,
float *color, unsigned offset, float scale_factor, uintptr_t texture)
{
gfx_display_ctx_draw_t draw;
gfx_display_ctx_rotate_draw_t rotate_draw;
struct video_coords coords;
math_matrix_4x4 mymat;