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 extern VOID _gx_chromart_simulation_display_driver_565rgb_setup(GX_DISPLAY *display, VOID *aux_data,
29                                                                 VOID (*toggle_function)(struct GX_CANVAS_STRUCT *canvas,
30                                                                                         GX_RECTANGLE *dirty_area));
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    win32_chromart_simulation_565rgb_bitmap_header_create               */
37 /*                                                         PORTABLE C     */
38 /*                                                           6.1.3        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function creates bitmap header for 565rgb driver.              */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    display                               Pointer to GX_DISPLAY         */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    win32_chromart_graphics_driver_setup_565rgb                         */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
68 /*                                                                        */
69 /**************************************************************************/
win32_565rgb_bitmap_header_create(GX_DISPLAY * display)70 static void win32_565rgb_bitmap_header_create(GX_DISPLAY *display)
71 {
72 DWORD                        *putmask;
73 GX_WIN32_DISPLAY_DRIVER_DATA *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 = 16;
81     instance -> win32_driver_bmpinfo.gx_bmp_header.biSizeImage = display -> gx_display_width * display -> gx_display_height * 2;
82     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrUsed = 65535;
83     instance -> win32_driver_bmpinfo.gx_bmp_header.biClrImportant = 65535;
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++ = 0x0000f800;
89     *putmask++ = 0x000007e0;
90     *putmask   = 0x0000001f;
91 }
92 
93 /**************************************************************************/
94 /*                                                                        */
95 /*  FUNCTION                                               RELEASE        */
96 /*                                                                        */
97 /*    win32_chromart_graphics_driver_setup_565rgb         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 565rgb chromart simulation */
106 /*    display driver.                                                     */
107 /*                                                                        */
108 /*  INPUT                                                                 */
109 /*                                                                        */
110 /*    display                               Pointer to GX_DISPLAY         */
111 /*                                                                        */
112 /*  OUTPUT                                                                */
113 /*                                                                        */
114 /*    status                                Completion status             */
115 /*                                                                        */
116 /*  CALLS                                                                 */
117 /*                                                                        */
118 /*    _gx_chromart_simulation_display_driver_565rgb_setup                 */
119 /*                                          guix display setup funciton.  */
120 /*    win32_chromart_simulation_565rgb_bitmap_header_create               */
121 /*                                          Create bitmap header info     */
122 /*    gx_win32_get_free_data_instance       Get display data instance     */
123 /*    GX_WIN32_EVENT_THREAD_CREATE          Create event thread           */
124 /*                                                                        */
125 /*  CALLED BY                                                             */
126 /*                                                                        */
127 /*    Application Code                                                    */
128 /*                                                                        */
129 /*  RELEASE HISTORY                                                       */
130 /*                                                                        */
131 /*    DATE              NAME                      DESCRIPTION             */
132 /*                                                                        */
133 /*  12-31-2020     Kenneth Maxwell          Initial Version 6.1.3         */
134 /*  01-31-2022     Ting Zhu                 Modified comment(s),          */
135 /*                                            improved logic,             */
136 /*                                            resulting in version 6.1.10 */
137 /*                                                                        */
138 /**************************************************************************/
win32_chromeart_graphics_driver_setup_565rgb(GX_DISPLAY * display)139 UINT win32_chromeart_graphics_driver_setup_565rgb(GX_DISPLAY *display)
140 {
141 GX_WIN32_DISPLAY_DRIVER_DATA *data;
142 
143     /* Initialize the low-level drawing function pointers.
144 
145        For windows, these are always just the generic funcions,
146        but for some hardware, these will be customized,
147        optimized functions specific to that hardware. */
148 
149     data = gx_win32_get_free_data_instance();
150     if (!data)
151     {
152         /* We don't have any free display data instance. */
153         return(GX_FAILURE);
154     }
155 
156     /* Set display color format type. */
157     data -> win32_driver_type = GX_COLOR_FORMAT_565RGB;
158 
159     _gx_chromart_simulation_display_driver_565rgb_setup(display, data, gx_win32_display_buffer_toggle);
160 
161     win32_565rgb_bitmap_header_create(display);
162 
163     /* Create the GUIX / Windows event thread
164        This thread is a substitute for a touch display
165        or keyboard driver thread that would be running
166        on embedded hardware. */
167     GX_WIN32_EVENT_THREAD_CREATE(data, "GUI-WIN32-565rgb");
168 
169     return(GX_SUCCESS);
170 }
171 #endif /* WIN32 */
172 
173