blob: 5e49100cd4c8d206f5906a75c8fbaab821f32615 [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);
Doug Zongkera418aa72014-03-17 12:10:02 -0700111
112// Load a single alpha surface from a grayscale PNG image.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700113int res_create_alpha_surface(const char* name, GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700114
115// Load part of a grayscale PNG image that is the first match for the
116// given locale. The image is expected to be a composite of multiple
117// translations of the same text, with special added rows that encode
118// the subimages' size and intended locale in the pixel data. See
119// development/tools/recovery_l10n for an app that will generate these
120// specialized images from Android resources.
121int res_create_localized_alpha_surface(const char* name, const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700122 GRSurface** pSurface);
Doug Zongkera418aa72014-03-17 12:10:02 -0700123
124// Free a surface allocated by any of the res_create_*_surface()
125// functions.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700126void res_free_surface(GRSurface* surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800127
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500128#else //ifndef TW_USE_OLD_MINUI_H
129
130// This the old minui.old/minui.h for compatibility with building TWRP
131// in pre 6.0 trees.
132
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800133#include <stdbool.h>
134
135#ifdef __cplusplus
136extern "C" {
137#endif
138
Ethan Yonkera33161b2014-11-06 15:11:20 -0600139typedef void* gr_surface;
140typedef unsigned short gr_pixel;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800141
142int gr_init(void);
143void gr_exit(void);
144
145int gr_fb_width(void);
146int gr_fb_height(void);
Ethan Yonkera33161b2014-11-06 15:11:20 -0600147gr_pixel *gr_fb_data(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800148void gr_flip(void);
149void gr_fb_blank(bool blank);
150
151void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
152void gr_fill(int x1, int y1, int x2, int y2);
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200153
154// system/core/charger uses different gr_print signatures in diferent
155// Android versions, either with or without int bold.
156int gr_text(int x, int y, const char *s, ...);
157int gr_text_impl(int x, int y, const char *s, int bold);
158
Ethan Yonkera33161b2014-11-06 15:11:20 -0600159 void gr_texticon(int x, int y, gr_surface icon);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800160int gr_measure(const char *s);
161void gr_font_size(int *x, int *y);
Dees Troy62b75ab2014-05-02 13:20:33 +0000162void gr_get_memory_surface(gr_surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800163
164void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
165unsigned int gr_get_width(gr_surface surface);
166unsigned int gr_get_height(gr_surface surface);
167
168// input event structure, include <linux/input.h> for the definition.
169// see http://www.mjmwired.net/kernel/Documentation/input/ for info.
170struct input_event;
171
Ethan Yonker304f32f2014-11-07 10:14:05 -0600172typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800173typedef int (*ev_set_key_callback)(int code, int value, void *data);
174
175int ev_init(ev_callback input_cb, void *data);
176void ev_exit(void);
177int ev_add_fd(int fd, ev_callback cb, void *data);
178int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data);
179
180/* timeout has the same semantics as for poll
181 * 0 : don't block
182 * < 0 : block forever
183 * > 0 : block for 'timeout' milliseconds
184 */
185int ev_wait(int timeout);
186
Ethan Yonker304f32f2014-11-07 10:14:05 -0600187int ev_get_input(int fd, uint32_t epevents, struct input_event *ev);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800188void ev_dispatch(void);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600189int ev_get_epollfd(void);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800190
191// Resources
192
Ethan Yonkera33161b2014-11-06 15:11:20 -0600193// Returns 0 if no error, else negative.
194int res_create_surface(const char* name, gr_surface* pSurface);
Ethan Yonker304f32f2014-11-07 10:14:05 -0600195
196// Load an array of display surfaces from a single PNG image. The PNG
197// should have a 'Frames' text chunk whose value is the number of
198// frames this image represents. The pixel data itself is interlaced
199// by row.
200int res_create_multi_display_surface(const char* name,
201 int* frames, gr_surface** pSurface);
202
Ethan Yonkera33161b2014-11-06 15:11:20 -0600203int res_create_localized_surface(const char* name, gr_surface* pSurface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800204void res_free_surface(gr_surface surface);
Steve Kondik626009f2014-04-30 13:25:41 -0700205static inline int res_create_display_surface(const char* name, gr_surface* pSurface) {
206 return res_create_surface(name, pSurface);
207}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800208
Ethan Yonker304f32f2014-11-07 10:14:05 -0600209// These are new graphics functions from 5.0 that were not available in
210// 4.4 that are required by charger and healthd
211void gr_clear();
212
213
Doug Zongker28ce47c2011-10-28 10:33:05 -0700214#ifdef __cplusplus
215}
216#endif
217
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500218#endif // ifndef TW_USE_OLD_MINUI_H
219#endif // ifndef _MINUI_H_