blob: 766b943ff22a913c8f97a674eba45230303c97de [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 Yonker84d61ce2017-05-10 16:11:35 -050020#ifndef TW_USE_MINUI_21
Ethan Yonkerc798c9c2015-10-09 11:15:26 -050021
Doug Zongker830b3e32014-03-11 13:22:04 -070022#include <sys/types.h>
23
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070024#include <functional>
Ethan Yonker8373cfe2017-09-08 06:50:54 -050025#include <string>
Doug Zongker28ce47c2011-10-28 10:33:05 -070026
Elliott Hughes07138192015-04-10 09:40:53 -070027//
28// Graphics.
29//
30
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070031struct GRSurface {
Doug Zongker39cf4172014-03-06 16:16:05 -080032 int width;
33 int height;
34 int row_bytes;
35 int pixel_bytes;
36 unsigned char* data;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070037};
Doug Zongker39cf4172014-03-06 16:16:05 -080038
Damien Bargiacchi35fff612016-08-11 15:57:03 -070039struct GRFont {
40 GRSurface* texture;
41 int char_width;
42 int char_height;
43};
44
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070045int gr_init();
46void gr_exit();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080047
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070048int gr_fb_width();
49int gr_fb_height();
Doug Zongker39cf4172014-03-06 16:16:05 -080050
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070051void gr_flip();
Dima Zavin4daf48a2011-08-30 11:59:20 -070052void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080053
Doug Zongker39cf4172014-03-06 16:16:05 -080054void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080055void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080056void gr_fill(int x1, int y1, int x2, int y2);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070057
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070058void gr_texticon(int x, int y, GRSurface* icon);
Ethan Yonker39662b22017-05-23 08:34:02 -050059#ifdef TW_NO_MINUI_CUSTOM_FONTS
Ethan Yonker84d61ce2017-05-10 16:11:35 -050060void gr_text(int x, int y, const char *s, bool bold);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080061int gr_measure(const char *s);
Dima Zavin3c7f00e2011-08-30 11:58:24 -070062void gr_font_size(int *x, int *y);
nailykc45b2d52016-08-19 13:27:12 +020063void gr_set_font(__attribute__ ((unused))const char* name);
Ethan Yonker84d61ce2017-05-10 16:11:35 -050064#else
Damien Bargiacchi35fff612016-08-11 15:57:03 -070065
66const GRFont* gr_sys_font();
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -070067int gr_init_font(const char* name, GRFont** dest);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070068void gr_text(const GRFont* font, int x, int y, const char *s, bool bold);
69int gr_measure(const GRFont* font, const char *s);
70void gr_font_size(const GRFont* font, int *x, int *y);
Ethan Yonker84d61ce2017-05-10 16:11:35 -050071#endif
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080072
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070073void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
74unsigned int gr_get_width(GRSurface* surface);
75unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080076
Elliott Hughes07138192015-04-10 09:40:53 -070077//
78// Input events.
79//
80
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080081struct input_event;
82
Ethan Yonker8373cfe2017-09-08 06:50:54 -050083#ifdef TW_USE_MINUI_WITH_DATA
Elliott Hughes07138192015-04-10 09:40:53 -070084typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
85typedef int (*ev_set_key_callback)(int code, int value, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070086
Elliott Hughes07138192015-04-10 09:40:53 -070087int ev_init(ev_callback input_cb, void* data);
Elliott Hughes07138192015-04-10 09:40:53 -070088int ev_add_fd(int fd, ev_callback cb, void* data);
89int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
Ethan Yonker8373cfe2017-09-08 06:50:54 -050090#else
91using ev_callback = std::function<int(int fd, uint32_t epevents)>;
92using ev_set_key_callback = std::function<int(int code, int value)>;
93
94int ev_init(ev_callback input_cb);
95int ev_add_fd(int fd, ev_callback cb);
96int ev_sync_key_state(const ev_set_key_callback& set_key_cb);
97#endif
98void ev_exit();
99void ev_iterate_available_keys(const std::function<void(int)>& f);
Dima Zavinbc290632011-08-30 11:59:45 -0700100
Elliott Hughes07138192015-04-10 09:40:53 -0700101// 'timeout' has the same semantics as poll(2).
102// 0 : don't block
103// < 0 : block forever
104// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -0700105int ev_wait(int timeout);
106
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700107int ev_get_input(int fd, uint32_t epevents, input_event* ev);
108void ev_dispatch();
109int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800110
Elliott Hughes07138192015-04-10 09:40:53 -0700111//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800112// Resources
Elliott Hughes07138192015-04-10 09:40:53 -0700113//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800114
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500115bool matches_locale(const std::string& prefix, const std::string& locale);
Tianjie Xu2430e292016-04-19 15:02:41 -0700116
Doug Zongkera418aa72014-03-17 12:10:02 -0700117// 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 Hughes0a5cb0c2015-04-15 10:58:56 -0700128int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700129
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 Baob723f4f2015-12-11 15:18:51 -0800134int res_create_multi_display_surface(const char* name, int* frames,
135 int* fps, GRSurface*** pSurface);
Ethan Yonker534d4e02016-08-26 10:05:03 -0500136int res_create_multi_display_surface(const char* name, int* frames,
137 GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700138
139// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700140int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700141
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 Yonker8373cfe2017-09-08 06:50:54 -0500146// bootable/recovery/tools/recovery_l10n for an app that will generate
147// these specialized images from Android resources.
Doug Zongkera418aa72014-03-17 12:10:02 -0700148int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700149 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700150
151// Free a surface allocated by any of the res_create_*_surface()
152// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700153void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800154
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500155#else //ifndef TW_USE_MINUI_21
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500156
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500157// This the old minui21/minui.h for compatibility with building TWRP
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500158// in pre 6.0 trees.
159
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800160#include <stdbool.h>
161
162#ifdef __cplusplus
163extern "C" {
164#endif
165
Ethan Yonkera33161b2014-11-06 15:11:20 -0600166typedef void* gr_surface;
167typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800168
169int gr_init(void);
170void gr_exit(void);
171
172int gr_fb_width(void);
173int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600174gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800175void gr_flip(void);
176void gr_fb_blank(bool blank);
177
178void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
179void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200180
181// system/core/charger uses different gr_print signatures in diferent
182// Android versions, either with or without int bold.
183int gr_text(int x, int y, const char *s, ...);
184int gr_text_impl(int x, int y, const char *s, int bold);
185
Ethan Yonkera33161b2014-11-06 15:11:20 -0600186 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800187int gr_measure(const char *s);
188void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000189void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800190
191void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
192unsigned int gr_get_width(gr_surface surface);
193unsigned 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.
197struct input_event;
198
Ethan Yonker304f32f2014-11-07 10:14:05 -0600199typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800200typedef int (*ev_set_key_callback)(int code, int value, void *data);
201
202int ev_init(ev_callback input_cb, void *data);
203void ev_exit(void);
204int ev_add_fd(int fd, ev_callback cb, void *data);
205int 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 */
212int ev_wait(int timeout);
213
Ethan Yonker304f32f2014-11-07 10:14:05 -0600214int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800215void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600216int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800217
218// Resources
219
Ethan Yonkera33161b2014-11-06 15:11:20 -0600220// Returns 0 if no error, else negative.
221int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600222
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.
227int res_create_multi_display_surface(const char* name,
228 int* frames, gr_surface** pSurface);
229
Ethan Yonkera33161b2014-11-06 15:11:20 -0600230int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800231void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700232static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
233 return res_create_surface(name, pSurface);
234}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800235
Ethan Yonker304f32f2014-11-07 10:14:05 -0600236// These are new graphics functions from 5.0 that were not available in
237// 4.4 that are required by charger and healthd
238void gr_clear();
239
240
Doug Zongker28ce47c2011-10-28 10:33:05 -0700241#ifdef __cplusplus
242}
243#endif
244
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500245#endif // ifndef TW_USE_MINUI_21
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500246#endif // ifndef _MINUI_H_