-
Notifications
You must be signed in to change notification settings - Fork 11
/
egi_fbdev.h
236 lines (206 loc) · 10.2 KB
/
egi_fbdev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*------------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
Referring to: http://blog.chinaunix.net/uid-22666248-id-285417.html
本文的copyright归[email protected] 所有,使用GPL发布,可以自由拷贝,转载。
但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
博客:yuweixian4230.blog.chinaunix.net
Modified and appended by: Midas Zhou
[email protected](Not in use since 2022_03_01)
-----------------------------------------------------------------------------*/
#ifndef __EGI_FBDEV_H__
#define __EGI_FBDEV_H__
#include <stdio.h>
#include <linux/fb.h>
#include <stdint.h>
#include <stdbool.h>
//#include "egi.h" /* definition conflict */
#include "egi_filo.h"
#include "egi_imgbuf.h"
#include "egi_color.h"
//#include "egi_image.h" /* definition conflict */
#ifdef __cplusplus
extern "C" {
#endif
/* See FBDEV.devname, or use gv_fb_dev.devname="/dev/fb0" as default. */
//#ifdef LETS_NOTE
//#define EGI_FBDEV_NAME "/dev/fb0" //1
//#else
//#define EGI_FBDEV_NAME "/dev/fb0"
//#endif
#define FBDEV_BUFFER_PAGES 3 /* Max FB buffer pages */
/*** NOTE:
* 1. FBDEV is considered to be statically allocated!
* 2. (.fbfd <=0) is deemed as an uninitialized FBDEV.
*/
typedef struct fbdev{
const char* devname; /* FB device name, if NULL, use default "/dev/fb0" */
int fbfd; /* FB device file descriptor, open "dev/fbx"
* If <=0, as an uninitialized FBDEV.
*/
bool virt; /* 1. TRUE: virtural fbdev, it maps to an EGI_IMGBUF
* and fbfd will be ineffective.
* vinfo.xres,vinfo.yres and vinfo.screensize MUST set.
* as .width and .height of the EGI_IMGBUF.
* 2. FALSE: maps to true FB device, fbfd is effective.
* 3. FB FILO will be ineffective then.
*/
struct fb_var_screeninfo vinfo; /* !!! WARNING !!!
* vinfo.line_length/bytes_per_pixel may NOT equal vinfo.xres
* In some case, line_length/bytes_per_pixel > xres, because of LCD size limit,
* not of controller RAM limit!
* But in all functions we assume xres==info.line_length/bytes_per_pixel, so lookt it over
* if problem arises.
*/
struct fb_fix_screeninfo finfo;
int *zbuff; /* Pixel depth, for totally xres*yres pixels. NOW: integer type, ( TODO: float type)
* Rest all to 0 when clear working buffer.
* NOT for virt FB.
* TODO: CAVEAT: zbuff[] allocated without considering vinfo.line_length/bytes_per_pixel!
* TODO: Init as INT32_MIN (-2147483648) OR INT64_MIN (-__INT64_C(9223372036854775807)-1)
* TODO: zbuff[] does NOT consider pos_rotation.
*/
bool zbuff_on;
bool zbuff_IgnoreEqual; /* If pixZ compares equal to the buffered zbuff[] value, DO NOT refresh it then!
* FALSE(default): if( pixz >= zbuff[] ) then refresh/re_buffer.
* TRUE: if( pixz >zbuff[]) then refresh/re_buffer.
*/
bool flipZ; /* If ture, pixz will be flipped to be -pixz before compare and buffer to zbuff[] */
int pixz; /* Pixel z value, 0 as bkground layer If DEFAULT!(surfaces) */
unsigned long screensize; /* in bytes */
/* TODO: To hook up map_fb and map_buff[] with EGI_IMGBUFs */
unsigned char *map_fb; /* Pointer to kernel FB buffer, mmap to FB data */
/* BUFF number as unsigned int */
#define FBDEV_WORKING_BUFF 0 /* map_buff[page FBDEV_WORKING_BUFF] */
#define FBDEV_BKG_BUFF 1 /* map_buff[page FBDEV_BKG_BUFF] */
unsigned char *map_buff; /* Pointer to user FB buffers, 1-3 pages, maybe more.
* Default:
* 1st buff page as working buffer.
* 2nd buff page as background buffer.
* Only when ENABLE_BACK_BUFFER is defined, then map_buff will be allocated.
*/
unsigned char *map_bk; /* Pointer to curret working back buffer page, mmap mem
* 1. When ENABLE_BACK_BUFFER is defined, map_bk is pointed to map_buff; all write/read
* operation to the FB will be directed to the map_buff through map_bk,
* map_fb pointered data will be updated only when fb_refresh() is called, or
* memcpy back buffer to it explicitly.
* 2. If ENABLE_BACK_BUFFER not defined, map_buff will not be allocated and map_bk is set to NULL.
* All write/read operation will affect to FB mem directly throuhg map_fb.
* 3. When fb_set_directFB() is called after init_fbdev(), then map_bk will be re-appointed to map_fb
* or map_buff. However, if ENABLE_BACK_BUFFER is not defined, then it will be invalid/fail to call
* fb_set_directFB(false), for map_buff and map_bk are all NULL.
*/
unsigned int npg; /* index of back buffer page, Now npg=0 or 1, maybe 2 */
/* --- For Virtual FBDEV --- */
EGI_IMGBUF *virt_fb; /* virtual FB, as an EGI_IMGBUF, see also vimg_owner */
EGI_IMGBUF *VFrameImg; /* To hold a Virtual Frame IMGBUF. as result of a completed frame. render result.
* vfb_render(): copy virt_fb to VFrameImg.
*/
bool vimg_owner; /* Ownership of virt_fb(imgbuf) and VFrameImg.
* True: FBDEV has the ownership, usually imgbuf is created/allocated during init_virt_fbdev().
* and virt_fb will be released when release_virt_fbdev().
* False: Usually the imgbuf is created/allocated by the caller, and FBDEV will NOT
* try to free it when release_virt_fbdev().
*/
bool antialias_on; /* Carry out anti-aliasing functions
* True:
* //XXX draw_line() CALLs draw_line_antialias().
* draw_line() CALLs fdraw_line().
* False:
* draw_line() CALLs draw_line_simple().
*/
bool pixcolor_on; /* default/init as off, If ture: draw_dot() use pixcolor, else: draw_dot() use fb_color.
* Usually to set pixcolor_on immediately after init_(virt_)fbdev.
*/
uint16_t pixcolor; /* pixel color */
unsigned char pixalpha; /* pixel alpha value in use, 0: 100% bkcolor, 255: 100% frontcolor */
bool pixalpha_hold; /* Normally, pixalpha will be reset to 255 after each draw_dot() operation
* True: pixalpha will NOT be reset after draw_dot(), it keeps effective
* to all draw_dot()/writeFB() operations afterward.
* False: As defaulst set.
* Note: Any function that need to set pixalpha_hold MUST reset it and
* reassign pixcolor to 255 before the end.
*/
int lumadelt; /* Luminance adjustment value if !=0
* If it applys, then fbget_pixColor() will NOT get the original color, since it's changed.
*/
/* Screen Position Rotation: Not applicable for virtual FBDEV!
* Call fb_position_rotate() to change following items.
*/
int pos_rotate;
/* 0: default X,Y coordinate of FB
* 1: clockwise rotation 90 deg: Y maps to (vinfo.xres-1)-FB.X,
* X maps to FB.Y
* 2: clockwise rotation 180 deg
* 3: clockwise rotation 270 deg
* Others: as default 0
* Note: Default FB set, as pos_rotate=0, is faster than other sets.
* for it only needs value assignment, while other sets need
* coordinate transforming/mapping calculations.
* Rotation coord as per RIGHT HAND RULE of LCD X,Y ( x-->y grip direction. thumb --> z )
*/
int pos_xres; /* Resolution for X and Y direction, as per pos_rotate */
/* CAVEAT: confusion with fb_dev->finfo.line_length! */
int pos_yres;
/* pthread_mutex_t fbmap_lock; */
EGI_FILO *fb_filo;
int filo_on; /* >0, activate FILO push */
// uint16_t *buffer[FBDEV_BUFFER_PAGES]; /* FB image data buffer */
}FBDEV;
/* distinguished from PIXEL in egi_bjp.h */
typedef struct fbpixel {
long int position;
#ifdef LETS_NOTE
uint32_t argb;
#else
uint16_t color;
#endif
}FBPIX;
/* Default sys FBDEV, global variale, Frame buffer device
* Note: Most EGI advanced elements only support gv_fb_dev as default FBDEV,
* however, you can create a new FBDEV by init_fbdev(), and write data to it by calling
* supportive functions, which are usually basic element functions.
*/
extern FBDEV gv_fb_dev;
/* functions */
int init_fbdev(FBDEV *dev);
void release_fbdev(FBDEV *dev);
//int fb_set_screenVinfo(FBDEV *fb_dev, struct fb_var_screeninfo *old_vinfo, const struct fb_var_screeninfo *new_vinfo);
//int fb_set_screenPos(FBDEV *fb_dev, unsigned int xres, unsigned int yres);
int init_virt_fbdev(FBDEV *fb_dev, EGI_IMGBUF *fbimg, EGI_IMGBUF *FrameImg);
int virt_fbdev_updateImg(FBDEV *fb_dev, EGI_IMGBUF *fbimg, EGI_IMGBUF *FrameImg);
int init_virt_fbdev2(FBDEV *fb_dev, int xres, int yres, int alpha, EGI_16BIT_COLOR color);
void release_virt_fbdev(FBDEV *dev);
int reinit_virt_fbdev(FBDEV *dev, EGI_IMGBUF *fbimg, EGI_IMGBUF *FrameImg);
void fb_shift_buffPage(FBDEV *fb_dev, unsigned int numpg);
void fb_set_directFB(FBDEV *fb_dev, bool directFB);
int fb_get_FBmode(FBDEV *fb_dev);
void fb_init_FBbuffers(FBDEV *fb_dev);
void fb_copy_FBbuffer(FBDEV *fb_dev,unsigned int from_numpg, unsigned int to_numpg);
void fb_clear_backBuff(FBDEV *dev, uint32_t color);
void fb_clear_workBuff(FBDEV *fb_dev, EGI_16BIT_COLOR color);
void fb_clear_bkgBuff(FBDEV *fb_dev, EGI_16BIT_COLOR color);
void fb_reset_zbuff(FBDEV *fb_dev);
void fb_init_zbuff(FBDEV *fb_dev, int z0);
void fb_block_zbuff(FBDEV *fb_dev, int x0, int y0, unsigned int w, unsigned int h, int pixz);
void fb_clear_mapBuffer(FBDEV *dev, unsigned int numpg, uint16_t color); /* for 16bit color only */
int fb_page_refresh(FBDEV *dev, unsigned int numpg);
void fb_lines_refresh(FBDEV *dev, unsigned int numpg, unsigned int startln, int n);
int fb_render(FBDEV *dev);
int vfb_render(FBDEV *dev);
int fb_page_saveToBuff(FBDEV *dev, unsigned int buffNum);
int fb_page_restoreFromBuff(FBDEV *dev, unsigned int buffNum);
int fb_page_refresh_flyin(FBDEV *dev, int speed);
int fb_slide_refresh(FBDEV *dev, int offl);
void fb_filo_on(FBDEV *dev);
void fb_filo_off(FBDEV *dev);
void fb_filo_flush(FBDEV *dev);
void fb_filo_dump(FBDEV *dev);
void fb_position_rotate(FBDEV *dev, unsigned char pos);
void fb_gammaCorrect(FBDEV *fb_dev, float gampow);
#ifdef __cplusplus
}
#endif
#endif