1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
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 
32 /* Bring in externs for caller checking code.  */
33 GX_CALLER_CHECKING_EXTERNS
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _gxe_canvas_create                                  PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Kenneth Maxwell, Microsoft Corporation                              */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function checks for errors in the canvas function call.        */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    canvas                                Canvas control block          */
53 /*    name                                  Name of canvas                */
54 /*    display                               Display control block         */
55 /*    type                                  Type of canvas                */
56 /*    width                                 Width of canvas               */
57 /*    height                                Height of canvas              */
58 /*    memory_area                           Memory area of canvas with    */
59 /*                                            each pixel of GX_COLOR      */
60 /*    memory_size                           Size of canvas memory area    */
61 /*    canvas_control_block_size             Size of the canvas control    */
62 /*                                            block                       */
63 /*                                                                        */
64 /*  OUTPUT                                                                */
65 /*                                                                        */
66 /*    status                                Completion status             */
67 /*                                                                        */
68 /*  CALLS                                                                 */
69 /*                                                                        */
70 /*    _gx_canvas_create                     Actual canvas create call     */
71 /*                                                                        */
72 /*  CALLED BY                                                             */
73 /*                                                                        */
74 /*    Application Code                                                    */
75 /*                                                                        */
76 /*  RELEASE HISTORY                                                       */
77 /*                                                                        */
78 /*    DATE              NAME                      DESCRIPTION             */
79 /*                                                                        */
80 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
81 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
82 /*                                            resulting in version 6.1    */
83 /*                                                                        */
84 /**************************************************************************/
_gxe_canvas_create(GX_CANVAS * canvas,GX_CONST GX_CHAR * name,GX_DISPLAY * display,UINT type,UINT width,UINT height,GX_COLOR * memory_area,ULONG memory_size,UINT canvas_control_block_size)85 UINT  _gxe_canvas_create(GX_CANVAS *canvas, GX_CONST GX_CHAR *name, GX_DISPLAY *display, UINT type,
86                          UINT width, UINT height, GX_COLOR *memory_area, ULONG memory_size,
87                          UINT canvas_control_block_size)
88 {
89 UINT status;
90 UINT pitch;
91 
92     /* Check for appropriate caller.  */
93     GX_INIT_AND_THREADS_CALLER_CHECKING
94 
95     /* Check for invalid input pointers.  */
96     if ((canvas == GX_NULL) || (display == GX_NULL))
97     {
98         return(GX_PTR_ERROR);
99     }
100 
101     if (canvas_control_block_size != sizeof(GX_CANVAS))
102     {
103         return(GX_INVALID_CANVAS_SIZE);
104     }
105 
106     /* Check for widget already created.  */
107     if (canvas -> gx_canvas_display != GX_NULL)
108     {
109         return(GX_ALREADY_CREATED);
110     }
111 
112     pitch = (UINT)(display -> gx_display_driver_row_pitch_get((USHORT)width));
113     if (memory_size < pitch * height)
114     {
115         return GX_INVALID_SIZE;
116     }
117 
118     if (type & (~((UINT)(GX_CANVAS_SIMPLE | GX_CANVAS_MANAGED | GX_CANVAS_VISIBLE |
119                          GX_CANVAS_MODIFIED | GX_CANVAS_COMPOSITE))))
120     {
121         return(GX_INVALID_TYPE);
122     }
123 
124     /* Call the actual canvas create function.  */
125     status = _gx_canvas_create(canvas, name, display, type, width, height, memory_area, memory_size);
126 
127     /* Return completion status.  */
128     return status;
129 }
130 
131