blob: dee46411e9a6acb80b4a9fe7bfe5c6b79c4dc752 [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 Yonkerc798c9c2015-10-09 11:15:26 -050020#ifndef TW_USE_OLD_MINUI_H
21
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
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070038int gr_init();
39void gr_exit();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080040
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070041int gr_fb_width();
42int gr_fb_height();
Doug Zongker39cf4172014-03-06 16:16:05 -080043
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070044void gr_flip();
Dima Zavin4daf48a2011-08-30 11:59:20 -070045void gr_fb_blank(bool blank);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080046
Doug Zongker39cf4172014-03-06 16:16:05 -080047void gr_clear(); // clear entire surface to current color
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080048void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Doug Zongkerc560a672012-12-18 16:31:27 -080049void gr_fill(int x1, int y1, int x2, int y2);
Elliott Hughes8fd86d72015-04-13 14:36:02 -070050void gr_text(int x, int y, const char *s, bool bold);
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070051void gr_texticon(int x, int y, GRSurface* icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052int gr_measure(const char *s);
Dima Zavin3c7f00e2011-08-30 11:58:24 -070053void gr_font_size(int *x, int *y);
nailykc45b2d52016-08-19 13:27:12 +020054void gr_set_font(__attribute__ ((unused))const char* name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080055
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070056void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
57unsigned int gr_get_width(GRSurface* surface);
58unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080059
Elliott Hughes07138192015-04-10 09:40:53 -070060//
61// Input events.
62//
63
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080064struct input_event;
65
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070066// TODO: move these over to std::function.
Elliott Hughes07138192015-04-10 09:40:53 -070067typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
68typedef int (*ev_set_key_callback)(int code, int value, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070069
Elliott Hughes07138192015-04-10 09:40:53 -070070int ev_init(ev_callback input_cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070071void ev_exit();
Elliott Hughes07138192015-04-10 09:40:53 -070072int ev_add_fd(int fd, ev_callback cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070073void ev_iterate_available_keys(std::function<void(int)> f);
Elliott Hughes07138192015-04-10 09:40:53 -070074int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070075
Elliott Hughes07138192015-04-10 09:40:53 -070076// 'timeout' has the same semantics as poll(2).
77// 0 : don't block
78// < 0 : block forever
79// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -070080int ev_wait(int timeout);
81
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070082int ev_get_input(int fd, uint32_t epevents, input_event* ev);
83void ev_dispatch();
84int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080085
Elliott Hughes07138192015-04-10 09:40:53 -070086//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080087// Resources
Elliott Hughes07138192015-04-10 09:40:53 -070088//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080089
Tianjie Xu2430e292016-04-19 15:02:41 -070090bool matches_locale(const char* prefix, const char* locale);
91
Doug Zongkera418aa72014-03-17 12:10:02 -070092// res_create_*_surface() functions return 0 if no error, else
93// negative.
94//
95// A "display" surface is one that is intended to be drawn to the
96// screen with gr_blit(). An "alpha" surface is a grayscale image
97// interpreted as an alpha mask used to render text in the current
98// color (with gr_text() or gr_texticon()).
99//
100// All these functions load PNG images from "/res/images/${name}.png".
101
102// Load a single display surface from a PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700103int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700104
105// Load an array of display surfaces from a single PNG image. The PNG
106// should have a 'Frames' text chunk whose value is the number of
107// frames this image represents. The pixel data itself is interlaced
108// by row.
Tao Baob723f4f2015-12-11 15:18:51 -0800109int res_create_multi_display_surface(const char* name, int* frames,
110 int* fps, GRSurface*** pSurface);
Ethan Yonker534d4e02016-08-26 10:05:03 -0500111int res_create_multi_display_surface(const char* name, int* frames,
112 GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700113
114// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700115int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700116
117// Load part of a grayscale PNG image that is the first match for the
118// given locale. The image is expected to be a composite of multiple
119// translations of the same text, with special added rows that encode
120// the subimages' size and intended locale in the pixel data. See
121// development/tools/recovery_l10n for an app that will generate these
122// specialized images from Android resources.
123int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700124 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700125
126// Free a surface allocated by any of the res_create_*_surface()
127// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700128void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800129
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500130#else //ifndef TW_USE_OLD_MINUI_H
131
132// This the old minui.old/minui.h for compatibility with building TWRP
133// in pre 6.0 trees.
134
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800135#include <stdbool.h>
136
137#ifdef __cplusplus
138extern "C" {
139#endif
140
Ethan Yonkera33161b2014-11-06 15:11:20 -0600141typedef void* gr_surface;
142typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800143
144int gr_init(void);
145void gr_exit(void);
146
147int gr_fb_width(void);
148int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600149gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800150void gr_flip(void);
151void gr_fb_blank(bool blank);
152
153void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
154void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200155
156// system/core/charger uses different gr_print signatures in diferent
157// Android versions, either with or without int bold.
158int gr_text(int x, int y, const char *s, ...);
159int gr_text_impl(int x, int y, const char *s, int bold);
160
Ethan Yonkera33161b2014-11-06 15:11:20 -0600161 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800162int gr_measure(const char *s);
163void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000164void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800165
166void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
167unsigned int gr_get_width(gr_surface surface);
168unsigned int gr_get_height(gr_surface surface);
169
170// input event structure, include <linux/input.h> for the definition.
171// see http://www.mjmwired.net/kernel/Documentation/input/ for info.
172struct input_event;
173
Ethan Yonker304f32f2014-11-07 10:14:05 -0600174typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800175typedef int (*ev_set_key_callback)(int code, int value, void *data);
176
177int ev_init(ev_callback input_cb, void *data);
178void ev_exit(void);
179int ev_add_fd(int fd, ev_callback cb, void *data);
180int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
181
182/* timeout has the same semantics as for poll
183 * 0 : don't block
184 * < 0 : block forever
185 * > 0 : block for 'timeout' milliseconds
186 */
187int ev_wait(int timeout);
188
Ethan Yonker304f32f2014-11-07 10:14:05 -0600189int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800190void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600191int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800192
193// Resources
194
Ethan Yonkera33161b2014-11-06 15:11:20 -0600195// Returns 0 if no error, else negative.
196int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600197
198// Load an array of display surfaces from a single PNG image. The PNG
199// should have a 'Frames' text chunk whose value is the number of
200// frames this image represents. The pixel data itself is interlaced
201// by row.
202int res_create_multi_display_surface(const char* name,
203 int* frames, gr_surface** pSurface);
204
Ethan Yonkera33161b2014-11-06 15:11:20 -0600205int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800206void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700207static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
208 return res_create_surface(name, pSurface);
209}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800210
Ethan Yonker304f32f2014-11-07 10:14:05 -0600211// These are new graphics functions from 5.0 that were not available in
212// 4.4 that are required by charger and healthd
213void gr_clear();
214
215
Doug Zongker28ce47c2011-10-28 10:33:05 -0700216#ifdef __cplusplus
217}
218#endif
219
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500220#endif // ifndef TW_USE_OLD_MINUI_H
221#endif // ifndef _MINUI_H_