Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / fblog / 0004-fblog-implement-fblog_redraw.patch
1 From 086525bfbf807d8c2792b18d35127c791289d0b8 Mon Sep 17 00:00:00 2001
2 From: David Herrmann <dh.herrmann@googlemail.com>
3 Date: Sat, 16 Jun 2012 23:01:41 +0200
4 Subject: [PATCH 04/10] fblog: implement fblog_redraw()
5
6 This mostly copies the functionality from drivers/video/console/bitblit.c
7 so we can draw the console content on all available framebuffers.
8
9 All speed optimizations have been removed for simplicity. The original
10 code depends heavily on CONFIG_VT so we cannot share the codebase here.
11
12 Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
13 ---
14  drivers/video/console/fblog.c |  126 +++++++++++++++++++++++++++++++++++++++++
15  1 file changed, 126 insertions(+)
16
17 diff --git a/drivers/video/console/fblog.c b/drivers/video/console/fblog.c
18 index 8038dcc..e790971 100644
19 --- a/drivers/video/console/fblog.c
20 +++ b/drivers/video/console/fblog.c
21 @@ -197,6 +197,131 @@ static void fblog_buf_write(struct fblog_buf *buf, const char *str, size_t len)
22         }
23  }
24  
25 +static void fblog_redraw_aligned(struct fblog_fb *fb, const char *s, u32 cnt,
26 +                                u32 d_pitch, u32 s_pitch, u32 cellsize,
27 +                                struct fb_image *image, u8 *dst)
28 +{
29 +       struct fb_info *info = fb->info;
30 +       const struct font_desc *font = fb->font;
31 +       u32 idx = font->width >> 3;
32 +       u8 *src;
33 +
34 +       while (cnt--) {
35 +               src = (void*)(font->data + (*s++ & 0xff) * cellsize);
36 +               fb_pad_aligned_buffer(dst, d_pitch, src, idx, image->height);
37 +               dst += s_pitch;
38 +       }
39 +
40 +       info->fbops->fb_imageblit(info, image);
41 +}
42 +
43 +static void fblog_redraw_unaligned(struct fblog_fb *fb, const char *s, u32 cnt,
44 +                                  u32 d_pitch, u32 s_pitch, u32 cellsize,
45 +                                  struct fb_image *image, u8 *dst)
46 +{
47 +       struct fb_info *info = fb->info;
48 +       const struct font_desc *font = fb->font;
49 +       u32 shift_low = 0, mod = font->width % 8;
50 +       u32 shift_high = 8;
51 +       u32 idx = font->width >> 3;
52 +       u8 *src;
53 +
54 +       while (cnt--) {
55 +               src = (void*)(font->data + (*s++ & 0xff) * cellsize);
56 +               fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
57 +                                       image->height, shift_high,
58 +                                       shift_low, mod);
59 +               shift_low += mod;
60 +               dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
61 +               shift_low &= 7;
62 +               shift_high = 8 - shift_low;
63 +       }
64 +
65 +       info->fbops->fb_imageblit(info, image);
66 +}
67 +
68 +static void fblog_redraw_line(struct fblog_fb *fb, size_t line,
69 +                             const char *str, size_t len)
70 +{
71 +       struct fb_info *info = fb->info;
72 +       const struct font_desc *font = fb->font;
73 +       struct fb_image image;
74 +       u32 width = DIV_ROUND_UP(font->width, 8);
75 +       u32 cellsize = width * font->height;
76 +       u32 maxcnt = info->pixmap.size / cellsize;
77 +       u32 scan_align = info->pixmap.scan_align - 1;
78 +       u32 buf_align = info->pixmap.buf_align - 1;
79 +       u32 mod = font->width % 8;
80 +       u32 cnt, pitch, size;
81 +       u8 *dst;
82 +
83 +       image.fg_color = 7;
84 +       image.bg_color = 0;
85 +       image.dx = 0;
86 +       image.dy = line * font->height;
87 +       image.height = font->height;
88 +       image.depth = 1;
89 +
90 +       while (len) {
91 +               if (len > maxcnt)
92 +                       cnt = maxcnt;
93 +               else
94 +                       cnt = len;
95 +
96 +               image.width = font->width * cnt;
97 +               pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
98 +               pitch &= ~scan_align;
99 +               size = pitch * image.height + buf_align;
100 +               size &= ~buf_align;
101 +               dst = fb_get_buffer_offset(info, &info->pixmap, size);
102 +               image.data = dst;
103 +
104 +               if (!mod)
105 +                       fblog_redraw_aligned(fb, str, cnt, pitch, width,
106 +                                            cellsize, &image, dst);
107 +               else
108 +                       fblog_redraw_unaligned(fb, str, cnt, pitch, width,
109 +                                              cellsize, &image, dst);
110 +
111 +               image.dx += cnt * font->width;
112 +               len -= cnt;
113 +               str += cnt;
114 +       }
115 +}
116 +
117 +static void fblog_redraw_clear(struct fblog_fb *fb)
118 +{
119 +       struct fb_fillrect region;
120 +       struct fb_info *info = fb->info;
121 +
122 +       region.color = 0;
123 +       region.dx = 0;
124 +       region.dy = 0;
125 +       region.width = info->var.xres;
126 +       region.height = info->var.yres;
127 +       region.rop = ROP_COPY;
128 +
129 +       info->fbops->fb_fillrect(info, &region);
130 +}
131 +
132 +static void fblog_redraw(struct fblog_fb *fb)
133 +{
134 +       size_t i, len;
135 +
136 +       if (!fb || !fb->font || test_bit(FBLOG_KILLED, &fb->flags) ||
137 +           test_bit(FBLOG_SUSPENDED, &fb->flags) ||
138 +           test_bit(FBLOG_BLANKED, &fb->flags))
139 +               return;
140 +
141 +       fblog_redraw_clear(fb);
142 +
143 +       for (i = 0; i < fb->buf.height; ++i) {
144 +               len = strnlen(fb->buf.lines[i], fb->buf.width);
145 +               if (len)
146 +                       fblog_redraw_line(fb, i, fb->buf.lines[i], len);
147 +       }
148 +}
149 +
150  static struct fblog_fb *fblog_info2fb(struct fb_info *info)
151  {
152         if (!info || info->node < 0 || info->node >= FB_MAX ||
153 @@ -244,6 +369,7 @@ static void fblog_register(struct fb_info *info)
154                 width = info->var.xres / fb->font->width;
155                 height = info->var.yres / fb->font->height;
156                 fblog_buf_resize(&fb->buf, width, height);
157 +               fblog_redraw(fb);
158         }
159  
160         return;
161 -- 
162 1.7.10.4
163