1 
2 /***************************************************************************
3  * Copyright (c) 2024 Microsoft Corporation
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the MIT License which is available at
7  * https://opensource.org/licenses/MIT.
8  *
9  * SPDX-License-Identifier: MIT
10  **************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Dispaly Management (Dispaly)                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_display.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_display_driver_4bpp_mouse_restore               PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This service restores captured memory under the mouse area.         */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    display                               Display control block         */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*  CALLS                                                                 */
51 /*                                                                        */
52 /*                                                                        */
53 /*  CALLED BY                                                             */
54 /*                                                                        */
55 /*    GUIX Internal Code                                                  */
56 /*                                                                        */
57 /*  RELEASE HISTORY                                                       */
58 /*                                                                        */
59 /*    DATE              NAME                      DESCRIPTION             */
60 /*                                                                        */
61 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
62 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
63 /*                                            resulting in version 6.1    */
64 /*                                                                        */
65 /**************************************************************************/
66 #if defined(GX_MOUSE_SUPPORT)
67 #if !defined(GX_HARDWARE_MOUSE_SUPPORT)
_gx_display_driver_4bpp_mouse_restore(GX_DISPLAY * display)68 VOID _gx_display_driver_4bpp_mouse_restore(GX_DISPLAY *display)
69 {
70 INT         row;
71 INT         column;
72 INT         height;
73 INT         width;
74 GX_UBYTE   *putrow;
75 GX_UBYTE   *put;
76 GX_UBYTE   *get;
77 GX_UBYTE   *getrow;
78 GX_UBYTE    getmask;
79 GX_UBYTE    putmask;
80 GX_UBYTE    pixel;
81 GX_CANVAS  *canvas;
82 
83     if (display -> gx_display_mouse.gx_mouse_cursor_info)
84     {
85         if (display -> gx_display_mouse.gx_mouse_capture_memory &&
86             (display -> gx_display_mouse.gx_mouse_status & GX_MOUSE_VISIBLE))
87         {
88             canvas = display -> gx_display_mouse.gx_mouse_canvas;
89             height = display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_bottom - display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_top + 1;
90             width = display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_right - display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_left + 1;
91 
92             if (width > 0 && height > 0)
93             {
94                 getrow = (GX_UBYTE *)display -> gx_display_mouse.gx_mouse_capture_memory;
95                 putrow = (GX_UBYTE *)canvas -> gx_canvas_memory;
96                 putrow += ((canvas -> gx_canvas_x_resolution + 1) >> 1) * display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_top;
97                 putrow += display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_left >> 1;
98 
99                 for (row = 0; row < height; row++)
100                 {
101                     getmask = 0xf0;
102                     if (display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_left & 1)
103                     {
104                         putmask = 0x0f;
105                     }
106                     else
107                     {
108                         putmask = 0xf0;
109                     }
110                     put = putrow;
111                     get = getrow;
112                     for (column = 0; column < width; column++)
113                     {
114                         pixel = (*get) & getmask;
115                         if (getmask == 0x0f)
116                         {
117                             get++;
118                             getmask = 0xf0;
119                             pixel |= (GX_UBYTE)(pixel << 4);
120                         }
121                         else
122                         {
123                             getmask = 0x0f;
124                             pixel |= pixel >> 4;
125                         }
126 
127                         *put &= (GX_UBYTE)(~putmask);
128                         *put |= pixel & putmask;
129                         putmask >>= 4;
130                         if (putmask == 0)
131                         {
132                             putmask = 0xf0;
133                             put++;
134                         }
135                     }
136                     putrow += (display -> gx_display_width + 1) >> 1;
137                     getrow += (width + 1) >> 1;
138                 }
139             }
140         }
141         display -> gx_display_mouse.gx_mouse_status &= (GX_UBYTE)(~GX_MOUSE_VISIBLE);
142     }
143 }
144 #endif
145 #endif
146 
147