The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tao Bao | 0ecbd76 | 2017-01-16 21:16:58 -0800 | [diff] [blame] | 17 | #include "graphics.h" |
| 18 | |
Tao Bao | e8020f4 | 2017-02-03 09:30:07 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 20 | #include <stdlib.h> |
Elliott Hughes | cd3c55a | 2015-01-29 20:50:08 -0800 | [diff] [blame] | 21 | #include <string.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 22 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 23 | #include <memory> |
| 24 | |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 25 | #include "font_10x18.h" |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 26 | #include "graphics_adf.h" |
| 27 | #include "graphics_drm.h" |
| 28 | #include "graphics_fbdev.h" |
Tao Bao | 0ecbd76 | 2017-01-16 21:16:58 -0800 | [diff] [blame] | 29 | #include "minui/minui.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 30 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 31 | static GRFont* gr_font = NULL; |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 32 | static MinuiBackend* gr_backend = nullptr; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 33 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 34 | static int overscan_percent = OVERSCAN_PERCENT; |
| 35 | static int overscan_offset_x = 0; |
| 36 | static int overscan_offset_y = 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 37 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 38 | static unsigned char gr_current_r = 255; |
| 39 | static unsigned char gr_current_g = 255; |
| 40 | static unsigned char gr_current_b = 255; |
| 41 | static unsigned char gr_current_a = 255; |
| 42 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 43 | static GRSurface* gr_draw = NULL; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 44 | |
| 45 | static bool outside(int x, int y) |
| 46 | { |
| 47 | return x < 0 || x >= gr_draw->width || y < 0 || y >= gr_draw->height; |
| 48 | } |
| 49 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 50 | const GRFont* gr_sys_font() |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 51 | { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 52 | return gr_font; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 55 | int gr_measure(const GRFont* font, const char *s) |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 56 | { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 57 | return font->char_width * strlen(s); |
| 58 | } |
| 59 | |
| 60 | void gr_font_size(const GRFont* font, int *x, int *y) |
| 61 | { |
| 62 | *x = font->char_width; |
| 63 | *y = font->char_height; |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 66 | static void text_blend(unsigned char* src_p, int src_row_bytes, |
| 67 | unsigned char* dst_p, int dst_row_bytes, |
| 68 | int width, int height) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 69 | { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 70 | for (int j = 0; j < height; ++j) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 71 | unsigned char* sx = src_p; |
| 72 | unsigned char* px = dst_p; |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 73 | for (int i = 0; i < width; ++i) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 74 | unsigned char a = *sx++; |
| 75 | if (gr_current_a < 255) a = ((int)a * gr_current_a) / 255; |
| 76 | if (a == 255) { |
| 77 | *px++ = gr_current_r; |
| 78 | *px++ = gr_current_g; |
| 79 | *px++ = gr_current_b; |
| 80 | px++; |
| 81 | } else if (a > 0) { |
| 82 | *px = (*px * (255-a) + gr_current_r * a) / 255; |
| 83 | ++px; |
| 84 | *px = (*px * (255-a) + gr_current_g * a) / 255; |
| 85 | ++px; |
| 86 | *px = (*px * (255-a) + gr_current_b * a) / 255; |
| 87 | ++px; |
| 88 | ++px; |
| 89 | } else { |
| 90 | px += 4; |
| 91 | } |
| 92 | } |
| 93 | src_p += src_row_bytes; |
| 94 | dst_p += dst_row_bytes; |
| 95 | } |
| 96 | } |
| 97 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 98 | void gr_text(const GRFont* font, int x, int y, const char *s, bool bold) |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 99 | { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 100 | if (!font->texture || gr_current_a == 0) return; |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 101 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 102 | bold = bold && (font->texture->height != font->char_height); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 103 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 104 | x += overscan_offset_x; |
| 105 | y += overscan_offset_y; |
| 106 | |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 107 | unsigned char ch; |
| 108 | while ((ch = *s++)) { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 109 | if (outside(x, y) || outside(x+font->char_width-1, y+font->char_height-1)) break; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 110 | |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 111 | if (ch < ' ' || ch > '~') { |
| 112 | ch = '?'; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 113 | } |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 114 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 115 | unsigned char* src_p = font->texture->data + ((ch - ' ') * font->char_width) + |
| 116 | (bold ? font->char_height * font->texture->row_bytes : 0); |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 117 | unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; |
| 118 | |
| 119 | text_blend(src_p, font->texture->row_bytes, |
| 120 | dst_p, gr_draw->row_bytes, |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 121 | font->char_width, font->char_height); |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 122 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 123 | x += font->char_width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 124 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 127 | void gr_texticon(int x, int y, GRSurface* icon) { |
| 128 | if (icon == NULL) return; |
| 129 | |
| 130 | if (icon->pixel_bytes != 1) { |
| 131 | printf("gr_texticon: source has wrong format\n"); |
Doug Zongker | 52eeea4f | 2012-09-04 14:28:25 -0700 | [diff] [blame] | 132 | return; |
| 133 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 134 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 135 | x += overscan_offset_x; |
| 136 | y += overscan_offset_y; |
| 137 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 138 | if (outside(x, y) || outside(x+icon->width-1, y+icon->height-1)) return; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 139 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 140 | unsigned char* src_p = icon->data; |
| 141 | unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 142 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 143 | text_blend(src_p, icon->row_bytes, |
| 144 | dst_p, gr_draw->row_bytes, |
| 145 | icon->width, icon->height); |
| 146 | } |
| 147 | |
| 148 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) |
| 149 | { |
Tony Kuo | fd778e3 | 2015-02-05 21:25:56 +0800 | [diff] [blame] | 150 | #if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) |
| 151 | gr_current_r = b; |
| 152 | gr_current_g = g; |
| 153 | gr_current_b = r; |
| 154 | gr_current_a = a; |
| 155 | #else |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 156 | gr_current_r = r; |
| 157 | gr_current_g = g; |
| 158 | gr_current_b = b; |
| 159 | gr_current_a = a; |
Tony Kuo | fd778e3 | 2015-02-05 21:25:56 +0800 | [diff] [blame] | 160 | #endif |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void gr_clear() |
| 164 | { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 165 | if (gr_current_r == gr_current_g && gr_current_r == gr_current_b) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 166 | memset(gr_draw->data, gr_current_r, gr_draw->height * gr_draw->row_bytes); |
| 167 | } else { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 168 | unsigned char* px = gr_draw->data; |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 169 | for (int y = 0; y < gr_draw->height; ++y) { |
| 170 | for (int x = 0; x < gr_draw->width; ++x) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 171 | *px++ = gr_current_r; |
| 172 | *px++ = gr_current_g; |
| 173 | *px++ = gr_current_b; |
| 174 | px++; |
| 175 | } |
| 176 | px += gr_draw->row_bytes - (gr_draw->width * gr_draw->pixel_bytes); |
| 177 | } |
| 178 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 181 | void gr_fill(int x1, int y1, int x2, int y2) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 182 | { |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 183 | x1 += overscan_offset_x; |
| 184 | y1 += overscan_offset_y; |
| 185 | |
| 186 | x2 += overscan_offset_x; |
| 187 | y2 += overscan_offset_y; |
| 188 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 189 | if (outside(x1, y1) || outside(x2-1, y2-1)) return; |
| 190 | |
| 191 | unsigned char* p = gr_draw->data + y1 * gr_draw->row_bytes + x1 * gr_draw->pixel_bytes; |
| 192 | if (gr_current_a == 255) { |
| 193 | int x, y; |
| 194 | for (y = y1; y < y2; ++y) { |
| 195 | unsigned char* px = p; |
| 196 | for (x = x1; x < x2; ++x) { |
| 197 | *px++ = gr_current_r; |
| 198 | *px++ = gr_current_g; |
| 199 | *px++ = gr_current_b; |
| 200 | px++; |
| 201 | } |
| 202 | p += gr_draw->row_bytes; |
| 203 | } |
| 204 | } else if (gr_current_a > 0) { |
| 205 | int x, y; |
| 206 | for (y = y1; y < y2; ++y) { |
| 207 | unsigned char* px = p; |
| 208 | for (x = x1; x < x2; ++x) { |
| 209 | *px = (*px * (255-gr_current_a) + gr_current_r * gr_current_a) / 255; |
| 210 | ++px; |
| 211 | *px = (*px * (255-gr_current_a) + gr_current_g * gr_current_a) / 255; |
| 212 | ++px; |
| 213 | *px = (*px * (255-gr_current_a) + gr_current_b * gr_current_a) / 255; |
| 214 | ++px; |
| 215 | ++px; |
| 216 | } |
| 217 | p += gr_draw->row_bytes; |
| 218 | } |
| 219 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 222 | void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) { |
| 223 | if (source == NULL) return; |
| 224 | |
| 225 | if (gr_draw->pixel_bytes != source->pixel_bytes) { |
| 226 | printf("gr_blit: source has wrong format\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 227 | return; |
| 228 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 229 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 230 | dx += overscan_offset_x; |
| 231 | dy += overscan_offset_y; |
| 232 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 233 | if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return; |
| 234 | |
| 235 | unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes; |
| 236 | unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes; |
| 237 | |
| 238 | int i; |
| 239 | for (i = 0; i < h; ++i) { |
| 240 | memcpy(dst_p, src_p, w * source->pixel_bytes); |
| 241 | src_p += source->row_bytes; |
| 242 | dst_p += gr_draw->row_bytes; |
| 243 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 246 | unsigned int gr_get_width(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 247 | if (surface == NULL) { |
| 248 | return 0; |
| 249 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 250 | return surface->width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 253 | unsigned int gr_get_height(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 254 | if (surface == NULL) { |
| 255 | return 0; |
| 256 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 257 | return surface->height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 260 | int gr_init_font(const char* name, GRFont** dest) { |
Rahul Chaudhry | 4f7faac | 2016-11-08 16:06:13 -0800 | [diff] [blame] | 261 | GRFont* font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font))); |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 262 | if (font == nullptr) { |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | int res = res_create_alpha_surface(name, &(font->texture)); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 267 | if (res < 0) { |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 268 | free(font); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 269 | return res; |
| 270 | } |
| 271 | |
| 272 | // The font image should be a 96x2 array of character images. The |
| 273 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 274 | // top row is regular text; the bottom row is bold. |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 275 | font->char_width = font->texture->width / 96; |
| 276 | font->char_height = font->texture->height / 2; |
| 277 | |
| 278 | *dest = font; |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 283 | static void gr_init_font(void) |
| 284 | { |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 285 | int res = gr_init_font("font", &gr_font); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 286 | if (res == 0) { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 287 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 288 | } |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 289 | |
| 290 | printf("failed to read font: res=%d\n", res); |
| 291 | |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 292 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 293 | // fall back to the compiled-in font. |
Rahul Chaudhry | 4f7faac | 2016-11-08 16:06:13 -0800 | [diff] [blame] | 294 | gr_font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font))); |
| 295 | gr_font->texture = static_cast<GRSurface*>(malloc(sizeof(*gr_font->texture))); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 296 | gr_font->texture->width = font.width; |
| 297 | gr_font->texture->height = font.height; |
| 298 | gr_font->texture->row_bytes = font.width; |
| 299 | gr_font->texture->pixel_bytes = 1; |
| 300 | |
Rahul Chaudhry | 4f7faac | 2016-11-08 16:06:13 -0800 | [diff] [blame] | 301 | unsigned char* bits = static_cast<unsigned char*>(malloc(font.width * font.height)); |
Rahul Chaudhry | 1cf93f5 | 2016-11-08 16:35:22 -0800 | [diff] [blame] | 302 | gr_font->texture->data = bits; |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 303 | |
| 304 | unsigned char data; |
| 305 | unsigned char* in = font.rundata; |
| 306 | while((data = *in++)) { |
| 307 | memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f); |
| 308 | bits += (data & 0x7f); |
| 309 | } |
| 310 | |
| 311 | gr_font->char_width = font.char_width; |
| 312 | gr_font->char_height = font.char_height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 315 | void gr_flip() { |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 316 | gr_draw = gr_backend->Flip(); |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 319 | int gr_init() { |
| 320 | gr_init_font(); |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 321 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 322 | auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendAdf>() }; |
| 323 | gr_draw = backend->Init(); |
Greg Hackmann | 41909dd | 2014-04-25 10:39:50 -0700 | [diff] [blame] | 324 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 325 | if (!gr_draw) { |
| 326 | backend = std::make_unique<MinuiBackendDrm>(); |
| 327 | gr_draw = backend->Init(); |
| 328 | } |
Stéphane Marchesin | 1a92c44 | 2015-06-29 20:05:48 -0700 | [diff] [blame] | 329 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 330 | if (!gr_draw) { |
| 331 | backend = std::make_unique<MinuiBackendFbdev>(); |
| 332 | gr_draw = backend->Init(); |
| 333 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 334 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 335 | if (!gr_draw) { |
| 336 | return -1; |
| 337 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 338 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 339 | gr_backend = backend.release(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 340 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 341 | overscan_offset_x = gr_draw->width * overscan_percent / 100; |
| 342 | overscan_offset_y = gr_draw->height * overscan_percent / 100; |
| 343 | |
| 344 | gr_flip(); |
| 345 | gr_flip(); |
| 346 | |
| 347 | return 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 350 | void gr_exit() { |
| 351 | delete gr_backend; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 354 | int gr_fb_width() { |
| 355 | return gr_draw->width - 2 * overscan_offset_x; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 358 | int gr_fb_height() { |
| 359 | return gr_draw->height - 2 * overscan_offset_y; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 360 | } |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 361 | |
Tao Bao | 557fa1f | 2017-02-07 12:51:00 -0800 | [diff] [blame] | 362 | void gr_fb_blank(bool blank) { |
| 363 | gr_backend->Blank(blank); |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 364 | } |