GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_block_move.c Lines: 26 26 100.0 %
Date: 2026-03-06 19:21:09 Branches: 19 20 95.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
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
/**   Canvas Management (Canvas)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_utility.h"
30
#include "gx_canvas.h"
31
#include "gx_display.h"
32
#include "gx_window.h"
33
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_canvas_block_move.c                             PORTABLE C      */
40
/*                                                           6.3.0        */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This function copies a block of pixel from one reference position   */
48
/*    to another.                                                         */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    block                                 Rectangle to move             */
53
/*    x_shift                               Distance to move in x         */
54
/*                                            direction                   */
55
/*    y_shift                               Distance to move in y         */
56
/*                                            direction                   */
57
/*    dirty                                 Flag of dirty block           */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    status                                Completion status             */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _gx_utility_rectangle_inside_detect   Detect if a second rectangle  */
66
/*                                            is completely within the    */
67
/*                                            first one                   */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    Application Code                                                    */
72
/*    _gx_window_client_scroll                                            */
73
/*                                                                        */
74
/**************************************************************************/
75
2762
UINT _gx_canvas_block_move(GX_RECTANGLE *block, GX_VALUE x_shift, GX_VALUE y_shift, GX_RECTANGLE *dirty)
76
{
77
GX_DRAW_CONTEXT *context;
78
GX_DISPLAY      *display;
79
GX_VIEW         *view;
80
2762
UINT             status = GX_FAILURE;
81
82
83
    /* pick up the current drawing context */
84
2762
    context = _gx_system_current_draw_context;
85
86
    /* If the caller hasn't opened the canvas, we can't do anything */
87
2762
    if (!context)
88
    {
89
1
        return status;
90
    }
91
92
    /* pick up current display driver */
93
2761
    display = context -> gx_draw_context_display;
94
95
    /* check to see if this driver supports block move */
96

2761
    if (!display -> gx_display_driver_block_move || (context -> gx_draw_context_canvas -> gx_canvas_status & GX_CANVAS_PARTIAL_FRAME_BUFFER))
97
    {
98
        /* this driver doesn't support block move. If we are
99
           partial drawing just mark the caller as dirty so that
100
           a normal redraw operation occurs.
101
         */
102
1
        return status;
103
    }
104
105
    /* test to determine if any viewport of the caller contains the block to move.
106
       If yes, we can do the block move. If no, we have to
107
       do a normal invalidation and redraw.
108
     */
109
2760
    view = context -> gx_draw_context_view_head;
110
111
2807
    while (view)
112
    {
113
2740
        if (_gx_utility_rectangle_inside_detect(&view -> gx_view_rectangle, block))
114
        {
115
2693
            context -> gx_draw_context_clip = block;
116
2693
            display -> gx_display_driver_block_move(context, block, x_shift, y_shift);
117
2693
            status = GX_SUCCESS;
118
2693
            break;
119
        }
120
47
        view = view -> gx_view_next;
121
    }
122
123

2760
    if (status == GX_SUCCESS && dirty)
124
    {
125
        /* we were able to aid drawing by doing a block move. Mark
126
            the remainder that was not updated as dirty so that the
127
            caller can redraw that portion
128
         */
129
2669
        *dirty = *block;
130
131
2669
        if (x_shift)
132
        {
133
1681
            if (x_shift > 0)
134
            {
135
805
                dirty -> gx_rectangle_right = (GX_VALUE)(dirty -> gx_rectangle_left + x_shift - 1);
136
            }
137
            else
138
            {
139
876
                dirty -> gx_rectangle_left = (GX_VALUE)(dirty -> gx_rectangle_right + x_shift + 1);
140
            }
141
        }
142
        else
143
        {
144
988
            if (y_shift > 0)
145
            {
146
235
                dirty -> gx_rectangle_bottom = (GX_VALUE)(dirty -> gx_rectangle_top + y_shift - 1);
147
            }
148
            else
149
            {
150
753
                dirty -> gx_rectangle_top = (GX_VALUE)(dirty -> gx_rectangle_bottom + y_shift + 1);
151
            }
152
        }
153
    }
154
2760
    return(status);
155
}
156