GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_display_driver_32bpp_rotated_block_move.c Lines: 68 68 100.0 %
Date: 2024-12-05 08:52:37 Branches: 20 20 100.0 %

Line Branch Exec Source
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
/**************************************************************************/
71
147
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
147
    GX_SWAP_VALS(xshift, yshift);
83
84
147
    if (context -> gx_draw_context_display -> gx_display_rotation_angle == GX_SCREEN_ROTATION_CW)
85
    {
86
109
        rotated_block.gx_rectangle_left = block -> gx_rectangle_top;
87
109
        rotated_block.gx_rectangle_right = block -> gx_rectangle_bottom;
88
109
        rotated_block.gx_rectangle_top = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_right - 1);
89
109
        rotated_block.gx_rectangle_bottom = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_x_resolution - block -> gx_rectangle_left - 1);
90
91
109
        yshift = -yshift;
92
    }
93
    else
94
    {
95
38
        rotated_block.gx_rectangle_left = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_bottom - 1);
96
38
        rotated_block.gx_rectangle_right = (GX_VALUE)(context -> gx_draw_context_canvas -> gx_canvas_y_resolution - block -> gx_rectangle_top - 1);
97
38
        rotated_block.gx_rectangle_top = block -> gx_rectangle_left;
98
38
        rotated_block.gx_rectangle_bottom = block -> gx_rectangle_right;
99
100
38
        xshift = -xshift;
101
    }
102
103
147
    if (xshift)
104
    {
105
143
        if (xshift > 0)
106
        {
107
            /* Have to copy from left to right.  */
108
38
            pPut = context -> gx_draw_context_memory;
109
38
            pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
110
38
            pPut += rotated_block.gx_rectangle_left + xshift;
111
112
38
            pGet = context -> gx_draw_context_memory;
113
38
            pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
114
38
            pGet += rotated_block.gx_rectangle_left;
115
116
38
            width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 - xshift;
117
38
            width_in_bytes = width * (int)sizeof(GX_COLOR);
118
119
38
            if (width_in_bytes <= 0)
120
            {
121
2
                return;
122
            }
123
124
8368
            for (y = rotated_block.gx_rectangle_top; y <= rotated_block.gx_rectangle_bottom; y++)
125
            {
126
8331
                memmove(pPut, pGet, (size_t)width_in_bytes);
127
128
8331
                pPut += context -> gx_draw_context_pitch;
129
8331
                pGet += context -> gx_draw_context_pitch;
130
            }
131
        }
132
        else
133
        {
134
            /* Have to copy from right to left.  */
135
105
            pPut = context -> gx_draw_context_memory;
136
105
            pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
137
105
            pPut += rotated_block.gx_rectangle_left;
138
139
105
            pGet = context -> gx_draw_context_memory;
140
105
            pGet += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
141
105
            pGet += rotated_block.gx_rectangle_left - xshift;
142
143
105
            width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1 + xshift;
144
105
            width_in_bytes = width * (int)sizeof(GX_COLOR);
145
146
105
            if (width_in_bytes <= 0)
147
            {
148
1
                return;
149
            }
150
151
23352
            for (y = rotated_block.gx_rectangle_top; y <= rotated_block.gx_rectangle_bottom; y++)
152
            {
153
23248
                memmove(pPut, pGet, (size_t)width_in_bytes);
154
155
23248
                pPut += context -> gx_draw_context_pitch;
156
23248
                pGet += context -> gx_draw_context_pitch;
157
            }
158
        }
159
    }
160
    else
161
    {
162
4
        width = rotated_block.gx_rectangle_right - rotated_block.gx_rectangle_left + 1;
163
4
        width_in_bytes = width * (int)sizeof(GX_COLOR);
164
165
4
        if (yshift > 0)
166
        {
167
            /* Have to copy from top to bottom.  */
168
2
            pPut = context -> gx_draw_context_memory;
169
2
            pPut += rotated_block.gx_rectangle_bottom * context -> gx_draw_context_pitch;
170
2
            pPut += rotated_block.gx_rectangle_left;
171
172
2
            pGet = context -> gx_draw_context_memory;
173
2
            pGet += (rotated_block.gx_rectangle_bottom - yshift) * context -> gx_draw_context_pitch;
174
2
            pGet += rotated_block.gx_rectangle_left;
175
176
2
            height = rotated_block.gx_rectangle_bottom - rotated_block.gx_rectangle_top + 1 - yshift;
177
178
170
            for (y = 0; y < height; y++)
179
            {
180
168
                memmove(pPut, pGet, (size_t)width_in_bytes);
181
182
168
                pPut -= context -> gx_draw_context_pitch;
183
168
                pGet -= context -> gx_draw_context_pitch;
184
            }
185
        }
186
        else
187
        {
188
            /* Have to copy from bottom to top.  */
189
2
            pPut = context -> gx_draw_context_memory;
190
2
            pPut += rotated_block.gx_rectangle_top * context -> gx_draw_context_pitch;
191
2
            pPut += rotated_block.gx_rectangle_left;
192
193
2
            pGet = context -> gx_draw_context_memory;
194
2
            pGet += (rotated_block.gx_rectangle_top - yshift) * context -> gx_draw_context_pitch;
195
2
            pGet += rotated_block.gx_rectangle_left;
196
197
2
            height = rotated_block.gx_rectangle_bottom - rotated_block.gx_rectangle_top + 1 + yshift;
198
199
170
            for (y = 0; y < height; y++)
200
            {
201
168
                memmove(pPut, pGet, (size_t)width_in_bytes);
202
203
168
                pPut += context -> gx_draw_context_pitch;
204
168
                pGet += context -> gx_draw_context_pitch;
205
            }
206
        }
207
    }
208
}
209