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 | |
| 17 | #ifndef _MINUI_H_ |
| 18 | #define _MINUI_H_ |
| 19 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 20 | #ifndef TW_USE_MINUI_21 |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 21 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 22 | #include <sys/types.h> |
| 23 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 24 | #include <functional> |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 25 | #include <string> |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 26 | |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 27 | // |
| 28 | // Graphics. |
| 29 | // |
| 30 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 31 | struct GRSurface { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 32 | int width; |
| 33 | int height; |
| 34 | int row_bytes; |
| 35 | int pixel_bytes; |
| 36 | unsigned char* data; |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 37 | }; |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 38 | |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 39 | struct GRFont { |
| 40 | GRSurface* texture; |
| 41 | int char_width; |
| 42 | int char_height; |
| 43 | }; |
| 44 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 45 | int gr_init(); |
| 46 | void gr_exit(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 47 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 48 | int gr_fb_width(); |
| 49 | int gr_fb_height(); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 50 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 51 | void gr_flip(); |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 52 | void gr_fb_blank(bool blank); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 53 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 54 | void gr_clear(); // clear entire surface to current color |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 55 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 56 | void gr_fill(int x1, int y1, int x2, int y2); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 57 | |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 58 | void gr_texticon(int x, int y, GRSurface* icon); |
Ethan Yonker | 39662b2 | 2017-05-23 08:34:02 -0500 | [diff] [blame] | 59 | #ifdef TW_NO_MINUI_CUSTOM_FONTS |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 60 | void gr_text(int x, int y, const char *s, bool bold); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 61 | int gr_measure(const char *s); |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 62 | void gr_font_size(int *x, int *y); |
nailyk | c45b2d5 | 2016-08-19 13:27:12 +0200 | [diff] [blame] | 63 | void gr_set_font(__attribute__ ((unused))const char* name); |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 64 | #else |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 65 | |
| 66 | const GRFont* gr_sys_font(); |
Damien Bargiacchi | d00f5eb | 2016-09-09 07:14:08 -0700 | [diff] [blame] | 67 | int gr_init_font(const char* name, GRFont** dest); |
Damien Bargiacchi | 35fff61 | 2016-08-11 15:57:03 -0700 | [diff] [blame] | 68 | void gr_text(const GRFont* font, int x, int y, const char *s, bool bold); |
| 69 | int gr_measure(const GRFont* font, const char *s); |
| 70 | void gr_font_size(const GRFont* font, int *x, int *y); |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 71 | #endif |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 72 | |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 73 | void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy); |
| 74 | unsigned int gr_get_width(GRSurface* surface); |
| 75 | unsigned int gr_get_height(GRSurface* surface); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 76 | |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 77 | // |
| 78 | // Input events. |
| 79 | // |
| 80 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 81 | struct input_event; |
| 82 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 83 | #ifdef TW_USE_MINUI_WITH_DATA |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 84 | typedef int (*ev_callback)(int fd, uint32_t epevents, void* data); |
| 85 | typedef int (*ev_set_key_callback)(int code, int value, void* data); |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 86 | |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 87 | int ev_init(ev_callback input_cb, void* data); |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 88 | int ev_add_fd(int fd, ev_callback cb, void* data); |
| 89 | int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data); |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 90 | #else |
| 91 | using ev_callback = std::function<int(int fd, uint32_t epevents)>; |
| 92 | using ev_set_key_callback = std::function<int(int code, int value)>; |
| 93 | |
| 94 | int ev_init(ev_callback input_cb); |
| 95 | int ev_add_fd(int fd, ev_callback cb); |
| 96 | int ev_sync_key_state(const ev_set_key_callback& set_key_cb); |
| 97 | #endif |
| 98 | void ev_exit(); |
| 99 | void ev_iterate_available_keys(const std::function<void(int)>& f); |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 100 | |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 101 | // 'timeout' has the same semantics as poll(2). |
| 102 | // 0 : don't block |
| 103 | // < 0 : block forever |
| 104 | // > 0 : block for 'timeout' milliseconds |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 105 | int ev_wait(int timeout); |
| 106 | |
Elliott Hughes | 07cfb8f | 2015-04-10 13:12:05 -0700 | [diff] [blame] | 107 | int ev_get_input(int fd, uint32_t epevents, input_event* ev); |
| 108 | void ev_dispatch(); |
| 109 | int ev_get_epollfd(); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 110 | |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 111 | // |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 112 | // Resources |
Elliott Hughes | 0713819 | 2015-04-10 09:40:53 -0700 | [diff] [blame] | 113 | // |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 114 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 115 | bool matches_locale(const std::string& prefix, const std::string& locale); |
Tianjie Xu | 2430e29 | 2016-04-19 15:02:41 -0700 | [diff] [blame] | 116 | |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 117 | // res_create_*_surface() functions return 0 if no error, else |
| 118 | // negative. |
| 119 | // |
| 120 | // A "display" surface is one that is intended to be drawn to the |
| 121 | // screen with gr_blit(). An "alpha" surface is a grayscale image |
| 122 | // interpreted as an alpha mask used to render text in the current |
| 123 | // color (with gr_text() or gr_texticon()). |
| 124 | // |
| 125 | // All these functions load PNG images from "/res/images/${name}.png". |
| 126 | |
| 127 | // Load a single display surface from a PNG image. |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 128 | int res_create_display_surface(const char* name, GRSurface** pSurface); |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 129 | |
| 130 | // Load an array of display surfaces from a single PNG image. The PNG |
| 131 | // should have a 'Frames' text chunk whose value is the number of |
| 132 | // frames this image represents. The pixel data itself is interlaced |
| 133 | // by row. |
Tao Bao | b723f4f | 2015-12-11 15:18:51 -0800 | [diff] [blame] | 134 | int res_create_multi_display_surface(const char* name, int* frames, |
| 135 | int* fps, GRSurface*** pSurface); |
Ethan Yonker | 534d4e0 | 2016-08-26 10:05:03 -0500 | [diff] [blame] | 136 | int res_create_multi_display_surface(const char* name, int* frames, |
| 137 | GRSurface*** pSurface); |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 138 | |
| 139 | // Load a single alpha surface from a grayscale PNG image. |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 140 | int res_create_alpha_surface(const char* name, GRSurface** pSurface); |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 141 | |
| 142 | // Load part of a grayscale PNG image that is the first match for the |
| 143 | // given locale. The image is expected to be a composite of multiple |
| 144 | // translations of the same text, with special added rows that encode |
| 145 | // the subimages' size and intended locale in the pixel data. See |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 146 | // bootable/recovery/tools/recovery_l10n for an app that will generate |
| 147 | // these specialized images from Android resources. |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 148 | int res_create_localized_alpha_surface(const char* name, const char* locale, |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 149 | GRSurface** pSurface); |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 150 | |
| 151 | // Free a surface allocated by any of the res_create_*_surface() |
| 152 | // functions. |
Elliott Hughes | 0a5cb0c | 2015-04-15 10:58:56 -0700 | [diff] [blame] | 153 | void res_free_surface(GRSurface* surface); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 154 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 155 | #else //ifndef TW_USE_MINUI_21 |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 156 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 157 | // This the old minui21/minui.h for compatibility with building TWRP |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 158 | // in pre 6.0 trees. |
| 159 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 160 | #include <stdbool.h> |
| 161 | |
| 162 | #ifdef __cplusplus |
| 163 | extern "C" { |
| 164 | #endif |
| 165 | |
Ethan Yonker | a33161b | 2014-11-06 15:11:20 -0600 | [diff] [blame] | 166 | typedef void* gr_surface; |
| 167 | typedef unsigned short gr_pixel; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 168 | |
| 169 | int gr_init(void); |
| 170 | void gr_exit(void); |
| 171 | |
| 172 | int gr_fb_width(void); |
| 173 | int gr_fb_height(void); |
Ethan Yonker | a33161b | 2014-11-06 15:11:20 -0600 | [diff] [blame] | 174 | gr_pixel *gr_fb_data(void); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 175 | void gr_flip(void); |
| 176 | void gr_fb_blank(bool blank); |
| 177 | |
| 178 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
| 179 | void gr_fill(int x1, int y1, int x2, int y2); |
Vojtech Bocek | 65fdcdd | 2013-09-06 21:32:22 +0200 | [diff] [blame] | 180 | |
| 181 | // system/core/charger uses different gr_print signatures in diferent |
| 182 | // Android versions, either with or without int bold. |
| 183 | int gr_text(int x, int y, const char *s, ...); |
| 184 | int gr_text_impl(int x, int y, const char *s, int bold); |
| 185 | |
Ethan Yonker | a33161b | 2014-11-06 15:11:20 -0600 | [diff] [blame] | 186 | void gr_texticon(int x, int y, gr_surface icon); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 187 | int gr_measure(const char *s); |
| 188 | void gr_font_size(int *x, int *y); |
Dees Troy | 62b75ab | 2014-05-02 13:20:33 +0000 | [diff] [blame] | 189 | void gr_get_memory_surface(gr_surface); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 190 | |
| 191 | void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy); |
| 192 | unsigned int gr_get_width(gr_surface surface); |
| 193 | unsigned int gr_get_height(gr_surface surface); |
| 194 | |
| 195 | // input event structure, include <linux/input.h> for the definition. |
| 196 | // see http://www.mjmwired.net/kernel/Documentation/input/ for info. |
| 197 | struct input_event; |
| 198 | |
Ethan Yonker | 304f32f | 2014-11-07 10:14:05 -0600 | [diff] [blame] | 199 | typedef int (*ev_callback)(int fd, uint32_t epevents, void *data); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 200 | typedef int (*ev_set_key_callback)(int code, int value, void *data); |
| 201 | |
| 202 | int ev_init(ev_callback input_cb, void *data); |
| 203 | void ev_exit(void); |
| 204 | int ev_add_fd(int fd, ev_callback cb, void *data); |
| 205 | int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data); |
| 206 | |
| 207 | /* timeout has the same semantics as for poll |
| 208 | * 0 : don't block |
| 209 | * < 0 : block forever |
| 210 | * > 0 : block for 'timeout' milliseconds |
| 211 | */ |
| 212 | int ev_wait(int timeout); |
| 213 | |
Ethan Yonker | 304f32f | 2014-11-07 10:14:05 -0600 | [diff] [blame] | 214 | int ev_get_input(int fd, uint32_t epevents, struct input_event *ev); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 215 | void ev_dispatch(void); |
Ethan Yonker | 304f32f | 2014-11-07 10:14:05 -0600 | [diff] [blame] | 216 | int ev_get_epollfd(void); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 217 | |
| 218 | // Resources |
| 219 | |
Ethan Yonker | a33161b | 2014-11-06 15:11:20 -0600 | [diff] [blame] | 220 | // Returns 0 if no error, else negative. |
| 221 | int res_create_surface(const char* name, gr_surface* pSurface); |
Ethan Yonker | 304f32f | 2014-11-07 10:14:05 -0600 | [diff] [blame] | 222 | |
| 223 | // Load an array of display surfaces from a single PNG image. The PNG |
| 224 | // should have a 'Frames' text chunk whose value is the number of |
| 225 | // frames this image represents. The pixel data itself is interlaced |
| 226 | // by row. |
| 227 | int res_create_multi_display_surface(const char* name, |
| 228 | int* frames, gr_surface** pSurface); |
| 229 | |
Ethan Yonker | a33161b | 2014-11-06 15:11:20 -0600 | [diff] [blame] | 230 | int res_create_localized_surface(const char* name, gr_surface* pSurface); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 231 | void res_free_surface(gr_surface surface); |
Steve Kondik | 626009f | 2014-04-30 13:25:41 -0700 | [diff] [blame] | 232 | static inline int res_create_display_surface(const char* name, gr_surface* pSurface) { |
| 233 | return res_create_surface(name, pSurface); |
| 234 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 235 | |
Ethan Yonker | 304f32f | 2014-11-07 10:14:05 -0600 | [diff] [blame] | 236 | // These are new graphics functions from 5.0 that were not available in |
| 237 | // 4.4 that are required by charger and healthd |
| 238 | void gr_clear(); |
| 239 | |
| 240 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 241 | #ifdef __cplusplus |
| 242 | } |
| 243 | #endif |
| 244 | |
Ethan Yonker | 84d61ce | 2017-05-10 16:11:35 -0500 | [diff] [blame] | 245 | #endif // ifndef TW_USE_MINUI_21 |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 246 | #endif // ifndef _MINUI_H_ |