blob: 18173b19822d4a630ed8f6e7eab5c98dddcf4af1 [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);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080054
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070055void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy);
56unsigned int gr_get_width(GRSurface* surface);
57unsigned int gr_get_height(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080058
Elliott Hughes07138192015-04-10 09:40:53 -070059//
60// Input events.
61//
62
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080063struct input_event;
64
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070065// TODO: move these over to std::function.
Elliott Hughes07138192015-04-10 09:40:53 -070066typedef int (*ev_callback)(int fd, uint32_t epevents, void* data);
67typedef int (*ev_set_key_callback)(int code, int value, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070068
Elliott Hughes07138192015-04-10 09:40:53 -070069int ev_init(ev_callback input_cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070070void ev_exit();
Elliott Hughes07138192015-04-10 09:40:53 -070071int ev_add_fd(int fd, ev_callback cb, void* data);
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070072void ev_iterate_available_keys(std::function<void(int)> f);
Elliott Hughes07138192015-04-10 09:40:53 -070073int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data);
Dima Zavinbc290632011-08-30 11:59:45 -070074
Elliott Hughes07138192015-04-10 09:40:53 -070075// 'timeout' has the same semantics as poll(2).
76// 0 : don't block
77// < 0 : block forever
78// > 0 : block for 'timeout' milliseconds
Dima Zavinbc290632011-08-30 11:59:45 -070079int ev_wait(int timeout);
80
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070081int ev_get_input(int fd, uint32_t epevents, input_event* ev);
82void ev_dispatch();
83int ev_get_epollfd();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080084
Elliott Hughes07138192015-04-10 09:40:53 -070085//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080086// Resources
Elliott Hughes07138192015-04-10 09:40:53 -070087//
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080088
Doug Zongkera418aa72014-03-17 12:10:02 -070089// 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 Hughes0a5cb0c2015-04-15 10:58:56 -0700100int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700101
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.
106int res_create_multi_display_surface(const char* name,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700107 int* frames, GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700108
109// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700110int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700111
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.
118int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700119 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700120
121// Free a surface allocated by any of the res_create_*_surface()
122// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700123void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800124
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500125#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 Projectc24a8e62009-03-03 19:28:42 -0800130#include <stdbool.h>
131
132#ifdef __cplusplus
133extern "C" {
134#endif
135
Ethan Yonkera33161b2014-11-06 15:11:20 -0600136typedef void* gr_surface;
137typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800138
139int gr_init(void);
140void gr_exit(void);
141
142int gr_fb_width(void);
143int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600144gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800145void gr_flip(void);
146void gr_fb_blank(bool blank);
147
148void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
149void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200150
151// system/core/charger uses different gr_print signatures in diferent
152// Android versions, either with or without int bold.
153int gr_text(int x, int y, const char *s, ...);
154int gr_text_impl(int x, int y, const char *s, int bold);
155
Ethan Yonkera33161b2014-11-06 15:11:20 -0600156 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800157int gr_measure(const char *s);
158void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000159void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800160
161void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
162unsigned int gr_get_width(gr_surface surface);
163unsigned 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.
167struct input_event;
168
Ethan Yonker304f32f2014-11-07 10:14:05 -0600169typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800170typedef int (*ev_set_key_callback)(int code, int value, void *data);
171
172int ev_init(ev_callback input_cb, void *data);
173void ev_exit(void);
174int ev_add_fd(int fd, ev_callback cb, void *data);
175int 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 */
182int ev_wait(int timeout);
183
Ethan Yonker304f32f2014-11-07 10:14:05 -0600184int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800185void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600186int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800187
188// Resources
189
Ethan Yonkera33161b2014-11-06 15:11:20 -0600190// Returns 0 if no error, else negative.
191int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600192
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.
197int res_create_multi_display_surface(const char* name,
198 int* frames, gr_surface** pSurface);
199
Ethan Yonkera33161b2014-11-06 15:11:20 -0600200int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800201void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700202static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
203 return res_create_surface(name, pSurface);
204}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800205
Ethan Yonker304f32f2014-11-07 10:14:05 -0600206// These are new graphics functions from 5.0 that were not available in
207// 4.4 that are required by charger and healthd
208void gr_clear();
209
210
Doug Zongker28ce47c2011-10-28 10:33:05 -0700211#ifdef __cplusplus
212}
213#endif
214
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500215#endif // ifndef TW_USE_OLD_MINUI_H
216#endif // ifndef _MINUI_H_