blob: 9df058e2989f3cac2823bfd2e78ddc3a6b78260d [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
Tao Bao0ecbd762017-01-16 21:16:58 -080017#include "graphics.h"
18
Luke Song846012f2017-09-13 15:56:16 -070019#include <stdint.h>
Tao Baoe8020f42017-02-03 09:30:07 -080020#include <stdio.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080021#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080022#include <string.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080023
Tao Bao557fa1f2017-02-07 12:51:00 -080024#include <memory>
25
Tao Bao557fa1f2017-02-07 12:51:00 -080026#include "graphics_adf.h"
27#include "graphics_drm.h"
28#include "graphics_fbdev.h"
Tao Bao0ecbd762017-01-16 21:16:58 -080029#include "minui/minui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080030
Tao Bao9f426332018-06-13 10:39:44 -070031static GRFont* gr_font = nullptr;
Tao Bao557fa1f2017-02-07 12:51:00 -080032static MinuiBackend* gr_backend = nullptr;
Doug Zongker16f97c32014-03-06 16:16:05 -080033
Doug Zongkerc560a672012-12-18 16:31:27 -080034static int overscan_percent = OVERSCAN_PERCENT;
35static int overscan_offset_x = 0;
36static int overscan_offset_y = 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080037
Luke Song846012f2017-09-13 15:56:16 -070038static uint32_t gr_current = ~0;
39static constexpr uint32_t alpha_mask = 0xff000000;
Doug Zongker16f97c32014-03-06 16:16:05 -080040
Tao Bao9f426332018-06-13 10:39:44 -070041// gr_draw is owned by backends.
42static const GRSurface* gr_draw = nullptr;
Tao Bao44478df2018-07-31 22:01:03 -070043static GRRotation rotation = GRRotation::NONE;
Doug Zongker16f97c32014-03-06 16:16:05 -080044
Luke Song846012f2017-09-13 15:56:16 -070045static bool outside(int x, int y) {
Tao Bao44478df2018-07-31 22:01:03 -070046 auto swapped = (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT);
47 return x < 0 || x >= (swapped ? gr_draw->height : gr_draw->width) || y < 0 ||
48 y >= (swapped ? gr_draw->width : gr_draw->height);
Doug Zongker16f97c32014-03-06 16:16:05 -080049}
50
Luke Song846012f2017-09-13 15:56:16 -070051const GRFont* gr_sys_font() {
52 return gr_font;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080053}
54
Luke Song846012f2017-09-13 15:56:16 -070055int gr_measure(const GRFont* font, const char* s) {
Tianjie Xu842f2a32018-05-31 18:16:28 -070056 if (font == nullptr) {
57 return -1;
58 }
59
Luke Song846012f2017-09-13 15:56:16 -070060 return font->char_width * strlen(s);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070061}
62
Tianjie Xu842f2a32018-05-31 18:16:28 -070063int gr_font_size(const GRFont* font, int* x, int* y) {
64 if (font == nullptr) {
65 return -1;
66 }
67
Luke Song846012f2017-09-13 15:56:16 -070068 *x = font->char_width;
69 *y = font->char_height;
Tianjie Xu842f2a32018-05-31 18:16:28 -070070 return 0;
Dima Zavin3c7f00e2011-08-30 11:58:24 -070071}
72
Luke Song846012f2017-09-13 15:56:16 -070073// Blends gr_current onto pix value, assumes alpha as most significant byte.
74static inline uint32_t pixel_blend(uint8_t alpha, uint32_t pix) {
75 if (alpha == 255) return gr_current;
76 if (alpha == 0) return pix;
77 uint32_t pix_r = pix & 0xff;
78 uint32_t pix_g = pix & 0xff00;
79 uint32_t pix_b = pix & 0xff0000;
80 uint32_t cur_r = gr_current & 0xff;
81 uint32_t cur_g = gr_current & 0xff00;
82 uint32_t cur_b = gr_current & 0xff0000;
83
84 uint32_t out_r = (pix_r * (255 - alpha) + cur_r * alpha) / 255;
85 uint32_t out_g = (pix_g * (255 - alpha) + cur_g * alpha) / 255;
86 uint32_t out_b = (pix_b * (255 - alpha) + cur_b * alpha) / 255;
87
88 return (out_r & 0xff) | (out_g & 0xff00) | (out_b & 0xff0000) | (gr_current & 0xff000000);
89}
90
Tao Bao9f426332018-06-13 10:39:44 -070091// Increments pixel pointer right, with current rotation.
Luke Song846012f2017-09-13 15:56:16 -070092static void incr_x(uint32_t** p, int row_pixels) {
Tao Bao44478df2018-07-31 22:01:03 -070093 if (rotation == GRRotation::LEFT) {
94 *p = *p - row_pixels;
95 } else if (rotation == GRRotation::RIGHT) {
96 *p = *p + row_pixels;
97 } else if (rotation == GRRotation::DOWN) {
98 *p = *p - 1;
99 } else { // GRRotation::NONE
100 *p = *p + 1;
Luke Song846012f2017-09-13 15:56:16 -0700101 }
102}
103
Tao Bao9f426332018-06-13 10:39:44 -0700104// Increments pixel pointer down, with current rotation.
Luke Song846012f2017-09-13 15:56:16 -0700105static void incr_y(uint32_t** p, int row_pixels) {
Tao Bao44478df2018-07-31 22:01:03 -0700106 if (rotation == GRRotation::LEFT) {
107 *p = *p + 1;
108 } else if (rotation == GRRotation::RIGHT) {
109 *p = *p - 1;
110 } else if (rotation == GRRotation::DOWN) {
111 *p = *p - row_pixels;
112 } else { // GRRotation::NONE
113 *p = *p + row_pixels;
Luke Song846012f2017-09-13 15:56:16 -0700114 }
115}
116
Tao Bao9f426332018-06-13 10:39:44 -0700117// Returns pixel pointer at given coordinates with rotation adjustment.
118static uint32_t* pixel_at(const GRSurface* surf, int x, int y, int row_pixels) {
Luke Song846012f2017-09-13 15:56:16 -0700119 switch (rotation) {
Tao Bao44478df2018-07-31 22:01:03 -0700120 case GRRotation::NONE:
Luke Song846012f2017-09-13 15:56:16 -0700121 return reinterpret_cast<uint32_t*>(surf->data) + y * row_pixels + x;
Tao Bao44478df2018-07-31 22:01:03 -0700122 case GRRotation::RIGHT:
Luke Song846012f2017-09-13 15:56:16 -0700123 return reinterpret_cast<uint32_t*>(surf->data) + x * row_pixels + (surf->width - y);
Tao Bao44478df2018-07-31 22:01:03 -0700124 case GRRotation::DOWN:
Luke Song846012f2017-09-13 15:56:16 -0700125 return reinterpret_cast<uint32_t*>(surf->data) + (surf->height - 1 - y) * row_pixels +
126 (surf->width - 1 - x);
Tao Bao44478df2018-07-31 22:01:03 -0700127 case GRRotation::LEFT:
Luke Song846012f2017-09-13 15:56:16 -0700128 return reinterpret_cast<uint32_t*>(surf->data) + (surf->height - 1 - x) * row_pixels + y;
129 default:
Tao Bao44478df2018-07-31 22:01:03 -0700130 printf("invalid rotation %d", static_cast<int>(rotation));
Luke Song846012f2017-09-13 15:56:16 -0700131 }
132 return nullptr;
133}
134
135static void text_blend(uint8_t* src_p, int src_row_bytes, uint32_t* dst_p, int dst_row_pixels,
136 int width, int height) {
137 uint8_t alpha_current = static_cast<uint8_t>((alpha_mask & gr_current) >> 24);
138 for (int j = 0; j < height; ++j) {
139 uint8_t* sx = src_p;
140 uint32_t* px = dst_p;
141 for (int i = 0; i < width; ++i, incr_x(&px, dst_row_pixels)) {
142 uint8_t a = *sx++;
143 if (alpha_current < 255) a = (static_cast<uint32_t>(a) * alpha_current) / 255;
144 *px = pixel_blend(a, *px);
Doug Zongker16f97c32014-03-06 16:16:05 -0800145 }
Luke Song846012f2017-09-13 15:56:16 -0700146 src_p += src_row_bytes;
147 incr_y(&dst_p, dst_row_pixels);
148 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800149}
150
Luke Song846012f2017-09-13 15:56:16 -0700151void gr_text(const GRFont* font, int x, int y, const char* s, bool bold) {
152 if (!font || !font->texture || (gr_current & alpha_mask) == 0) return;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800153
Luke Song846012f2017-09-13 15:56:16 -0700154 if (font->texture->pixel_bytes != 1) {
155 printf("gr_text: font has wrong format\n");
156 return;
157 }
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800158
Luke Song846012f2017-09-13 15:56:16 -0700159 bold = bold && (font->texture->height != font->char_height);
Doug Zongkerc560a672012-12-18 16:31:27 -0800160
Luke Song846012f2017-09-13 15:56:16 -0700161 x += overscan_offset_x;
162 y += overscan_offset_y;
Doug Zongker16f97c32014-03-06 16:16:05 -0800163
Luke Song846012f2017-09-13 15:56:16 -0700164 unsigned char ch;
165 while ((ch = *s++)) {
166 if (outside(x, y) || outside(x + font->char_width - 1, y + font->char_height - 1)) break;
Elliott Hughes01a4d082015-03-24 15:21:48 -0700167
Luke Song846012f2017-09-13 15:56:16 -0700168 if (ch < ' ' || ch > '~') {
169 ch = '?';
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800170 }
Luke Song846012f2017-09-13 15:56:16 -0700171
172 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
173 uint8_t* src_p = font->texture->data + ((ch - ' ') * font->char_width) +
174 (bold ? font->char_height * font->texture->row_bytes : 0);
175 uint32_t* dst_p = pixel_at(gr_draw, x, y, row_pixels);
176
177 text_blend(src_p, font->texture->row_bytes, dst_p, row_pixels, font->char_width,
178 font->char_height);
179
180 x += font->char_width;
181 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800182}
183
Doug Zongker16f97c32014-03-06 16:16:05 -0800184void gr_texticon(int x, int y, GRSurface* icon) {
Tao Bao9f426332018-06-13 10:39:44 -0700185 if (icon == nullptr) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800186
Luke Song846012f2017-09-13 15:56:16 -0700187 if (icon->pixel_bytes != 1) {
188 printf("gr_texticon: source has wrong format\n");
189 return;
190 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700191
Luke Song846012f2017-09-13 15:56:16 -0700192 x += overscan_offset_x;
193 y += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800194
Luke Song846012f2017-09-13 15:56:16 -0700195 if (outside(x, y) || outside(x + icon->width - 1, y + icon->height - 1)) return;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700196
Luke Song846012f2017-09-13 15:56:16 -0700197 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
198 uint8_t* src_p = icon->data;
199 uint32_t* dst_p = pixel_at(gr_draw, x, y, row_pixels);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700200
Luke Song846012f2017-09-13 15:56:16 -0700201 text_blend(src_p, icon->row_bytes, dst_p, row_pixels, icon->width, icon->height);
Doug Zongker16f97c32014-03-06 16:16:05 -0800202}
203
Luke Song846012f2017-09-13 15:56:16 -0700204void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
205 uint32_t r32 = r, g32 = g, b32 = b, a32 = a;
Tony Kuofd778e32015-02-05 21:25:56 +0800206#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
Luke Song846012f2017-09-13 15:56:16 -0700207 gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32;
Tony Kuofd778e32015-02-05 21:25:56 +0800208#else
Luke Song846012f2017-09-13 15:56:16 -0700209 gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32;
Tony Kuofd778e32015-02-05 21:25:56 +0800210#endif
Doug Zongker16f97c32014-03-06 16:16:05 -0800211}
212
Luke Song846012f2017-09-13 15:56:16 -0700213void gr_clear() {
214 if ((gr_current & 0xff) == ((gr_current >> 8) & 0xff) &&
215 (gr_current & 0xff) == ((gr_current >> 16) & 0xff) &&
216 (gr_current & 0xff) == ((gr_current >> 24) & 0xff) &&
217 gr_draw->row_bytes == gr_draw->width * gr_draw->pixel_bytes) {
218 memset(gr_draw->data, gr_current & 0xff, gr_draw->height * gr_draw->row_bytes);
219 } else {
220 uint32_t* px = reinterpret_cast<uint32_t*>(gr_draw->data);
221 int row_diff = gr_draw->row_bytes / gr_draw->pixel_bytes - gr_draw->width;
222 for (int y = 0; y < gr_draw->height; ++y) {
223 for (int x = 0; x < gr_draw->width; ++x) {
224 *px++ = gr_current;
225 }
226 px += row_diff;
Doug Zongker16f97c32014-03-06 16:16:05 -0800227 }
Luke Song846012f2017-09-13 15:56:16 -0700228 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700229}
230
Luke Song846012f2017-09-13 15:56:16 -0700231void gr_fill(int x1, int y1, int x2, int y2) {
232 x1 += overscan_offset_x;
233 y1 += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800234
Luke Song846012f2017-09-13 15:56:16 -0700235 x2 += overscan_offset_x;
236 y2 += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800237
Luke Song846012f2017-09-13 15:56:16 -0700238 if (outside(x1, y1) || outside(x2 - 1, y2 - 1)) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800239
Luke Song846012f2017-09-13 15:56:16 -0700240 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
241 uint32_t* p = pixel_at(gr_draw, x1, y1, row_pixels);
242 uint8_t alpha = static_cast<uint8_t>(((gr_current & alpha_mask) >> 24));
243 if (alpha > 0) {
244 for (int y = y1; y < y2; ++y) {
245 uint32_t* px = p;
246 for (int x = x1; x < x2; ++x) {
247 *px = pixel_blend(alpha, *px);
248 incr_x(&px, row_pixels);
249 }
250 incr_y(&p, row_pixels);
Doug Zongker16f97c32014-03-06 16:16:05 -0800251 }
Luke Song846012f2017-09-13 15:56:16 -0700252 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800253}
254
Doug Zongker16f97c32014-03-06 16:16:05 -0800255void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
Tao Bao9f426332018-06-13 10:39:44 -0700256 if (source == nullptr) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800257
Luke Song846012f2017-09-13 15:56:16 -0700258 if (gr_draw->pixel_bytes != source->pixel_bytes) {
259 printf("gr_blit: source has wrong format\n");
260 return;
261 }
262
263 dx += overscan_offset_x;
264 dy += overscan_offset_y;
265
266 if (outside(dx, dy) || outside(dx + w - 1, dy + h - 1)) return;
267
Tao Bao44478df2018-07-31 22:01:03 -0700268 if (rotation != GRRotation::NONE) {
Luke Song846012f2017-09-13 15:56:16 -0700269 int src_row_pixels = source->row_bytes / source->pixel_bytes;
270 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
271 uint32_t* src_py = reinterpret_cast<uint32_t*>(source->data) + sy * source->row_bytes / 4 + sx;
272 uint32_t* dst_py = pixel_at(gr_draw, dx, dy, row_pixels);
273
274 for (int y = 0; y < h; y += 1) {
275 uint32_t* src_px = src_py;
276 uint32_t* dst_px = dst_py;
277 for (int x = 0; x < w; x += 1) {
278 *dst_px = *src_px++;
279 incr_x(&dst_px, row_pixels);
280 }
281 src_py += src_row_pixels;
282 incr_y(&dst_py, row_pixels);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800283 }
Luke Song846012f2017-09-13 15:56:16 -0700284 } else {
285 unsigned char* src_p = source->data + sy * source->row_bytes + sx * source->pixel_bytes;
286 unsigned char* dst_p = gr_draw->data + dy * gr_draw->row_bytes + dx * gr_draw->pixel_bytes;
Doug Zongker16f97c32014-03-06 16:16:05 -0800287
Tao Bao9f426332018-06-13 10:39:44 -0700288 for (int i = 0; i < h; ++i) {
Luke Song846012f2017-09-13 15:56:16 -0700289 memcpy(dst_p, src_p, w * source->pixel_bytes);
290 src_p += source->row_bytes;
291 dst_p += gr_draw->row_bytes;
Doug Zongker16f97c32014-03-06 16:16:05 -0800292 }
Luke Song846012f2017-09-13 15:56:16 -0700293 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800294}
295
Tao Bao9f426332018-06-13 10:39:44 -0700296unsigned int gr_get_width(const GRSurface* surface) {
297 if (surface == nullptr) {
Luke Song846012f2017-09-13 15:56:16 -0700298 return 0;
299 }
300 return surface->width;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800301}
302
Tao Bao9f426332018-06-13 10:39:44 -0700303unsigned int gr_get_height(const GRSurface* surface) {
304 if (surface == nullptr) {
Luke Song846012f2017-09-13 15:56:16 -0700305 return 0;
306 }
307 return surface->height;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800308}
309
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700310int gr_init_font(const char* name, GRFont** dest) {
Luke Song846012f2017-09-13 15:56:16 -0700311 GRFont* font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
312 if (font == nullptr) {
313 return -1;
314 }
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700315
Luke Song846012f2017-09-13 15:56:16 -0700316 int res = res_create_alpha_surface(name, &(font->texture));
317 if (res < 0) {
318 free(font);
319 return res;
320 }
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700321
Luke Song846012f2017-09-13 15:56:16 -0700322 // The font image should be a 96x2 array of character images. The
323 // columns are the printable ASCII characters 0x20 - 0x7f. The
324 // top row is regular text; the bottom row is bold.
325 font->char_width = font->texture->width / 96;
326 font->char_height = font->texture->height / 2;
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700327
Luke Song846012f2017-09-13 15:56:16 -0700328 *dest = font;
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700329
Luke Song846012f2017-09-13 15:56:16 -0700330 return 0;
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700331}
332
Doug Zongker5290f202014-03-11 13:22:04 -0700333void gr_flip() {
Tao Bao557fa1f2017-02-07 12:51:00 -0800334 gr_draw = gr_backend->Flip();
Doug Zongker5290f202014-03-11 13:22:04 -0700335}
336
Tao Bao557fa1f2017-02-07 12:51:00 -0800337int gr_init() {
Tianjie Xu55a2c4e2018-03-29 11:07:50 -0700338 int ret = gr_init_font("font", &gr_font);
339 if (ret != 0) {
Tianjie Xu842f2a32018-05-31 18:16:28 -0700340 printf("Failed to init font: %d, continuing graphic backend initialization without font file\n",
341 ret);
Tianjie Xu55a2c4e2018-03-29 11:07:50 -0700342 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800343
Tao Bao557fa1f2017-02-07 12:51:00 -0800344 auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendAdf>() };
345 gr_draw = backend->Init();
Greg Hackmann41909dd2014-04-25 10:39:50 -0700346
Tao Bao557fa1f2017-02-07 12:51:00 -0800347 if (!gr_draw) {
348 backend = std::make_unique<MinuiBackendDrm>();
349 gr_draw = backend->Init();
350 }
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700351
Tao Bao557fa1f2017-02-07 12:51:00 -0800352 if (!gr_draw) {
353 backend = std::make_unique<MinuiBackendFbdev>();
354 gr_draw = backend->Init();
355 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800356
Tao Bao557fa1f2017-02-07 12:51:00 -0800357 if (!gr_draw) {
358 return -1;
359 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800360
Tao Bao557fa1f2017-02-07 12:51:00 -0800361 gr_backend = backend.release();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800362
Tao Bao557fa1f2017-02-07 12:51:00 -0800363 overscan_offset_x = gr_draw->width * overscan_percent / 100;
364 overscan_offset_y = gr_draw->height * overscan_percent / 100;
365
366 gr_flip();
367 gr_flip();
Tianjie Xuccf00a22018-06-05 17:10:23 -0700368 if (!gr_draw) {
369 printf("gr_init: gr_draw becomes nullptr after gr_flip\n");
370 return -1;
371 }
Tao Bao557fa1f2017-02-07 12:51:00 -0800372
Tao Bao44478df2018-07-31 22:01:03 -0700373#define __STRINGIFY(x) #x
374#define STRINGIFY(x) __STRINGIFY(x)
375
376 std::string rotation_str(STRINGIFY(DEFAULT_ROTATION));
377 if (rotation_str == "ROTATION_RIGHT") {
378 gr_rotate(GRRotation::RIGHT);
379 } else if (rotation_str == "ROTATION_DOWN") {
380 gr_rotate(GRRotation::DOWN);
381 } else if (rotation_str == "ROTATION_LEFT") {
382 gr_rotate(GRRotation::LEFT);
383 } else { // "ROTATION_NONE"
384 gr_rotate(GRRotation::NONE);
385 }
Luke Song846012f2017-09-13 15:56:16 -0700386
387 if (gr_draw->pixel_bytes != 4) {
388 printf("gr_init: Only 4-byte pixel formats supported\n");
389 }
390
Tao Bao557fa1f2017-02-07 12:51:00 -0800391 return 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800392}
393
Tao Bao557fa1f2017-02-07 12:51:00 -0800394void gr_exit() {
395 delete gr_backend;
Tao Bao9f426332018-06-13 10:39:44 -0700396 gr_backend = nullptr;
397
398 delete gr_font;
399 gr_font = nullptr;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800400}
401
Tao Bao557fa1f2017-02-07 12:51:00 -0800402int gr_fb_width() {
Tao Bao44478df2018-07-31 22:01:03 -0700403 return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT)
404 ? gr_draw->height - 2 * overscan_offset_y
405 : gr_draw->width - 2 * overscan_offset_x;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800406}
407
Tao Bao557fa1f2017-02-07 12:51:00 -0800408int gr_fb_height() {
Tao Bao44478df2018-07-31 22:01:03 -0700409 return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT)
410 ? gr_draw->width - 2 * overscan_offset_x
411 : gr_draw->height - 2 * overscan_offset_y;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800412}
Dima Zavin4daf48a2011-08-30 11:59:20 -0700413
Tao Bao557fa1f2017-02-07 12:51:00 -0800414void gr_fb_blank(bool blank) {
415 gr_backend->Blank(blank);
Dima Zavin4daf48a2011-08-30 11:59:20 -0700416}
Luke Song846012f2017-09-13 15:56:16 -0700417
418void gr_rotate(GRRotation rot) {
419 rotation = rot;
420}