blob: bff146add8384de384c655cd64ef1e9a2344dce1 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
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 Yonker8373cfe2017-09-08 06:50:54 -050020#ifndef TW_USE_MINUI_21
21
Doug Zongker830b3e32014-03-11 13:22:04 -070022#include <sys/types.h>
23
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070024#include <functional>
Tianjie Xu0a599562017-03-28 20:11:15 +000025#include <string>
Tianjie Xu29d55752017-09-20 17:53:46 -070026#include <vector>
Doug Zongker28ce47c2011-10-28 10:33:05 -070027
Elliott Hughes07138192015-04-10 09:40:53 -070028//
29// Graphics.
30//
31
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070032struct GRSurface {
Luke Song846012f2017-09-13 15:56:16 -070033 int width;
34 int height;
35 int row_bytes;
36 int pixel_bytes;
37 unsigned char* data;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070038};
Doug Zongker39cf4172014-03-06 16:16:05 -080039
Damien Bargiacchi35fff612016-08-11 15:57:03 -070040struct GRFont {
Luke Song846012f2017-09-13 15:56:16 -070041 GRSurface* texture;
42 int char_width;
43 int char_height;
44};
45
46enum GRRotation {
47 ROTATION_NONE = 0,
48 ROTATION_RIGHT = 1,
49 ROTATION_DOWN = 2,
50 ROTATION_LEFT = 3,
Damien Bargiacchi35fff612016-08-11 15:57:03 -070051};
52
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070053int gr_init();
54void gr_exit();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080055
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070056int gr_fb_width();
57int gr_fb_height();
Doug Zongker39cf4172014-03-06 16:16:05 -080058
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070059void gr_flip();
Dima Zavin4daf48a2011-08-30 11:59:20 -070060void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080061
Doug Zongker39cf4172014-03-06 16:16:05 -080062void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080063void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080064void gr_fill(int x1, int y1, int x2, int y2);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070065
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070066void gr_texticon(int x, int y, GRSurface* icon);
Ethan Yonker8373cfe2017-09-08 06:50:54 -050067#ifdef TW_NO_MINUI_CUSTOM_FONTS
68void gr_text(int x, int y, const char *s, bool bold);
69int gr_measure(const char *s);
70void gr_font_size(int *x, int *y);
71void gr_set_font(__attribute__ ((unused))const char* name);
72#else
Damien Bargiacchi35fff612016-08-11 15:57:03 -070073
74const GRFont* gr_sys_font();
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -070075int gr_init_font(const char* name, GRFont** dest);
Luke Song846012f2017-09-13 15:56:16 -070076void gr_text(const GRFont* font, int x, int y, const char* s, bool bold);
77int gr_measure(const GRFont* font, const char* s);
78void gr_font_size(const GRFont* font, int* x, int* y);
Ethan Yonker8373cfe2017-09-08 06:50:54 -050079#endif
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080080
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070081void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
82unsigned int gr_get_width(GRSurface* surface);
83unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080084
Luke Song846012f2017-09-13 15:56:16 -070085// Set rotation, flips gr_fb_width/height if 90 degree rotation difference
86void gr_rotate(GRRotation rotation);
87
Elliott Hughes07138192015-04-10 09:40:53 -070088//
89// Input events.
90//
91
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080092struct input_event;
93
Ethan Yonker8373cfe2017-09-08 06:50:54 -050094#ifdef TW_USE_MINUI_WITH_DATA
95typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
96typedef int (*ev_set_key_callback)(int code, int value, void* data);
97
98int ev_init(ev_callback input_cb, void* data);
99int ev_add_fd(int fd, ev_callback cb, void* data);
100int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
101#else
Tao Bao0b1118d2017-01-14 07:46:10 -0800102using ev_callback = std::function<int(int fd, uint32_t epevents)>;
103using ev_set_key_callback = std::function<int(int code, int value)>;
Dima Zavinbc290632011-08-30 11:59:45 -0700104
Ethan Yonkerecbd3e82017-12-14 14:43:59 -0600105#ifdef TW_USE_MINUI_WITH_OPTIONAL_TOUCH_EVENTS
Tao Baoaf9f8b42017-07-28 00:05:40 -0700106int ev_init(ev_callback input_cb, bool allow_touch_inputs = false);
Tao Baoaf9f8b42017-07-28 00:05:40 -0700107void ev_iterate_touch_inputs(const std::function<void(int)>& action);
Ethan Yonkerecbd3e82017-12-14 14:43:59 -0600108#else
Tao Bao0b1118d2017-01-14 07:46:10 -0800109int ev_init(ev_callback input_cb);
Ethan Yonkerecbd3e82017-12-14 14:43:59 -0600110#endif
Tao Bao0b1118d2017-01-14 07:46:10 -0800111int ev_add_fd(int fd, ev_callback cb);
Tao Bao0b1118d2017-01-14 07:46:10 -0800112int ev_sync_key_state(const ev_set_key_callback& set_key_cb);
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500113#endif
114void ev_exit();
115void ev_iterate_available_keys(const std::function<void(int)>& f);
Dima Zavinbc290632011-08-30 11:59:45 -0700116
Elliott Hughes07138192015-04-10 09:40:53 -0700117// 'timeout' has the same semantics as poll(2).
118// 0 : don't block
119// < 0 : block forever
120// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -0700121int ev_wait(int timeout);
122
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700123int ev_get_input(int fd, uint32_t epevents, input_event* ev);
124void ev_dispatch();
125int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800126
Elliott Hughes07138192015-04-10 09:40:53 -0700127//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800128// Resources
Elliott Hughes07138192015-04-10 09:40:53 -0700129//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800130
Tianjie Xu0a599562017-03-28 20:11:15 +0000131bool matches_locale(const std::string& prefix, const std::string& locale);
Tianjie Xu2430e292016-04-19 15:02:41 -0700132
Doug Zongkera418aa72014-03-17 12:10:02 -0700133// res_create_*_surface() functions return 0 if no error, else
134// negative.
135//
136// A "display" surface is one that is intended to be drawn to the
137// screen with gr_blit(). An "alpha" surface is a grayscale image
138// interpreted as an alpha mask used to render text in the current
139// color (with gr_text() or gr_texticon()).
140//
141// All these functions load PNG images from "/res/images/${name}.png".
142
143// Load a single display surface from a PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700144int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700145
146// Load an array of display surfaces from a single PNG image. The PNG
147// should have a 'Frames' text chunk whose value is the number of
148// frames this image represents. The pixel data itself is interlaced
149// by row.
Tao Baob723f4f2015-12-11 15:18:51 -0800150int res_create_multi_display_surface(const char* name, int* frames,
151 int* fps, GRSurface*** pSurface);
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500152int res_create_multi_display_surface(const char* name, int* frames,
153 GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700154
155// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700156int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700157
158// Load part of a grayscale PNG image that is the first match for the
159// given locale. The image is expected to be a composite of multiple
160// translations of the same text, with special added rows that encode
161// the subimages' size and intended locale in the pixel data. See
Tianjie Xu9a259772016-07-28 14:15:00 -0700162// bootable/recovery/tools/recovery_l10n for an app that will generate
163// these specialized images from Android resources.
Doug Zongkera418aa72014-03-17 12:10:02 -0700164int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700165 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700166
Tianjie Xu29d55752017-09-20 17:53:46 -0700167// Return a list of locale strings embedded in |png_name|. Return a empty list in case of failure.
168std::vector<std::string> get_locales_in_png(const std::string& png_name);
169
Doug Zongkera418aa72014-03-17 12:10:02 -0700170// Free a surface allocated by any of the res_create_*_surface()
171// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700172void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800173
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500174#else //ifndef TW_USE_MINUI_21
175
176// This the old minui21/minui.h for compatibility with building TWRP
177// in pre 6.0 trees.
178
179#include <stdbool.h>
180
181#ifdef __cplusplus
182extern "C" {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800183#endif
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500184
185typedef void* gr_surface;
186typedef unsigned short gr_pixel;
187
188int gr_init(void);
189void gr_exit(void);
190
191int gr_fb_width(void);
192int gr_fb_height(void);
193gr_pixel *gr_fb_data(void);
194void gr_flip(void);
195void gr_fb_blank(bool blank);
196
197void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
198void gr_fill(int x1, int y1, int x2, int y2);
199
200// system/core/charger uses different gr_print signatures in diferent
201// Android versions, either with or without int bold.
202int gr_text(int x, int y, const char *s, ...);
203int gr_text_impl(int x, int y, const char *s, int bold);
204
205 void gr_texticon(int x, int y, gr_surface icon);
206int gr_measure(const char *s);
207void gr_font_size(int *x, int *y);
208void gr_get_memory_surface(gr_surface);
209
210void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
211unsigned int gr_get_width(gr_surface surface);
212unsigned int gr_get_height(gr_surface surface);
213
214// input event structure, include <linux/input.h> for the definition.
215// see http://www.mjmwired.net/kernel/Documentation/input/ for info.
216struct input_event;
217
218typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
219typedef int (*ev_set_key_callback)(int code, int value, void *data);
220
221int ev_init(ev_callback input_cb, void *data);
222void ev_exit(void);
223int ev_add_fd(int fd, ev_callback cb, void *data);
224int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
225
226/* timeout has the same semantics as for poll
227 * 0 : don't block
228 * < 0 : block forever
229 * > 0 : block for 'timeout' milliseconds
230 */
231int ev_wait(int timeout);
232
233int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
234void ev_dispatch(void);
235int ev_get_epollfd(void);
236
237// Resources
238
239// Returns 0 if no error, else negative.
240int res_create_surface(const char* name, gr_surface* pSurface);
241
242// Load an array of display surfaces from a single PNG image. The PNG
243// should have a 'Frames' text chunk whose value is the number of
244// frames this image represents. The pixel data itself is interlaced
245// by row.
246int res_create_multi_display_surface(const char* name,
247 int* frames, gr_surface** pSurface);
248
249int res_create_localized_surface(const char* name, gr_surface* pSurface);
250void res_free_surface(gr_surface surface);
251static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
252 return res_create_surface(name, pSurface);
253}
254
255// These are new graphics functions from 5.0 that were not available in
256// 4.4 that are required by charger and healthd
257void gr_clear();
258
259
260#ifdef __cplusplus
261}
262#endif
263
264#endif // ifndef TW_USE_MINUI_21
265#endif // ifndef _MINUI_H_