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 /* FUNCTION RELEASE */ 34 /* */ 35 /* _gx_display_driver_1bpp_canvas_copy PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Kenneth Maxwell, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* Canvas copy function for the 1bpp display driver. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* canvas The canvas to copy from */ 48 /* composite The canvas to copy to */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* None */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _gx_utility_rectangle_shift Move the rectangle */ 57 /* _gx_utility_rectangle_overlap_detect Detect two rectangles being */ 58 /* overlap to each other */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* GUIX Internal Code */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 69 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _gx_display_driver_1bpp_canvas_copy(GX_CANVAS * canvas,GX_CANVAS * composite)73VOID _gx_display_driver_1bpp_canvas_copy(GX_CANVAS *canvas, GX_CANVAS *composite) 74 { 75 GX_RECTANGLE dirty; 76 GX_RECTANGLE overlap; 77 GX_UBYTE *read; 78 GX_UBYTE *write; 79 INT row; 80 INT column; 81 UINT read_pos; 82 UINT write_pos; 83 GX_UBYTE read_mask; 84 GX_UBYTE write_mask; 85 INT readstride; 86 INT writestride; 87 INT offset; 88 89 dirty.gx_rectangle_left = dirty.gx_rectangle_top = 0; 90 dirty.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - (GX_VALUE)1); 91 dirty.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - (GX_VALUE)1); 92 readstride = (canvas->gx_canvas_x_resolution + 7) >> 3; 93 writestride = (composite->gx_canvas_x_resolution + 7) >> 3; 94 95 _gx_utility_rectangle_shift(&dirty, canvas -> gx_canvas_display_offset_x, canvas -> gx_canvas_display_offset_y); 96 97 if (_gx_utility_rectangle_overlap_detect(&dirty, &composite -> gx_canvas_dirty_area, &overlap)) 98 { 99 offset = overlap.gx_rectangle_left - dirty.gx_rectangle_left; 100 read_pos = (UINT)((overlap.gx_rectangle_top - dirty.gx_rectangle_top) * readstride + (offset >> 3)); 101 write_pos = (UINT)(overlap.gx_rectangle_top * writestride + (overlap.gx_rectangle_left >> 3)); 102 103 for (row = overlap.gx_rectangle_top; row <= overlap.gx_rectangle_bottom; row++) 104 { 105 read = (GX_UBYTE *)canvas -> gx_canvas_memory; 106 write = (GX_UBYTE *)composite -> gx_canvas_memory; 107 read += read_pos; 108 write += write_pos; 109 read_mask = (GX_UBYTE)(((GX_UBYTE)0x80) >> (offset & 0x07)); 110 write_mask = (GX_UBYTE)(0x80 >> (overlap.gx_rectangle_left & 0x07)); 111 112 for (column = overlap.gx_rectangle_left; column <= overlap.gx_rectangle_right; column++) 113 { 114 if (((*read) & read_mask) == read_mask) 115 { 116 *write |= write_mask; 117 } 118 else 119 { 120 *write = (GX_UBYTE)((*write) & (~write_mask)); 121 } 122 read_mask >>= 1; 123 write_mask >>= 1; 124 if (!read_mask) 125 { 126 read++; 127 read_mask = 0x80; 128 } 129 if (!write_mask) 130 { 131 write++; 132 write_mask = 0x80; 133 } 134 } 135 write_pos = (UINT)((INT)write_pos + writestride); 136 read_pos = (UINT)((INT)read_pos + readstride); 137 } 138 } 139 } 140 141