1 /* RetroArch - A frontend for libretro.
2 * Copyright (C) 2011-2017 - Daniel De Matteis
3 * Copyright (C) 2016-2019 - Brad Parker
4 *
5 * RetroArch is free software: you can redistribute it and/or modify it under the terms
6 * of the GNU General Public License as published by the Free Software Found-
7 * ation, either version 3 of the License, or (at your option) any later version.
8 *
9 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with RetroArch.
14 * If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <time.h>
18
19 #include <clamping.h>
20 #include <queues/message_queue.h>
21 #include <retro_miscellaneous.h>
22
23 #include "../../config.def.h"
24 #include "../font_driver.h"
25 #include "../../retroarch.h"
26 #include "../../verbosity.h"
27
28 #include "../gfx_display.h"
29
30 #if defined(_WIN32) && !defined(_XBOX)
31 #include "../common/win32_common.h"
32 #include "../common/gdi_common.h"
33 #endif
34
gfx_display_gdi_get_default_vertices(void)35 static const float *gfx_display_gdi_get_default_vertices(void)
36 {
37 static float dummy[16] = {0.0f};
38 return &dummy[0];
39 }
40
gfx_display_gdi_get_default_tex_coords(void)41 static const float *gfx_display_gdi_get_default_tex_coords(void)
42 {
43 static float dummy[16] = {0.0f};
44 return &dummy[0];
45 }
46
gfx_display_gdi_draw(gfx_display_ctx_draw_t * draw,void * data,unsigned video_width,unsigned video_height)47 static void gfx_display_gdi_draw(gfx_display_ctx_draw_t *draw,
48 void *data, unsigned video_width, unsigned video_height)
49 {
50 struct gdi_texture *texture = NULL;
51 gdi_t *gdi = (gdi_t*)data;
52 BITMAPINFO info = {{0}};
53
54 if (!gdi || !draw || draw->x < 0 || draw->y < 0 || draw->width <= 1 || draw->height <= 1)
55 return;
56
57 texture = (struct gdi_texture*)draw->texture;
58
59 if (!texture || texture->width <= 1 || texture->height <= 1)
60 return;
61
62 info.bmiHeader.biBitCount = 32;
63 info.bmiHeader.biWidth = texture->width;
64 info.bmiHeader.biHeight = -texture->height;
65 info.bmiHeader.biPlanes = 1;
66 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
67 info.bmiHeader.biSizeImage = 0;
68 info.bmiHeader.biCompression = BI_RGB;
69
70 if (gdi->memDC)
71 {
72 #if _WIN32_WINNT >= 0x0410 /* Win98 */
73 BLENDFUNCTION blend = {0};
74 #endif
75
76 if (!gdi->texDC)
77 gdi->texDC = CreateCompatibleDC(gdi->winDC);
78
79 if (texture->bmp)
80 texture->bmp_old = (HBITMAP)SelectObject(gdi->texDC, texture->bmp);
81 else
82 {
83 /* scale texture data into a bitmap we can easily blit later */
84 texture->bmp = CreateCompatibleBitmap(gdi->winDC, draw->width, draw->height);
85 texture->bmp_old = (HBITMAP)SelectObject(gdi->texDC, texture->bmp);
86
87 StretchDIBits(gdi->texDC, 0, 0, draw->width, draw->height, 0, 0, texture->width, texture->height, texture->data, &info, DIB_RGB_COLORS, SRCCOPY);
88 }
89
90 gdi->bmp_old = (HBITMAP)SelectObject(gdi->memDC, gdi->bmp);
91
92 #if _WIN32_WINNT >= 0x0410 /* Win98 */
93 blend.BlendOp = AC_SRC_OVER;
94 blend.BlendFlags = 0;
95 blend.SourceConstantAlpha = 255;
96 #if 0
97 clamp_8bit(draw->coords->color[3] * 255.0f);
98 #endif
99 blend.AlphaFormat = AC_SRC_ALPHA;
100
101 /* AlphaBlend() is only available since Win98 */
102 AlphaBlend(gdi->memDC, draw->x, video_height - draw->height - draw->y, draw->width, draw->height, gdi->texDC, 0, 0, draw->width, draw->height, blend);
103 #if 0
104 TransparentBlt(gdi->memDC, draw->x, video_height - draw->height - draw->y, draw->width, draw->height, gdi->texDC, 0, 0, draw->width, draw->height, 0);
105 #endif
106 #else
107 /* Just draw without the blending */
108 StretchBlt(gdi->memDC, draw->x, video_height - draw->height - draw->y, draw->width, draw->height, gdi->texDC, 0, 0, draw->width, draw->height, SRCCOPY);
109
110 #endif
111
112 SelectObject(gdi->memDC, gdi->bmp_old);
113 SelectObject(gdi->texDC, texture->bmp_old);
114 }
115 }
116
gfx_display_gdi_font_init_first(void ** font_handle,void * video_data,const char * font_path,float gdi_font_size,bool is_threaded)117 static bool gfx_display_gdi_font_init_first(
118 void **font_handle, void *video_data,
119 const char *font_path, float gdi_font_size,
120 bool is_threaded)
121 {
122 font_data_t **handle = (font_data_t**)font_handle;
123 if (!(*handle = font_driver_init_first(video_data,
124 font_path, gdi_font_size, true,
125 is_threaded,
126 FONT_DRIVER_RENDER_GDI)))
127 return false;
128 return true;
129 }
130
131 gfx_display_ctx_driver_t gfx_display_ctx_gdi = {
132 gfx_display_gdi_draw,
133 NULL, /* draw_pipeline */
134 NULL, /* blend_begin */
135 NULL, /* blend_end */
136 NULL, /* get_default_mvp */
137 gfx_display_gdi_get_default_vertices,
138 gfx_display_gdi_get_default_tex_coords,
139 gfx_display_gdi_font_init_first,
140 GFX_VIDEO_DRIVER_GDI,
141 "gdi",
142 false,
143 NULL, /* scissor_begin */
144 NULL /* scissor_end */
145 };
146