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_565rgb_bitmap_header_create                   PORTABLE C      */
33 /*                                                           6.1.3        */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    Kenneth Maxwell, Microsoft Corporation                              */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    This function creates bitmap header for 565rgb 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_565rgb                                  */
57 /*                                                                        */
58 /*  RELEASE HISTORY                                                       */
59 /*                                                                        */
60 /*    DATE              NAME                      DESCRIPTION             */
61 /*                                                                        */
62 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
63 /*                                                                        */
64 /**************************************************************************/
win32_565rgb_bitmap_header_create(GX_DISPLAY * display)65 static void win32_565rgb_bitmap_header_create(GX_DISPLAY *display)
66 {
67 DWORD                        *putmask;
68 
69 GX_WIN32_DISPLAY_DRIVER_DATA *instance = (GX_WIN32_DISPLAY_DRIVER_DATA *)display -> gx_display_driver_data;
70 
71     instance -> win32_driver_bmpinfo.gx_bmp_header.biSize = sizeof(BITMAPINFOHEADER);
72     instance -> win32_driver_bmpinfo.gx_bmp_header.biWidth = display -> gx_display_width;
73     instance -> win32_driver_bmpinfo.gx_bmp_header.biHeight = display -> gx_display_height;
74 
75     instance -> win32_driver_bmpinfo.gx_bmp_header.biPlanes = 1;
76     instance -> win32_driver_bmpinfo.gx_bmp_header.biBitCount = 16;
77     instance -> win32_driver_bmpinfo.gx_bmp_header.biSizeImage = display -> gx_display_width * display -> gx_display_height * 2;
78     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrUsed = 65535;
79     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrImportant = 65535;
80     instance -> win32_driver_bmpinfo.gx_bmp_header.biCompression = BI_BITFIELDS;
81 
82     putmask = (DWORD *)&(instance -> win32_driver_bmpinfo.gx_bmp_colors[0]);
83 
84     *putmask++ = 0x0000f800;
85     *putmask++ = 0x000007e0;
86     *putmask   = 0x0000001f;
87 }
88 
89 /**************************************************************************/
90 /*                                                                        */
91 /*  FUNCTION                                               RELEASE        */
92 /*                                                                        */
93 /*    win32_graphics_driver_setup_565rgb                  PORTABLE C      */
94 /*                                                           6.1.10       */
95 /*  AUTHOR                                                                */
96 /*                                                                        */
97 /*    Kenneth Maxwell, Microsoft Corporation                              */
98 /*                                                                        */
99 /*  DESCRIPTION                                                           */
100 /*                                                                        */
101 /*    This function creates a Windows specific 565rgb display driver.     */
102 /*                                                                        */
103 /*  INPUT                                                                 */
104 /*                                                                        */
105 /*    display                               Pointer to GX_DISPLAY         */
106 /*                                                                        */
107 /*  OUTPUT                                                                */
108 /*                                                                        */
109 /*    status                                Completion status             */
110 /*                                                                        */
111 /*  CALLS                                                                 */
112 /*                                                                        */
113 /*    _gx_display_driver_565rgb_setup       guix display setup funciton.  */
114 /*    win32_565rgb_bitmap_header_create     Create bitmap header info     */
115 /*    gx_win32_get_free_data_instance       Get display data instance     */
116 /*    GX_WIN32_EVENT_THREAD_CREATE          Create event thread           */
117 /*                                                                        */
118 /*  CALLED BY                                                             */
119 /*                                                                        */
120 /*    Application Code                                                    */
121 /*                                                                        */
122 /*  RELEASE HISTORY                                                       */
123 /*                                                                        */
124 /*    DATE              NAME                      DESCRIPTION             */
125 /*                                                                        */
126 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
127 /*  01-31-2022     Ting Zhu                 Modified comment(s),          */
128 /*                                            improved logic,             */
129 /*                                            resulting in version 6.1.10 */
130 /*                                                                        */
131 /**************************************************************************/
win32_graphics_driver_setup_565rgb(GX_DISPLAY * display)132 UINT win32_graphics_driver_setup_565rgb(GX_DISPLAY *display)
133 {
134 GX_WIN32_DISPLAY_DRIVER_DATA *data;
135 
136     /* Initialize the low-level drawing function pointers.
137 
138        For windows, these are always just the generic funcions,
139        but for some hardware, these will be customized,
140        optimized functions specific to that hardware. */
141 
142     data = gx_win32_get_free_data_instance();
143     if (!data)
144     {
145         /* we don't have any free display data instance */
146         return(GX_FAILURE);
147     }
148 
149     /* Save off the format of display driver.*/
150     data -> win32_driver_type = GX_COLOR_FORMAT_565RGB;
151 
152     _gx_display_driver_565rgb_setup(display, data, gx_win32_display_buffer_toggle);
153 
154     /* Create bitmap header for 565rgb display driver. */
155     win32_565rgb_bitmap_header_create(display);
156 
157     /* Create the GUIX / Windows event thread
158        This thread is a substitute for a touch display
159        or keyboard driver thread that would be running
160        on embedded hardware. */
161     GX_WIN32_EVENT_THREAD_CREATE(data, "GUI-WIN32-565rgb");
162 
163     return(GX_SUCCESS);
164 }
165 #endif /* WIN32 */
166 
167