comparison src/cs/drivers/drv_app/r2d/r2d_i.c @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /**
2
3 @file: r2d_i.c
4
5 @author Christophe Favergeon
6
7 @version 0.5
8
9 Purpose: Low level utilities functions for R2D
10
11 */
12
13 /*
14
15 Date Modification
16 ------------------------------------
17 06/02/2001 Create
18 10/18/2001 Version 0.5 for first integration with Riviera database
19
20
21 (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
22 */
23
24
25
26 #include "rv/general.h"
27 #include "rvf/rvf_api.h"
28 #include "r2d/r2d_config.h"
29 #include "r2d/r2d.h"
30 #include "r2d/r2d_i.h"
31 #include "r2d/r2d_independance_layer.h"
32 #if (R2D_DEBUG == R2D_ON)
33 #include <stdio.h>
34 #endif
35
36 #if (R2D_EMBEDDED_LCD == R2D_PC_COLOR_LCD)
37 #include "Windows.h"
38 #endif
39
40
41 ////////////////////////////////////////
42 //
43 // GLOBALS
44 //
45
46 UINT32 *r2d_g_dithering_matrix;
47
48 #if (R2D_ASM == R2D_ON)
49 T_RVF_MUTEX * r2d_g_blit_mutex;
50 T_R2D_DRAWING_MODE r2d_g_old_mode;
51 R2D_BOOLEAN r2d_g_old_use_foreground;
52 INT32 r2d_g_old_srcdst;
53 UINT32 r2d_g_old_foreground_pixelvalue;
54 UINT32 r2d_g_old_background_pixelvalue;
55 #endif
56
57 T_RVF_MUTEX * r2d_g_global_mutex;
58
59
60 ////////////////////////////////////////
61 //
62 // Class definitions
63 //
64
65 const T_R2D_CLASS_SHAPE r2d_class_rectangle=
66 {
67 NULL,
68 r2d_release_rectangle,
69 r2d_draw_rectangle_shape,
70 r2d_fill_rectangle_shape,
71 r2d_clone_rectangle_shape,
72 r2d_translate_rectangle_shape,
73 r2d_point_in_rectangle_shape
74 };
75
76 const T_R2D_CLASS_SHAPE r2d_class_circle=
77 {
78 NULL,
79 r2d_release_circle,
80 r2d_draw_circle_shape,
81 r2d_fill_circle_shape,
82 r2d_clone_circle_shape,
83 r2d_translate_point_shape,
84 r2d_point_in_circle_shape
85 };
86
87 const T_R2D_CLASS_SHAPE r2d_class_ellipse=
88 {
89 NULL,
90 r2d_release_ellipse,
91 r2d_draw_ellipse_shape,
92 r2d_fill_ellipse_shape,
93 r2d_clone_rectangle_shape,
94 r2d_translate_rectangle_shape,
95 r2d_point_in_ellipse_shape
96 };
97
98 const T_R2D_CLASS_SHAPE r2d_class_round_rectangle=
99 {
100 NULL,
101 r2d_release_round_rectangle,
102 r2d_draw_round_rectangle_shape,
103 r2d_fill_round_rectangle_shape,
104 r2d_clone_round_rectangle_shape,
105 r2d_translate_rectangle_shape,
106 r2d_point_in_round_rectangle_shape
107 };
108
109 const T_R2D_CLASS_SHAPE r2d_class_arc=
110 {
111 NULL,
112 r2d_release_arc,
113 r2d_draw_arc_shape,
114 r2d_fill_arc_shape,
115 r2d_clone_arc_shape,
116 r2d_translate_rectangle_shape,
117 r2d_point_in_not_supported_shape
118 };
119
120 const T_R2D_CLASS_SHAPE r2d_class_text=
121 {
122 NULL,
123 r2d_release_text,
124 r2d_draw_text_shape,
125 r2d_fill_text_shape,
126 r2d_clone_text_shape,
127 r2d_translate_point_shape,
128 r2d_point_in_not_supported_shape
129 };
130
131 //////////////////////////////////
132 //
133 // All globals must be protected
134 // with semaphores
135
136
137 T_R2D_FRAMEBUFFER* r2d_g_framebuffer;
138
139 // Pointer for default initializations of graphical context
140 T_R2D_FRAMEBUFFER *r2d_g_default_font_framebuffer;
141 INT32 *r2d_g_default_font_metrics;
142 INT32 *r2d_g_default_font_table;
143
144
145 BOOLEAN r2d_g_event_was_sent;
146 INT16 r2d_g_refresh_disabled;
147
148 T_R2D_FONT_DESCRIPTION *r2d_g_font_configuration;
149
150 //////////////////////////////////
151 //
152 // Common C code
153 //
154
155 T_R2D_DRAWING_OP r2d_get_drawing_op(T_R2D_GC *gc,T_R2D_DRAWING_MODE mode)
156 {
157 if (((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->kind!=R2D_FULL_KIND)
158 {
159 return(r2d_g_lcd_operators[mode]);
160 }
161 else
162 return(r2d_g_color_operators[mode]);
163 }
164
165 #if (R2D_ASM == R2D_ON)
166 UINT32 * r2d_get_asm_drawing_op(T_R2D_GC *gc,T_R2D_DRAWING_MODE mode)
167 {
168 if (((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->kind!=R2D_FULL_KIND)
169 {
170 return(r2d_g_asm_lcd_operators[mode]);
171 }
172 else
173 return(r2d_g_asm_color_operators[mode]);
174 }
175 #endif
176
177
178 // Get max component
179 UINT16 r2d_max_color(UINT16 red,UINT16 green, UINT16 blue)
180 {
181 UINT16 result=red;
182 if (green > result)
183 result=green;
184 if (blue > result)
185 result=blue;
186 return(result);
187 }
188
189 // Get min component
190 UINT16 r2d_min_color(UINT16 red,UINT16 green, UINT16 blue)
191 {
192 UINT16 result=red;
193 if (green < result)
194 result=green;
195 if (blue < result)
196 result=blue;
197 return(result);
198 }
199
200 #if (R2D_DITHERING == R2D_ON)
201
202 // Set element (x,y) of dithering or dithered matrix
203 void r2d_set_dithering_matrix_entry(UINT32 *matrix,UINT32 elem,INT16 x,INT16 y)
204 {
205 UINT32 *p=matrix;
206 p+=(x&1)+(y&1)*2;
207 *p=elem;
208 }
209
210
211 #else
212 #define r2d_set_dithering_matrix_entry(matrix,elem,x,y)
213 #endif
214
215
216 static UINT32 r2d_color_copy_operator(UINT32 old,UINT32 value)
217 {
218 return(value);
219 }
220 static UINT32 r2d_color_or_operator(UINT32 old,UINT32 value)
221 {
222 if ((value&0x00FFFFFF)==0)
223 return(value);
224 else
225 return(old);
226
227 }
228 static UINT32 r2d_color_and_operator(UINT32 old,UINT32 value)
229 {
230 return(old & value);
231 }
232 static UINT32 r2d_color_xor_operator(UINT32 old,UINT32 value)
233 {
234 return(old ^ value) ;
235 }
236 static UINT32 r2d_color_not_copy_operator(UINT32 old,UINT32 value)
237 {
238 return(~value);
239 }
240 static UINT32 r2d_color_not_or_operator(UINT32 old,UINT32 value)
241 {
242 return(~(old | value));
243 }
244 static UINT32 r2d_color_not_and_operator(UINT32 old,UINT32 value)
245 {
246 return(~(old & value));
247 }
248 static UINT32 r2d_color_not_xor_operator(UINT32 old,UINT32 value)
249 {
250 return(~(old ^ value)) ;
251 }
252
253 static UINT32 r2d_color_erase_operator(UINT32 old,UINT32 value)
254 {
255 if ((value & 0xFFFFFF)==0xFFFFFF)
256 return(0);
257 else
258 return(old);
259 }
260
261 UINT32 r2d_color_alpha_operator(UINT32 old,UINT32 value)
262 {
263 INT16 a,rs,gs,bs,rd,gd,bd;
264
265 a=(value >> 24) & 0x0FF;
266
267 value=~value;
268 old=~old;
269
270 bs=(value & 0xFF);
271 value=value>>8;
272 gs=(value & 0xFF);
273 value=value>>8;
274 rs=(value & 0xFF);
275 value=value>>8;
276
277
278
279
280 bd=(old & 0xFF);
281 old=old>>8;
282 gd=(old & 0xFF);
283 old=old>>8;
284 rd=(old & 0xFF);
285
286 // Pixel value has been complemented before being
287 // saved so that the white correspond to 0 and be
288 // compatible with formulas for other modes.
289 // But alpha value is not complemented
290 // So a=0xFF correspond tranparency
291 bd=((a)*bd+(0x100 - a)*bs) >> 8;
292 gd=((a)*gd+(0x100 - a)*gs) >> 8;
293 rd=((a)*rd+(0x100 - a)*rs) >> 8;
294
295 old=0;
296 old=old|(rd&0xFF);
297 old=old<<8;
298 old=old|(gd&0xFF);
299 old=old<<8;
300 old=old|(bd&0xFF);
301 old=(~old) & 0x00FFFFFF;
302 return(old);
303 }
304
305
306 const T_R2D_DRAWING_OPERATORS r2d_g_color_operators=
307 {
308 &r2d_color_copy_operator,
309 &r2d_color_or_operator,
310 &r2d_color_and_operator,
311 &r2d_color_xor_operator,
312 &r2d_color_not_copy_operator,
313 &r2d_color_not_or_operator,
314 &r2d_color_not_and_operator,
315 &r2d_color_not_xor_operator,
316 &r2d_color_alpha_operator,
317 &r2d_color_erase_operator
318 };
319
320 void r2d_convert_foreground_color_color(T_R2D_GC *gc,UINT32 color)
321 {
322 UINT32 lcolor;
323 gc->foreground_pixel_value=r2d_alpha(color);
324 gc->foreground_pixel_value<<=24;
325
326 lcolor=0;
327 lcolor|=r2d_red(color);
328 lcolor=lcolor<<8;
329 lcolor|=r2d_green(color);
330 lcolor=lcolor<<8;
331 lcolor|=r2d_blue(color);
332
333 gc->foreground_pixel_value|=(~lcolor) & 0x00FFFFFF;
334
335
336 }
337
338 // Return the pixel value to write on the LCD or the offscreen
339 // pixmap
340 // LCD DEPENDENT
341 void r2d_convert_background_color_color(T_R2D_GC *gc,UINT32 color)
342 {
343 UINT32 lcolor;
344 gc->background_pixel_value=r2d_alpha(color);
345 gc->background_pixel_value<<=24;
346
347 lcolor=0;
348 lcolor|=r2d_red(color);
349 lcolor=lcolor<<8;
350 lcolor|=r2d_green(color);
351 lcolor=lcolor<<8;
352 lcolor|=r2d_blue(color);
353
354
355 gc->background_pixel_value|=(~color) & 0x00FFFFFF;
356
357 }
358
359
360 // Select pixel of a color framebuffer as being
361 // a foreground or background one
362 BOOLEAN r2d_color_framebuffer_foreground_pixel(UINT32 lcd_value,T_R2D_GC_PTR src_gc)
363 {
364 if ((lcd_value & 0x00FFFFFF))
365 return(TRUE);
366 else
367 return(FALSE);
368 }
369
370
371 INT32 r2d_ptree_find(INT32 *tree,INT32 unicode)
372 {
373 INT32 state=0;
374 INT32 current_block;
375
376 current_block=unicode>>R2D_PTREE_SHIFT;
377 while (tree[state+R2D_PTREE_TYPE]!=R2D_PTREE_T_LEAF)
378 {
379 if (current_block & tree[state+R2D_PTREE_PREFIX])
380 state=tree[state+R2D_PTREE_RIGHT];
381 else
382 state=tree[state+R2D_PTREE_LEFT];
383 }
384
385 if (tree[state+R2D_PTREE_UNICODE_BLOCK]==current_block)
386 {
387 return(unicode + (tree[state+R2D_PTREE_CONVERSION]));
388 }
389 else
390 return(0);
391 }
392
393
394
395 INT32 r2d_get_point_side(INT16 x,INT16 y,INT32 sa,INT32 sb)
396 {
397 INT32 ret;
398 ret=((sb>>1)*x+((-sa)>>1)*y);
399 return(ret);
400 }
401
402 BOOLEAN r2d_check_is_in_arc_region(INT16 x,INT16 y,T_R2D_ARC_REGION *rgn)
403 {
404 INT32 a,b;
405
406 a=r2d_get_point_side(x,y,rgn->sa,rgn->sb);
407 b=r2d_get_point_side(x,y,rgn->ea,rgn->eb);
408
409 /*if (a&&b)
410 r2d_set_foreground_color_with_argb(r2d_g_lcd_gc,0,255,0,0);
411 else if (!a && !b)
412 r2d_set_foreground_color_with_argb(r2d_g_lcd_gc,0,0,255,0);
413 else if (!a && b)
414 r2d_set_foreground_color_with_argb(r2d_g_lcd_gc,0,0,0,255);
415 else if (a && !b)
416 r2d_set_foreground_color_with_argb(r2d_g_lcd_gc,0,255,255,0);*/
417
418 if (rgn->one_sector==0)
419 return(((a>=0) && (b>=0)));
420 else
421 return(!(!(a>=0) && !(b>=0)));
422
423 }
424
425 void r2d_arc_region_y_reflect(T_R2D_ARC_REGION *rgn)
426 {
427 rgn->sa=-rgn->sa;
428 rgn->ea=-rgn->ea;
429 }
430
431 void r2d_arc_region_x_reflect(T_R2D_ARC_REGION *rgn)
432 {
433 rgn->sb=-rgn->sb;
434 rgn->eb=-rgn->eb;
435 }
436
437 void r2d_arc_region_diagonal_reflect(T_R2D_ARC_REGION *rgn)
438 {
439 INT32 tmp;
440
441 tmp=rgn->sa;
442 rgn->sa=rgn->sb;
443 rgn->sb=tmp;
444
445 tmp=rgn->ea;
446 rgn->ea=rgn->eb;
447 rgn->eb=tmp;
448 }