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 /**   Screen Management (Screen)                                          */
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_display.h"
31 #include "gx_canvas.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_canvas_pixelmap_draw                            PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function prepares to draw the specified pixelmap at the        */
46 /*    requested position.                                                 */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    x_position                            Top-left x-coord to place     */
51 /*                                            pixelmap                    */
52 /*    y_position                            Top-left y-coord to place     */
53 /*                                            pixelmap                    */
54 /*    pixelmap                              Pointer to actual pixelmap    */
55 /*                                            to draw                     */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    status                                Completion status             */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*    _gx_utility_rectangle_define          Define a rectangle            */
63 /*    _gx_utility_rectangle_overlap_detect  Detect rectangle overlap      */
64 /*    [gx_display_driver_pixelmap_draw]     The display driver pixelmap   */
65 /*                                            draw routine                */
66 /*    [gx_display_driver_jpeg_draw]         The display driver JPEG draw  */
67 /*                                            routine                     */
68 /*    [gx_display_driver_png_draw]          The display driver PNG draw   */
69 /*                                            routine                     */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    _gx_canvas_pixelmap_blend                                           */
74 /*    _gx_canvas_pixelmap_tile                                            */
75 /*    _gx_checkbox_draw                                                   */
76 /*    _gx_icon_button_draw                                                */
77 /*    _gx_icon_draw                                                       */
78 /*    _gx_pixelmap_button_draw                                            */
79 /*    _gx_pixelmap_prompt_draw                                            */
80 /*    _gx_pixelmap_slider_draw                                            */
81 /*    _gx_radio_button_draw                                               */
82 /*    _gx_scroll_thumb_draw                                               */
83 /*    _gx_scrollbar_draw                                                  */
84 /*    _gx_window_draw                                                     */
85 /*    _gx_scroll_thumb_draw                                               */
86 /*                                                                        */
87 /*  RELEASE HISTORY                                                       */
88 /*                                                                        */
89 /*    DATE              NAME                      DESCRIPTION             */
90 /*                                                                        */
91 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
92 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
93 /*                                            resulting in version 6.1    */
94 /*                                                                        */
95 /**************************************************************************/
_gx_canvas_pixelmap_draw(GX_VALUE x_position,GX_VALUE y_position,GX_PIXELMAP * pixelmap)96 UINT  _gx_canvas_pixelmap_draw(GX_VALUE x_position, GX_VALUE y_position, GX_PIXELMAP *pixelmap)
97 {
98 GX_DRAW_CONTEXT *context;
99 GX_DISPLAY      *display;
100 GX_RECTANGLE     clip_rect;
101 GX_RECTANGLE     bound;
102 GX_VIEW         *view;
103 VOID             (*pmp_function)(GX_DRAW_CONTEXT *, INT, INT, GX_PIXELMAP *);
104 
105     /* pick up the current drawing context */
106     context = _gx_system_current_draw_context;
107 
108     /* pick up current display driver */
109     display = context -> gx_draw_context_display;
110 
111     /* calculate rectangle that bounds the pixelmap */
112     _gx_utility_rectangle_define(&bound, x_position, y_position,
113                                  (GX_VALUE)(x_position + pixelmap -> gx_pixelmap_width - 1),
114                                  (GX_VALUE)(y_position + pixelmap -> gx_pixelmap_height - 1));
115 
116     /* clip the line bounding box to the dirty rectangle */
117     if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
118     {
119         /* nothing to draw, return */
120         return GX_SUCCESS;
121     }
122 
123     /* pickup pointer to correct pixelmap drawing function */
124     pmp_function = GX_NULL;
125 
126     if (pixelmap -> gx_pixelmap_flags & GX_PIXELMAP_RAW_FORMAT)
127     {
128 #if defined(GX_SOFTWARE_DECODER_SUPPORT)
129         if ((pixelmap->gx_pixelmap_data[0] == 0xff) && (pixelmap->gx_pixelmap_data[1] == 0xd8))
130         {
131             /* JPEG */
132             pmp_function = display -> gx_display_driver_jpeg_draw;
133         }
134         else
135         {
136             if (pixelmap -> gx_pixelmap_data[1] == 'P')
137             {
138                 /* PNG */
139                 pmp_function = display -> gx_display_driver_png_draw;
140             }
141         }
142 #endif
143     }
144     else
145     {
146         if (pixelmap -> gx_pixelmap_format == GX_COLOR_FORMAT_8BIT_ALPHAMAP)
147         {
148             pmp_function = display -> gx_display_driver_alphamap_draw;
149         }
150         else
151         {
152             pmp_function = display -> gx_display_driver_pixelmap_draw;
153         }
154     }
155 
156     if (!pmp_function)
157     {
158         /* display driver does not support requested action */
159         return GX_FAILURE;
160     }
161 
162     /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
163        into. For each view that overlaps the bounding rectangle, do some drawing.
164      */
165     view = context -> gx_draw_context_view_head;
166 
167     while (view)
168     {
169         if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
170         {
171             view = view -> gx_view_next;
172             continue;
173         }
174 
175         /* we have a view into which we can draw the pixelmap, do it */
176 
177         /* first, set the context clip rectangle */
178         context -> gx_draw_context_clip = &clip_rect;
179 
180         /* now pass the context and drawing params to driver level function */
181         pmp_function(context, x_position, y_position, pixelmap);
182 
183         /* go to the next view */
184         view = view -> gx_view_next;
185     }
186 
187     /* Return successful completion.  */
188     return(GX_SUCCESS);
189 }
190 
191