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
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _gx_canvas_create PORTABLE C */
38 /* 6.1.3 */
39 /* AUTHOR */
40 /* */
41 /* Kenneth Maxwell, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function creates a canvas associated with the specified */
46 /* display. */
47 /* */
48 /* INPUT */
49 /* */
50 /* canvas Canvas control block */
51 /* name Name of canvas */
52 /* display Display control block */
53 /* type Type of canvas */
54 /* width Width of canvas */
55 /* height Height of canvas */
56 /* memory_area Memory area of canvas with */
57 /* each pixel of GX_COLOR */
58 /* memory_size Size of canvas memory area */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* status Completion status */
63 /* */
64 /* CALLS */
65 /* */
66 /* memset Set control block and canvas */
67 /* memory to zero */
68 /* _gx_utility_rectangle_define Define a rectangle */
69 /* */
70 /* CALLED BY */
71 /* */
72 /* Application Code */
73 /* _gx_animation_canvas_define */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
80 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* 12-31-2020 Kenneth Maxwell Modified comment(s), */
83 /* resulting in version 6.1.3 */
84 /* */
85 /**************************************************************************/
_gx_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)86 UINT _gx_canvas_create(GX_CANVAS *canvas, GX_CONST GX_CHAR *name, GX_DISPLAY *display,
87 UINT type, UINT width, UINT height, GX_COLOR *memory_area, ULONG memory_size)
88 {
89 /* Clear the canvas control block. */
90 memset(canvas, 0, sizeof(GX_CANVAS));
91
92 /* Setup the canvas. */
93 canvas -> gx_canvas_display = display;
94 canvas -> gx_canvas_memory = memory_area;
95 canvas -> gx_canvas_memory_size = memory_size;
96 canvas -> gx_canvas_alpha = GX_ALPHA_VALUE_OPAQUE;
97 canvas -> gx_canvas_display_offset_x = 0;
98 canvas -> gx_canvas_display_offset_y = 0;
99 canvas -> gx_canvas_draw_count = 0;
100 canvas -> gx_canvas_draw_nesting = 0;
101 canvas -> gx_canvas_dirty_count = 0;
102 canvas -> gx_canvas_status = type;
103 canvas -> gx_canvas_x_resolution = (GX_VALUE) width;
104 canvas -> gx_canvas_y_resolution = (GX_VALUE) height;
105 canvas -> gx_canvas_hardware_layer = (GX_BYTE) -1;
106
107 /* Determine if there is a memory area. */
108 if (memory_area)
109 {
110 /* Yes, clear it! */
111 memset(memory_area, 0, memory_size);
112 }
113
114 /* Setup the dirty area. */
115 _gx_utility_rectangle_define(&canvas -> gx_canvas_dirty_area, 0, 0, -1, -1);
116
117 /* Now link the canvas control block on the list of created canvases. */
118
119 /* Load the canvas ID field in the canvas control block. */
120 canvas -> gx_canvas_id = GX_CANVAS_ID;
121
122 /* Save the canvas name. */
123 canvas -> gx_canvas_name = name;
124
125 /* If running on Win32, create padded memory, only if needed */
126 #ifdef GX_TARGET_WIN32
127 _win32_compatible_canvas_memory_allocate(canvas);
128 #endif
129
130 /* initialize previous and next pointers */
131 canvas -> gx_canvas_created_previous = GX_NULL;
132 canvas -> gx_canvas_created_next = GX_NULL;
133
134 /* lock access to gx_system */
135
136 GX_ENTER_CRITICAL
137
138 /* Place the canvas on the list of created canvass. First,
139 check for an empty list. */
140 _gx_system_canvas_created_count++;
141
142 if (_gx_system_canvas_created_count > 1)
143 {
144 /* Place the new canvas in the list. */
145 _gx_system_canvas_created_list -> gx_canvas_created_previous = canvas;
146 canvas -> gx_canvas_created_next = _gx_system_canvas_created_list;
147 }
148
149 /* point start of list at this new canvas */
150 _gx_system_canvas_created_list = canvas;
151
152 /* unlock gx_system. */
153 GX_EXIT_CRITICAL
154
155 /* Return successful status. */
156 return(GX_SUCCESS);
157 }
158
159 #ifdef GX_TARGET_WIN32
_win32_compatible_canvas_memory_allocate(GX_CANVAS * canvas)160 VOID _win32_compatible_canvas_memory_allocate(GX_CANVAS *canvas)
161 {
162 USHORT rotation;
163 INT padded_width;
164 USHORT row_byte_width;
165 INT color_format = GX_COLOR_FORMAT_565RGB;
166 GX_DISPLAY *display = canvas -> gx_canvas_display;
167
168 /* Windows bitmaps must be padded to an even multiple of 4 bytes in width.
169 When the GUIX canvas does not meet this requirement, we create a padded canvas memory
170 so that we can pass the padded canvas memory off to Windows for display as a bitmap.
171 This happens often when running at sub-byte color depth, but can occur at any color depth
172 if the display resolution is very odd. */
173
174 padded_width = canvas -> gx_canvas_x_resolution;
175
176 if (display == GX_NULL)
177 {
178 return;
179 }
180
181 rotation = display -> gx_display_rotation_angle;
182
183 padded_width = canvas -> gx_canvas_x_resolution;
184
185 row_byte_width = display -> gx_display_driver_row_pitch_get(padded_width);
186
187 while (row_byte_width % 4)
188 {
189 padded_width++;
190 row_byte_width = display -> gx_display_driver_row_pitch_get(padded_width);
191 }
192
193 if ((padded_width != canvas -> gx_canvas_x_resolution) || rotation)
194 {
195 /* We are forced to create a padded buffer to hold Win32 compatible canvas memory. */
196 canvas -> gx_canvas_padded_memory = (GX_COLOR *)malloc(row_byte_width * canvas -> gx_canvas_y_resolution);
197 }
198 }
199
200 #endif
201
202