Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Channagoud Kadabi | 7af9fbc | 2015-02-13 20:09:55 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2015, The Linux Foundation. All rights reserved. |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 6 | * |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 7 | * 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 |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | * 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 Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 35 | #include <splash.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 36 | #include <platform.h> |
| 37 | #include <string.h> |
Channagoud Kadabi | 7af9fbc | 2015-02-13 20:09:55 -0800 | [diff] [blame] | 38 | #include <arch/ops.h> |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 39 | #if ENABLE_WBC |
| 40 | #include <pm_app_smbchg.h> |
| 41 | #endif |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 42 | |
| 43 | #include "font5x12.h" |
| 44 | |
| 45 | struct pos { |
| 46 | int x; |
| 47 | int y; |
| 48 | }; |
| 49 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 50 | struct fb_color { |
| 51 | uint32_t fg; |
| 52 | uint32_t bg; |
| 53 | }; |
| 54 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 55 | static struct fbcon_config *config = NULL; |
| 56 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 57 | #define RGB565_BLACK 0x0000 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 58 | #define RGB565_WHITE 0xffff |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 59 | #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 |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 65 | #define RGB565_GREEN 0x3666 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 66 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 67 | #define RGB888_BLACK 0x000000 |
| 68 | #define RGB888_WHITE 0xffffff |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 69 | #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 |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 75 | #define RGB888_GREEN 0x00ff00 |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 76 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 77 | #define FONT_WIDTH 5 |
| 78 | #define FONT_HEIGHT 12 |
| 79 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 80 | #define SCALE_FACTOR 2 |
| 81 | |
| 82 | static uint32_t BGCOLOR; |
| 83 | static uint32_t FGCOLOR; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 84 | static uint32_t SELECT_BGCOLOR; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 85 | |
| 86 | static struct pos cur_pos; |
| 87 | static struct pos max_pos; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 88 | static struct fb_color *fb_color_formats; |
| 89 | static struct fb_color fb_color_formats_555[] = { |
| 90 | [FBCON_COMMON_MSG] = {RGB565_WHITE, RGB565_BLACK}, |
| 91 | [FBCON_UNLOCK_TITLE_MSG] = {RGB565_CYAN, RGB565_BLACK}, |
| 92 | [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}, |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 97 | [FBCON_GREEN_MSG] = {RGB565_GREEN, RGB565_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 98 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB565_WHITE, RGB565_BLUE}}; |
| 99 | |
| 100 | static struct fb_color fb_color_formats_888[] = { |
| 101 | [FBCON_COMMON_MSG] = {RGB888_WHITE, RGB888_BLACK}, |
| 102 | [FBCON_UNLOCK_TITLE_MSG] = {RGB888_CYAN, RGB888_BLACK}, |
| 103 | [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}, |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 108 | [FBCON_GREEN_MSG] = {RGB888_GREEN, RGB888_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 109 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB888_WHITE, RGB888_BLUE}}; |
| 110 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 111 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 112 | static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 113 | unsigned bpp, unsigned *glyph, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 114 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 115 | unsigned x, y, i, j, k; |
| 116 | unsigned data, temp; |
| 117 | uint32_t fg_color = paint; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 118 | stride -= FONT_WIDTH * scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 119 | |
| 120 | data = glyph[0]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 121 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 122 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 123 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 124 | data = temp; |
| 125 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 126 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 127 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 128 | fg_color = paint; |
| 129 | for (k = 0; k < bpp; k++) { |
| 130 | *pixels = (unsigned char) fg_color; |
| 131 | fg_color = fg_color >> 8; |
| 132 | pixels++; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | else |
| 137 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 138 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 139 | pixels = pixels + bpp; |
| 140 | } |
| 141 | } |
| 142 | data >>= 1; |
| 143 | } |
| 144 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 145 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | data = glyph[1]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 149 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 150 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 151 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 152 | data = temp; |
| 153 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 154 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 155 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 156 | fg_color = paint; |
| 157 | for (k = 0; k < bpp; k++) { |
| 158 | *pixels = (unsigned char) fg_color; |
| 159 | fg_color = fg_color >> 8; |
| 160 | pixels++; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | else |
| 165 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 166 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 167 | pixels = pixels + bpp; |
| 168 | } |
| 169 | } |
| 170 | data >>= 1; |
| 171 | } |
| 172 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 173 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 174 | } |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 175 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 176 | } |
| 177 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 178 | void fbcon_draw_msg_background(unsigned y_start, unsigned y_end, |
| 179 | uint32_t old_paint, int update) |
| 180 | { |
| 181 | unsigned i, j; |
| 182 | uint32_t bg_color, check_color, tmp_color, tmp1_color; |
| 183 | char *pixels; |
| 184 | unsigned count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1); |
| 185 | |
| 186 | pixels = config->base; |
| 187 | pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 188 | |
| 189 | if (update) { |
| 190 | bg_color = SELECT_BGCOLOR; |
| 191 | check_color = old_paint; |
| 192 | } else { |
| 193 | bg_color = old_paint; |
| 194 | check_color = SELECT_BGCOLOR; |
| 195 | } |
| 196 | |
| 197 | for (i = 0; i < count; i++) { |
| 198 | tmp1_color = bg_color; |
| 199 | tmp_color = 0; |
| 200 | for (j = 0; j < (config->bpp / 8); j++) { |
| 201 | tmp_color |= *(pixels+j) << j*8; |
| 202 | } |
| 203 | |
| 204 | if (tmp_color == check_color) { |
| 205 | for (j = 0; j < (config->bpp / 8); j++) { |
| 206 | *pixels = (unsigned char) tmp1_color; |
| 207 | tmp1_color = tmp1_color >> 8; |
| 208 | pixels++; |
| 209 | } |
| 210 | } else { |
| 211 | pixels += config->bpp / 8; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 216 | static void fbcon_flush(void) |
| 217 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 218 | unsigned total_x, total_y; |
| 219 | unsigned bytes_per_bpp; |
| 220 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 221 | if (config->update_start) |
| 222 | config->update_start(); |
| 223 | if (config->update_done) |
| 224 | while (!config->update_done()); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 225 | |
| 226 | total_x = config->width; |
| 227 | total_y = config->height; |
| 228 | bytes_per_bpp = ((config->bpp) / 8); |
| 229 | arch_clean_invalidate_cache_range((addr_t) config->base, (total_x * total_y * bytes_per_bpp)); |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 232 | /* TODO: Take stride into account */ |
| 233 | static void fbcon_scroll_up(void) |
| 234 | { |
| 235 | unsigned short *dst = config->base; |
| 236 | unsigned short *src = dst + (config->width * FONT_HEIGHT); |
| 237 | unsigned count = config->width * (config->height - FONT_HEIGHT); |
| 238 | |
| 239 | while(count--) { |
| 240 | *dst++ = *src++; |
| 241 | } |
| 242 | |
| 243 | count = config->width * FONT_HEIGHT; |
| 244 | while(count--) { |
| 245 | *dst++ = BGCOLOR; |
| 246 | } |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 247 | |
| 248 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 249 | } |
| 250 | |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 251 | void fbcon_draw_line(uint32_t type) |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 252 | { |
| 253 | char *pixels; |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 254 | uint32_t line_color, tmp_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 255 | int i, j; |
| 256 | |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 257 | /* set line's color via diffrent type */ |
| 258 | line_color = fb_color_formats[type].fg; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 259 | |
| 260 | pixels = config->base; |
| 261 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 262 | pixels += cur_pos.x * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 263 | |
| 264 | for (i = 0; i < (int)config->width; i++) { |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 265 | tmp_color = line_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 266 | for (j = 0; j < (int)(config->bpp / 8); j++) { |
| 267 | *pixels = (unsigned char) tmp_color; |
| 268 | tmp_color = tmp_color >> 8; |
| 269 | pixels++; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | cur_pos.y += 1; |
| 274 | cur_pos.x = 0; |
| 275 | if(cur_pos.y >= max_pos.y) { |
| 276 | cur_pos.y = max_pos.y - 1; |
| 277 | fbcon_scroll_up(); |
| 278 | } else |
| 279 | fbcon_flush(); |
| 280 | } |
| 281 | |
| 282 | static void fbcon_set_colors(int type) |
| 283 | { |
| 284 | BGCOLOR = fb_color_formats[type].bg; |
| 285 | FGCOLOR = fb_color_formats[type].fg; |
| 286 | } |
| 287 | |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 288 | void fbcon_clear(void) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 289 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 290 | unsigned long i = 0, j = 0; |
| 291 | unsigned char *pixels = config->base; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 292 | unsigned count = config->width * config->height; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 293 | uint32_t bg_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 294 | |
| 295 | fbcon_set_colors(FBCON_COMMON_MSG); |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 296 | for (i = 0; i < count; i++) { |
| 297 | bg_color = BGCOLOR; |
| 298 | for (j = 0; j < (config->bpp / 8); j++) { |
| 299 | *pixels = (unsigned char) bg_color; |
| 300 | bg_color = bg_color >> 8; |
| 301 | pixels++; |
| 302 | } |
| 303 | } |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 304 | cur_pos.x = 0; |
| 305 | cur_pos.y = 0; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 306 | } |
| 307 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 308 | void fbcon_putc_factor(char c, int type, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 309 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 310 | char *pixels; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 311 | |
| 312 | /* ignore anything that happens before fbcon is initialized */ |
| 313 | if (!config) |
| 314 | return; |
| 315 | |
| 316 | if((unsigned char)c > 127) |
| 317 | return; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 318 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 319 | if((unsigned char)c < 32) { |
| 320 | if(c == '\n') |
| 321 | goto newline; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 322 | else if (c == '\r') { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 323 | cur_pos.x = 0; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | else |
| 327 | return; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 328 | } |
| 329 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 330 | if (cur_pos.x == 0 && (unsigned char)c == ' ' && |
| 331 | type != FBCON_SUBTITLE_MSG && |
| 332 | type != FBCON_TITLE_MSG) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 333 | return; |
| 334 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 335 | fbcon_set_colors(type); |
| 336 | |
| 337 | pixels = config->base; |
| 338 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 339 | pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 340 | |
| 341 | fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8), |
| 342 | font5x12 + (c - 32) * 2, scale_factor); |
| 343 | |
| 344 | cur_pos.x++; |
| 345 | if (cur_pos.x >= (int)(max_pos.x / scale_factor)) |
| 346 | goto newline; |
| 347 | |
| 348 | return; |
| 349 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 350 | newline: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 351 | cur_pos.y += scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 352 | cur_pos.x = 0; |
| 353 | if(cur_pos.y >= max_pos.y) { |
| 354 | cur_pos.y = max_pos.y - 1; |
| 355 | fbcon_scroll_up(); |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 356 | } else |
| 357 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 358 | } |
| 359 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 360 | void fbcon_putc(char c) |
| 361 | { |
| 362 | fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR); |
| 363 | } |
| 364 | |
| 365 | uint32_t fbcon_get_current_line(void) |
| 366 | { |
| 367 | return cur_pos.y; |
| 368 | } |
| 369 | |
| 370 | uint32_t fbcon_get_max_x(void) |
| 371 | { |
| 372 | return max_pos.x; |
| 373 | } |
| 374 | |
| 375 | uint32_t fbcon_get_current_bg(void) |
| 376 | { |
| 377 | return BGCOLOR; |
| 378 | } |
| 379 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 380 | void fbcon_setup(struct fbcon_config *_config) |
| 381 | { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 382 | ASSERT(_config); |
| 383 | |
| 384 | config = _config; |
| 385 | |
| 386 | switch (config->format) { |
| 387 | case FB_FORMAT_RGB565: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 388 | fb_color_formats = fb_color_formats_555; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 389 | break; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 390 | case FB_FORMAT_RGB888: |
| 391 | fb_color_formats = fb_color_formats_888; |
| 392 | break; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 393 | default: |
| 394 | dprintf(CRITICAL, "unknown framebuffer pixel format\n"); |
| 395 | ASSERT(0); |
| 396 | break; |
| 397 | } |
| 398 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 399 | SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg; |
| 400 | fbcon_set_colors(FBCON_COMMON_MSG); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 401 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 402 | cur_pos.x = 0; |
| 403 | cur_pos.y = 0; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 404 | max_pos.x = config->width / (FONT_WIDTH+1); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 405 | max_pos.y = (config->height - 1) / FONT_HEIGHT; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 406 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 407 | #if !DISPLAY_SPLASH_SCREEN |
| 408 | fbcon_clear(); |
| 409 | #endif |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 410 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 411 | } |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 412 | |
| 413 | struct fbcon_config* fbcon_display(void) |
| 414 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 415 | return config; |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 416 | } |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 417 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 418 | void fbcon_extract_to_screen(logo_img_header *header, void* address) |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 419 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 420 | const uint8_t *imagestart = (const uint8_t *)address; |
| 421 | uint pos = 0, offset; |
| 422 | uint count = 0; |
| 423 | uint x = 0, y = 0; |
| 424 | uint8_t *base, *p; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 425 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 426 | if (!config || header->width > config->width |
| 427 | || header->height > config->height) { |
| 428 | dprintf(INFO, "the logo img is too large\n"); |
| 429 | return; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 430 | } |
| 431 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 432 | base = (uint8_t *) config->base; |
| 433 | |
| 434 | /* put the logo to be center */ |
| 435 | offset = (config->height - header->height) / 2; |
| 436 | if (offset) |
| 437 | base += (offset * config->width) * 3; |
| 438 | offset = (config->width - header->width ) / 2; |
| 439 | |
| 440 | x = offset; |
| 441 | while (count < (uint)header->height * (uint)header->width) { |
| 442 | uint8_t run = *(imagestart + pos); |
| 443 | bool repeat_run = (run & 0x80); |
| 444 | uint runlen = (run & 0x7f) + 1; |
| 445 | uint runpos; |
| 446 | |
| 447 | /* consume the run byte */ |
| 448 | pos++; |
| 449 | |
| 450 | p = base + (y * config->width + x) * 3; |
| 451 | |
| 452 | /* start of a run */ |
| 453 | for (runpos = 0; runpos < runlen; runpos++) { |
| 454 | *p++ = *(imagestart + pos); |
| 455 | *p++ = *(imagestart + pos + 1); |
| 456 | *p++ = *(imagestart + pos + 2); |
| 457 | count++; |
| 458 | |
| 459 | x++; |
| 460 | |
| 461 | /* if a run of raw pixels, consume an input pixel */ |
| 462 | if (!repeat_run) |
| 463 | pos += 3; |
| 464 | } |
| 465 | |
| 466 | /* if this was a run of repeated pixels, consume the one input pixel we repeated */ |
| 467 | if (repeat_run) |
| 468 | pos += 3; |
| 469 | |
| 470 | /* the generator will keep compressing data line by line */ |
| 471 | /* don't cross the lines */ |
| 472 | if (x == header->width + offset) { |
| 473 | y++; |
| 474 | x = offset; |
| 475 | } |
| 476 | } |
| 477 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 478 | } |
| 479 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 480 | void display_default_image_on_screen(void) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 481 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 482 | unsigned i = 0; |
| 483 | unsigned total_x; |
| 484 | unsigned total_y; |
| 485 | unsigned bytes_per_bpp; |
| 486 | unsigned image_base; |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 487 | #if DISPLAY_TYPE_MIPI |
| 488 | char *image = NULL; |
| 489 | #endif |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 490 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 491 | if (!config) { |
| 492 | dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n"); |
| 493 | return; |
| 494 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 495 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 496 | fbcon_clear(); // clear screen with Black color |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 497 | |
| 498 | total_x = config->width; |
| 499 | total_y = config->height; |
| 500 | bytes_per_bpp = ((config->bpp) / 8); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 501 | image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) * |
| 502 | (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2))); |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 503 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 504 | #if DISPLAY_TYPE_MIPI |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 505 | #if ENABLE_WBC |
| 506 | image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888); |
| 507 | #else |
| 508 | image = imageBuffer_rgb888; |
| 509 | #endif |
| 510 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 511 | if (bytes_per_bpp == 3) { |
| 512 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 513 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 514 | image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 515 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 516 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 517 | } |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 518 | fbcon_flush(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 519 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 520 | if(is_cmd_mode_enabled()) |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 521 | mipi_dsi_cmd_mode_trigger(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 522 | #endif |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 523 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 524 | #else |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 525 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 526 | if (bytes_per_bpp == 2) { |
| 527 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
| 528 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
| 529 | imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
| 530 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | fbcon_flush(); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 534 | #endif |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 535 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 536 | |
| 537 | |
| 538 | void display_image_on_screen(void) |
| 539 | { |
| 540 | #if DISPLAY_TYPE_MIPI |
| 541 | int fetch_image_from_partition(); |
| 542 | |
| 543 | if (fetch_image_from_partition() < 0) { |
| 544 | display_default_image_on_screen(); |
| 545 | } else { |
| 546 | /* data has been put into the right place */ |
| 547 | fbcon_flush(); |
| 548 | } |
| 549 | #else |
| 550 | display_default_image_on_screen(); |
| 551 | #endif |
| 552 | } |