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 /**   Application Interface (API)                                         */
18 /**                                                                       */
19 /**************************************************************************/
20 #include "gx_api.h"
21 #include "gx_system.h"
22 #include "gx_display.h"
23 #include "gx_validation_utility.h"
24 
25 extern int gx_validation_record_frame;
26 extern TEST_PARAM test_parameter;
27 
28 static int width, height;
29 static int header_created = 0;
30 
31 
_gx_validation_display_buffer_monochrome_toggle(GX_CANVAS * canvas,GX_RECTANGLE * dirty)32 VOID _gx_validation_display_buffer_monochrome_toggle(GX_CANVAS *canvas, GX_RECTANGLE *dirty)
33 {
34 
35     GX_UBYTE *read;
36     GX_UBYTE *write;
37     GX_RECTANGLE overlap;
38     int read_pos;
39     int write_pos;
40     GX_UBYTE read_mask;
41     GX_UBYTE write_mask;
42     int y;
43     int x;
44 
45     if(header_created == 0)
46     {
47         if(test_parameter.x_start < 0)
48             test_parameter.x_start = 0;
49 
50         if(test_parameter.y_start < 0)
51             test_parameter.y_start = 0;
52 
53         if((test_parameter.x_end < 0) || (test_parameter.x_end >= canvas -> gx_canvas_x_resolution))
54             test_parameter.x_end = canvas -> gx_canvas_x_resolution - 1;
55 
56         if((test_parameter.y_end < 0) || (test_parameter.y_end >= canvas -> gx_canvas_y_resolution))
57             test_parameter.y_end = canvas -> gx_canvas_y_resolution - 1;
58 
59         width = test_parameter.x_end - test_parameter.x_start + 1;
60         height = test_parameter.y_end - test_parameter.y_start + 1;
61 
62         if(width & 0x1f)
63         {
64             width += 32 - (width & 0x1f);
65         }
66 
67         gx_validation_create_output_file("1bpp", width, height);
68         gx_validation_create_frame_buffer((width >> 3) * height);
69 
70         header_created = 1;
71 
72     }
73 
74     if(!gx_validation_frame_buffer)
75     {
76         return;
77     }
78 
79     gx_utility_rectangle_define(&overlap, test_parameter.x_start, test_parameter.y_start,
80         test_parameter.x_end, test_parameter.y_end);
81 
82     if(gx_utility_rectangle_overlap_detect(dirty, &overlap, &overlap))
83     {
84         read_pos = overlap.gx_rectangle_top * canvas -> gx_canvas_x_resolution;
85         read_pos += overlap.gx_rectangle_left;
86         write_pos = (overlap.gx_rectangle_top - test_parameter.y_start) * width;
87         write_pos += (overlap.gx_rectangle_left - test_parameter.x_start);
88 
89         for(y = overlap.gx_rectangle_top; y <= overlap.gx_rectangle_bottom; y++)
90         {
91             read = (GX_UBYTE *)canvas -> gx_canvas_memory;
92             read += (read_pos >> 3);
93             read_mask = (GX_UBYTE)(0x80 >> (read_pos & 0x7));
94 
95             write = (GX_UBYTE *)gx_validation_frame_buffer;
96             write += (write_pos >> 3);
97             write_mask = (GX_UBYTE)(0x80 >> (write_pos & 0x07));
98 
99             for(x = overlap.gx_rectangle_left; x <= overlap.gx_rectangle_right; x++)
100             {
101                 if((*read) & read_mask)
102                 {
103                     *write |= write_mask;
104                 }
105                 else
106                 {
107                     *write = (GX_UBYTE)((*write)&(~write_mask));
108                 }
109                 read_mask >>= 1;
110                 write_mask >>= 1;
111 
112                 if(!read_mask)
113                 {
114                     read++;
115                     read_mask = 0x80;
116                 }
117 
118                 if(!write_mask)
119                 {
120                     write++;
121                     write_mask = 0x80;
122                 }
123             }
124             read_pos += canvas -> gx_canvas_x_resolution;
125             write_pos += width;
126         }
127     }
128 
129     if(gx_validation_record_frame == 0)
130     {
131         return;
132     }
133 
134     gx_validation_record_frame = 0;
135 
136     /* Dump frame area */
137     gx_validation_write_frame_buffer();
138 }
139 
140 
141 
gx_validation_graphics_driver_setup_monochrome(GX_DISPLAY * display)142 UINT gx_validation_graphics_driver_setup_monochrome(GX_DISPLAY *display)
143 {
144 
145     /* Initialize the low-level drawing function pointers
146 
147        for windows, these are always just the generic funcions,
148        but for some hardware, these will be customized,
149        optimized functions specific to that hardware
150      */
151 
152     _gx_display_driver_monochrome_setup(display, (VOID*)1, _gx_validation_display_buffer_monochrome_toggle);
153 
154 
155     return(GX_SUCCESS);
156 }
157 
gx_validation_graphics_driver_cleanup_1bpp(GX_DISPLAY * display)158 VOID gx_validation_graphics_driver_cleanup_1bpp(GX_DISPLAY *display)
159 {
160 
161     /* Do nothing */
162 
163 }
164 
165 
166