|
1 |
|
2 /* |
|
3 * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved. |
|
4 * |
|
5 * Permission is hereby granted, free of charge, to any person obtaining a |
|
6 * copy of this software and associated documentation files (the "Software"), |
|
7 * to deal in the Software without restriction, including without limitation |
|
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
9 * and/or sell copies of the Software, and to permit persons to whom the |
|
10 * Software is furnished to do so, subject to the following conditions: |
|
11 * |
|
12 * The above copyright notice and this permission notice (including the next |
|
13 * paragraph) shall be included in all copies or substantial portions of the |
|
14 * Software. |
|
15 * |
|
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
22 * DEALINGS IN THE SOFTWARE. |
|
23 */ |
|
24 |
|
25 #include <sys/types.h> |
|
26 #include <errno.h> |
|
27 #include <signal.h> /* signal() */ |
|
28 #include <stdio.h> |
|
29 #include <stropts.h> /* ioctl() */ |
|
30 #include <unistd.h> /* ioctl(), sleep() */ |
|
31 #include <sys/mman.h> |
|
32 |
|
33 #include "gfx_common.h" /* VTS Graphics Test common routines */ |
|
34 #include "graphicstest.h" |
|
35 #include "gfx_vts.h" /* VTS Graphics Test common routines */ |
|
36 #include "ast.h" |
|
37 |
|
38 void |
|
39 box(struct ast_info *pAST, int x1, int y1, int x2, int y2, unsigned int color) |
|
40 { |
|
41 int tmp; |
|
42 int width; |
|
43 int height; |
|
44 |
|
45 if (x2 < x1) { |
|
46 tmp = x2; |
|
47 x2 = x1; |
|
48 x1 = tmp; |
|
49 } |
|
50 if (y2 < y1) { |
|
51 tmp = y2; |
|
52 y2 = y1; |
|
53 y1 = tmp; |
|
54 } |
|
55 |
|
56 width = x2 - x1; |
|
57 height = y2 - y1; |
|
58 |
|
59 ASTSetupForSolidFill(pAST, color, 0xf0); |
|
60 ASTSolidFillRect(pAST, x1, y1, width, height); |
|
61 |
|
62 } /* box() */ |
|
63 |
|
64 void |
|
65 line(struct ast_info *pAST, |
|
66 int x1, |
|
67 int y1, |
|
68 int x2, |
|
69 int y2, |
|
70 unsigned int color |
|
71 ) |
|
72 { |
|
73 ASTSetupForSolidLine(pAST, color, 0xf0); |
|
74 ASTSolidLine(pAST, x1, y1, x2, y2); |
|
75 |
|
76 } /* line() */ |
|
77 |
|
78 |
|
79 void |
|
80 draw_cascaded_box(struct ast_info *pAST, int width, int height) |
|
81 { |
|
82 unsigned int x1; |
|
83 unsigned int y1; |
|
84 unsigned int x2; |
|
85 unsigned int y2; |
|
86 unsigned int w; |
|
87 unsigned int h; |
|
88 int i; |
|
89 unsigned int k = 0; |
|
90 |
|
91 for (i = 0; i < 256; i++) { |
|
92 |
|
93 x1 = (unsigned int)((width * i) / 512); |
|
94 x2 = width - x1; |
|
95 w = x2 - x1; |
|
96 |
|
97 y1 = (unsigned int)((height * i) / 512); |
|
98 y2 = height - y1; |
|
99 |
|
100 k = (i<<24 | i<<16 | i<<8 | i); |
|
101 |
|
102 box(pAST, x1, y1, x2, y2, k); |
|
103 } |
|
104 |
|
105 } /* draw_cascaded_box() */ |
|
106 |
|
107 |
|
108 void |
|
109 draw_lines(struct ast_info *pAST, int width, int height) |
|
110 { |
|
111 unsigned int x1; |
|
112 unsigned int y1; |
|
113 unsigned int x2; |
|
114 unsigned int y2; |
|
115 int k; |
|
116 int i; |
|
117 int nlines = 128; |
|
118 |
|
119 k = 0; |
|
120 for (i = 0; i < nlines; i++) { |
|
121 k = 0x00af0000 | (i << 8) | i; |
|
122 |
|
123 x1 = (unsigned int)((width * i) / nlines); |
|
124 x2 = x1; |
|
125 y1 = 0; |
|
126 y2 = height; |
|
127 |
|
128 line(pAST, x1, y1, x2, y2, k); |
|
129 } |
|
130 |
|
131 for (i = 0; i < nlines; i++) { |
|
132 k = 0x00af0000 | (i << 8) | i; |
|
133 |
|
134 x1 = 0; |
|
135 x2 = width; |
|
136 y1 = (unsigned int)((height * i) / nlines); |
|
137 y2 = y1; |
|
138 |
|
139 line(pAST, x1, y1, x2, y2, k); |
|
140 } |
|
141 } |
|
142 |
|
143 void |
|
144 chip_test(return_packet *rp, int fd) |
|
145 { |
|
146 struct ast_info ast_info; |
|
147 struct ast_info *pAST; |
|
148 unsigned int red; |
|
149 unsigned char *fbaddr; |
|
150 int i; |
|
151 int bytepp; |
|
152 int fb_offset, fb_pitch, fb_height, fb_width; |
|
153 |
|
154 pAST = &ast_info; |
|
155 pAST->fd = fd; |
|
156 |
|
157 /* |
|
158 * map the registers & frame buffers memory |
|
159 */ |
|
160 if (ast_map_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) { |
|
161 return; |
|
162 } |
|
163 |
|
164 /* |
|
165 * initialize ast info |
|
166 */ |
|
167 if (ast_init_info(pAST) == -1) { |
|
168 return; |
|
169 } |
|
170 |
|
171 /* |
|
172 * only support 32 bits depth for now |
|
173 */ |
|
174 if (pAST->bytesPerPixel == 1) { |
|
175 goto done; |
|
176 } |
|
177 |
|
178 /* |
|
179 * enable 2D, initialize command queue |
|
180 */ |
|
181 ASTEnable2D(pAST); |
|
182 |
|
183 if (ASTInitCMDQ(pAST) == -1) { |
|
184 pAST->MMIO2D = 1; |
|
185 } else {; |
|
186 ASTEnableCMDQ(pAST); |
|
187 } |
|
188 |
|
189 ASTSaveState(pAST); |
|
190 |
|
191 /* |
|
192 * set clipping rectangle |
|
193 */ |
|
194 ASTSetClippingRectangle(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight); |
|
195 |
|
196 /* |
|
197 * Clear screen |
|
198 */ |
|
199 box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0); |
|
200 ASTWaitEngIdle(pAST); |
|
201 |
|
202 /* |
|
203 * line test |
|
204 */ |
|
205 draw_lines(pAST, pAST->screenWidth, pAST->screenHeight); |
|
206 ASTWaitEngIdle(pAST); |
|
207 sleep(2); |
|
208 |
|
209 /* |
|
210 * fill test |
|
211 */ |
|
212 draw_cascaded_box(pAST, pAST->screenWidth, pAST->screenHeight); |
|
213 ASTWaitEngIdle(pAST); |
|
214 sleep(2); |
|
215 |
|
216 /* |
|
217 * Clear screen |
|
218 */ |
|
219 box(pAST, 0, 0, pAST->screenWidth, pAST->screenHeight, 0xff); |
|
220 ASTWaitEngIdle(pAST); |
|
221 sleep(2); |
|
222 |
|
223 ASTResetState(pAST); |
|
224 |
|
225 done: |
|
226 /* |
|
227 * Unmap the registers & frame buffers memory |
|
228 */ |
|
229 if (ast_unmap_mem(pAST, rp, GRAPHICS_ERR_CHIP) == -1) { |
|
230 return; |
|
231 } |
|
232 |
|
233 |
|
234 if (close(fd) == -1) { |
|
235 gfx_vts_set_message(rp, 1, GRAPHICS_ERR_CHIP, "error closing device\n"); |
|
236 return; |
|
237 } |
|
238 |
|
239 } /* chip_test() */ |
|
240 |
|
241 |
|
242 /* End of chip.c */ |