GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_utility_gradient_delete.c Lines: 22 22 100.0 %
Date: 2026-03-06 19:21:09 Branches: 18 18 100.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
/**   Utility (Utility)                                                   */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_canvas.h"
28
#include "gx_system.h"
29
#include "gx_utility.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_utility_gradient_delete                         PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function deletes a previously created gradient.                */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    gradient                              Pointer to GX_GRADIENT        */
48
/*                                                                        */
49
/*  OUTPUT                                                                */
50
/*                                                                        */
51
/*    None                                                                */
52
/*                                                                        */
53
/*  CALLS                                                                 */
54
/*                                                                        */
55
/*  CALLED BY                                                             */
56
/*                                                                        */
57
/**************************************************************************/
58
23
UINT _gx_utility_gradient_delete(GX_GRADIENT *gradient)
59
{
60
23
const GX_UBYTE *data_ptr = gradient -> gx_gradient_pixelmap.gx_pixelmap_data;
61
GX_GRADIENT    *search;
62
23
GX_BOOL         in_use = GX_FALSE;
63
64
23
    GX_ENTER_CRITICAL
65
66
23
    if (data_ptr)
67
    {
68
        /* check to see if any other gradients are using same pixelmap data,
69
           if not, then time to delete pixelmap data
70
         */
71
9
        search = _gx_system_gradient_list;
72
73
21
        while (search)
74
        {
75
18
            if (search != gradient &&
76
12
                search -> gx_gradient_pixelmap.gx_pixelmap_data == data_ptr)
77
            {
78
6
                in_use = GX_TRUE;
79
6
                break;
80
            }
81
12
            search = search -> gx_gradient_next;
82
        }
83
84
        /* unlink this gradient from gradient list */
85
86
9
        if (gradient -> gx_gradient_next)
87
        {
88
5
            gradient -> gx_gradient_next -> gx_gradient_previous = gradient -> gx_gradient_previous;
89
        }
90
9
        if (gradient -> gx_gradient_previous)
91
        {
92
4
            gradient -> gx_gradient_previous -> gx_gradient_next = gradient -> gx_gradient_next;
93
        }
94
        else
95
        {
96
5
            _gx_system_gradient_list = gradient -> gx_gradient_next;
97
        }
98
    }
99
100
23
    GX_EXIT_CRITICAL
101
102

23
    if (data_ptr && !in_use && _gx_system_memory_free)
103
    {
104
2
        _gx_system_memory_free((void *)data_ptr);
105
    }
106
107
23
    memset(gradient, 0, sizeof(GX_GRADIENT));
108
109
23
    return GX_SUCCESS;
110
}
111