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 /**   Display Management (Display)                                        */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_display.h"
28 #include "gx_system.h"
29 #include "gx_utility.h"
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_display_driver_32bpp_block_move                 PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    Generic 32bpp color format display driver block moving function.    */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    context                               Draw context                  */
47 /*    block                                 The rectangle to be moved     */
48 /*    xshift                                Amount to move on X-axis      */
49 /*    yshift                                Amount to move on Y-axis      */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    memmove                                Move memory content          */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    GUIX Internal Code                                                  */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
68 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_gx_display_driver_32bpp_block_move(GX_DRAW_CONTEXT * context,GX_RECTANGLE * block,INT xshift,INT yshift)72 VOID _gx_display_driver_32bpp_block_move(GX_DRAW_CONTEXT *context,
73                                          GX_RECTANGLE *block, INT xshift, INT yshift)
74 {
75 GX_COLOR *pGet;
76 GX_COLOR *pPut;
77 int       width;
78 int       width_in_bytes;
79 int       y;
80 int       height;
81 
82     if (xshift)
83     {
84         if (xshift > 0)
85         {
86             /* have to copy from left to right. */
87             pPut = context -> gx_draw_context_memory;
88             pPut += block -> gx_rectangle_top * context -> gx_draw_context_pitch;
89             pPut += block -> gx_rectangle_left + xshift;
90 
91             pGet = context -> gx_draw_context_memory;
92             pGet += block -> gx_rectangle_top * context -> gx_draw_context_pitch;
93             pGet += block -> gx_rectangle_left;
94 
95             width = block -> gx_rectangle_right - block -> gx_rectangle_left + 1 - xshift;
96             width_in_bytes = width * (int)sizeof(GX_COLOR);
97 
98             if (width_in_bytes <= 0)
99             {
100                 return;
101             }
102 
103             for (y = block -> gx_rectangle_top; y <= block -> gx_rectangle_bottom; y++)
104             {
105                 memmove(pPut, pGet, (size_t)width_in_bytes);
106 
107                 pPut += context -> gx_draw_context_pitch;
108                 pGet += context -> gx_draw_context_pitch;
109             }
110         }
111         else
112         {
113             /* have to copy from right to left */
114             pPut = context -> gx_draw_context_memory;
115             pPut += block -> gx_rectangle_top * context -> gx_draw_context_pitch;
116             pPut += block -> gx_rectangle_left;
117 
118             pGet = context -> gx_draw_context_memory;
119             pGet += block -> gx_rectangle_top * context -> gx_draw_context_pitch;
120             pGet += block -> gx_rectangle_left - xshift;
121 
122             width = block -> gx_rectangle_right - block -> gx_rectangle_left + 1 + xshift;
123             width_in_bytes = width * (int)sizeof(GX_COLOR);
124 
125             if (width_in_bytes <= 0)
126             {
127                 return;
128             }
129 
130             for (y = block -> gx_rectangle_top; y <= block -> gx_rectangle_bottom; y++)
131             {
132                 memmove(pPut, pGet, (size_t)width_in_bytes);
133 
134                 pPut += context -> gx_draw_context_pitch;
135                 pGet += context -> gx_draw_context_pitch;
136             }
137         }
138     }
139     else
140     {
141         width = block -> gx_rectangle_right - block -> gx_rectangle_left + 1;
142         width_in_bytes = width * (int)sizeof(GX_COLOR);
143 
144         if (yshift > 0)
145         {
146             /* have to copy from top to bottom */
147             pPut = context -> gx_draw_context_memory;
148             pPut += block -> gx_rectangle_bottom * context -> gx_draw_context_pitch;
149             pPut += block -> gx_rectangle_left;
150 
151             pGet = context -> gx_draw_context_memory;
152             pGet += (block -> gx_rectangle_bottom - yshift) * context -> gx_draw_context_pitch;
153             pGet += block -> gx_rectangle_left;
154 
155             height = block -> gx_rectangle_bottom - block -> gx_rectangle_top + 1 - yshift;
156 
157             for (y = 0; y < height; y++)
158             {
159                 memmove(pPut, pGet, (size_t)width_in_bytes);
160 
161                 pPut -= context -> gx_draw_context_pitch;
162                 pGet -= context -> gx_draw_context_pitch;
163             }
164         }
165         else
166         {
167             /* have to copy from bottom to top */
168             pPut = context -> gx_draw_context_memory;
169             pPut += block -> gx_rectangle_top * context -> gx_draw_context_pitch;
170             pPut += block -> gx_rectangle_left;
171 
172             pGet = context -> gx_draw_context_memory;
173             pGet += (block -> gx_rectangle_top - yshift) * context -> gx_draw_context_pitch;
174             pGet += block -> gx_rectangle_left;
175 
176             height = block -> gx_rectangle_bottom - block -> gx_rectangle_top + 1 + yshift;
177 
178             for (y = 0; y < height; y++)
179             {
180                 memmove(pPut, pGet, (size_t)width_in_bytes);
181 
182                 pPut += context -> gx_draw_context_pitch;
183                 pGet += context -> gx_draw_context_pitch;
184             }
185         }
186     }
187 }
188 
189