blob: 8f951756d93be5a1539b9bc58c09303841fbe966 [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
Dima Zavin4daf48a2011-08-30 11:59:20 -070017#include <stdbool.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080018#include <stdlib.h>
19#include <unistd.h>
20
Dees Troy62b75ab2014-05-02 13:20:33 +000021#include <errno.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080022#include <fcntl.h>
23#include <stdio.h>
24
25#include <sys/ioctl.h>
26#include <sys/mman.h>
27#include <sys/types.h>
28
29#include <linux/fb.h>
30#include <linux/kd.h>
31
32#include <pixelflinger/pixelflinger.h>
33
Doug Zongker6fd59ac2013-03-06 15:01:11 -080034#include "font_10x18.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080035#include "minui.h"
36
Michael Ward9d1bcdf2011-06-22 14:30:34 -070037#if defined(RECOVERY_BGRA)
38#define PIXEL_FORMAT GGL_PIXEL_FORMAT_BGRA_8888
39#define PIXEL_SIZE 4
40#elif defined(RECOVERY_RGBX)
Doug Zongkerbe3e6f12011-01-13 16:43:44 -080041#define PIXEL_FORMAT GGL_PIXEL_FORMAT_RGBX_8888
42#define PIXEL_SIZE 4
43#else
44#define PIXEL_FORMAT GGL_PIXEL_FORMAT_RGB_565
45#define PIXEL_SIZE 2
46#endif
47
Devin Kim862d0262012-07-19 10:47:34 -070048#define NUM_BUFFERS 2
49
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080050typedef struct {
Doug Zongker55a36ac2013-03-04 15:49:02 -080051 GGLSurface* texture;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080052 unsigned cwidth;
53 unsigned cheight;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080054} GRFont;
55
56static GRFont *gr_font = 0;
57static GGLContext *gr_context = 0;
58static GGLSurface gr_font_texture;
Devin Kim862d0262012-07-19 10:47:34 -070059static GGLSurface gr_framebuffer[NUM_BUFFERS];
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060static GGLSurface gr_mem_surface;
61static unsigned gr_active_fb = 0;
Octavian Purdila0e348802011-07-01 17:57:45 +030062static unsigned double_buffering = 0;
Doug Zongkerc560a672012-12-18 16:31:27 -080063static int overscan_percent = OVERSCAN_PERCENT;
64static int overscan_offset_x = 0;
65static int overscan_offset_y = 0;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080066
67static int gr_fb_fd = -1;
68static int gr_vt_fd = -1;
69
70static struct fb_var_screeninfo vi;
Michael Ward9d1bcdf2011-06-22 14:30:34 -070071static struct fb_fix_screeninfo fi;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080072
Dees Troy62b75ab2014-05-02 13:20:33 +000073static bool has_overlay = false;
74
75bool target_has_overlay(char *version);
76int free_ion_mem(void);
77int alloc_ion_mem(unsigned int size);
78int allocate_overlay(int fd, GGLSurface gr_fb[]);
79int free_overlay(int fd);
80int overlay_display_frame(int fd, GGLubyte* data, size_t size);
81
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080082static int get_framebuffer(GGLSurface *fb)
83{
84 int fd;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080085 void *bits;
86
87 fd = open("/dev/graphics/fb0", O_RDWR);
88 if (fd < 0) {
89 perror("cannot open fb0");
90 return -1;
91 }
92
Michael Ward3dbe66b2011-06-23 19:28:53 -070093 if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080094 perror("failed to get fb0 info");
95 close(fd);
96 return -1;
97 }
98
Michael Ward3dbe66b2011-06-23 19:28:53 -070099 vi.bits_per_pixel = PIXEL_SIZE * 8;
100 if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_BGRA_8888) {
101 vi.red.offset = 8;
102 vi.red.length = 8;
103 vi.green.offset = 16;
104 vi.green.length = 8;
105 vi.blue.offset = 24;
106 vi.blue.length = 8;
107 vi.transp.offset = 0;
108 vi.transp.length = 8;
109 } else if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_RGBX_8888) {
110 vi.red.offset = 24;
111 vi.red.length = 8;
112 vi.green.offset = 16;
113 vi.green.length = 8;
114 vi.blue.offset = 8;
115 vi.blue.length = 8;
116 vi.transp.offset = 0;
117 vi.transp.length = 8;
118 } else { /* RGB565*/
119 vi.red.offset = 11;
120 vi.red.length = 5;
121 vi.green.offset = 5;
122 vi.green.length = 6;
123 vi.blue.offset = 0;
124 vi.blue.length = 5;
125 vi.transp.offset = 0;
126 vi.transp.length = 0;
127 }
128 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vi) < 0) {
129 perror("failed to put fb0 info");
130 close(fd);
131 return -1;
132 }
133
134 if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800135 perror("failed to get fb0 info");
136 close(fd);
137 return -1;
138 }
139
Dees Troy62b75ab2014-05-02 13:20:33 +0000140 has_overlay = target_has_overlay(fi.id);
141
142 if (!has_overlay) {
143 bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
144 if (bits == MAP_FAILED) {
145 perror("failed to mmap framebuffer");
146 close(fd);
147 return -1;
148 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800149 }
150
Doug Zongkerc560a672012-12-18 16:31:27 -0800151 overscan_offset_x = vi.xres * overscan_percent / 100;
152 overscan_offset_y = vi.yres * overscan_percent / 100;
153
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800154 fb->version = sizeof(*fb);
155 fb->width = vi.xres;
156 fb->height = vi.yres;
Michael Ward9d1bcdf2011-06-22 14:30:34 -0700157 fb->stride = fi.line_length/PIXEL_SIZE;
Doug Zongkerbe3e6f12011-01-13 16:43:44 -0800158 fb->format = PIXEL_FORMAT;
Dees Troy62b75ab2014-05-02 13:20:33 +0000159 if (!has_overlay) {
160 fb->data = bits;
161 memset(fb->data, 0, vi.yres * fi.line_length);
162 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800163
164 fb++;
165
Octavian Purdila0e348802011-07-01 17:57:45 +0300166 /* check if we can use double buffering */
167 if (vi.yres * fi.line_length * 2 > fi.smem_len)
168 return fd;
169
170 double_buffering = 1;
171
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800172 fb->version = sizeof(*fb);
173 fb->width = vi.xres;
174 fb->height = vi.yres;
Michael Ward9d1bcdf2011-06-22 14:30:34 -0700175 fb->stride = fi.line_length/PIXEL_SIZE;
Doug Zongkerbe3e6f12011-01-13 16:43:44 -0800176 fb->format = PIXEL_FORMAT;
Dees Troy62b75ab2014-05-02 13:20:33 +0000177 if (!has_overlay) {
178 fb->data = (void*) (((unsigned) bits) + vi.yres * fi.line_length);
179 memset(fb->data, 0, vi.yres * fi.line_length);
180 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800181
182 return fd;
183}
184
185static void get_memory_surface(GGLSurface* ms) {
186 ms->version = sizeof(*ms);
187 ms->width = vi.xres;
188 ms->height = vi.yres;
Michael Ward9d1bcdf2011-06-22 14:30:34 -0700189 ms->stride = fi.line_length/PIXEL_SIZE;
190 ms->data = malloc(fi.line_length * vi.yres);
Doug Zongkerbe3e6f12011-01-13 16:43:44 -0800191 ms->format = PIXEL_FORMAT;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800192}
193
194static void set_active_framebuffer(unsigned n)
195{
Octavian Purdila0e348802011-07-01 17:57:45 +0300196 if (n > 1 || !double_buffering) return;
Devin Kim862d0262012-07-19 10:47:34 -0700197 vi.yres_virtual = vi.yres * NUM_BUFFERS;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800198 vi.yoffset = n * vi.yres;
Doug Zongkerbe3e6f12011-01-13 16:43:44 -0800199 vi.bits_per_pixel = PIXEL_SIZE * 8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800200 if (ioctl(gr_fb_fd, FBIOPUT_VSCREENINFO, &vi) < 0) {
201 perror("active fb swap failed");
202 }
203}
204
205void gr_flip(void)
206{
Dees Troy62b75ab2014-05-02 13:20:33 +0000207 if (-EINVAL == overlay_display_frame(gr_fb_fd, gr_mem_surface.data,
208 (fi.line_length * vi.yres))) {
209 GGLContext *gl = gr_context;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800210
Dees Troy62b75ab2014-05-02 13:20:33 +0000211 /* swap front and back buffers */
212 if (double_buffering)
213 gr_active_fb = (gr_active_fb + 1) & 1;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800214
Dees Troy62b75ab2014-05-02 13:20:33 +0000215 /* copy data from the in-memory surface to the buffer we're about
216 * to make active. */
217 memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data,
218 fi.line_length * vi.yres);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800219
Dees Troy62b75ab2014-05-02 13:20:33 +0000220 /* inform the display driver */
221 set_active_framebuffer(gr_active_fb);
222 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800223}
224
225void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
226{
227 GGLContext *gl = gr_context;
228 GGLint color[4];
229 color[0] = ((r << 8) | r) + 1;
230 color[1] = ((g << 8) | g) + 1;
231 color[2] = ((b << 8) | b) + 1;
232 color[3] = ((a << 8) | a) + 1;
233 gl->color4xv(gl, color);
234}
235
236int gr_measure(const char *s)
237{
238 return gr_font->cwidth * strlen(s);
239}
240
Dima Zavin3c7f00e2011-08-30 11:58:24 -0700241void gr_font_size(int *x, int *y)
242{
243 *x = gr_font->cwidth;
244 *y = gr_font->cheight;
245}
246
Vojtech Bocek65fdcdd2013-09-06 21:32:22 +0200247int gr_text(int x, int y, const char *s, ...)
248{
249 return gr_text_impl(x, y, s, 0);
250}
251
252int gr_text_impl(int x, int y, const char *s, int bold)
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800253{
254 GGLContext *gl = gr_context;
255 GRFont *font = gr_font;
256 unsigned off;
257
Doug Zongker55a36ac2013-03-04 15:49:02 -0800258 if (!font->texture) return x;
259
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800260 bold = bold && (font->texture->height != font->cheight);
261
Doug Zongkerc560a672012-12-18 16:31:27 -0800262 x += overscan_offset_x;
263 y += overscan_offset_y;
264
Doug Zongker55a36ac2013-03-04 15:49:02 -0800265 gl->bindTexture(gl, font->texture);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800266 gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
267 gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
268 gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
269 gl->enable(gl, GGL_TEXTURE_2D);
270
271 while((off = *s++)) {
272 off -= 32;
273 if (off < 96) {
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800274 gl->texCoord2i(gl, (off * font->cwidth) - x,
275 (bold ? font->cheight : 0) - y);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800276 gl->recti(gl, x, y, x + font->cwidth, y + font->cheight);
277 }
278 x += font->cwidth;
279 }
280
281 return x;
282}
283
Doug Zongker02ec6b82012-08-22 17:26:40 -0700284void gr_texticon(int x, int y, gr_surface icon) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700285 if (gr_context == NULL || icon == NULL) {
286 return;
287 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700288 GGLContext* gl = gr_context;
289
Doug Zongkerc560a672012-12-18 16:31:27 -0800290 x += overscan_offset_x;
291 y += overscan_offset_y;
292
Doug Zongker02ec6b82012-08-22 17:26:40 -0700293 gl->bindTexture(gl, (GGLSurface*) icon);
294 gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
295 gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
296 gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
297 gl->enable(gl, GGL_TEXTURE_2D);
298
299 int w = gr_get_width(icon);
300 int h = gr_get_height(icon);
301
302 gl->texCoord2i(gl, -x, -y);
303 gl->recti(gl, x, y, x+gr_get_width(icon), y+gr_get_height(icon));
304}
305
Doug Zongkerc560a672012-12-18 16:31:27 -0800306void gr_fill(int x1, int y1, int x2, int y2)
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800307{
Doug Zongkerc560a672012-12-18 16:31:27 -0800308 x1 += overscan_offset_x;
309 y1 += overscan_offset_y;
310
311 x2 += overscan_offset_x;
312 y2 += overscan_offset_y;
313
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800314 GGLContext *gl = gr_context;
315 gl->disable(gl, GGL_TEXTURE_2D);
Doug Zongkerc560a672012-12-18 16:31:27 -0800316 gl->recti(gl, x1, y1, x2, y2);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800317}
318
319void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700320 if (gr_context == NULL || source == NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800321 return;
322 }
323 GGLContext *gl = gr_context;
324
Doug Zongkerc560a672012-12-18 16:31:27 -0800325 dx += overscan_offset_x;
326 dy += overscan_offset_y;
327
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800328 gl->bindTexture(gl, (GGLSurface*) source);
329 gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
330 gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
331 gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
332 gl->enable(gl, GGL_TEXTURE_2D);
333 gl->texCoord2i(gl, sx - dx, sy - dy);
334 gl->recti(gl, dx, dy, dx + w, dy + h);
335}
336
337unsigned int gr_get_width(gr_surface surface) {
338 if (surface == NULL) {
339 return 0;
340 }
341 return ((GGLSurface*) surface)->width;
342}
343
344unsigned int gr_get_height(gr_surface surface) {
345 if (surface == NULL) {
346 return 0;
347 }
348 return ((GGLSurface*) surface)->height;
349}
350
351static void gr_init_font(void)
352{
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800353 gr_font = calloc(sizeof(*gr_font), 1);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800354
Doug Zongker55a36ac2013-03-04 15:49:02 -0800355 int res = res_create_surface("font", (void**)&(gr_font->texture));
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800356 if (res == 0) {
357 // The font image should be a 96x2 array of character images. The
358 // columns are the printable ASCII characters 0x20 - 0x7f. The
359 // top row is regular text; the bottom row is bold.
360 gr_font->cwidth = gr_font->texture->width / 96;
361 gr_font->cheight = gr_font->texture->height / 2;
362 } else {
Doug Zongker55a36ac2013-03-04 15:49:02 -0800363 printf("failed to read font: res=%d\n", res);
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800364
365 // fall back to the compiled-in font.
366 gr_font->texture = malloc(sizeof(*gr_font->texture));
367 gr_font->texture->width = font.width;
368 gr_font->texture->height = font.height;
369 gr_font->texture->stride = font.width;
370
371 unsigned char* bits = malloc(font.width * font.height);
372 gr_font->texture->data = (void*) bits;
373
374 unsigned char data;
375 unsigned char* in = font.rundata;
376 while((data = *in++)) {
377 memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f);
378 bits += (data & 0x7f);
379 }
380
381 gr_font->cwidth = font.cwidth;
382 gr_font->cheight = font.cheight;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800383 }
384
Doug Zongker55a36ac2013-03-04 15:49:02 -0800385 // interpret the grayscale as alpha
386 gr_font->texture->format = GGL_PIXEL_FORMAT_A_8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800387}
388
389int gr_init(void)
390{
391 gglInit(&gr_context);
392 GGLContext *gl = gr_context;
393
394 gr_init_font();
395 gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC);
396 if (gr_vt_fd < 0) {
397 // This is non-fatal; post-Cupcake kernels don't have tty0.
398 perror("can't open /dev/tty0");
399 } else if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) {
400 // However, if we do open tty0, we expect the ioctl to work.
401 perror("failed KDSETMODE to KD_GRAPHICS on tty0");
402 gr_exit();
403 return -1;
404 }
405
406 gr_fb_fd = get_framebuffer(gr_framebuffer);
407 if (gr_fb_fd < 0) {
408 gr_exit();
409 return -1;
410 }
411
412 get_memory_surface(&gr_mem_surface);
413
Dees Troy62b75ab2014-05-02 13:20:33 +0000414 fprintf(stderr, "framebuffer: fd %d (%d x %d)\n",
415 gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800416
Dees Troy62b75ab2014-05-02 13:20:33 +0000417 /* start with 0 as front (displayed) and 1 as back (drawing) */
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800418 gr_active_fb = 0;
Dees Troy62b75ab2014-05-02 13:20:33 +0000419 if (!has_overlay)
420 set_active_framebuffer(0);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800421 gl->colorBuffer(gl, &gr_mem_surface);
422
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800423 gl->activeTexture(gl, 0);
424 gl->enable(gl, GGL_BLEND);
425 gl->blendFunc(gl, GGL_SRC_ALPHA, GGL_ONE_MINUS_SRC_ALPHA);
426
Doug Zongkerf6abd402011-09-27 13:09:48 -0700427 gr_fb_blank(true);
428 gr_fb_blank(false);
429
Dees Troy62b75ab2014-05-02 13:20:33 +0000430 if (!alloc_ion_mem(fi.line_length * vi.yres))
431 allocate_overlay(gr_fb_fd, gr_framebuffer);
432
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800433 return 0;
434}
435
436void gr_exit(void)
437{
Dees Troy62b75ab2014-05-02 13:20:33 +0000438 free_overlay(gr_fb_fd);
439 free_ion_mem();
440
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800441 close(gr_fb_fd);
442 gr_fb_fd = -1;
443
444 free(gr_mem_surface.data);
445
446 ioctl(gr_vt_fd, KDSETMODE, (void*) KD_TEXT);
447 close(gr_vt_fd);
448 gr_vt_fd = -1;
449}
450
451int gr_fb_width(void)
452{
Doug Zongkerc560a672012-12-18 16:31:27 -0800453 return gr_framebuffer[0].width - 2*overscan_offset_x;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800454}
455
456int gr_fb_height(void)
457{
Doug Zongkerc560a672012-12-18 16:31:27 -0800458 return gr_framebuffer[0].height - 2*overscan_offset_y;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800459}
460
461gr_pixel *gr_fb_data(void)
462{
463 return (unsigned short *) gr_mem_surface.data;
464}
Dima Zavin4daf48a2011-08-30 11:59:20 -0700465
466void gr_fb_blank(bool blank)
467{
Matt Mower4a5db2d2014-01-20 16:14:25 -0600468#if defined(TW_NO_SCREEN_BLANK) && defined(TW_BRIGHTNESS_PATH) && defined(TW_MAX_BRIGHTNESS)
Ethan Chen0940e412013-10-22 13:48:50 -0700469 int fd;
Matt Mower4a5db2d2014-01-20 16:14:25 -0600470 char brightness[4];
471 snprintf(brightness, 4, "%03d", TW_MAX_BRIGHTNESS/2);
Ethan Chen0940e412013-10-22 13:48:50 -0700472
Matt Mower4a5db2d2014-01-20 16:14:25 -0600473 fd = open(TW_BRIGHTNESS_PATH, O_RDWR);
Ethan Chen0940e412013-10-22 13:48:50 -0700474 if (fd < 0) {
475 perror("cannot open LCD backlight");
476 return;
477 }
Matt Mower4a5db2d2014-01-20 16:14:25 -0600478 write(fd, blank ? "000" : brightness, 3);
Ethan Chen0940e412013-10-22 13:48:50 -0700479 close(fd);
480#else
Dima Zavin4daf48a2011-08-30 11:59:20 -0700481 int ret;
Dees Troy62b75ab2014-05-02 13:20:33 +0000482 if (blank)
483 free_overlay(gr_fb_fd);
Dima Zavin4daf48a2011-08-30 11:59:20 -0700484
485 ret = ioctl(gr_fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
486 if (ret < 0)
487 perror("ioctl(): blank");
Dees Troy62b75ab2014-05-02 13:20:33 +0000488
489 if (!blank)
490 allocate_overlay(gr_fb_fd, gr_framebuffer);
Ethan Chen0940e412013-10-22 13:48:50 -0700491#endif
Dima Zavin4daf48a2011-08-30 11:59:20 -0700492}
Dees Troy62b75ab2014-05-02 13:20:33 +0000493
494void gr_get_memory_surface(gr_surface surface)
495{
496 get_memory_surface( (GGLSurface*) surface);
497}