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_rotated_block_move PORTABLE C */
35 /* 6.1.4 */
36 /* AUTHOR */
37 /* */
38 /* Kenneth Maxwell, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* Generic rotated 32bpp color format display driver block moving */
43 /* function. */
44 /* */
45 /* INPUT */
46 /* */
47 /* context Draw context */
48 /* block The rectangle to be moved */
49 /* xshift Amount to move on X-axis */
50 /* yshift Amount to move on Y-axis */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* None */
55 /* */
56 /* CALLS */
57 /* */
58 /* memmove Move memory content */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* GUIX Internal Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 02-02-2021 Kenneth Maxwell Initial Version 6.1.4 */
69 /* */
70 /**************************************************************************/
_gx_display_driver_32bpp_rotated_block_move(GX_DRAW_CONTEXT * context,GX_RECTANGLE * block,INT xshift,INT yshift)71 VOID _gx_display_driver_32bpp_rotated_block_move(GX_DRAW_CONTEXT *context,
72 GX_RECTANGLE *block, INT xshift, INT yshift)
73 {
74 GX_COLOR *pGet;
75 GX_COLOR *pPut;
76 int width;
77 int width_in_bytes;
78 int y;
79 int height;
80 GX_RECTANGLE rotated_block;
81
82 GX_SWAP_VALS(xshift, yshift);
83
84 if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
85 {
86 rotated_block.gx_rectangle_left = block -> gx_rectangle_top;
87 rotated_block.gx_rectangle_right = block -> gx_rectangle_bottom;
88 rotated_block.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_right - 1);
89 rotated_block.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_left - 1);
90
91 yshift = -yshift;
92 }
93 else
94 {
95 rotated_block.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_bottom - 1);
96 rotated_block.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_top - 1);
97 rotated_block.gx_rectangle_top = block -> gx_rectangle_left;
98 rotated_block.gx_rectangle_bottom = block -> gx_rectangle_right;
99
100 xshift = -xshift;
101 }
102
103 if (xshift)
104 {
105 if (xshift > 0)
106 {
107 /* Have to copy from left to right. */
108 pPut = context -> gx_draw_context_memory;
109 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
110 pPut += rotated_block.gx_rectangle_left + xshift;
111
112 pGet = context -> gx_draw_context_memory;
113 pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
114 pGet += rotated_block.gx_rectangle_left;
115
116 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 - xshift;
117 width_in_bytes = width * (int)sizeof(GX_COLOR);
118
119 if (width_in_bytes <= 0)
120 {
121 return;
122 }
123
124 for (y = rotated_block.gx_rectangle_top; y <= rotated_block.gx_rectangle_bottom; y++)
125 {
126 memmove(pPut, pGet, (size_t)width_in_bytes);
127
128 pPut += context -> gx_draw_context_pitch;
129 pGet += context -> gx_draw_context_pitch;
130 }
131 }
132 else
133 {
134 /* Have to copy from right to left. */
135 pPut = context -> gx_draw_context_memory;
136 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
137 pPut += rotated_block.gx_rectangle_left;
138
139 pGet = context -> gx_draw_context_memory;
140 pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
141 pGet += rotated_block.gx_rectangle_left - xshift;
142
143 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 + xshift;
144 width_in_bytes = width * (int)sizeof(GX_COLOR);
145
146 if (width_in_bytes <= 0)
147 {
148 return;
149 }
150
151 for (y = rotated_block.gx_rectangle_top; y <= rotated_block.gx_rectangle_bottom; y++)
152 {
153 memmove(pPut, pGet, (size_t)width_in_bytes);
154
155 pPut += context -> gx_draw_context_pitch;
156 pGet += context -> gx_draw_context_pitch;
157 }
158 }
159 }
160 else
161 {
162 width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1;
163 width_in_bytes = width * (int)sizeof(GX_COLOR);
164
165 if (yshift > 0)
166 {
167 /* Have to copy from top to bottom. */
168 pPut = context -> gx_draw_context_memory;
169 pPut += rotated_block.gx_rectangle_bottom * context -> gx_draw_context_pitch;
170 pPut += rotated_block.gx_rectangle_left;
171
172 pGet = context -> gx_draw_context_memory;
173 pGet += (rotated_block.gx_rectangle_bottom - yshift) * context -> gx_draw_context_pitch;
174 pGet += rotated_block.gx_rectangle_left;
175
176 height = rotated_block.gx_rectangle_bottom - rotated_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 else
187 {
188 /* Have to copy from bottom to top. */
189 pPut = context -> gx_draw_context_memory;
190 pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
191 pPut += rotated_block.gx_rectangle_left;
192
193 pGet = context -> gx_draw_context_memory;
194 pGet += (rotated_block.gx_rectangle_top - yshift) * context -> gx_draw_context_pitch;
195 pGet += rotated_block.gx_rectangle_left;
196
197 height = rotated_block.gx_rectangle_bottom - rotated_block.gx_rectangle_top + 1 + yshift;
198
199 for (y = 0; y < height; y++)
200 {
201 memmove(pPut, pGet, (size_t)width_in_bytes);
202
203 pPut += context -> gx_draw_context_pitch;
204 pGet += context -> gx_draw_context_pitch;
205 }
206 }
207 }
208 }
209
210