1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** GUIX Component */
16 /** */
17 /** Display Management (Display) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "gx_api.h"
27 #include "gx_display.h"
28 #include "gx_utility.h"
29
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _gx_display_driver_16bpp_canvas_copy PORTABLE C */
37 /* 6.3.0 */
38 /* AUTHOR */
39 /* */
40 /* Kenneth Maxwell, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* Generic 16bpp canvas copy function. */
45 /* */
46 /* INPUT */
47 /* */
48 /* canvas The canvas to copy from */
49 /* composite The canvas to copy to */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* None */
54 /* */
55 /* CALLS */
56 /* */
57 /* _gx_utility_rectangle_shift Move the rectangle */
58 /* _gx_utility_rectangle_overlap_detect Detect two rectangles being */
59 /* overlap to each other */
60 /* memcpy Move canvas data */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* GUIX Internal Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
71 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* 10-31-2023 Ting Zhu Modified comment(s), */
74 /* added canvas status check, */
75 /* resulting in version 6.3.0 */
76 /* */
77 /**************************************************************************/
_gx_display_driver_16bpp_canvas_copy(GX_CANVAS * canvas,GX_CANVAS * composite)78 VOID _gx_display_driver_16bpp_canvas_copy(GX_CANVAS *canvas, GX_CANVAS *composite)
79 {
80 GX_RECTANGLE dirty;
81 GX_RECTANGLE overlap;
82 USHORT *read;
83 USHORT *write;
84 INT width;
85 INT row;
86
87 #ifdef GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER
88 if (canvas -> gx_canvas_status & GX_CANVAS_PARTIAL_FRAME_BUFFER)
89 {
90 /* Not supported. */
91 return;
92 }
93 #endif
94
95 dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0;
96 dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - (GX_VALUE)1);
97 dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - (GX_VALUE)1);
98
99 _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y);
100
101 if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap))
102 {
103 width = overlap.gx_rectangle_right - overlap.gx_rectangle_left + 1;
104 read = (USHORT *)canvas -> gx_canvas_memory;
105
106 /* index into starting row */
107 read += (overlap.gx_rectangle_top - dirty.gx_rectangle_top) * canvas -> gx_canvas_x_resolution;
108
109 /* index into pixel */
110
111 read += overlap.gx_rectangle_left - dirty.gx_rectangle_left;
112
113 /* calculate the write pointer */
114 write = (USHORT *)composite -> gx_canvas_memory;
115 write += overlap.gx_rectangle_top * composite -> gx_canvas_x_resolution;
116 write += overlap.gx_rectangle_left;
117
118 for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++)
119 {
120 memcpy(write, read, (size_t)(width * 2)); /* Use case of memcpy is verified. */
121
122 write += composite -> gx_canvas_x_resolution;
123 read += canvas -> gx_canvas_x_resolution;
124 }
125 }
126 }
127
128