blob: bb3c5f959fc791f856cb3b1c96711f97efc7b51b [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>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080025
Tao Baoed876a72018-07-31 21:32:50 -070026#include <android-base/properties.h>
27
Tao Bao557fa1f2017-02-07 12:51:00 -080028#include "graphics_adf.h"
Andreas Schneider58d68e52017-11-02 17:54:36 +010029#endif
Tao Bao557fa1f2017-02-07 12:51:00 -080030#include "graphics_drm.h"
31#include "graphics_fbdev.h"
Ethan Yonker8373cfe2017-09-08 06:50:54 -050032#include "graphics_overlay.h"
Tao Bao0ecbd762017-01-16 21:16:58 -080033#include "minui/minui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080034
Tao Bao9f426332018-06-13 10:39:44 -070035static GRFont* gr_font = nullptr;
Tao Bao557fa1f2017-02-07 12:51:00 -080036static MinuiBackend* gr_backend = nullptr;
Doug Zongker16f97c32014-03-06 16:16:05 -080037
Doug Zongkerc560a672012-12-18 16:31:27 -080038static int overscan_offset_x = 0;
39static int overscan_offset_y = 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080040
Ethan Yonker58f21322018-08-24 11:17:36 -050041#ifdef TW_NO_MINUI_CUSTOM_FONTS
Doug Zongker16f97c32014-03-06 16:16:05 -080042static unsigned char gr_current_r = 255;
43static unsigned char gr_current_g = 255;
44static unsigned char gr_current_b = 255;
Ethan Yonker58f21322018-08-24 11:17:36 -050045#endif
Doug Zongker16f97c32014-03-06 16:16:05 -080046static unsigned char gr_current_a = 255;
Ethan Yonkere96182e2015-10-13 19:32:03 -050047static unsigned char rgb_555[2];
48static unsigned char gr_current_r5 = 31;
49static unsigned char gr_current_g5 = 63;
50static unsigned char gr_current_b5 = 31;
Doug Zongker16f97c32014-03-06 16:16:05 -080051
Luke Song846012f2017-09-13 15:56:16 -070052static uint32_t gr_current = ~0;
53static constexpr uint32_t alpha_mask = 0xff000000;
Doug Zongker16f97c32014-03-06 16:16:05 -080054
Tao Bao9f426332018-06-13 10:39:44 -070055// gr_draw is owned by backends.
Tao Bao92bdb5a2018-10-21 12:12:37 -070056static GRSurface* gr_draw = nullptr;
Tao Bao44478df2018-07-31 22:01:03 -070057static GRRotation rotation = GRRotation::NONE;
Tao Baoed876a72018-07-31 21:32:50 -070058static PixelFormat pixel_format = PixelFormat::UNKNOWN;
Doug Zongker16f97c32014-03-06 16:16:05 -080059
Luke Song846012f2017-09-13 15:56:16 -070060static bool outside(int x, int y) {
Tao Bao44478df2018-07-31 22:01:03 -070061 auto swapped = (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT);
62 return x < 0 || x >= (swapped ? gr_draw->height : gr_draw->width) || y < 0 ||
63 y >= (swapped ? gr_draw->width : gr_draw->height);
Doug Zongker16f97c32014-03-06 16:16:05 -080064}
Ethan Yonker39662b22017-05-23 08:34:02 -050065
66#ifdef TW_NO_MINUI_CUSTOM_FONTS
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080067int gr_measure(const char *s)
68{
Ethan Yonker84d61ce2017-05-10 16:11:35 -050069 return gr_font->char_width * strlen(s);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080070}
71
Dima Zavin3c7f00e2011-08-30 11:58:24 -070072void gr_font_size(int *x, int *y)
73{
Ethan Yonker84d61ce2017-05-10 16:11:35 -050074 *x = gr_font->char_width;
75 *y = gr_font->char_height;
Dima Zavin3c7f00e2011-08-30 11:58:24 -070076}
Ethan Yonker84d61ce2017-05-10 16:11:35 -050077#else // TW_USE_MINUI_CUSTOM_FONTS
Luke Song846012f2017-09-13 15:56:16 -070078const GRFont* gr_sys_font() {
79 return gr_font;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080080}
81
Tao Baoed876a72018-07-31 21:32:50 -070082PixelFormat gr_pixel_format() {
83 return pixel_format;
84}
85
Luke Song846012f2017-09-13 15:56:16 -070086int gr_measure(const GRFont* font, const char* s) {
Tianjie Xu842f2a32018-05-31 18:16:28 -070087 if (font == nullptr) {
88 return -1;
89 }
90
Luke Song846012f2017-09-13 15:56:16 -070091 return font->char_width * strlen(s);
Damien Bargiacchi35fff612016-08-11 15:57:03 -070092}
93
Tianjie Xu842f2a32018-05-31 18:16:28 -070094int gr_font_size(const GRFont* font, int* x, int* y) {
95 if (font == nullptr) {
96 return -1;
97 }
98
Luke Song846012f2017-09-13 15:56:16 -070099 *x = font->char_width;
100 *y = font->char_height;
Tianjie Xu842f2a32018-05-31 18:16:28 -0700101 return 0;
Dima Zavin3c7f00e2011-08-30 11:58:24 -0700102}
Ethan Yonker39662b22017-05-23 08:34:02 -0500103#endif // TW_NO_MINUI_CUSTOM_FONTS
Dima Zavin3c7f00e2011-08-30 11:58:24 -0700104
Ethan Yonkere96182e2015-10-13 19:32:03 -0500105void blend_16bpp(unsigned char* px, unsigned r5, unsigned g5, unsigned b5, unsigned char a)
106{
107 unsigned char orig[2];
108 orig[0] = px[0];
109 orig[1] = px[1];
110
111 /* This code is a little easier to read
112 unsigned oldred = (orig[1] >> 3);
113 unsigned oldgreen = (((orig[0] >> 5) << 3) + (orig[1] & 0x7));
114 unsigned oldblue = (orig[0] & 0x1F);
115
116 unsigned newred = (oldred * (255-a) + r5 * a) / 255;
117 unsigned newgreen = (oldgreen * (255-a) + g5 * a) / 255;
118 unsigned newblue = (oldblue * (255-a) + b5 * a) / 255;
119 */
120
121 unsigned newred = ((orig[1] >> 3) * (255-a) + r5 * a) / 255;
122 unsigned newgreen = ((((orig[0] >> 5) << 3) + (orig[1] & 0x7)) * (255-a) + g5 * a) / 255;
123 unsigned newblue = ((orig[0] & 0x1F) * (255-a) + b5 * a) / 255;
124
125 *px++ = (newgreen << 5) + (newblue);
126 *px++ = (newred << 3) + (newgreen >> 3);
127}
128
Ethan Yonker58f21322018-08-24 11:17:36 -0500129#ifdef TW_NO_MINUI_CUSTOM_FONTS
130static void text_blend_old(unsigned char* src_p, int src_row_bytes,
Doug Zongker16f97c32014-03-06 16:16:05 -0800131 unsigned char* dst_p, int dst_row_bytes,
132 int width, int height)
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800133{
Elliott Hughes01a4d082015-03-24 15:21:48 -0700134 for (int j = 0; j < height; ++j) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800135 unsigned char* sx = src_p;
136 unsigned char* px = dst_p;
Elliott Hughes01a4d082015-03-24 15:21:48 -0700137 for (int i = 0; i < width; ++i) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800138 unsigned char a = *sx++;
139 if (gr_current_a < 255) a = ((int)a * gr_current_a) / 255;
140 if (a == 255) {
Ethan Yonkere96182e2015-10-13 19:32:03 -0500141 if (gr_draw->pixel_bytes == 2) {
142 *px++ = rgb_555[0];
143 *px++ = rgb_555[1];
144 } else {
145 *px++ = gr_current_r;
146 *px++ = gr_current_g;
147 *px++ = gr_current_b;
148 px++;
149 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800150 } else if (a > 0) {
Ethan Yonkere96182e2015-10-13 19:32:03 -0500151 if (gr_draw->pixel_bytes == 2) {
152 blend_16bpp(px, gr_current_r5, gr_current_g5, gr_current_b5, a);
153 px += gr_draw->pixel_bytes;
154 } else {
155 *px = (*px * (255-a) + gr_current_r * a) / 255;
156 ++px;
157 *px = (*px * (255-a) + gr_current_g * a) / 255;
158 ++px;
159 *px = (*px * (255-a) + gr_current_b * a) / 255;
160 ++px;
161 ++px;
162 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800163 } else {
Ethan Yonkere96182e2015-10-13 19:32:03 -0500164 px += gr_draw->pixel_bytes;
Doug Zongker16f97c32014-03-06 16:16:05 -0800165 }
166 }
167 src_p += src_row_bytes;
168 dst_p += dst_row_bytes;
169 }
170}
Ethan Yonker58f21322018-08-24 11:17:36 -0500171#endif // TW_NO_MINUI_CUSTOM_FONTS
172
173// Blends gr_current onto pix value, assumes alpha as most significant byte.
174static inline uint16_t pixel_blend16(uint8_t a, uint16_t pix) {
175 unsigned char orig[2];
176 orig[0] = (pix & 0xFF00) >> 8;
177 orig[1] = pix & 0x00FF;
178
179 /* This code is a little easier to read
180 unsigned oldred = (orig[1] >> 3);
181 unsigned oldgreen = (((orig[0] >> 5) << 3) + (orig[1] & 0x7));
182 unsigned oldblue = (orig[0] & 0x1F);
183
184 unsigned newred = (oldred * (255-a) + r5 * a) / 255;
185 unsigned newgreen = (oldgreen * (255-a) + g5 * a) / 255;
186 unsigned newblue = (oldblue * (255-a) + b5 * a) / 255;
187 */
188
189 unsigned newred = ((orig[1] >> 3) * (255-a) + gr_current_r5 * a) / 255;
190 unsigned newgreen = ((((orig[0] >> 5) << 3) + (orig[1] & 0x7)) * (255-a) + gr_current_g5 * a) / 255;
191 unsigned newblue = ((orig[0] & 0x1F) * (255-a) + gr_current_b5 * a) / 255;
192
193 uint16_t newpix = (newred << 10) + (newgreen << 5) + newblue;
194 return newpix;
195}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800196
Luke Song846012f2017-09-13 15:56:16 -0700197// Blends gr_current onto pix value, assumes alpha as most significant byte.
198static inline uint32_t pixel_blend(uint8_t alpha, uint32_t pix) {
199 if (alpha == 255) return gr_current;
200 if (alpha == 0) return pix;
201 uint32_t pix_r = pix & 0xff;
202 uint32_t pix_g = pix & 0xff00;
203 uint32_t pix_b = pix & 0xff0000;
204 uint32_t cur_r = gr_current & 0xff;
205 uint32_t cur_g = gr_current & 0xff00;
206 uint32_t cur_b = gr_current & 0xff0000;
207
208 uint32_t out_r = (pix_r * (255 - alpha) + cur_r * alpha) / 255;
209 uint32_t out_g = (pix_g * (255 - alpha) + cur_g * alpha) / 255;
210 uint32_t out_b = (pix_b * (255 - alpha) + cur_b * alpha) / 255;
211
212 return (out_r & 0xff) | (out_g & 0xff00) | (out_b & 0xff0000) | (gr_current & 0xff000000);
213}
214
Tao Bao9f426332018-06-13 10:39:44 -0700215// Increments pixel pointer right, with current rotation.
Luke Song846012f2017-09-13 15:56:16 -0700216static void incr_x(uint32_t** p, int row_pixels) {
Tao Bao44478df2018-07-31 22:01:03 -0700217 if (rotation == GRRotation::LEFT) {
218 *p = *p - row_pixels;
219 } else if (rotation == GRRotation::RIGHT) {
220 *p = *p + row_pixels;
221 } else if (rotation == GRRotation::DOWN) {
222 *p = *p - 1;
223 } else { // GRRotation::NONE
224 *p = *p + 1;
Luke Song846012f2017-09-13 15:56:16 -0700225 }
226}
227
Tao Bao9f426332018-06-13 10:39:44 -0700228// Increments pixel pointer down, with current rotation.
Luke Song846012f2017-09-13 15:56:16 -0700229static void incr_y(uint32_t** p, int row_pixels) {
Tao Bao44478df2018-07-31 22:01:03 -0700230 if (rotation == GRRotation::LEFT) {
231 *p = *p + 1;
232 } else if (rotation == GRRotation::RIGHT) {
233 *p = *p - 1;
234 } else if (rotation == GRRotation::DOWN) {
235 *p = *p - row_pixels;
236 } else { // GRRotation::NONE
237 *p = *p + row_pixels;
Luke Song846012f2017-09-13 15:56:16 -0700238 }
239}
240
Tao Bao9f426332018-06-13 10:39:44 -0700241// Returns pixel pointer at given coordinates with rotation adjustment.
Tao Bao92bdb5a2018-10-21 12:12:37 -0700242static uint32_t* PixelAt(GRSurface* surface, int x, int y, int row_pixels) {
Luke Song846012f2017-09-13 15:56:16 -0700243 switch (rotation) {
Tao Bao44478df2018-07-31 22:01:03 -0700244 case GRRotation::NONE:
Tao Bao92bdb5a2018-10-21 12:12:37 -0700245 return reinterpret_cast<uint32_t*>(surface->data()) + y * row_pixels + x;
Tao Bao44478df2018-07-31 22:01:03 -0700246 case GRRotation::RIGHT:
Tao Bao92bdb5a2018-10-21 12:12:37 -0700247 return reinterpret_cast<uint32_t*>(surface->data()) + x * row_pixels + (surface->width - y);
Tao Bao44478df2018-07-31 22:01:03 -0700248 case GRRotation::DOWN:
Tao Bao92bdb5a2018-10-21 12:12:37 -0700249 return reinterpret_cast<uint32_t*>(surface->data()) + (surface->height - 1 - y) * row_pixels +
250 (surface->width - 1 - x);
Tao Bao44478df2018-07-31 22:01:03 -0700251 case GRRotation::LEFT:
Tao Bao92bdb5a2018-10-21 12:12:37 -0700252 return reinterpret_cast<uint32_t*>(surface->data()) + (surface->height - 1 - x) * row_pixels +
253 y;
Luke Song846012f2017-09-13 15:56:16 -0700254 default:
Tao Bao44478df2018-07-31 22:01:03 -0700255 printf("invalid rotation %d", static_cast<int>(rotation));
Luke Song846012f2017-09-13 15:56:16 -0700256 }
257 return nullptr;
258}
259
Tao Bao92bdb5a2018-10-21 12:12:37 -0700260static void TextBlend(const uint8_t* src_p, int src_row_bytes, uint32_t* dst_p, int dst_row_pixels,
261 int width, int height) {
Luke Song846012f2017-09-13 15:56:16 -0700262 uint8_t alpha_current = static_cast<uint8_t>((alpha_mask & gr_current) >> 24);
263 for (int j = 0; j < height; ++j) {
Tao Bao92bdb5a2018-10-21 12:12:37 -0700264 const uint8_t* sx = src_p;
Luke Song846012f2017-09-13 15:56:16 -0700265 uint32_t* px = dst_p;
266 for (int i = 0; i < width; ++i, incr_x(&px, dst_row_pixels)) {
267 uint8_t a = *sx++;
268 if (alpha_current < 255) a = (static_cast<uint32_t>(a) * alpha_current) / 255;
269 *px = pixel_blend(a, *px);
Doug Zongker16f97c32014-03-06 16:16:05 -0800270 }
Luke Song846012f2017-09-13 15:56:16 -0700271 src_p += src_row_bytes;
272 incr_y(&dst_p, dst_row_pixels);
273 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800274}
275
Doug Zongker16f97c32014-03-06 16:16:05 -0800276
Ethan Yonker39662b22017-05-23 08:34:02 -0500277#ifdef TW_NO_MINUI_CUSTOM_FONTS
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700278void gr_text(int x, int y, const char *s, bool bold)
Doug Zongker16f97c32014-03-06 16:16:05 -0800279{
Elliott Hughes01a4d082015-03-24 15:21:48 -0700280 GRFont* font = gr_font;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800281
Elliott Hughes01a4d082015-03-24 15:21:48 -0700282 if (!font->texture || gr_current_a == 0) return;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800283
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500284 bold = bold && (font->texture->height != font->char_height);
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800285
Doug Zongkerc560a672012-12-18 16:31:27 -0800286 x += overscan_offset_x;
287 y += overscan_offset_y;
288
Elliott Hughes01a4d082015-03-24 15:21:48 -0700289 unsigned char ch;
290 while ((ch = *s++)) {
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500291 if (outside(x, y) || outside(x+font->char_width-1, y+font->char_height-1)) break;
Doug Zongker16f97c32014-03-06 16:16:05 -0800292
Elliott Hughes01a4d082015-03-24 15:21:48 -0700293 if (ch < ' ' || ch > '~') {
294 ch = '?';
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800295 }
Elliott Hughes01a4d082015-03-24 15:21:48 -0700296
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500297 unsigned char* src_p = font->texture->data + ((ch - ' ') * font->char_width) +
298 (bold ? font->char_height * font->texture->row_bytes : 0);
Elliott Hughes01a4d082015-03-24 15:21:48 -0700299 unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes;
300
Ethan Yonker58f21322018-08-24 11:17:36 -0500301 text_blend_old(src_p, font->texture->row_bytes,
302 dst_p, gr_draw->row_bytes,
303 font->char_width, font->char_height);
Elliott Hughes01a4d082015-03-24 15:21:48 -0700304
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500305 x += font->char_width;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800306 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800307}
Ethan Yonker39662b22017-05-23 08:34:02 -0500308#else //TW_NO_MINUI_CUSTOM_FONTS
Luke Song846012f2017-09-13 15:56:16 -0700309void gr_text(const GRFont* font, int x, int y, const char* s, bool bold) {
310 if (!font || !font->texture || (gr_current & alpha_mask) == 0) return;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800311
Luke Song846012f2017-09-13 15:56:16 -0700312 if (font->texture->pixel_bytes != 1) {
313 printf("gr_text: font has wrong format\n");
314 return;
315 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800316
Luke Song846012f2017-09-13 15:56:16 -0700317 bold = bold && (font->texture->height != font->char_height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800318
Luke Song846012f2017-09-13 15:56:16 -0700319 x += overscan_offset_x;
320 y += overscan_offset_y;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800321
Luke Song846012f2017-09-13 15:56:16 -0700322 unsigned char ch;
323 while ((ch = *s++)) {
324 if (outside(x, y) || outside(x + font->char_width - 1, y + font->char_height - 1)) break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800325
Luke Song846012f2017-09-13 15:56:16 -0700326 if (ch < ' ' || ch > '~') {
327 ch = '?';
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800328 }
Luke Song846012f2017-09-13 15:56:16 -0700329
330 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
Tao Bao92bdb5a2018-10-21 12:12:37 -0700331 const uint8_t* src_p = font->texture->data() + ((ch - ' ') * font->char_width) +
332 (bold ? font->char_height * font->texture->row_bytes : 0);
333 uint32_t* dst_p = PixelAt(gr_draw, x, y, row_pixels);
Luke Song846012f2017-09-13 15:56:16 -0700334
Tao Bao92bdb5a2018-10-21 12:12:37 -0700335 TextBlend(src_p, font->texture->row_bytes, dst_p, row_pixels, font->char_width,
336 font->char_height);
Luke Song846012f2017-09-13 15:56:16 -0700337
338 x += font->char_width;
339 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800340}
Ethan Yonker39662b22017-05-23 08:34:02 -0500341#endif //TW_NO_MINUI_CUSTOM_FONTS
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800342
Tao Bao92bdb5a2018-10-21 12:12:37 -0700343void gr_texticon(int x, int y, const GRSurface* icon) {
Tao Bao9f426332018-06-13 10:39:44 -0700344 if (icon == nullptr) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800345
Luke Song846012f2017-09-13 15:56:16 -0700346 if (icon->pixel_bytes != 1) {
347 printf("gr_texticon: source has wrong format\n");
348 return;
349 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700350
Luke Song846012f2017-09-13 15:56:16 -0700351 x += overscan_offset_x;
352 y += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800353
Luke Song846012f2017-09-13 15:56:16 -0700354 if (outside(x, y) || outside(x + icon->width - 1, y + icon->height - 1)) return;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700355
Luke Song846012f2017-09-13 15:56:16 -0700356 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
Tao Bao92bdb5a2018-10-21 12:12:37 -0700357 const uint8_t* src_p = icon->data();
358 uint32_t* dst_p = PixelAt(gr_draw, x, y, row_pixels);
359 TextBlend(src_p, icon->row_bytes, dst_p, row_pixels, icon->width, icon->height);
Doug Zongker16f97c32014-03-06 16:16:05 -0800360}
361
Ethan Yonker58f21322018-08-24 11:17:36 -0500362void gr_convert_rgb_555(unsigned char r, unsigned char g, unsigned char b)
Ethan Yonkere96182e2015-10-13 19:32:03 -0500363{
Ethan Yonker58f21322018-08-24 11:17:36 -0500364 gr_current_r5 = (((r & 0xFF) * 0x1F) + 0x7F) / 0xFF;
365 gr_current_g5 = (((g & 0xFF) * 0x3F) + 0x7F) / 0xFF;
366 gr_current_b5 = (((b & 0xFF) * 0x1F) + 0x7F) / 0xFF;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500367
368 rgb_555[0] = (gr_current_g5 << 5) + (gr_current_b5);
369 rgb_555[1] = (gr_current_r5 << 3) + (gr_current_g5 >> 3);
370}
371
Luke Song846012f2017-09-13 15:56:16 -0700372void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
Ethan Yonker58f21322018-08-24 11:17:36 -0500373#ifdef TW_NO_MINUI_CUSTOM_FONTS
Tony Kuofd778e32015-02-05 21:25:56 +0800374#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
Ethan Yonker58f21322018-08-24 11:17:36 -0500375 gr_current_r = b;
376 gr_current_g = g;
377 gr_current_b = r;
Tony Kuofd778e32015-02-05 21:25:56 +0800378#else
Ethan Yonker58f21322018-08-24 11:17:36 -0500379 gr_current_r = r;
380 gr_current_g = g;
381 gr_current_b = b;
Tony Kuofd778e32015-02-05 21:25:56 +0800382#endif
Ethan Yonker58f21322018-08-24 11:17:36 -0500383#endif
384
385 if (gr_draw->pixel_bytes == 2) {
386 gr_current_a = a;
387 gr_convert_rgb_555(r, g, b);
388 return;
389 }
390
Luke Song846012f2017-09-13 15:56:16 -0700391 uint32_t r32 = r, g32 = g, b32 = b, a32 = a;
Tao Baoed876a72018-07-31 21:32:50 -0700392 if (pixel_format == PixelFormat::ABGR || pixel_format == PixelFormat::BGRA) {
393 gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32;
394 } else {
395 gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32;
396 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800397}
398
Luke Song846012f2017-09-13 15:56:16 -0700399void gr_clear() {
Ethan Yonker58f21322018-08-24 11:17:36 -0500400 if (gr_draw->pixel_bytes == 2) {
401 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
402 return;
403 }
Ethan Yonkere96182e2015-10-13 19:32:03 -0500404
Ethan Yonker58f21322018-08-24 11:17:36 -0500405 // This code only works on 32bpp devices
Luke Song846012f2017-09-13 15:56:16 -0700406 if ((gr_current & 0xff) == ((gr_current >> 8) & 0xff) &&
407 (gr_current & 0xff) == ((gr_current >> 16) & 0xff) &&
408 (gr_current & 0xff) == ((gr_current >> 24) & 0xff) &&
409 gr_draw->row_bytes == gr_draw->width * gr_draw->pixel_bytes) {
Tao Bao92bdb5a2018-10-21 12:12:37 -0700410 memset(gr_draw->data(), gr_current & 0xff, gr_draw->height * gr_draw->row_bytes);
Luke Song846012f2017-09-13 15:56:16 -0700411 } else {
Tao Bao92bdb5a2018-10-21 12:12:37 -0700412 uint32_t* px = reinterpret_cast<uint32_t*>(gr_draw->data());
Luke Song846012f2017-09-13 15:56:16 -0700413 int row_diff = gr_draw->row_bytes / gr_draw->pixel_bytes - gr_draw->width;
414 for (int y = 0; y < gr_draw->height; ++y) {
415 for (int x = 0; x < gr_draw->width; ++x) {
416 *px++ = gr_current;
417 }
418 px += row_diff;
Doug Zongker16f97c32014-03-06 16:16:05 -0800419 }
Luke Song846012f2017-09-13 15:56:16 -0700420 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700421}
422
Luke Song846012f2017-09-13 15:56:16 -0700423void gr_fill(int x1, int y1, int x2, int y2) {
424 x1 += overscan_offset_x;
425 y1 += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800426
Luke Song846012f2017-09-13 15:56:16 -0700427 x2 += overscan_offset_x;
428 y2 += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800429
Luke Song846012f2017-09-13 15:56:16 -0700430 if (outside(x1, y1) || outside(x2 - 1, y2 - 1)) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800431
Luke Song846012f2017-09-13 15:56:16 -0700432 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
Tao Bao92bdb5a2018-10-21 12:12:37 -0700433 uint32_t* p = PixelAt(gr_draw, x1, y1, row_pixels);
Luke Song846012f2017-09-13 15:56:16 -0700434 uint8_t alpha = static_cast<uint8_t>(((gr_current & alpha_mask) >> 24));
435 if (alpha > 0) {
436 for (int y = y1; y < y2; ++y) {
437 uint32_t* px = p;
438 for (int x = x1; x < x2; ++x) {
439 *px = pixel_blend(alpha, *px);
440 incr_x(&px, row_pixels);
441 }
442 incr_y(&p, row_pixels);
Doug Zongker16f97c32014-03-06 16:16:05 -0800443 }
Luke Song846012f2017-09-13 15:56:16 -0700444 }
Ethan Yonker58f21322018-08-24 11:17:36 -0500445 } // close brace to maintain separation between uint16_t p and uint32_t p
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800446}
447
Ethan Yonkere96182e2015-10-13 19:32:03 -0500448void gr_blit_32to16(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
Ethan Yonker58f21322018-08-24 11:17:36 -0500449 if (rotation)
450 printf("gr_blit_32to16 does not support rotation!\n"); // but we'll draw something in the wrong spot anyway because, why not!
Ethan Yonkere96182e2015-10-13 19:32:03 -0500451
Ethan Yonker58f21322018-08-24 11:17:36 -0500452 dx += overscan_offset_x;
453 dy += overscan_offset_y;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500454
Ethan Yonker58f21322018-08-24 11:17:36 -0500455 if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500456
Ethan Yonker58f21322018-08-24 11:17:36 -0500457 unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes;
458 unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500459
Ethan Yonker58f21322018-08-24 11:17:36 -0500460 int i, j;
461 for (i = 0; i < h; ++i) {
462 unsigned char* spx = src_p;
463 unsigned char* dpx = dst_p;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500464
Ethan Yonker58f21322018-08-24 11:17:36 -0500465 for (j = 0; j < w; ++j) {
466 unsigned a = spx[3];
467
468 if (a == 0) {
469 spx += source->pixel_bytes;
470 dpx += gr_draw->pixel_bytes;
471 } else {
472 unsigned r5 = (((*spx++ & 0xFF) * 0x1F) + 0x7F) / 0xFF;
473 unsigned g5 = (((*spx++ & 0xFF) * 0x3F) + 0x7F) / 0xFF;
474 unsigned b5 = (((*spx++ & 0xFF) * 0x1F) + 0x7F) / 0xFF;
475 spx++;
476 if (a == 255) {
477 *dpx++ = (g5 << 5) + (b5);
478 *dpx++ = (r5 << 3) + (g5 >> 3);
479 } else {
480 blend_16bpp(dpx, r5, g5, b5, a);
481 spx += source->pixel_bytes;
Ethan Yonkere96182e2015-10-13 19:32:03 -0500482 }
Ethan Yonker58f21322018-08-24 11:17:36 -0500483 }
Ethan Yonkere96182e2015-10-13 19:32:03 -0500484 }
Ethan Yonker58f21322018-08-24 11:17:36 -0500485 src_p += source->row_bytes;
486 dst_p += gr_draw->row_bytes;
487 }
Ethan Yonkere96182e2015-10-13 19:32:03 -0500488}
489
Tao Bao92bdb5a2018-10-21 12:12:37 -0700490void gr_blit(const GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
Tao Bao9f426332018-06-13 10:39:44 -0700491 if (source == nullptr) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800492
Luke Song846012f2017-09-13 15:56:16 -0700493 if (gr_draw->pixel_bytes != source->pixel_bytes) {
Ethan Yonker58f21322018-08-24 11:17:36 -0500494 if (gr_draw->pixel_bytes == 2 && source->pixel_bytes == 4) {
495 gr_blit_32to16(source, sx, sy, w, h, dx, dy);
496 return;
497 } else {
498 printf("gr_blit: source has wrong format\n");
499 return;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800500 }
Luke Song846012f2017-09-13 15:56:16 -0700501 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800502
Luke Song846012f2017-09-13 15:56:16 -0700503 dx += overscan_offset_x;
504 dy += overscan_offset_y;
Doug Zongkerc560a672012-12-18 16:31:27 -0800505
Luke Song846012f2017-09-13 15:56:16 -0700506 if (outside(dx, dy) || outside(dx + w - 1, dy + h - 1)) return;
Doug Zongker16f97c32014-03-06 16:16:05 -0800507
Tao Bao44478df2018-07-31 22:01:03 -0700508 if (rotation != GRRotation::NONE) {
Luke Song846012f2017-09-13 15:56:16 -0700509 int src_row_pixels = source->row_bytes / source->pixel_bytes;
510 int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes;
Tao Bao92bdb5a2018-10-21 12:12:37 -0700511 const uint32_t* src_py =
512 reinterpret_cast<const uint32_t*>(source->data()) + sy * source->row_bytes / 4 + sx;
513 uint32_t* dst_py = PixelAt(gr_draw, dx, dy, row_pixels);
Luke Song846012f2017-09-13 15:56:16 -0700514
515 for (int y = 0; y < h; y += 1) {
Tao Bao92bdb5a2018-10-21 12:12:37 -0700516 const uint32_t* src_px = src_py;
Luke Song846012f2017-09-13 15:56:16 -0700517 uint32_t* dst_px = dst_py;
518 for (int x = 0; x < w; x += 1) {
519 *dst_px = *src_px++;
520 incr_x(&dst_px, row_pixels);
521 }
522 src_py += src_row_pixels;
523 incr_y(&dst_py, row_pixels);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800524 }
Luke Song846012f2017-09-13 15:56:16 -0700525 } else {
Tao Bao92bdb5a2018-10-21 12:12:37 -0700526 const uint8_t* src_p = source->data() + sy * source->row_bytes + sx * source->pixel_bytes;
527 uint8_t* dst_p = gr_draw->data() + dy * gr_draw->row_bytes + dx * gr_draw->pixel_bytes;
Doug Zongker16f97c32014-03-06 16:16:05 -0800528
Tao Bao9f426332018-06-13 10:39:44 -0700529 for (int i = 0; i < h; ++i) {
Luke Song846012f2017-09-13 15:56:16 -0700530 memcpy(dst_p, src_p, w * source->pixel_bytes);
531 src_p += source->row_bytes;
532 dst_p += gr_draw->row_bytes;
Doug Zongker16f97c32014-03-06 16:16:05 -0800533 }
Luke Song846012f2017-09-13 15:56:16 -0700534 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800535}
536
Tao Bao9f426332018-06-13 10:39:44 -0700537unsigned int gr_get_width(const GRSurface* surface) {
538 if (surface == nullptr) {
Luke Song846012f2017-09-13 15:56:16 -0700539 return 0;
540 }
541 return surface->width;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800542}
543
Tao Bao9f426332018-06-13 10:39:44 -0700544unsigned int gr_get_height(const GRSurface* surface) {
545 if (surface == nullptr) {
Luke Song846012f2017-09-13 15:56:16 -0700546 return 0;
547 }
548 return surface->height;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800549}
550
Ethan Yonker39662b22017-05-23 08:34:02 -0500551#ifdef TW_NO_MINUI_CUSTOM_FONTS
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800552static void gr_init_font(void)
553{
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700554 gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800555
Doug Zongkera418aa72014-03-17 12:10:02 -0700556 int res = res_create_alpha_surface("font", &(gr_font->texture));
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800557 if (res == 0) {
558 // The font image should be a 96x2 array of character images. The
559 // columns are the printable ASCII characters 0x20 - 0x7f. The
560 // top row is regular text; the bottom row is bold.
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500561 gr_font->char_width = gr_font->texture->width / 96;
562 gr_font->char_height = gr_font->texture->height / 2;
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800563 } else {
Doug Zongker55a36ac2013-03-04 15:49:02 -0800564 printf("failed to read font: res=%d\n", res);
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800565
566 // fall back to the compiled-in font.
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700567 gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800568 gr_font->texture->width = font.width;
569 gr_font->texture->height = font.height;
Doug Zongker16f97c32014-03-06 16:16:05 -0800570 gr_font->texture->row_bytes = font.width;
571 gr_font->texture->pixel_bytes = 1;
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800572
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700573 unsigned char* bits = reinterpret_cast<unsigned char*>(malloc(font.width * font.height));
574 gr_font->texture->data = reinterpret_cast<unsigned char*>(bits);
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800575
576 unsigned char data;
577 unsigned char* in = font.rundata;
578 while((data = *in++)) {
579 memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f);
580 bits += (data & 0x7f);
581 }
582
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500583 gr_font->char_width = font.char_width;
584 gr_font->char_height = font.char_height;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800585 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800586}
587
Ethan Yonker84d61ce2017-05-10 16:11:35 -0500588void gr_set_font(__attribute__ ((unused))const char* name) {
589 //this cm function is made to change font. Don't care, just init the font:
590 gr_init_font();
591 return;
592}
Ethan Yonker39662b22017-05-23 08:34:02 -0500593#else // TW_NO_MINUI_CUSTOM_FONTS
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700594int gr_init_font(const char* name, GRFont** dest) {
Luke Song846012f2017-09-13 15:56:16 -0700595 GRFont* font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
596 if (font == nullptr) {
597 return -1;
598 }
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700599
Luke Song846012f2017-09-13 15:56:16 -0700600 int res = res_create_alpha_surface(name, &(font->texture));
601 if (res < 0) {
602 free(font);
603 return res;
604 }
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700605
Luke Song846012f2017-09-13 15:56:16 -0700606 // The font image should be a 96x2 array of character images. The
607 // columns are the printable ASCII characters 0x20 - 0x7f. The
608 // top row is regular text; the bottom row is bold.
609 font->char_width = font->texture->width / 96;
610 font->char_height = font->texture->height / 2;
Damien Bargiacchid00f5eb2016-09-09 07:14:08 -0700611
Luke Song846012f2017-09-13 15:56:16 -0700612 *dest = font;
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700613
Luke Song846012f2017-09-13 15:56:16 -0700614 return 0;
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700615}
616
Doug Zongker5290f202014-03-11 13:22:04 -0700617void gr_flip() {
Tao Bao557fa1f2017-02-07 12:51:00 -0800618 gr_draw = gr_backend->Flip();
Doug Zongker5290f202014-03-11 13:22:04 -0700619}
620
Tao Bao557fa1f2017-02-07 12:51:00 -0800621int gr_init() {
Tao Baoed876a72018-07-31 21:32:50 -0700622 // pixel_format needs to be set before loading any resources or initializing backends.
Tao Bao050feb02018-09-05 21:45:42 -0700623 std::string format = android::base::GetProperty("ro.minui.pixel_format", "");
Tao Baoed876a72018-07-31 21:32:50 -0700624 if (format == "ABGR_8888") {
625 pixel_format = PixelFormat::ABGR;
626 } else if (format == "RGBX_8888") {
627 pixel_format = PixelFormat::RGBX;
628 } else if (format == "BGRA_8888") {
629 pixel_format = PixelFormat::BGRA;
630 } else {
631 pixel_format = PixelFormat::UNKNOWN;
632 }
633
Tianjie Xu55a2c4e2018-03-29 11:07:50 -0700634 int ret = gr_init_font("font", &gr_font);
635 if (ret != 0) {
Tianjie Xu842f2a32018-05-31 18:16:28 -0700636 printf("Failed to init font: %d, continuing graphic backend initialization without font file\n",
637 ret);
Tianjie Xu55a2c4e2018-03-29 11:07:50 -0700638 }
Doug Zongker16f97c32014-03-06 16:16:05 -0800639
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500640 auto backend = std::unique_ptr<MinuiBackend>{ std::make_unique<MinuiBackendOverlay>() };
Tao Bao557fa1f2017-02-07 12:51:00 -0800641 gr_draw = backend->Init();
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800642
Ethan Yonkerb386f712017-01-20 14:30:28 -0600643#ifdef MSM_BSP
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500644 if (gr_draw) {
645 printf("Using overlay graphics.\n");
Ethan Yonkera59da092015-10-13 19:35:05 -0500646 }
Ethan Yonkerb386f712017-01-20 14:30:28 -0600647#endif
Ethan Yonkera59da092015-10-13 19:35:05 -0500648
Greg Hackmann41909dd2014-04-25 10:39:50 -0700649
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500650 if (!gr_draw) {
651 backend = std::make_unique<MinuiBackendDrm>();
652 gr_draw = backend->Init();
Ethan Yonkera59da092015-10-13 19:35:05 -0500653 if (gr_draw)
654 printf("Using drm graphics.\n");
Stéphane Marchesin1a92c442015-06-29 20:05:48 -0700655 }
656
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500657 if (!gr_draw) {
658 backend = std::make_unique<MinuiBackendFbdev>();
659 gr_draw = backend->Init();
660 if (gr_draw)
Ethan Yonkera59da092015-10-13 19:35:05 -0500661 printf("Using fbdev graphics.\n");
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800662
Tao Bao557fa1f2017-02-07 12:51:00 -0800663 if (!gr_draw) {
664 return -1;
665 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800666
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800667
Tao Bao050feb02018-09-05 21:45:42 -0700668 int overscan_percent = android::base::GetIntProperty("ro.minui.overscan_percent", 0);
Tao Bao557fa1f2017-02-07 12:51:00 -0800669 overscan_offset_x = gr_draw->width * overscan_percent / 100;
670 overscan_offset_y = gr_draw->height * overscan_percent / 100;
671
672 gr_flip();
673 gr_flip();
Tianjie Xuccf00a22018-06-05 17:10:23 -0700674 if (!gr_draw) {
675 printf("gr_init: gr_draw becomes nullptr after gr_flip\n");
676 return -1;
677 }
Tao Bao557fa1f2017-02-07 12:51:00 -0800678
Tao Baoed876a72018-07-31 21:32:50 -0700679 std::string rotation_str =
Tao Bao050feb02018-09-05 21:45:42 -0700680 android::base::GetProperty("ro.minui.default_rotation", "ROTATION_NONE");
Tao Bao44478df2018-07-31 22:01:03 -0700681 if (rotation_str == "ROTATION_RIGHT") {
682 gr_rotate(GRRotation::RIGHT);
683 } else if (rotation_str == "ROTATION_DOWN") {
684 gr_rotate(GRRotation::DOWN);
685 } else if (rotation_str == "ROTATION_LEFT") {
686 gr_rotate(GRRotation::LEFT);
Tao Baoed876a72018-07-31 21:32:50 -0700687 } else { // "ROTATION_NONE" or unknown string
Tao Bao44478df2018-07-31 22:01:03 -0700688 gr_rotate(GRRotation::NONE);
689 }
Luke Song846012f2017-09-13 15:56:16 -0700690
691 if (gr_draw->pixel_bytes != 4) {
692 printf("gr_init: Only 4-byte pixel formats supported\n");
693 }
694
Tao Bao557fa1f2017-02-07 12:51:00 -0800695 return 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800696}
697
Tao Bao557fa1f2017-02-07 12:51:00 -0800698void gr_exit() {
699 delete gr_backend;
Tao Bao9f426332018-06-13 10:39:44 -0700700 gr_backend = nullptr;
701
702 delete gr_font;
703 gr_font = nullptr;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800704}
705
Tao Bao557fa1f2017-02-07 12:51:00 -0800706int gr_fb_width() {
Tao Bao44478df2018-07-31 22:01:03 -0700707 return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT)
708 ? gr_draw->height - 2 * overscan_offset_y
709 : gr_draw->width - 2 * overscan_offset_x;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800710}
711
Tao Bao557fa1f2017-02-07 12:51:00 -0800712int gr_fb_height() {
Tao Bao44478df2018-07-31 22:01:03 -0700713 return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT)
714 ? gr_draw->width - 2 * overscan_offset_x
715 : gr_draw->height - 2 * overscan_offset_y;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800716}
Dima Zavin4daf48a2011-08-30 11:59:20 -0700717
Tao Bao557fa1f2017-02-07 12:51:00 -0800718void gr_fb_blank(bool blank) {
719 gr_backend->Blank(blank);
Dima Zavin4daf48a2011-08-30 11:59:20 -0700720}
Luke Song846012f2017-09-13 15:56:16 -0700721
722void gr_rotate(GRRotation rot) {
723 rotation = rot;
724}