The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Doug Zongker | 830b3e3 | 2014-03-11 13:22:04 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 22 | #include <stdbool.h> |
| 23 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 28 | typedef struct { |
| 29 | int width; |
| 30 | int height; |
| 31 | int row_bytes; |
| 32 | int pixel_bytes; |
| 33 | unsigned char* data; |
| 34 | } GRSurface; |
| 35 | |
| 36 | typedef GRSurface* gr_surface; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 37 | |
| 38 | int gr_init(void); |
| 39 | void gr_exit(void); |
| 40 | |
| 41 | int gr_fb_width(void); |
| 42 | int gr_fb_height(void); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 43 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 44 | void gr_flip(void); |
Dima Zavin | 4daf48a | 2011-08-30 11:59:20 -0700 | [diff] [blame] | 45 | void gr_fb_blank(bool blank); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 46 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 47 | void gr_clear(); // clear entire surface to current color |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 48 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a); |
Doug Zongker | c560a67 | 2012-12-18 16:31:27 -0800 | [diff] [blame] | 49 | void gr_fill(int x1, int y1, int x2, int y2); |
Vojtech Bocek | 65fdcdd | 2013-09-06 21:32:22 +0200 | [diff] [blame] | 50 | |
| 51 | // system/core/charger uses different gr_print signatures in diferent |
| 52 | // Android versions, either with or without int bold. |
| 53 | int gr_text(int x, int y, const char *s, ...); |
| 54 | int gr_text_impl(int x, int y, const char *s, int bold); |
| 55 | |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 56 | void gr_texticon(int x, int y, gr_surface icon); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 57 | int gr_measure(const char *s); |
Dima Zavin | 3c7f00e | 2011-08-30 11:58:24 -0700 | [diff] [blame] | 58 | void gr_font_size(int *x, int *y); |
Dees Troy | 62b75ab | 2014-05-02 13:20:33 +0000 | [diff] [blame] | 59 | void gr_get_memory_surface(gr_surface); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 60 | |
| 61 | void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy); |
| 62 | unsigned int gr_get_width(gr_surface surface); |
| 63 | unsigned int gr_get_height(gr_surface surface); |
| 64 | |
| 65 | // input event structure, include <linux/input.h> for the definition. |
| 66 | // see http://www.mjmwired.net/kernel/Documentation/input/ for info. |
| 67 | struct input_event; |
| 68 | |
Todd Poynor | a5ef19f | 2013-09-17 13:39:10 -0700 | [diff] [blame] | 69 | typedef int (*ev_callback)(int fd, uint32_t epevents, void *data); |
Dima Zavin | 441031d | 2011-10-12 15:53:29 -0700 | [diff] [blame] | 70 | typedef int (*ev_set_key_callback)(int code, int value, void *data); |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 71 | |
| 72 | int ev_init(ev_callback input_cb, void *data); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | void ev_exit(void); |
Dima Zavin | 3658367 | 2011-09-02 11:51:31 -0700 | [diff] [blame] | 74 | int ev_add_fd(int fd, ev_callback cb, void *data); |
Dima Zavin | 441031d | 2011-10-12 15:53:29 -0700 | [diff] [blame] | 75 | int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data); |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 76 | |
| 77 | /* timeout has the same semantics as for poll |
| 78 | * 0 : don't block |
| 79 | * < 0 : block forever |
| 80 | * > 0 : block for 'timeout' milliseconds |
| 81 | */ |
| 82 | int ev_wait(int timeout); |
| 83 | |
Todd Poynor | a5ef19f | 2013-09-17 13:39:10 -0700 | [diff] [blame] | 84 | int ev_get_input(int fd, uint32_t epevents, struct input_event *ev); |
Dima Zavin | bc29063 | 2011-08-30 11:59:45 -0700 | [diff] [blame] | 85 | void ev_dispatch(void); |
Todd Poynor | 4665ede | 2013-09-10 17:03:45 -0700 | [diff] [blame] | 86 | int ev_get_epollfd(void); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | |
| 88 | // Resources |
| 89 | |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 90 | // 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. |
| 101 | int res_create_display_surface(const char* name, gr_surface* pSurface); |
| 102 | |
| 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. |
| 107 | int res_create_multi_display_surface(const char* name, |
| 108 | int* frames, gr_surface** pSurface); |
| 109 | |
| 110 | // Load a single alpha surface from a grayscale PNG image. |
| 111 | int res_create_alpha_surface(const char* name, gr_surface* pSurface); |
| 112 | |
| 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. |
| 119 | int res_create_localized_alpha_surface(const char* name, const char* locale, |
| 120 | gr_surface* pSurface); |
| 121 | |
| 122 | // Free a surface allocated by any of the res_create_*_surface() |
| 123 | // functions. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 124 | void res_free_surface(gr_surface surface); |
Steve Kondik | 626009f | 2014-04-30 13:25:41 -0700 | [diff] [blame] | 125 | static inline int res_create_display_surface(const char* name, gr_surface* pSurface) { |
| 126 | return res_create_surface(name, pSurface); |
| 127 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 128 | |
Doug Zongker | 28ce47c | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 129 | #ifdef __cplusplus |
| 130 | } |
| 131 | #endif |
| 132 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 133 | #endif |