blob: 098a041ef9a95d4cc46f7ad21b2aa666861ca815 [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
Doug Zongkera418aa72014-03-17 12:10:02 -070090// res_create_*_surface() functions return 0 if no error, else
91// negative.
92//
93// A "display" surface is one that is intended to be drawn to the
94// screen with gr_blit(). An "alpha" surface is a grayscale image
95// interpreted as an alpha mask used to render text in the current
96// color (with gr_text() or gr_texticon()).
97//
98// All these functions load PNG images from "/res/images/${name}.png".
99
100// Load a single display surface from a PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700101int res_create_display_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700102
103// Load an array of display surfaces from a single PNG image. The PNG
104// should have a 'Frames' text chunk whose value is the number of
105// frames this image represents. The pixel data itself is interlaced
106// by row.
107int res_create_multi_display_surface(const char* name,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700108 int* frames, GRSurface*** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700109
110// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700111int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700112
113// Load part of a grayscale PNG image that is the first match for the
114// given locale. The image is expected to be a composite of multiple
115// translations of the same text, with special added rows that encode
116// the subimages' size and intended locale in the pixel data. See
117// development/tools/recovery_l10n for an app that will generate these
118// specialized images from Android resources.
119int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700120 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700121
122// Free a surface allocated by any of the res_create_*_surface()
123// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700124void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800125
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500126#else //ifndef TW_USE_OLD_MINUI_H
127
128// This the old minui.old/minui.h for compatibility with building TWRP
129// in pre 6.0 trees.
130
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800131#include <stdbool.h>
132
133#ifdef __cplusplus
134extern "C" {
135#endif
136
Ethan Yonkera33161b2014-11-06 15:11:20 -0600137typedef void* gr_surface;
138typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800139
140int gr_init(void);
141void gr_exit(void);
142
143int gr_fb_width(void);
144int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600145gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800146void gr_flip(void);
147void gr_fb_blank(bool blank);
148
149void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
150void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200151
152// system/core/charger uses different gr_print signatures in diferent
153// Android versions, either with or without int bold.
154int gr_text(int x, int y, const char *s, ...);
155int gr_text_impl(int x, int y, const char *s, int bold);
156
Ethan Yonkera33161b2014-11-06 15:11:20 -0600157 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800158int gr_measure(const char *s);
159void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000160void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800161
162void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
163unsigned int gr_get_width(gr_surface surface);
164unsigned int gr_get_height(gr_surface surface);
165
166// input event structure, include <linux/input.h> for the definition.
167// see http://www.mjmwired.net/kernel/Documentation/input/ for info.
168struct input_event;
169
Ethan Yonker304f32f2014-11-07 10:14:05 -0600170typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800171typedef int (*ev_set_key_callback)(int code, int value, void *data);
172
173int ev_init(ev_callback input_cb, void *data);
174void ev_exit(void);
175int ev_add_fd(int fd, ev_callback cb, void *data);
176int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
177
178/* timeout has the same semantics as for poll
179 * 0 : don't block
180 * < 0 : block forever
181 * > 0 : block for 'timeout' milliseconds
182 */
183int ev_wait(int timeout);
184
Ethan Yonker304f32f2014-11-07 10:14:05 -0600185int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800186void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600187int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800188
189// Resources
190
Ethan Yonkera33161b2014-11-06 15:11:20 -0600191// Returns 0 if no error, else negative.
192int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600193
194// Load an array of display surfaces from a single PNG image. The PNG
195// should have a 'Frames' text chunk whose value is the number of
196// frames this image represents. The pixel data itself is interlaced
197// by row.
198int res_create_multi_display_surface(const char* name,
199 int* frames, gr_surface** pSurface);
200
Ethan Yonkera33161b2014-11-06 15:11:20 -0600201int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800202void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700203static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
204 return res_create_surface(name, pSurface);
205}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800206
Ethan Yonker304f32f2014-11-07 10:14:05 -0600207// These are new graphics functions from 5.0 that were not available in
208// 4.4 that are required by charger and healthd
209void gr_clear();
210
211
Doug Zongker28ce47c2011-10-28 10:33:05 -0700212#ifdef __cplusplus
213}
214#endif
215
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500216#endif // ifndef TW_USE_OLD_MINUI_H
217#endif // ifndef _MINUI_H_