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