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 /**   Display Management (Display)                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_display.h"
29 #include "gx_utility.h"
30 
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _gx_display_driver_32bpp_canvas_copy                PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Kenneth Maxwell, Microsoft Corporation                              */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Generic 32bpp canvas copy function.                                 */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*   canvas                                 The canvas to copy from       */
50 /*   composite                              The canvas to copy to         */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _gx_utility_rectangle_shift           Move the rectangle            */
59 /*    _gx_utility_rectangle_overlap_detect  Detect two rectangles being   */
60 /*                                            overlap to each other       */
61 /*    memcpy                                Move canvas data              */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    GUIX Internal Code                                                  */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_gx_display_driver_32bpp_canvas_copy(GX_CANVAS * canvas,GX_CANVAS * composite)76 VOID _gx_display_driver_32bpp_canvas_copy(GX_CANVAS *canvas, GX_CANVAS *composite)
77 {
78 GX_RECTANGLE dirty;
79 GX_RECTANGLE overlap;
80 ULONG       *read;
81 ULONG       *write;
82 INT          width;
83 INT          row;
84 
85     dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
86     dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
87     dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
88 
89     _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
90 
91     if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
92     {
93         width = overlap.gx_rectangle_right - overlap.gx_rectangle_left + 1;
94         read = (ULONG *)canvas -> gx_canvas_memory;
95 
96         /* index into starting row */
97         read += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
98 
99         /* index into pixel */
100 
101         read += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
102 
103         /* calculate the write pointer */
104         write = (ULONG *)composite -> gx_canvas_memory;
105         write += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
106         write += overlap.gx_rectangle_left;
107 
108         for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
109         {
110             memcpy(write, read, (size_t)width * 4); /* Use case of memcpy is verified. */
111 
112             write += composite -> gx_canvas_x_resolution;
113             read += canvas -> gx_canvas_x_resolution;
114         }
115     }
116 }
117 
118