blob: cc5e09e306050ba3d8a433f96ec9cd9ccd9fd821 [file] [log] [blame]
Dima Zavind5b0b6a2009-01-15 18:09:25 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Wenjun Zhang4e63ce42017-11-28 05:11:34 -05005 * Copyright (c) 2009-2015, 2018 The Linux Foundation. All rights reserved.
Shashank Mittal4f99a882010-02-01 13:58:50 -08006 *
Dima Zavind5b0b6a2009-01-15 18:09:25 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
lijuang7cfbfe32018-02-06 17:09:13 +080024 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
Dima Zavind5b0b6a2009-01-15 18:09:25 -080025 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <err.h>
33#include <stdlib.h>
34#include <dev/fbcon.h>
Chandan Uddaraju40b227d2010-08-03 19:25:41 -070035#include <splash.h>
Greg Griscod6250552011-06-29 14:40:23 -070036#include <platform.h>
37#include <string.h>
Channagoud Kadabi7af9fbc2015-02-13 20:09:55 -080038#include <arch/ops.h>
Channagoud Kadabi875a2a72015-04-24 17:26:38 -070039#if ENABLE_WBC
40#include <pm_app_smbchg.h>
41#endif
Dima Zavind5b0b6a2009-01-15 18:09:25 -080042
43#include "font5x12.h"
44
45struct pos {
46 int x;
47 int y;
48};
49
lijuangdd73d652015-06-05 21:29:37 +080050struct fb_color {
51 uint32_t fg;
52 uint32_t bg;
53};
54
Dima Zavind5b0b6a2009-01-15 18:09:25 -080055static struct fbcon_config *config = NULL;
56
Chandan Uddaraju2943fd62010-06-21 10:56:39 -070057#define RGB565_BLACK 0x0000
Dima Zavind5b0b6a2009-01-15 18:09:25 -080058#define RGB565_WHITE 0xffff
lijuangdd73d652015-06-05 21:29:37 +080059#define RGB565_CYAN 0x07ff
60#define RGB565_BLUE 0x001f
61#define RGB565_SILVER 0xc618
62#define RGB565_YELLOW 0xffe0
63#define RGB565_ORANGE 0xfd20
64#define RGB565_RED 0xf800
lijuang4304fce2015-08-14 20:52:47 +080065#define RGB565_GREEN 0x3666
Dima Zavind5b0b6a2009-01-15 18:09:25 -080066
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070067#define RGB888_BLACK 0x000000
68#define RGB888_WHITE 0xffffff
lijuangdd73d652015-06-05 21:29:37 +080069#define RGB888_CYAN 0x00ffff
70#define RGB888_BLUE 0x0000FF
71#define RGB888_SILVER 0xc0c0c0
72#define RGB888_YELLOW 0xffff00
73#define RGB888_ORANGE 0xffa500
74#define RGB888_RED 0xff0000
lijuang4304fce2015-08-14 20:52:47 +080075#define RGB888_GREEN 0x00ff00
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070076
Dima Zavind5b0b6a2009-01-15 18:09:25 -080077#define FONT_WIDTH 5
78#define FONT_HEIGHT 12
79
Sandeep Pandadf39f752015-05-08 14:01:16 +053080#define SCALE_FACTOR 2
81
82static uint32_t BGCOLOR;
83static uint32_t FGCOLOR;
lijuangdd73d652015-06-05 21:29:37 +080084static uint32_t SELECT_BGCOLOR;
Dima Zavind5b0b6a2009-01-15 18:09:25 -080085
86static struct pos cur_pos;
87static struct pos max_pos;
lijuangdd73d652015-06-05 21:29:37 +080088static struct fb_color *fb_color_formats;
89static struct fb_color fb_color_formats_555[] = {
90 [FBCON_COMMON_MSG] = {RGB565_WHITE, RGB565_BLACK},
lijuangf3d7fc52018-04-23 16:34:29 +080091 [FBCON_UNLOCK_TITLE_MSG] = {RGB565_RED, RGB565_BLACK},
lijuangdd73d652015-06-05 21:29:37 +080092 [FBCON_TITLE_MSG] = {RGB565_WHITE, RGB565_BLACK},
93 [FBCON_SUBTITLE_MSG] = {RGB565_SILVER, RGB565_BLACK},
94 [FBCON_YELLOW_MSG] = {RGB565_YELLOW, RGB565_BLACK},
95 [FBCON_ORANGE_MSG] = {RGB565_ORANGE, RGB565_BLACK},
96 [FBCON_RED_MSG] = {RGB565_RED, RGB565_BLACK},
lijuang4304fce2015-08-14 20:52:47 +080097 [FBCON_GREEN_MSG] = {RGB565_GREEN, RGB565_BLACK},
lijuangdd73d652015-06-05 21:29:37 +080098 [FBCON_SELECT_MSG_BG_COLOR] = {RGB565_WHITE, RGB565_BLUE}};
99
100static struct fb_color fb_color_formats_888[] = {
101 [FBCON_COMMON_MSG] = {RGB888_WHITE, RGB888_BLACK},
lijuangf3d7fc52018-04-23 16:34:29 +0800102 [FBCON_UNLOCK_TITLE_MSG] = {RGB888_RED, RGB888_BLACK},
lijuangdd73d652015-06-05 21:29:37 +0800103 [FBCON_TITLE_MSG] = {RGB888_WHITE, RGB888_BLACK},
104 [FBCON_SUBTITLE_MSG] = {RGB888_SILVER, RGB888_BLACK},
105 [FBCON_YELLOW_MSG] = {RGB888_YELLOW, RGB888_BLACK},
106 [FBCON_ORANGE_MSG] = {RGB888_ORANGE, RGB888_BLACK},
107 [FBCON_RED_MSG] = {RGB888_RED, RGB888_BLACK},
lijuang4304fce2015-08-14 20:52:47 +0800108 [FBCON_GREEN_MSG] = {RGB888_GREEN, RGB888_BLACK},
lijuangdd73d652015-06-05 21:29:37 +0800109 [FBCON_SELECT_MSG_BG_COLOR] = {RGB888_WHITE, RGB888_BLUE}};
110
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800111
lijuangb3812fb2015-12-16 15:42:02 +0800112static void fbcon_flush(void);
113
Sandeep Pandadf39f752015-05-08 14:01:16 +0530114static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride,
lijuangdd73d652015-06-05 21:29:37 +0800115 unsigned bpp, unsigned *glyph, unsigned scale_factor)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800116{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530117 unsigned x, y, i, j, k;
118 unsigned data, temp;
119 uint32_t fg_color = paint;
lijuangdd73d652015-06-05 21:29:37 +0800120 stride -= FONT_WIDTH * scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800121
122 data = glyph[0];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530123 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
124 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800125 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530126 data = temp;
127 for (x = 0; x < FONT_WIDTH; ++x) {
128 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800129 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530130 fg_color = paint;
131 for (k = 0; k < bpp; k++) {
132 *pixels = (unsigned char) fg_color;
133 fg_color = fg_color >> 8;
134 pixels++;
135 }
136 }
137 }
138 else
139 {
lijuangdd73d652015-06-05 21:29:37 +0800140 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530141 pixels = pixels + bpp;
142 }
143 }
144 data >>= 1;
145 }
146 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800147 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800148 }
149
150 data = glyph[1];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530151 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
152 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800153 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530154 data = temp;
155 for (x = 0; x < FONT_WIDTH; ++x) {
156 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800157 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530158 fg_color = paint;
159 for (k = 0; k < bpp; k++) {
160 *pixels = (unsigned char) fg_color;
161 fg_color = fg_color >> 8;
162 pixels++;
163 }
164 }
165 }
166 else
167 {
lijuangdd73d652015-06-05 21:29:37 +0800168 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530169 pixels = pixels + bpp;
170 }
171 }
172 data >>= 1;
173 }
174 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800175 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800176 }
Sandeep Pandadf39f752015-05-08 14:01:16 +0530177
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800178}
179
lijuangdd73d652015-06-05 21:29:37 +0800180void fbcon_draw_msg_background(unsigned y_start, unsigned y_end,
181 uint32_t old_paint, int update)
182{
183 unsigned i, j;
184 uint32_t bg_color, check_color, tmp_color, tmp1_color;
185 char *pixels;
lijuang7cfbfe32018-02-06 17:09:13 +0800186 unsigned count;
lijuangdd73d652015-06-05 21:29:37 +0800187
lijuang7cfbfe32018-02-06 17:09:13 +0800188 /* ignore anything that happens before fbcon is initialized */
189 if (!config)
190 return;
191
192 count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
lijuangdd73d652015-06-05 21:29:37 +0800193 pixels = config->base;
194 pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width);
195
196 if (update) {
197 bg_color = SELECT_BGCOLOR;
198 check_color = old_paint;
199 } else {
200 bg_color = old_paint;
201 check_color = SELECT_BGCOLOR;
202 }
203
204 for (i = 0; i < count; i++) {
205 tmp1_color = bg_color;
206 tmp_color = 0;
207 for (j = 0; j < (config->bpp / 8); j++) {
208 tmp_color |= *(pixels+j) << j*8;
209 }
210
211 if (tmp_color == check_color) {
212 for (j = 0; j < (config->bpp / 8); j++) {
213 *pixels = (unsigned char) tmp1_color;
214 tmp1_color = tmp1_color >> 8;
215 pixels++;
216 }
217 } else {
218 pixels += config->bpp / 8;
219 }
220 }
lijuangb3812fb2015-12-16 15:42:02 +0800221 fbcon_flush();
lijuangdd73d652015-06-05 21:29:37 +0800222}
223
Dima Zavin25ed9942009-01-28 17:04:19 -0800224static void fbcon_flush(void)
225{
Mao Flynn7b379f32015-04-20 00:28:30 +0800226 unsigned total_x, total_y;
227 unsigned bytes_per_bpp;
228
lijuang7cfbfe32018-02-06 17:09:13 +0800229 /* ignore anything that happens before fbcon is initialized */
230 if (!config)
231 return;
232
Dima Zavin25ed9942009-01-28 17:04:19 -0800233 if (config->update_start)
234 config->update_start();
235 if (config->update_done)
236 while (!config->update_done());
Mao Flynn7b379f32015-04-20 00:28:30 +0800237
238 total_x = config->width;
239 total_y = config->height;
240 bytes_per_bpp = ((config->bpp) / 8);
241 arch_clean_invalidate_cache_range((addr_t) config->base, (total_x * total_y * bytes_per_bpp));
Dima Zavin25ed9942009-01-28 17:04:19 -0800242}
243
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800244/* TODO: Take stride into account */
245static void fbcon_scroll_up(void)
246{
lijuang7cfbfe32018-02-06 17:09:13 +0800247 unsigned short *dst = NULL;
248 unsigned short *src = NULL;
249 unsigned count = 0;
250
251 /* ignore anything that happens before fbcon is initialized */
252 if (!config)
253 return;
254
255 dst = config->base;
256 src = dst + (config->width * FONT_HEIGHT);
257 count = config->width * (config->height - FONT_HEIGHT);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800258
259 while(count--) {
260 *dst++ = *src++;
261 }
262
263 count = config->width * FONT_HEIGHT;
264 while(count--) {
265 *dst++ = BGCOLOR;
266 }
Dima Zavin25ed9942009-01-28 17:04:19 -0800267
268 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800269}
270
lijuang4304fce2015-08-14 20:52:47 +0800271void fbcon_draw_line(uint32_t type)
lijuangdd73d652015-06-05 21:29:37 +0800272{
273 char *pixels;
lijuang4304fce2015-08-14 20:52:47 +0800274 uint32_t line_color, tmp_color;
lijuangdd73d652015-06-05 21:29:37 +0800275 int i, j;
276
lijuang7cfbfe32018-02-06 17:09:13 +0800277 /* ignore anything that happens before fbcon is initialized */
278 if (!config)
279 return;
280
lijuang4304fce2015-08-14 20:52:47 +0800281 /* set line's color via diffrent type */
282 line_color = fb_color_formats[type].fg;
lijuangdd73d652015-06-05 21:29:37 +0800283
284 pixels = config->base;
285 pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width);
286 pixels += cur_pos.x * ((config->bpp / 8) * (FONT_WIDTH + 1));
287
288 for (i = 0; i < (int)config->width; i++) {
lijuang4304fce2015-08-14 20:52:47 +0800289 tmp_color = line_color;
lijuangdd73d652015-06-05 21:29:37 +0800290 for (j = 0; j < (int)(config->bpp / 8); j++) {
291 *pixels = (unsigned char) tmp_color;
292 tmp_color = tmp_color >> 8;
293 pixels++;
294 }
295 }
296
297 cur_pos.y += 1;
298 cur_pos.x = 0;
299 if(cur_pos.y >= max_pos.y) {
300 cur_pos.y = max_pos.y - 1;
301 fbcon_scroll_up();
302 } else
303 fbcon_flush();
304}
305
306static void fbcon_set_colors(int type)
307{
308 BGCOLOR = fb_color_formats[type].bg;
309 FGCOLOR = fb_color_formats[type].fg;
310}
311
Shashank Mittal4f99a882010-02-01 13:58:50 -0800312void fbcon_clear(void)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800313{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530314 unsigned long i = 0, j = 0;
lijuang7cfbfe32018-02-06 17:09:13 +0800315 unsigned char *pixels = NULL;
316 unsigned count;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530317 uint32_t bg_color;
lijuangdd73d652015-06-05 21:29:37 +0800318
lijuang7cfbfe32018-02-06 17:09:13 +0800319 /* ignore anything that happens before fbcon is initialized */
320 if (!config)
321 return;
322
323 pixels = config->base;
324 count = config->width * config->height;
325
lijuangdd73d652015-06-05 21:29:37 +0800326 fbcon_set_colors(FBCON_COMMON_MSG);
Sandeep Pandadf39f752015-05-08 14:01:16 +0530327 for (i = 0; i < count; i++) {
328 bg_color = BGCOLOR;
329 for (j = 0; j < (config->bpp / 8); j++) {
330 *pixels = (unsigned char) bg_color;
331 bg_color = bg_color >> 8;
332 pixels++;
333 }
334 }
lijuangdd73d652015-06-05 21:29:37 +0800335 cur_pos.x = 0;
336 cur_pos.y = 0;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800337}
338
lijuangdd73d652015-06-05 21:29:37 +0800339void fbcon_putc_factor(char c, int type, unsigned scale_factor)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800340{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530341 char *pixels;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800342
343 /* ignore anything that happens before fbcon is initialized */
344 if (!config)
345 return;
346
347 if((unsigned char)c > 127)
348 return;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530349
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800350 if((unsigned char)c < 32) {
351 if(c == '\n')
352 goto newline;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530353 else if (c == '\r') {
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800354 cur_pos.x = 0;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530355 return;
356 }
357 else
358 return;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800359 }
360
lijuangdd73d652015-06-05 21:29:37 +0800361 if (cur_pos.x == 0 && (unsigned char)c == ' ' &&
362 type != FBCON_SUBTITLE_MSG &&
363 type != FBCON_TITLE_MSG)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800364 return;
365
lijuangdd73d652015-06-05 21:29:37 +0800366 fbcon_set_colors(type);
367
368 pixels = config->base;
369 pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width);
370 pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1));
371
372 fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8),
373 font5x12 + (c - 32) * 2, scale_factor);
374
375 cur_pos.x++;
376 if (cur_pos.x >= (int)(max_pos.x / scale_factor))
377 goto newline;
378
379 return;
380
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800381newline:
lijuangdd73d652015-06-05 21:29:37 +0800382 cur_pos.y += scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800383 cur_pos.x = 0;
384 if(cur_pos.y >= max_pos.y) {
385 cur_pos.y = max_pos.y - 1;
386 fbcon_scroll_up();
Dima Zavin25ed9942009-01-28 17:04:19 -0800387 } else
388 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800389}
390
lijuangdd73d652015-06-05 21:29:37 +0800391void fbcon_putc(char c)
392{
393 fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR);
394}
395
396uint32_t fbcon_get_current_line(void)
397{
398 return cur_pos.y;
399}
400
401uint32_t fbcon_get_max_x(void)
402{
403 return max_pos.x;
404}
405
lijuangf3d7fc52018-04-23 16:34:29 +0800406uint32_t fbcon_get_width(void)
407{
408 if (config)
409 return config->width;
410 else
411 return 0;
412}
413
414uint32_t fbcon_get_height(void)
415{
416 if (config)
417 return config->height;
418 else
419 return 0;
420}
421
lijuangdd73d652015-06-05 21:29:37 +0800422uint32_t fbcon_get_current_bg(void)
423{
424 return BGCOLOR;
425}
426
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800427void fbcon_setup(struct fbcon_config *_config)
428{
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800429 ASSERT(_config);
430
431 config = _config;
432
433 switch (config->format) {
434 case FB_FORMAT_RGB565:
lijuangdd73d652015-06-05 21:29:37 +0800435 fb_color_formats = fb_color_formats_555;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800436 break;
lijuangdd73d652015-06-05 21:29:37 +0800437 case FB_FORMAT_RGB888:
438 fb_color_formats = fb_color_formats_888;
439 break;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800440 default:
441 dprintf(CRITICAL, "unknown framebuffer pixel format\n");
442 ASSERT(0);
443 break;
444 }
445
lijuangdd73d652015-06-05 21:29:37 +0800446 SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg;
447 fbcon_set_colors(FBCON_COMMON_MSG);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800448
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800449 cur_pos.x = 0;
450 cur_pos.y = 0;
lijuangdd73d652015-06-05 21:29:37 +0800451 max_pos.x = config->width / (FONT_WIDTH+1);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800452 max_pos.y = (config->height - 1) / FONT_HEIGHT;
lijuangdd73d652015-06-05 21:29:37 +0800453
Shashank Mittal37040832010-08-24 15:57:57 -0700454#if !DISPLAY_SPLASH_SCREEN
455 fbcon_clear();
456#endif
lijuangdd73d652015-06-05 21:29:37 +0800457
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800458}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800459
460struct fbcon_config* fbcon_display(void)
461{
Mao Flynn7b379f32015-04-20 00:28:30 +0800462 return config;
Shashank Mittal4f99a882010-02-01 13:58:50 -0800463}
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700464
Mao Flynn7b379f32015-04-20 00:28:30 +0800465void fbcon_extract_to_screen(logo_img_header *header, void* address)
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530466{
Mao Flynn7b379f32015-04-20 00:28:30 +0800467 const uint8_t *imagestart = (const uint8_t *)address;
468 uint pos = 0, offset;
469 uint count = 0;
470 uint x = 0, y = 0;
471 uint8_t *base, *p;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530472
Mao Flynn7b379f32015-04-20 00:28:30 +0800473 if (!config || header->width > config->width
474 || header->height > config->height) {
475 dprintf(INFO, "the logo img is too large\n");
476 return;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530477 }
478
Mao Flynn7b379f32015-04-20 00:28:30 +0800479 base = (uint8_t *) config->base;
480
481 /* put the logo to be center */
482 offset = (config->height - header->height) / 2;
483 if (offset)
484 base += (offset * config->width) * 3;
485 offset = (config->width - header->width ) / 2;
486
487 x = offset;
488 while (count < (uint)header->height * (uint)header->width) {
489 uint8_t run = *(imagestart + pos);
490 bool repeat_run = (run & 0x80);
491 uint runlen = (run & 0x7f) + 1;
492 uint runpos;
493
494 /* consume the run byte */
495 pos++;
496
497 p = base + (y * config->width + x) * 3;
498
499 /* start of a run */
500 for (runpos = 0; runpos < runlen; runpos++) {
501 *p++ = *(imagestart + pos);
502 *p++ = *(imagestart + pos + 1);
503 *p++ = *(imagestart + pos + 2);
504 count++;
505
506 x++;
507
508 /* if a run of raw pixels, consume an input pixel */
509 if (!repeat_run)
510 pos += 3;
511 }
512
513 /* if this was a run of repeated pixels, consume the one input pixel we repeated */
514 if (repeat_run)
515 pos += 3;
516
517 /* the generator will keep compressing data line by line */
518 /* don't cross the lines */
519 if (x == header->width + offset) {
520 y++;
521 x = offset;
522 }
523 }
524
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530525}
526
Mao Flynn7b379f32015-04-20 00:28:30 +0800527void display_default_image_on_screen(void)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700528{
Mao Flynn7b379f32015-04-20 00:28:30 +0800529 unsigned i = 0;
530 unsigned total_x;
531 unsigned total_y;
532 unsigned bytes_per_bpp;
533 unsigned image_base;
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700534#if DISPLAY_TYPE_MIPI
535 char *image = NULL;
536#endif
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530537
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530538 if (!config) {
539 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
540 return;
541 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700542
Mao Flynn7b379f32015-04-20 00:28:30 +0800543 fbcon_clear(); // clear screen with Black color
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530544
545 total_x = config->width;
546 total_y = config->height;
547 bytes_per_bpp = ((config->bpp) / 8);
Mao Flynn7b379f32015-04-20 00:28:30 +0800548 image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) *
549 (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2)));
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530550
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700551#if ENABLE_WBC
552 image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888);
553#else
554 image = imageBuffer_rgb888;
555#endif
556
Mao Flynn7b379f32015-04-20 00:28:30 +0800557 if (bytes_per_bpp == 3) {
558 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530559 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700560 image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
Mao Flynn7b379f32015-04-20 00:28:30 +0800561 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530562 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700563 }
Zohaib Alam03708752014-10-23 17:51:57 -0400564
Mao Flynn7b379f32015-04-20 00:28:30 +0800565 if (bytes_per_bpp == 2) {
566 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
567 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
568 imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
569 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Zohaib Alam03708752014-10-23 17:51:57 -0400570 }
571 }
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500572
Zohaib Alam03708752014-10-23 17:51:57 -0400573 fbcon_flush();
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500574
575#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
576 if(is_cmd_mode_enabled())
577 mipi_dsi_cmd_mode_trigger();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800578#endif
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700579}
Mao Flynn7b379f32015-04-20 00:28:30 +0800580
581
582void display_image_on_screen(void)
583{
584#if DISPLAY_TYPE_MIPI
585 int fetch_image_from_partition();
586
587 if (fetch_image_from_partition() < 0) {
588 display_default_image_on_screen();
589 } else {
590 /* data has been put into the right place */
591 fbcon_flush();
592 }
593#else
594 display_default_image_on_screen();
595#endif
596}