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> |
Elliott Hughes | cd3c55a | 2015-01-29 20:50:08 -0800 | [diff] [blame] | 19 | #include <string.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 20 | #include <unistd.h> |
| 21 | |
| 22 | #include <fcntl.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #include <sys/ioctl.h> |
| 26 | #include <sys/mman.h> |
| 27 | #include <sys/types.h> |
| 28 | |
| 29 | #include <linux/fb.h> |
| 30 | #include <linux/kd.h> |
| 31 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 32 | #include <time.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 33 | |
maxwen | 39624d4 | 2015-12-01 22:02:07 +0100 | [diff] [blame] | 34 | #ifdef BOARD_USE_CUSTOM_RECOVERY_FONT |
| 35 | #include BOARD_USE_CUSTOM_RECOVERY_FONT |
| 36 | #else |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 37 | #include "font_10x18.h" |
maxwen | 39624d4 | 2015-12-01 22:02:07 +0100 | [diff] [blame] | 38 | #endif |
| 39 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 40 | #include "minui.h" |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 41 | #include "graphics.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 42 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 43 | static GRFont* gr_font = NULL; |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 44 | static minui_backend* gr_backend = NULL; |
Doug Zongker | 16f97c3 | 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 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 50 | static unsigned char gr_current_r = 255; |
| 51 | static unsigned char gr_current_g = 255; |
| 52 | static unsigned char gr_current_b = 255; |
| 53 | static unsigned char gr_current_a = 255; |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 54 | static unsigned char rgb_555[2]; |
| 55 | static unsigned char gr_current_r5 = 31; |
| 56 | static unsigned char gr_current_g5 = 63; |
| 57 | static unsigned char gr_current_b5 = 31; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 58 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 59 | static GRSurface* gr_draw = NULL; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 60 | |
| 61 | static bool outside(int x, int y) |
| 62 | { |
| 63 | return x < 0 || x >= gr_draw->width || y < 0 || y >= gr_draw->height; |
| 64 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 65 | //#define TW_USE_MINUI_CUSTOM_FONTS 1 |
| 66 | #ifndef TW_USE_MINUI_CUSTOM_FONTS |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 67 | int gr_measure(const char *s) |
| 68 | { |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 69 | return gr_font->char_width * strlen(s); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 72 | void gr_font_size(int *x, int *y) |
| 73 | { |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 74 | *x = gr_font->char_width; |
| 75 | *y = gr_font->char_height; |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 76 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 77 | #else // TW_USE_MINUI_CUSTOM_FONTS |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 78 | const GRFont* gr_sys_font() |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 79 | { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 80 | return gr_font; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 83 | int gr_measure(const GRFont* font, const char *s) |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 84 | { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 85 | return font->char_width * strlen(s); |
| 86 | } |
| 87 | |
| 88 | void gr_font_size(const GRFont* font, int *x, int *y) |
| 89 | { |
| 90 | *x = font->char_width; |
| 91 | *y = font->char_height; |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 92 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 93 | #endif // TW_USE_MINUI_CUSTOM_FONTS |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 94 | |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 95 | void blend_16bpp(unsigned char* px, unsigned r5, unsigned g5, unsigned b5, unsigned char a) |
| 96 | { |
| 97 | unsigned char orig[2]; |
| 98 | orig[0] = px[0]; |
| 99 | orig[1] = px[1]; |
| 100 | |
| 101 | /* This code is a little easier to read |
| 102 | unsigned oldred = (orig[1] >> 3); |
| 103 | unsigned oldgreen = (((orig[0] >> 5) << 3) + (orig[1] & 0x7)); |
| 104 | unsigned oldblue = (orig[0] & 0x1F); |
| 105 | |
| 106 | unsigned newred = (oldred * (255-a) + r5 * a) / 255; |
| 107 | unsigned newgreen = (oldgreen * (255-a) + g5 * a) / 255; |
| 108 | unsigned newblue = (oldblue * (255-a) + b5 * a) / 255; |
| 109 | */ |
| 110 | |
| 111 | unsigned newred = ((orig[1] >> 3) * (255-a) + r5 * a) / 255; |
| 112 | unsigned newgreen = ((((orig[0] >> 5) << 3) + (orig[1] & 0x7)) * (255-a) + g5 * a) / 255; |
| 113 | unsigned newblue = ((orig[0] & 0x1F) * (255-a) + b5 * a) / 255; |
| 114 | |
| 115 | *px++ = (newgreen << 5) + (newblue); |
| 116 | *px++ = (newred << 3) + (newgreen >> 3); |
| 117 | } |
| 118 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 119 | static void text_blend(unsigned char* src_p, int src_row_bytes, |
| 120 | unsigned char* dst_p, int dst_row_bytes, |
| 121 | int width, int height) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 122 | { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 123 | for (int j = 0; j < height; ++j) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 124 | unsigned char* sx = src_p; |
| 125 | unsigned char* px = dst_p; |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 126 | for (int i = 0; i < width; ++i) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 127 | unsigned char a = *sx++; |
| 128 | if (gr_current_a < 255) a = ((int)a * gr_current_a) / 255; |
| 129 | if (a == 255) { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 130 | if (gr_draw->pixel_bytes == 2) { |
| 131 | *px++ = rgb_555[0]; |
| 132 | *px++ = rgb_555[1]; |
| 133 | } else { |
| 134 | *px++ = gr_current_r; |
| 135 | *px++ = gr_current_g; |
| 136 | *px++ = gr_current_b; |
| 137 | px++; |
| 138 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 139 | } else if (a > 0) { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 140 | if (gr_draw->pixel_bytes == 2) { |
| 141 | blend_16bpp(px, gr_current_r5, gr_current_g5, gr_current_b5, a); |
| 142 | px += gr_draw->pixel_bytes; |
| 143 | } else { |
| 144 | *px = (*px * (255-a) + gr_current_r * a) / 255; |
| 145 | ++px; |
| 146 | *px = (*px * (255-a) + gr_current_g * a) / 255; |
| 147 | ++px; |
| 148 | *px = (*px * (255-a) + gr_current_b * a) / 255; |
| 149 | ++px; |
| 150 | ++px; |
| 151 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 152 | } else { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 153 | px += gr_draw->pixel_bytes; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | src_p += src_row_bytes; |
| 157 | dst_p += dst_row_bytes; |
| 158 | } |
| 159 | } |
| 160 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 161 | #ifndef TW_USE_MINUI_CUSTOM_FONTS |
Elliott Hughes | 8fd86d7 | 2015-04-13 14:36:02 -0700 | [diff] [blame] | 162 | void gr_text(int x, int y, const char *s, bool bold) |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 163 | { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 164 | GRFont* font = gr_font; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 165 | |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 166 | if (!font->texture || gr_current_a == 0) return; |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 167 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 168 | bold = bold && (font->texture->height != font->char_height); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 169 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 170 | x += overscan_offset_x; |
| 171 | y += overscan_offset_y; |
| 172 | |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 173 | unsigned char ch; |
| 174 | while ((ch = *s++)) { |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 175 | 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] | 176 | |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 177 | if (ch < ' ' || ch > '~') { |
| 178 | ch = '?'; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 179 | } |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 180 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 181 | unsigned char* src_p = font->texture->data + ((ch - ' ') * font->char_width) + |
| 182 | (bold ? font->char_height * font->texture->row_bytes : 0); |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 183 | unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; |
| 184 | |
| 185 | text_blend(src_p, font->texture->row_bytes, |
| 186 | dst_p, gr_draw->row_bytes, |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 187 | font->char_width, font->char_height); |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 188 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 189 | x += font->char_width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 190 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 191 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 192 | #else //TW_USE_MINUI_CUSTOM_FONTS |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 193 | void gr_text(const GRFont* font, int x, int y, const char *s, bool bold) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 194 | { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 195 | if (!font->texture || gr_current_a == 0) return; |
| 196 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 197 | bold = bold && (font->texture->height != font->char_height); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 198 | |
| 199 | x += overscan_offset_x; |
| 200 | y += overscan_offset_y; |
| 201 | |
| 202 | unsigned char ch; |
| 203 | while ((ch = *s++)) { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 204 | if (outside(x, y) || outside(x+font->char_width-1, y+font->char_height-1)) break; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 205 | |
| 206 | if (ch < ' ' || ch > '~') { |
| 207 | ch = '?'; |
| 208 | } |
| 209 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 210 | unsigned char* src_p = font->texture->data + ((ch - ' ') * font->char_width) + |
| 211 | (bold ? font->char_height * font->texture->row_bytes : 0); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 212 | unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; |
| 213 | |
| 214 | text_blend(src_p, font->texture->row_bytes, |
| 215 | dst_p, gr_draw->row_bytes, |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 216 | font->char_width, font->char_height); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 217 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 218 | x += font->char_width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 219 | } |
| 220 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 221 | #endif //TW_USE_MINUI_CUSTOM_FONTS |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 222 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 223 | void gr_texticon(int x, int y, GRSurface* icon) { |
| 224 | if (icon == NULL) return; |
| 225 | |
| 226 | if (icon->pixel_bytes != 1) { |
| 227 | printf("gr_texticon: source has wrong format\n"); |
Doug Zongker | 52eeea4f | 2012-09-04 14:28:25 -0700 | [diff] [blame] | 228 | return; |
| 229 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 230 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 231 | x += overscan_offset_x; |
| 232 | y += overscan_offset_y; |
| 233 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 234 | 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] | 235 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 236 | unsigned char* src_p = icon->data; |
| 237 | 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] | 238 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 239 | text_blend(src_p, icon->row_bytes, |
| 240 | dst_p, gr_draw->row_bytes, |
| 241 | icon->width, icon->height); |
| 242 | } |
| 243 | |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 244 | void gr_convert_rgb_555() |
| 245 | { |
| 246 | gr_current_r5 = (((gr_current_r & 0xFF) * 0x1F) + 0x7F) / 0xFF; |
| 247 | gr_current_g5 = (((gr_current_g & 0xFF) * 0x3F) + 0x7F) / 0xFF; |
| 248 | gr_current_b5 = (((gr_current_b & 0xFF) * 0x1F) + 0x7F) / 0xFF; |
| 249 | |
| 250 | rgb_555[0] = (gr_current_g5 << 5) + (gr_current_b5); |
| 251 | rgb_555[1] = (gr_current_r5 << 3) + (gr_current_g5 >> 3); |
| 252 | } |
| 253 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 254 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) |
| 255 | { |
Tony Kuo | fd778e3 | 2015-02-05 21:25:56 +0800 | [diff] [blame] | 256 | #if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) |
| 257 | gr_current_r = b; |
| 258 | gr_current_g = g; |
| 259 | gr_current_b = r; |
| 260 | gr_current_a = a; |
| 261 | #else |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 262 | gr_current_r = r; |
| 263 | gr_current_g = g; |
| 264 | gr_current_b = b; |
| 265 | gr_current_a = a; |
Tony Kuo | fd778e3 | 2015-02-05 21:25:56 +0800 | [diff] [blame] | 266 | #endif |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 267 | if (gr_draw->pixel_bytes == 2) { |
| 268 | gr_convert_rgb_555(); |
| 269 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void gr_clear() |
| 273 | { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 274 | if (gr_draw->pixel_bytes == 2) { |
| 275 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | // This code only works on 32bpp devices |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 280 | 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] | 281 | memset(gr_draw->data, gr_current_r, gr_draw->height * gr_draw->row_bytes); |
| 282 | } else { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 283 | unsigned char* px = gr_draw->data; |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 284 | for (int y = 0; y < gr_draw->height; ++y) { |
| 285 | for (int x = 0; x < gr_draw->width; ++x) { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 286 | *px++ = gr_current_r; |
| 287 | *px++ = gr_current_g; |
| 288 | *px++ = gr_current_b; |
| 289 | px++; |
| 290 | } |
| 291 | px += gr_draw->row_bytes - (gr_draw->width * gr_draw->pixel_bytes); |
| 292 | } |
| 293 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 296 | 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] | 297 | { |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 298 | x1 += overscan_offset_x; |
| 299 | y1 += overscan_offset_y; |
| 300 | |
| 301 | x2 += overscan_offset_x; |
| 302 | y2 += overscan_offset_y; |
| 303 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 304 | if (outside(x1, y1) || outside(x2-1, y2-1)) return; |
| 305 | |
| 306 | unsigned char* p = gr_draw->data + y1 * gr_draw->row_bytes + x1 * gr_draw->pixel_bytes; |
| 307 | if (gr_current_a == 255) { |
| 308 | int x, y; |
| 309 | for (y = y1; y < y2; ++y) { |
| 310 | unsigned char* px = p; |
| 311 | for (x = x1; x < x2; ++x) { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 312 | if (gr_draw->pixel_bytes == 2) { |
| 313 | *px++ = rgb_555[0]; |
| 314 | *px++ = rgb_555[1]; |
| 315 | } else { |
| 316 | *px++ = gr_current_r; |
| 317 | *px++ = gr_current_g; |
| 318 | *px++ = gr_current_b; |
| 319 | px++; |
| 320 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 321 | } |
| 322 | p += gr_draw->row_bytes; |
| 323 | } |
| 324 | } else if (gr_current_a > 0) { |
| 325 | int x, y; |
| 326 | for (y = y1; y < y2; ++y) { |
| 327 | unsigned char* px = p; |
| 328 | for (x = x1; x < x2; ++x) { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 329 | if (gr_draw->pixel_bytes == 2) { |
| 330 | blend_16bpp(px, gr_current_r5, gr_current_g5, gr_current_b5, gr_current_a); |
| 331 | px += gr_draw->row_bytes; |
| 332 | } else { |
| 333 | *px = (*px * (255-gr_current_a) + gr_current_r * gr_current_a) / 255; |
| 334 | ++px; |
| 335 | *px = (*px * (255-gr_current_a) + gr_current_g * gr_current_a) / 255; |
| 336 | ++px; |
| 337 | *px = (*px * (255-gr_current_a) + gr_current_b * gr_current_a) / 255; |
| 338 | ++px; |
| 339 | ++px; |
| 340 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 341 | } |
| 342 | p += gr_draw->row_bytes; |
| 343 | } |
| 344 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 347 | void gr_blit_32to16(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) { |
| 348 | dx += overscan_offset_x; |
| 349 | dy += overscan_offset_y; |
| 350 | |
| 351 | if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return; |
| 352 | |
| 353 | unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes; |
| 354 | unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes; |
| 355 | |
| 356 | int i, j; |
| 357 | for (i = 0; i < h; ++i) { |
| 358 | unsigned char* spx = src_p; |
| 359 | unsigned char* dpx = dst_p; |
| 360 | |
| 361 | for (j = 0; j < w; ++j) { |
| 362 | unsigned a = spx[3]; |
| 363 | |
| 364 | if (a == 0) { |
| 365 | spx += source->pixel_bytes; |
| 366 | dpx += gr_draw->pixel_bytes; |
| 367 | } else { |
| 368 | unsigned r5 = (((*spx++ & 0xFF) * 0x1F) + 0x7F) / 0xFF; |
| 369 | unsigned g5 = (((*spx++ & 0xFF) * 0x3F) + 0x7F) / 0xFF; |
| 370 | unsigned b5 = (((*spx++ & 0xFF) * 0x1F) + 0x7F) / 0xFF; |
| 371 | spx++; |
| 372 | if (a == 255) { |
| 373 | *dpx++ = (g5 << 5) + (b5); |
| 374 | *dpx++ = (r5 << 3) + (g5 >> 3); |
| 375 | } else { |
| 376 | blend_16bpp(dpx, r5, g5, b5, a); |
| 377 | spx += source->pixel_bytes; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | src_p += source->row_bytes; |
| 382 | dst_p += gr_draw->row_bytes; |
| 383 | } |
| 384 | } |
| 385 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 386 | void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) { |
| 387 | if (source == NULL) return; |
| 388 | |
| 389 | if (gr_draw->pixel_bytes != source->pixel_bytes) { |
Ethan Yonker | e96182e | 2015-10-13 19:32:03 -0500 | [diff] [blame] | 390 | if (gr_draw->pixel_bytes == 2 && source->pixel_bytes == 4) { |
| 391 | gr_blit_32to16(source, sx, sy, w, h, dx, dy); |
| 392 | return; |
| 393 | } else { |
| 394 | printf("gr_blit: source has wrong format\n"); |
| 395 | return; |
| 396 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 397 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 398 | |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 399 | dx += overscan_offset_x; |
| 400 | dy += overscan_offset_y; |
| 401 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 402 | if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return; |
| 403 | |
| 404 | unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes; |
| 405 | unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes; |
| 406 | |
| 407 | int i; |
| 408 | for (i = 0; i < h; ++i) { |
| 409 | memcpy(dst_p, src_p, w * source->pixel_bytes); |
| 410 | src_p += source->row_bytes; |
| 411 | dst_p += gr_draw->row_bytes; |
| 412 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 415 | unsigned int gr_get_width(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 416 | if (surface == NULL) { |
| 417 | return 0; |
| 418 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 419 | return surface->width; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 422 | unsigned int gr_get_height(GRSurface* surface) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 423 | if (surface == NULL) { |
| 424 | return 0; |
| 425 | } |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 426 | return surface->height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 429 | #ifndef TW_USE_MINUI_CUSTOM_FONTS |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 430 | static void gr_init_font(void) |
| 431 | { |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 432 | gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1)); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 433 | |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 434 | int res = res_create_alpha_surface("font", &(gr_font->texture)); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 435 | if (res == 0) { |
| 436 | // The font image should be a 96x2 array of character images. The |
| 437 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 438 | // top row is regular text; the bottom row is bold. |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 439 | gr_font->char_width = gr_font->texture->width / 96; |
| 440 | gr_font->char_height = gr_font->texture->height / 2; |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 441 | } else { |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 442 | printf("failed to read font: res=%d\n", res); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 443 | |
| 444 | // fall back to the compiled-in font. |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 445 | gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture))); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 446 | gr_font->texture->width = font.width; |
| 447 | gr_font->texture->height = font.height; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 448 | gr_font->texture->row_bytes = font.width; |
| 449 | gr_font->texture->pixel_bytes = 1; |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 450 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 451 | unsigned char* bits = reinterpret_cast<unsigned char*>(malloc(font.width * font.height)); |
| 452 | gr_font->texture->data = reinterpret_cast<unsigned char*>(bits); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 453 | |
| 454 | unsigned char data; |
| 455 | unsigned char* in = font.rundata; |
| 456 | while((data = *in++)) { |
| 457 | memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f); |
| 458 | bits += (data & 0x7f); |
| 459 | } |
| 460 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 461 | gr_font->char_width = font.char_width; |
| 462 | gr_font->char_height = font.char_height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 463 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 466 | void gr_set_font(__attribute__ ((unused))const char* name) { |
| 467 | //this cm function is made to change font. Don't care, just init the font: |
| 468 | gr_init_font(); |
| 469 | return; |
| 470 | } |
| 471 | #else |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 472 | int gr_init_font(const char* name, GRFont** dest) { |
| 473 | GRFont* font = reinterpret_cast<GRFont*>(calloc(1, sizeof(*gr_font))); |
| 474 | if (font == nullptr) { |
| 475 | return -1; |
| 476 | } |
| 477 | |
| 478 | int res = res_create_alpha_surface(name, &(font->texture)); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 479 | if (res < 0) { |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 480 | free(font); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 481 | return res; |
| 482 | } |
| 483 | |
| 484 | // The font image should be a 96x2 array of character images. The |
| 485 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 486 | // top row is regular text; the bottom row is bold. |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 487 | font->char_width = font->texture->width / 96; |
| 488 | font->char_height = font->texture->height / 2; |
| 489 | |
| 490 | *dest = font; |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 495 | static void gr_init_font(void) |
| 496 | { |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 497 | int res = gr_init_font("font", &gr_font); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 498 | if (res == 0) { |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 499 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 500 | } |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 501 | |
| 502 | printf("failed to read font: res=%d\n", res); |
| 503 | |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 504 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 505 | // fall back to the compiled-in font. |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 506 | gr_font = reinterpret_cast<GRFont*>(calloc(1, sizeof(*gr_font))); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 507 | gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture))); |
| 508 | gr_font->texture->width = font.width; |
| 509 | gr_font->texture->height = font.height; |
| 510 | gr_font->texture->row_bytes = font.width; |
| 511 | gr_font->texture->pixel_bytes = 1; |
| 512 | |
| 513 | unsigned char* bits = reinterpret_cast<unsigned char*>(malloc(font.width * font.height)); |
| 514 | gr_font->texture->data = reinterpret_cast<unsigned char*>(bits); |
| 515 | |
| 516 | unsigned char data; |
| 517 | unsigned char* in = font.rundata; |
| 518 | while((data = *in++)) { |
| 519 | memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f); |
| 520 | bits += (data & 0x7f); |
| 521 | } |
| 522 | |
| 523 | gr_font->char_width = font.char_width; |
| 524 | gr_font->char_height = font.char_height; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 525 | } |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 526 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 527 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 528 | #if 0 |
| 529 | // Exercises many of the gr_*() functions; useful for testing. |
| 530 | static void gr_test() { |
| 531 | GRSurface** images; |
| 532 | int frames; |
| 533 | int result = res_create_multi_surface("icon_installing", &frames, &images); |
| 534 | if (result < 0) { |
| 535 | printf("create surface %d\n", result); |
| 536 | gr_exit(); |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | time_t start = time(NULL); |
| 541 | int x; |
| 542 | for (x = 0; x <= 1200; ++x) { |
| 543 | if (x < 400) { |
| 544 | gr_color(0, 0, 0, 255); |
| 545 | } else { |
| 546 | gr_color(0, (x-400)%128, 0, 255); |
| 547 | } |
| 548 | gr_clear(); |
| 549 | |
| 550 | gr_color(255, 0, 0, 255); |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 551 | GRSurface* frame = images[x%frames]; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 552 | gr_blit(frame, 0, 0, frame->width, frame->height, x, 0); |
| 553 | |
| 554 | gr_color(255, 0, 0, 128); |
| 555 | gr_fill(400, 150, 600, 350); |
| 556 | |
| 557 | gr_color(255, 255, 255, 255); |
| 558 | gr_text(500, 225, "hello, world!", 0); |
| 559 | gr_color(255, 255, 0, 128); |
| 560 | gr_text(300+x, 275, "pack my box with five dozen liquor jugs", 1); |
| 561 | |
| 562 | gr_color(0, 0, 255, 128); |
| 563 | gr_fill(gr_draw->width - 200 - x, 300, gr_draw->width - x, 500); |
| 564 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 565 | gr_draw = gr_backend->flip(gr_backend); |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 566 | } |
| 567 | printf("getting end time\n"); |
| 568 | time_t end = time(NULL); |
| 569 | printf("got end time\n"); |
| 570 | printf("start %ld end %ld\n", (long)start, (long)end); |
| 571 | if (end > start) { |
| 572 | printf("%.2f fps\n", ((double)x) / (end-start)); |
| 573 | } |
| 574 | } |
| 575 | #endif |
| 576 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 577 | void gr_flip() { |
| 578 | gr_draw = gr_backend->flip(gr_backend); |
| 579 | } |
| 580 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 581 | int gr_init(void) |
| 582 | { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 583 | gr_init_font(); |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 584 | gr_draw = NULL; |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 585 | |
Ethan Yonker | b386f71 | 2017-01-20 14:30:28 -0600 | [diff] [blame] | 586 | #ifdef MSM_BSP |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 587 | gr_backend = open_overlay(); |
Greg Hackmann | 41909dd | 2014-04-25 10:39:50 -0700 | [diff] [blame] | 588 | if (gr_backend) { |
| 589 | gr_draw = gr_backend->init(gr_backend); |
| 590 | if (!gr_draw) { |
| 591 | gr_backend->exit(gr_backend); |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 592 | } else |
| 593 | printf("Using overlay graphics.\n"); |
| 594 | } |
Ethan Yonker | b386f71 | 2017-01-20 14:30:28 -0600 | [diff] [blame] | 595 | #endif |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 596 | |
| 597 | #ifndef MSM_BSP |
Ethan Yonker | b386f71 | 2017-01-20 14:30:28 -0600 | [diff] [blame] | 598 | if (!gr_backend || !gr_draw) { |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 599 | gr_backend = open_adf(); |
| 600 | if (gr_backend) { |
| 601 | gr_draw = gr_backend->init(gr_backend); |
| 602 | if (!gr_draw) { |
| 603 | gr_backend->exit(gr_backend); |
| 604 | } else |
| 605 | printf("Using adf graphics.\n"); |
Greg Hackmann | 41909dd | 2014-04-25 10:39:50 -0700 | [diff] [blame] | 606 | } |
| 607 | } |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 608 | #else |
| 609 | printf("Skipping adf graphics because TW_TARGET_USES_QCOM_BSP := true\n"); |
| 610 | #endif |
Greg Hackmann | 41909dd | 2014-04-25 10:39:50 -0700 | [diff] [blame] | 611 | |
Ethan Yonker | b386f71 | 2017-01-20 14:30:28 -0600 | [diff] [blame] | 612 | if (!gr_backend || !gr_draw) { |
Stéphane Marchesin | 1a92c44 | 2015-06-29 20:05:48 -0700 | [diff] [blame] | 613 | gr_backend = open_drm(); |
| 614 | gr_draw = gr_backend->init(gr_backend); |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 615 | if (gr_draw) |
| 616 | printf("Using drm graphics.\n"); |
Stéphane Marchesin | 1a92c44 | 2015-06-29 20:05:48 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Ethan Yonker | b386f71 | 2017-01-20 14:30:28 -0600 | [diff] [blame] | 619 | if (!gr_backend || !gr_draw) { |
Greg Hackmann | 41909dd | 2014-04-25 10:39:50 -0700 | [diff] [blame] | 620 | gr_backend = open_fbdev(); |
| 621 | gr_draw = gr_backend->init(gr_backend); |
| 622 | if (gr_draw == NULL) { |
| 623 | return -1; |
Ethan Yonker | a59da09 | 2015-10-13 19:35:05 -0500 | [diff] [blame] | 624 | } else |
| 625 | printf("Using fbdev graphics.\n"); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 628 | overscan_offset_x = gr_draw->width * overscan_percent / 100; |
| 629 | overscan_offset_y = gr_draw->height * overscan_percent / 100; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 630 | |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 631 | gr_flip(); |
| 632 | gr_flip(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | void gr_exit(void) |
| 638 | { |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 639 | gr_backend->exit(gr_backend); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | int gr_fb_width(void) |
| 643 | { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 644 | return gr_draw->width - 2*overscan_offset_x; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | int gr_fb_height(void) |
| 648 | { |
Doug Zongker | 16f97c3 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 649 | return gr_draw->height - 2*overscan_offset_y; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 650 | } |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 651 | |
| 652 | void gr_fb_blank(bool blank) |
| 653 | { |
Doug Zongker | 5290f20 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 654 | gr_backend->blank(gr_backend, blank); |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 655 | } |