1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** GUIX Component                                                        */
16 /**                                                                       */
17 /**   Win32 Display Management (Display)                                  */
18 /**                                                                       */
19 /**************************************************************************/
20 #ifdef WIN32
21 #include "tx_api.h"
22 #include "gx_api.h"
23 #include "gx_system.h"
24 #include "gx_display.h"
25 #include "windows.h"
26 #include "gx_win32_display_driver.h"
27 
28 /**************************************************************************/
29 /*                                                                        */
30 /*  FUNCTION                                               RELEASE        */
31 /*                                                                        */
32 /*    win32_24xrgb_bitmap_header_create                   PORTABLE C      */
33 /*                                                           6.1.4        */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    Kenneth Maxwell, Microsoft Corporation                              */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    This function creates bitmap header for 24xrgb driver.              */
41 /*                                                                        */
42 /*  INPUT                                                                 */
43 /*                                                                        */
44 /*    display                               Pointer to GX_DISPLAY         */
45 /*                                                                        */
46 /*  OUTPUT                                                                */
47 /*                                                                        */
48 /*    None                                                                */
49 /*                                                                        */
50 /*  CALLS                                                                 */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLED BY                                                             */
55 /*                                                                        */
56 /*    win32_graphics_driver_setup_24xrgb                                  */
57 /*                                                                        */
58 /*  RELEASE HISTORY                                                       */
59 /*                                                                        */
60 /*    DATE              NAME                      DESCRIPTION             */
61 /*                                                                        */
62 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
63 /*  02-02-2021     Kenneth Maxwell          Modified comment(s),          */
64 /*                                            Renamed function,           */
65 /*                                            resulting in version 6.1.4  */
66 /*                                                                        */
67 /**************************************************************************/
win32_32bpp_bitmap_header_create(GX_DISPLAY * display)68 VOID win32_32bpp_bitmap_header_create(GX_DISPLAY *display)
69 {
70 GX_WIN32_DISPLAY_DRIVER_DATA *instance;
71 DWORD                        *putmask;
72 
73     instance = (GX_WIN32_DISPLAY_DRIVER_DATA *)display -> gx_display_driver_data;
74 
75     instance -> win32_driver_bmpinfo.gx_bmp_header.biSize = sizeof(BITMAPINFOHEADER);
76     instance -> win32_driver_bmpinfo.gx_bmp_header.biWidth = display -> gx_display_width;
77     instance -> win32_driver_bmpinfo.gx_bmp_header.biHeight = display -> gx_display_height;
78 
79     instance -> win32_driver_bmpinfo.gx_bmp_header.biPlanes = 1;
80     instance -> win32_driver_bmpinfo.gx_bmp_header.biBitCount = 32;
81     instance -> win32_driver_bmpinfo.gx_bmp_header.biSizeImage = display -> gx_display_width * display -> gx_display_height * 4;
82     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrUsed = 16777215;
83     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrImportant = 16777215;
84     instance -> win32_driver_bmpinfo.gx_bmp_header.biCompression = BI_BITFIELDS;
85 
86     putmask = (DWORD *)&(instance -> win32_driver_bmpinfo.gx_bmp_colors[0]);
87 
88     *putmask++ = 0x00ff0000;
89     *putmask++ = 0x0000ff00;
90     *putmask   = 0x000000ff;
91 }
92 
93 /**************************************************************************/
94 /*                                                                        */
95 /*  FUNCTION                                               RELEASE        */
96 /*                                                                        */
97 /*    win32_graphics_driver_setup_24xrgb                  PORTABLE C      */
98 /*                                                           6.1.10       */
99 /*  AUTHOR                                                                */
100 /*                                                                        */
101 /*    Kenneth Maxwell, Microsoft Corporation                              */
102 /*                                                                        */
103 /*  DESCRIPTION                                                           */
104 /*                                                                        */
105 /*    This function creates a Windows specific 24xrgb display driver.     */
106 /*                                                                        */
107 /*  INPUT                                                                 */
108 /*                                                                        */
109 /*    display                               Pointer to GX_DISPLAY         */
110 /*                                                                        */
111 /*  OUTPUT                                                                */
112 /*                                                                        */
113 /*    status                                Completion status             */
114 /*                                                                        */
115 /*  CALLS                                                                 */
116 /*                                                                        */
117 /*    _gx_display_driver_24xrgb_setup       guix display setup funciton.  */
118 /*    win32_24xrgb_bitmap_header_create     Create bitmap header info     */
119 /*    gx_win32_get_free_data_instance       Get display data instance     */
120 /*    GX_WIN32_EVENT_THREAD_CREATE          Create event thread           */
121 /*                                                                        */
122 /*  CALLED BY                                                             */
123 /*                                                                        */
124 /*    Application Code                                                    */
125 /*                                                                        */
126 /*  RELEASE HISTORY                                                       */
127 /*                                                                        */
128 /*    DATE              NAME                      DESCRIPTION             */
129 /*                                                                        */
130 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
131 /*  02-02-2021     Kenneth Maxwell          Modified comment(s),          */
132 /*                                            Updated function name,      */
133 /*                                            resulting in version 6.1.4  */
134 /*  01-31-2022     Ting Zhu                 Modified comment(s),          */
135 /*                                            improved logic,             */
136 /*                                            resulting in version 6.1.10 */
137 /*                                                                        */
138 /**************************************************************************/
win32_graphics_driver_setup_24xrgb(GX_DISPLAY * display)139 UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display)
140 {
141 GX_WIN32_DISPLAY_DRIVER_DATA *data;
142 
143     /* Initialize the low-level drawing function pointers.
144        For windows, these are always just the generic funcions,
145        but for some hardware, these will be customized,
146        optimized functions specific to that hardware. */
147     data = gx_win32_get_free_data_instance();
148 
149     if (!data)
150     {
151         /* We don't have any free display data instance. */
152         return(GX_FAILURE);
153     }
154 
155     /* Save off the format of display driver. */
156     data -> win32_driver_type = GX_COLOR_FORMAT_24XRGB;
157 
158     _gx_display_driver_24xrgb_setup(display, data, gx_win32_display_buffer_toggle);
159 
160     /* Create bitmap header for 24xrgb display driver. */
161     win32_32bpp_bitmap_header_create(display);
162 
163     /* Create the GUIX / Windows event thread
164        This thread is a substitute for a touch screen
165        or keyboard driver thread that would be running
166        on embedded hardware. */
167     GX_WIN32_EVENT_THREAD_CREATE(data, "GUI-WIN32-24xrgb");
168 
169     return(GX_SUCCESS);
170 }
171 #endif /* WIN32 */
172 
173