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