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 | |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 17 | #include <stdbool.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <fcntl.h> |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #include <sys/ioctl.h> |
| 25 | #include <sys/mman.h> |
| 26 | #include <sys/types.h> |
| 27 | |
| 28 | #include <linux/fb.h> |
| 29 | #include <linux/kd.h> |
| 30 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 31 | #include <time.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 32 | |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 33 | #include "font_10x18.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | #include "minui.h" |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 35 | #include "graphics.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 36 | |
| 37 | typedef struct { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 38 | GRSurface* texture; |
| 39 | int cwidth; |
| 40 | int cheight; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 41 | } GRFont; |
| 42 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 43 | static GRFont* gr_font = NULL; |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 44 | static minui_backend* gr_backend = NULL; |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 45 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 46 | static int overscan_percent = OVERSCAN_PERCENT; |
| 47 | static int overscan_offset_x = 0; |
| 48 | static int overscan_offset_y = 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 49 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 50 | static int gr_vt_fd = -1; |
| 51 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 52 | static unsigned char gr_current_r = 255; |
| 53 | static unsigned char gr_current_g = 255; |
| 54 | static unsigned char gr_current_b = 255; |
| 55 | static unsigned char gr_current_a = 255; |
| 56 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 57 | static GRSurface* gr_draw = NULL; |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 58 | |
| 59 | static bool outside(int x, int y) |
| 60 | { |
| 61 | return x < 0 || x >= gr_draw->width || y < 0 || y >= gr_draw->height; |
| 62 | } |
| 63 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 64 | int gr_measure(const char *s) |
| 65 | { |
| 66 | return gr_font->cwidth * strlen(s); |
| 67 | } |
| 68 | |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 69 | void gr_font_size(int *x, int *y) |
| 70 | { |
| 71 | *x = gr_font->cwidth; |
| 72 | *y = gr_font->cheight; |
| 73 | } |
| 74 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 75 | static void text_blend(unsigned char* src_p, int src_row_bytes, |
| 76 | unsigned char* dst_p, int dst_row_bytes, |
| 77 | int width, int height) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 78 | { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 79 | int i, j; |
| 80 | for (j = 0; j < height; ++j) { |
| 81 | unsigned char* sx = src_p; |
| 82 | unsigned char* px = dst_p; |
| 83 | for (i = 0; i < width; ++i) { |
| 84 | unsigned char a = *sx++; |
| 85 | if (gr_current_a < 255) a = ((int)a * gr_current_a) / 255; |
| 86 | if (a == 255) { |
| 87 | *px++ = gr_current_r; |
| 88 | *px++ = gr_current_g; |
| 89 | *px++ = gr_current_b; |
| 90 | px++; |
| 91 | } else if (a > 0) { |
| 92 | *px = (*px * (255-a) + gr_current_r * a) / 255; |
| 93 | ++px; |
| 94 | *px = (*px * (255-a) + gr_current_g * a) / 255; |
| 95 | ++px; |
| 96 | *px = (*px * (255-a) + gr_current_b * a) / 255; |
| 97 | ++px; |
| 98 | ++px; |
| 99 | } else { |
| 100 | px += 4; |
| 101 | } |
| 102 | } |
| 103 | src_p += src_row_bytes; |
| 104 | dst_p += dst_row_bytes; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void gr_text(int x, int y, const char *s, int bold) |
| 110 | { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 111 | GRFont *font = gr_font; |
| 112 | unsigned off; |
| 113 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 114 | if (!font->texture) return; |
| 115 | if (gr_current_a == 0) return; |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 116 | |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 117 | bold = bold && (font->texture->height != font->cheight); |
| 118 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 119 | x += overscan_offset_x; |
| 120 | y += overscan_offset_y; |
| 121 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 122 | while((off = *s++)) { |
| 123 | off -= 32; |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 124 | if (outside(x, y) || outside(x+font->cwidth-1, y+font->cheight-1)) break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 125 | if (off < 96) { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 126 | |
| 127 | unsigned char* src_p = font->texture->data + (off * font->cwidth) + |
| 128 | (bold ? font->cheight * font->texture->row_bytes : 0); |
| 129 | unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; |
| 130 | |
| 131 | text_blend(src_p, font->texture->row_bytes, |
| 132 | dst_p, gr_draw->row_bytes, |
| 133 | font->cwidth, font->cheight); |
| 134 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 135 | } |
| 136 | x += font->cwidth; |
| 137 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 140 | void gr_texticon(int x, int y, GRSurface* icon) { |
| 141 | if (icon == NULL) return; |
| 142 | |
| 143 | if (icon->pixel_bytes != 1) { |
| 144 | printf("gr_texticon: source has wrong format\n"); |
Doug Zongker | 52eeea4f | 2012-09-04 14:28:25 -0700 | [diff] [blame] | 145 | return; |
| 146 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 147 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 148 | x += overscan_offset_x; |
| 149 | y += overscan_offset_y; |
| 150 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 151 | 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] | 152 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 153 | unsigned char* src_p = icon->data; |
| 154 | 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] | 155 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 156 | text_blend(src_p, icon->row_bytes, |
| 157 | dst_p, gr_draw->row_bytes, |
| 158 | icon->width, icon->height); |
| 159 | } |
| 160 | |
| 161 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) |
| 162 | { |
| 163 | gr_current_r = r; |
| 164 | gr_current_g = g; |
| 165 | gr_current_b = b; |
| 166 | gr_current_a = a; |
| 167 | } |
| 168 | |
| 169 | void gr_clear() |
| 170 | { |
| 171 | if (gr_current_r == gr_current_g && |
| 172 | gr_current_r == gr_current_b) { |
| 173 | memset(gr_draw->data, gr_current_r, gr_draw->height * gr_draw->row_bytes); |
| 174 | } else { |
| 175 | int x, y; |
| 176 | unsigned char* px = gr_draw->data; |
| 177 | for (y = 0; y < gr_draw->height; ++y) { |
| 178 | for (x = 0; x < gr_draw->width; ++x) { |
| 179 | *px++ = gr_current_r; |
| 180 | *px++ = gr_current_g; |
| 181 | *px++ = gr_current_b; |
| 182 | px++; |
| 183 | } |
| 184 | px += gr_draw->row_bytes - (gr_draw->width * gr_draw->pixel_bytes); |
| 185 | } |
| 186 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 189 | 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] | 190 | { |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 191 | x1 += overscan_offset_x; |
| 192 | y1 += overscan_offset_y; |
| 193 | |
| 194 | x2 += overscan_offset_x; |
| 195 | y2 += overscan_offset_y; |
| 196 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 197 | if (outside(x1, y1) || outside(x2-1, y2-1)) return; |
| 198 | |
| 199 | unsigned char* p = gr_draw->data + y1 * gr_draw->row_bytes + x1 * gr_draw->pixel_bytes; |
| 200 | if (gr_current_a == 255) { |
| 201 | int x, y; |
| 202 | for (y = y1; y < y2; ++y) { |
| 203 | unsigned char* px = p; |
| 204 | for (x = x1; x < x2; ++x) { |
| 205 | *px++ = gr_current_r; |
| 206 | *px++ = gr_current_g; |
| 207 | *px++ = gr_current_b; |
| 208 | px++; |
| 209 | } |
| 210 | p += gr_draw->row_bytes; |
| 211 | } |
| 212 | } else if (gr_current_a > 0) { |
| 213 | int x, y; |
| 214 | for (y = y1; y < y2; ++y) { |
| 215 | unsigned char* px = p; |
| 216 | for (x = x1; x < x2; ++x) { |
| 217 | *px = (*px * (255-gr_current_a) + gr_current_r * gr_current_a) / 255; |
| 218 | ++px; |
| 219 | *px = (*px * (255-gr_current_a) + gr_current_g * gr_current_a) / 255; |
| 220 | ++px; |
| 221 | *px = (*px * (255-gr_current_a) + gr_current_b * gr_current_a) / 255; |
| 222 | ++px; |
| 223 | ++px; |
| 224 | } |
| 225 | p += gr_draw->row_bytes; |
| 226 | } |
| 227 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 230 | void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) { |
| 231 | if (source == NULL) return; |
| 232 | |
| 233 | if (gr_draw->pixel_bytes != source->pixel_bytes) { |
| 234 | printf("gr_blit: source has wrong format\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 235 | return; |
| 236 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 237 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 238 | dx += overscan_offset_x; |
| 239 | dy += overscan_offset_y; |
| 240 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 241 | if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return; |
| 242 | |
| 243 | unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes; |
| 244 | unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes; |
| 245 | |
| 246 | int i; |
| 247 | for (i = 0; i < h; ++i) { |
| 248 | memcpy(dst_p, src_p, w * source->pixel_bytes); |
| 249 | src_p += source->row_bytes; |
| 250 | dst_p += gr_draw->row_bytes; |
| 251 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 254 | unsigned int gr_get_width(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 255 | if (surface == NULL) { |
| 256 | return 0; |
| 257 | } |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 258 | return surface->width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 261 | unsigned int gr_get_height(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 262 | if (surface == NULL) { |
| 263 | return 0; |
| 264 | } |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 265 | return surface->height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static void gr_init_font(void) |
| 269 | { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 270 | gr_font = calloc(sizeof(*gr_font), 1); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 271 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 272 | int res = res_create_surface("font", &(gr_font->texture)); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 273 | if (res == 0) { |
| 274 | // The font image should be a 96x2 array of character images. The |
| 275 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 276 | // top row is regular text; the bottom row is bold. |
| 277 | gr_font->cwidth = gr_font->texture->width / 96; |
| 278 | gr_font->cheight = gr_font->texture->height / 2; |
| 279 | } else { |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 280 | printf("failed to read font: res=%d\n", res); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 281 | |
| 282 | // fall back to the compiled-in font. |
| 283 | gr_font->texture = malloc(sizeof(*gr_font->texture)); |
| 284 | gr_font->texture->width = font.width; |
| 285 | gr_font->texture->height = font.height; |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 286 | gr_font->texture->row_bytes = font.width; |
| 287 | gr_font->texture->pixel_bytes = 1; |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 288 | |
| 289 | unsigned char* bits = malloc(font.width * font.height); |
| 290 | gr_font->texture->data = (void*) bits; |
| 291 | |
| 292 | unsigned char data; |
| 293 | unsigned char* in = font.rundata; |
| 294 | while((data = *in++)) { |
| 295 | memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f); |
| 296 | bits += (data & 0x7f); |
| 297 | } |
| 298 | |
| 299 | gr_font->cwidth = font.cwidth; |
| 300 | gr_font->cheight = font.cheight; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 301 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 304 | #if 0 |
| 305 | // Exercises many of the gr_*() functions; useful for testing. |
| 306 | static void gr_test() { |
| 307 | GRSurface** images; |
| 308 | int frames; |
| 309 | int result = res_create_multi_surface("icon_installing", &frames, &images); |
| 310 | if (result < 0) { |
| 311 | printf("create surface %d\n", result); |
| 312 | gr_exit(); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | time_t start = time(NULL); |
| 317 | int x; |
| 318 | for (x = 0; x <= 1200; ++x) { |
| 319 | if (x < 400) { |
| 320 | gr_color(0, 0, 0, 255); |
| 321 | } else { |
| 322 | gr_color(0, (x-400)%128, 0, 255); |
| 323 | } |
| 324 | gr_clear(); |
| 325 | |
| 326 | gr_color(255, 0, 0, 255); |
| 327 | gr_surface frame = images[x%frames]; |
| 328 | gr_blit(frame, 0, 0, frame->width, frame->height, x, 0); |
| 329 | |
| 330 | gr_color(255, 0, 0, 128); |
| 331 | gr_fill(400, 150, 600, 350); |
| 332 | |
| 333 | gr_color(255, 255, 255, 255); |
| 334 | gr_text(500, 225, "hello, world!", 0); |
| 335 | gr_color(255, 255, 0, 128); |
| 336 | gr_text(300+x, 275, "pack my box with five dozen liquor jugs", 1); |
| 337 | |
| 338 | gr_color(0, 0, 255, 128); |
| 339 | gr_fill(gr_draw->width - 200 - x, 300, gr_draw->width - x, 500); |
| 340 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 341 | gr_draw = gr_backend->flip(gr_backend); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 342 | } |
| 343 | printf("getting end time\n"); |
| 344 | time_t end = time(NULL); |
| 345 | printf("got end time\n"); |
| 346 | printf("start %ld end %ld\n", (long)start, (long)end); |
| 347 | if (end > start) { |
| 348 | printf("%.2f fps\n", ((double)x) / (end-start)); |
| 349 | } |
| 350 | } |
| 351 | #endif |
| 352 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 353 | void gr_flip() { |
| 354 | gr_draw = gr_backend->flip(gr_backend); |
| 355 | } |
| 356 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 357 | int gr_init(void) |
| 358 | { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 359 | gr_init_font(); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 360 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 361 | gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC); |
| 362 | if (gr_vt_fd < 0) { |
| 363 | // This is non-fatal; post-Cupcake kernels don't have tty0. |
| 364 | perror("can't open /dev/tty0"); |
| 365 | } else if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) { |
| 366 | // However, if we do open tty0, we expect the ioctl to work. |
| 367 | perror("failed KDSETMODE to KD_GRAPHICS on tty0"); |
| 368 | gr_exit(); |
| 369 | return -1; |
| 370 | } |
| 371 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 372 | gr_backend = open_fbdev(); |
| 373 | gr_draw = gr_backend->init(gr_backend); |
| 374 | if (gr_draw == NULL) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 375 | return -1; |
| 376 | } |
| 377 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 378 | overscan_offset_x = gr_draw->width * overscan_percent / 100; |
| 379 | overscan_offset_y = gr_draw->height * overscan_percent / 100; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 380 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 381 | gr_flip(); |
| 382 | gr_flip(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | void gr_exit(void) |
| 388 | { |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 389 | gr_backend->exit(gr_backend); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 390 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 391 | ioctl(gr_vt_fd, KDSETMODE, (void*) KD_TEXT); |
| 392 | close(gr_vt_fd); |
| 393 | gr_vt_fd = -1; |
| 394 | } |
| 395 | |
| 396 | int gr_fb_width(void) |
| 397 | { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 398 | return gr_draw->width - 2*overscan_offset_x; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | int gr_fb_height(void) |
| 402 | { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 403 | return gr_draw->height - 2*overscan_offset_y; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 404 | } |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 405 | |
| 406 | void gr_fb_blank(bool blank) |
| 407 | { |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame^] | 408 | gr_backend->blank(gr_backend, blank); |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 409 | } |