blob: abef036e47cbe6947f69149cf04b2fc540618895 [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>
Doug Zongker28ce47c2011-10-28 10:33:05 -070025
Elliott Hughes07138192015-04-10 09:40:53 -070026//
27// Graphics.
28//
29
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070030struct GRSurface {
Doug Zongker39cf4172014-03-06 16:16:05 -080031 int width;
32 int height;
33 int row_bytes;
34 int pixel_bytes;
35 unsigned char* data;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070036};
Doug Zongker39cf4172014-03-06 16:16:05 -080037
Damien Bargiacchi35fff612016-08-11 15:57:03 -070038struct GRFont {
39 GRSurface* texture;
40 int char_width;
41 int char_height;
42};
43
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070044int gr_init();
45void gr_exit();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080046
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070047int gr_fb_width();
48int gr_fb_height();
Doug Zongker39cf4172014-03-06 16:16:05 -080049
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070050void gr_flip();
Dima Zavin4daf48a2011-08-30 11:59:20 -070051void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052
Doug Zongker39cf4172014-03-06 16:16:05 -080053void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080054void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080055void gr_fill(int x1, int y1, int x2, int y2);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070056
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070057void gr_texticon(int x, int y, GRSurface* icon);
Ethan Yonker84d61ce2017-05-10 16:11:35 -050058#ifndef TW_USE_MINUI_CUSTOM_FONTS
59void gr_text(int x, int y, const char *s, bool bold);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060int gr_measure(const char *s);
Dima Zavin3c7f00e2011-08-30 11:58:24 -070061void gr_font_size(int *x, int *y);
nailykc45b2d52016-08-19 13:27:12 +020062void gr_set_font(__attribute__ ((unused))const char* name);
Ethan Yonker84d61ce2017-05-10 16:11:35 -050063#else
Damien Bargiacchi35fff612016-08-11 15:57:03 -070064
65const GRFont* gr_sys_font();
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -070066int gr_init_font(const char* name, GRFont** dest);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070067void gr_text(const GRFont* font, int x, int y, const char *s, bool bold);
68int gr_measure(const GRFont* font, const char *s);
69void gr_font_size(const GRFont* font, int *x, int *y);
Ethan Yonker84d61ce2017-05-10 16:11:35 -050070#endif
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080071
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070072void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
73unsigned int gr_get_width(GRSurface* surface);
74unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080075
Elliott Hughes07138192015-04-10 09:40:53 -070076//
77// Input events.
78//
79
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080080struct input_event;
81
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070082// TODO: move these over to std::function.
Elliott Hughes07138192015-04-10 09:40:53 -070083typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
84typedef int (*ev_set_key_callback)(int code, int value, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070085
Elliott Hughes07138192015-04-10 09:40:53 -070086int ev_init(ev_callback input_cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070087void ev_exit();
Elliott Hughes07138192015-04-10 09:40:53 -070088int ev_add_fd(int fd, ev_callback cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070089void ev_iterate_available_keys(std::function<void(int)> f);
Elliott Hughes07138192015-04-10 09:40:53 -070090int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070091
Elliott Hughes07138192015-04-10 09:40:53 -070092// 'timeout' has the same semantics as poll(2).
93// 0 : don't block
94// < 0 : block forever
95// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -070096int ev_wait(int timeout);
97
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070098int ev_get_input(int fd, uint32_t epevents, input_event* ev);
99void ev_dispatch();
100int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800101
Elliott Hughes07138192015-04-10 09:40:53 -0700102//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800103// Resources
Elliott Hughes07138192015-04-10 09:40:53 -0700104//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800105
Tianjie Xu2430e292016-04-19 15:02:41 -0700106bool matches_locale(const char* prefix, const char* locale);
107
Doug Zongkera418aa72014-03-17 12:10:02 -0700108// res_create_*_surface() functions return 0 if no error, else
109// negative.
110//
111// A "display" surface is one that is intended to be drawn to the
112// screen with gr_blit(). An "alpha" surface is a grayscale image
113// interpreted as an alpha mask used to render text in the current
114// color (with gr_text() or gr_texticon()).
115//
116// All these functions load PNG images from "/res/images/${name}.png".
117
118// Load a single display surface from a PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700119int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700120
121// Load an array of display surfaces from a single PNG image. The PNG
122// should have a 'Frames' text chunk whose value is the number of
123// frames this image represents. The pixel data itself is interlaced
124// by row.
Tao Baob723f4f2015-12-11 15:18:51 -0800125int res_create_multi_display_surface(const char* name, int* frames,
126 int* fps, GRSurface*** pSurface);
Ethan Yonker534d4e02016-08-26 10:05:03 -0500127int res_create_multi_display_surface(const char* name, int* frames,
128 GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700129
130// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700131int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700132
133// Load part of a grayscale PNG image that is the first match for the
134// given locale. The image is expected to be a composite of multiple
135// translations of the same text, with special added rows that encode
136// the subimages' size and intended locale in the pixel data. See
137// development/tools/recovery_l10n for an app that will generate these
138// specialized images from Android resources.
139int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700140 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700141
142// Free a surface allocated by any of the res_create_*_surface()
143// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700144void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800145
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500146#else //ifndef TW_USE_MINUI_21
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500147
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500148// This the old minui21/minui.h for compatibility with building TWRP
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500149// in pre 6.0 trees.
150
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800151#include <stdbool.h>
152
153#ifdef __cplusplus
154extern "C" {
155#endif
156
Ethan Yonkera33161b2014-11-06 15:11:20 -0600157typedef void* gr_surface;
158typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800159
160int gr_init(void);
161void gr_exit(void);
162
163int gr_fb_width(void);
164int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600165gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800166void gr_flip(void);
167void gr_fb_blank(bool blank);
168
169void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
170void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200171
172// system/core/charger uses different gr_print signatures in diferent
173// Android versions, either with or without int bold.
174int gr_text(int x, int y, const char *s, ...);
175int gr_text_impl(int x, int y, const char *s, int bold);
176
Ethan Yonkera33161b2014-11-06 15:11:20 -0600177 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800178int gr_measure(const char *s);
179void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000180void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800181
182void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
183unsigned int gr_get_width(gr_surface surface);
184unsigned int gr_get_height(gr_surface surface);
185
186// input event structure, include <linux/input.h> for the definition.
187// see http://www.mjmwired.net/kernel/Documentation/input/ for info.
188struct input_event;
189
Ethan Yonker304f32f2014-11-07 10:14:05 -0600190typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800191typedef int (*ev_set_key_callback)(int code, int value, void *data);
192
193int ev_init(ev_callback input_cb, void *data);
194void ev_exit(void);
195int ev_add_fd(int fd, ev_callback cb, void *data);
196int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
197
198/* timeout has the same semantics as for poll
199 * 0 : don't block
200 * < 0 : block forever
201 * > 0 : block for 'timeout' milliseconds
202 */
203int ev_wait(int timeout);
204
Ethan Yonker304f32f2014-11-07 10:14:05 -0600205int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800206void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600207int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800208
209// Resources
210
Ethan Yonkera33161b2014-11-06 15:11:20 -0600211// Returns 0 if no error, else negative.
212int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600213
214// Load an array of display surfaces from a single PNG image. The PNG
215// should have a 'Frames' text chunk whose value is the number of
216// frames this image represents. The pixel data itself is interlaced
217// by row.
218int res_create_multi_display_surface(const char* name,
219 int* frames, gr_surface** pSurface);
220
Ethan Yonkera33161b2014-11-06 15:11:20 -0600221int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800222void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700223static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
224 return res_create_surface(name, pSurface);
225}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800226
Ethan Yonker304f32f2014-11-07 10:14:05 -0600227// These are new graphics functions from 5.0 that were not available in
228// 4.4 that are required by charger and healthd
229void gr_clear();
230
231
Doug Zongker28ce47c2011-10-28 10:33:05 -0700232#ifdef __cplusplus
233}
234#endif
235
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500236#endif // ifndef TW_USE_MINUI_21
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500237#endif // ifndef _MINUI_H_