blob: b4efae421d2b19223b53c3c376e5215fbaa43062 [file] [log] [blame]
Ethan Yonkerfbb43532015-12-28 21:54:50 +01001/*
2 * Copyright (C) 2014 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#include <stdbool.h>
18#include <stdlib.h>
19#include <string.h>
20#include <unistd.h>
21#include <errno.h>
22
23#include <fcntl.h>
24#include <stdio.h>
25
26#include <sys/cdefs.h>
27#include <sys/ioctl.h>
28#include <sys/mman.h>
29#include <sys/types.h>
30
31#include <linux/fb.h>
32#include <linux/kd.h>
33
34#ifdef MSM_BSP
35#include <linux/msm_mdp.h>
36#include <linux/msm_ion.h>
37#endif
38
39#include "minui.h"
40#include "graphics.h"
41#include <pixelflinger/pixelflinger.h>
42
43#define MDP_V4_0 400
44#define MAX_DISPLAY_DIM 2048
45
46static GRSurface* overlay_init(minui_backend*);
47static GRSurface* overlay_flip(minui_backend*);
48static void overlay_blank(minui_backend*, bool);
49static void overlay_exit(minui_backend*);
50
51static GRSurface gr_framebuffer;
52static GRSurface* gr_draw = NULL;
Ethan Yonkerfbb43532015-12-28 21:54:50 +010053
54static fb_var_screeninfo vi;
55static int fb_fd = -1;
56static bool isMDP5 = false;
57static int leftSplit = 0;
58static int rightSplit = 0;
59#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
60
61static size_t frame_size = 0;
62
63#ifdef MSM_BSP
64typedef struct {
65 unsigned char *mem_buf;
66 int size;
67 int ion_fd;
68 int mem_fd;
69 struct ion_handle_data handle_data;
70} memInfo;
71
72//Left and right overlay id
73static int overlayL_id = MSMFB_NEW_REQUEST;
74static int overlayR_id = MSMFB_NEW_REQUEST;
75
76static memInfo mem_info;
77
78static int map_mdp_pixel_format()
79{
80 if (gr_framebuffer.format == GGL_PIXEL_FORMAT_RGB_565)
81 return MDP_RGB_565;
82 else if (gr_framebuffer.format == GGL_PIXEL_FORMAT_BGRA_8888)
83 return MDP_BGRA_8888;
84 else if (gr_framebuffer.format == GGL_PIXEL_FORMAT_RGBA_8888)
85 return MDP_RGBA_8888;
86 else if (gr_framebuffer.format == GGL_PIXEL_FORMAT_RGBX_8888)
87 return MDP_RGBA_8888;
88 printf("No known pixel format for map_mdp_pixel_format, defaulting to MDP_RGB_565.\n");
89 return MDP_RGB_565;
90}
91#endif // MSM_BSP
92
93static minui_backend my_backend = {
94 .init = overlay_init,
95 .flip = overlay_flip,
96 .blank = overlay_blank,
97 .exit = overlay_exit,
98};
99
100bool target_has_overlay(char *version)
101{
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100102 int mdp_version;
103 bool overlay_supported = false;
104
105 if (strlen(version) >= 8) {
106 if(!strncmp(version, "msmfb", strlen("msmfb"))) {
107 char str_ver[4];
108 memcpy(str_ver, version + strlen("msmfb"), 3);
109 str_ver[3] = '\0';
110 mdp_version = atoi(str_ver);
111 if (mdp_version >= MDP_V4_0) {
112 overlay_supported = true;
113 }
114 } else if (!strncmp(version, "mdssfb", strlen("mdssfb"))) {
115 overlay_supported = true;
116 isMDP5 = true;
117 }
118 }
119
120 return overlay_supported;
121}
122
123minui_backend* open_overlay() {
124 fb_fix_screeninfo fi;
125 int fd;
126
127 fd = open("/dev/graphics/fb0", O_RDWR);
128 if (fd < 0) {
129 perror("open_overlay cannot open fb0");
130 return NULL;
131 }
132
133 if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
134 perror("failed to get fb0 info");
135 close(fd);
136 return NULL;
137 }
138
139 if (target_has_overlay(fi.id)) {
140#ifdef MSM_BSP
141 close(fd);
142 return &my_backend;
143#else
144 printf("Overlay graphics may work (%s), but not enabled. Use TW_TARGET_USES_QCOM_BSP := true to enable.\n", fi.id);
145#endif
146 }
147 close(fd);
148 return NULL;
149}
150
151static void overlay_blank(minui_backend* backend __unused, bool blank)
152{
153#if defined(TW_NO_SCREEN_BLANK) && defined(TW_BRIGHTNESS_PATH) && defined(TW_MAX_BRIGHTNESS)
154 int fd;
155 char brightness[4];
156 snprintf(brightness, 4, "%03d", TW_MAX_BRIGHTNESS/2);
157
158 fd = open(TW_BRIGHTNESS_PATH, O_RDWR);
159 if (fd < 0) {
160 perror("cannot open LCD backlight");
161 return;
162 }
163 write(fd, blank ? "000" : brightness, 3);
164 close(fd);
AdrianDC2948b6f2016-02-07 03:44:44 +0100165
166#ifdef TW_SECONDARY_BRIGHTNESS_PATH
167 fd = open(TW_SECONDARY_BRIGHTNESS_PATH, O_RDWR);
168 if (fd < 0) {
169 perror("cannot open LCD backlight 2");
170 return;
171 }
172 write(fd, blank ? "000" : brightness, 3);
173 close(fd);
174#endif
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100175#else
176 int ret;
177
178 ret = ioctl(fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
179 if (ret < 0)
180 perror("ioctl(): blank");
181#endif
182}
183
184#ifdef MSM_BSP
185void setDisplaySplit(void) {
186 char split[64] = {0};
187 if (!isMDP5)
188 return;
189 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
190 if (fp) {
191 //Format "left right" space as delimiter
192 if(fread(split, sizeof(char), 64, fp)) {
193 leftSplit = atoi(split);
194 printf("Left Split=%d\n",leftSplit);
195 char *rght = strpbrk(split, " ");
196 if (rght)
197 rightSplit = atoi(rght + 1);
198 printf("Right Split=%d\n", rightSplit);
199 }
200 } else {
201 printf("Failed to open mdss_fb_split node\n");
202 }
203 if (fp)
204 fclose(fp);
205}
206
207int getLeftSplit(void) {
208 //Default even split for all displays with high res
209 int lSplit = vi.xres / 2;
210
211 //Override if split published by driver
212 if (leftSplit)
213 lSplit = leftSplit;
214
215 return lSplit;
216}
217
218int getRightSplit(void) {
219 return rightSplit;
220}
221
222int free_ion_mem(void) {
223 int ret = 0;
224
225 if (mem_info.mem_buf)
226 munmap(mem_info.mem_buf, mem_info.size);
227
228 if (mem_info.ion_fd >= 0) {
229 ret = ioctl(mem_info.ion_fd, ION_IOC_FREE, &mem_info.handle_data);
230 if (ret < 0)
231 perror("free_mem failed ");
232 }
233
234 if (mem_info.mem_fd >= 0)
235 close(mem_info.mem_fd);
236 if (mem_info.ion_fd >= 0)
237 close(mem_info.ion_fd);
238
239 memset(&mem_info, 0, sizeof(mem_info));
240 mem_info.mem_fd = -1;
241 mem_info.ion_fd = -1;
242 return 0;
243}
244
245int alloc_ion_mem(unsigned int size)
246{
247 int result;
248 struct ion_fd_data fd_data;
249 struct ion_allocation_data ionAllocData;
250
251 mem_info.ion_fd = open("/dev/ion", O_RDWR|O_DSYNC);
252 if (mem_info.ion_fd < 0) {
253 perror("ERROR: Can't open ion ");
254 return -errno;
255 }
256
257 ionAllocData.flags = 0;
258 ionAllocData.len = size;
259 ionAllocData.align = sysconf(_SC_PAGESIZE);
260#ifdef NEW_ION_HEAP
261 ionAllocData.heap_id_mask =
262#else
263 ionAllocData.heap_mask =
264#endif
265 ION_HEAP(ION_IOMMU_HEAP_ID) |
266 ION_HEAP(ION_SYSTEM_CONTIG_HEAP_ID);
267
268 result = ioctl(mem_info.ion_fd, ION_IOC_ALLOC, &ionAllocData);
269 if(result){
270 perror("ION_IOC_ALLOC Failed ");
271 close(mem_info.ion_fd);
272 return result;
273 }
274
275 fd_data.handle = ionAllocData.handle;
276 mem_info.handle_data.handle = ionAllocData.handle;
277 result = ioctl(mem_info.ion_fd, ION_IOC_MAP, &fd_data);
278 if (result) {
279 perror("ION_IOC_MAP Failed ");
280 free_ion_mem();
281 return result;
282 }
283 mem_info.mem_buf = (unsigned char *)mmap(NULL, size, PROT_READ |
284 PROT_WRITE, MAP_SHARED, fd_data.fd, 0);
285 mem_info.mem_fd = fd_data.fd;
286
287 if (!mem_info.mem_buf) {
288 perror("ERROR: mem_buf MAP_FAILED ");
289 free_ion_mem();
290 return -ENOMEM;
291 }
292
293 return 0;
294}
295
296bool isDisplaySplit(void) {
297 if (vi.xres > MAX_DISPLAY_DIM)
298 return true;
299 //check if right split is set by driver
300 if (getRightSplit())
301 return true;
302
303 return false;
304}
305
306int allocate_overlay(int fd, GRSurface gr_fb)
307{
308 int ret = 0;
309
310 if (!isDisplaySplit()) {
311 // Check if overlay is already allocated
312 if (MSMFB_NEW_REQUEST == overlayL_id) {
313 struct mdp_overlay overlayL;
314
315 memset(&overlayL, 0 , sizeof (struct mdp_overlay));
316
317 /* Fill Overlay Data */
318 overlayL.src.width = ALIGN(gr_fb.width, 32);
319 overlayL.src.height = gr_fb.height;
320 overlayL.src.format = map_mdp_pixel_format();
321 overlayL.src_rect.w = gr_fb.width;
322 overlayL.src_rect.h = gr_fb.height;
323 overlayL.dst_rect.w = gr_fb.width;
324 overlayL.dst_rect.h = gr_fb.height;
325 overlayL.alpha = 0xFF;
xadro7509bc52016-01-30 21:30:12 +0100326#ifdef BOARD_HAS_FLIPPED_SCREEN
327 overlayL.flags = MDP_ROT_180;
328#endif
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100329 overlayL.transp_mask = MDP_TRANSP_NOP;
330 overlayL.id = MSMFB_NEW_REQUEST;
331 ret = ioctl(fd, MSMFB_OVERLAY_SET, &overlayL);
332 if (ret < 0) {
333 perror("Overlay Set Failed");
334 return ret;
335 }
336 overlayL_id = overlayL.id;
337 }
338 } else {
339 float xres = vi.xres;
340 int lSplit = getLeftSplit();
341 float lSplitRatio = lSplit / xres;
342 float lCropWidth = gr_fb.width * lSplitRatio;
343 int lWidth = lSplit;
344 int rWidth = gr_fb.width - lSplit;
345 int height = gr_fb.height;
346
347 if (MSMFB_NEW_REQUEST == overlayL_id) {
348
349 struct mdp_overlay overlayL;
350
351 memset(&overlayL, 0 , sizeof (struct mdp_overlay));
352
353 /* Fill OverlayL Data */
354 overlayL.src.width = ALIGN(gr_fb.width, 32);
355 overlayL.src.height = gr_fb.height;
356 overlayL.src.format = map_mdp_pixel_format();
357 overlayL.src_rect.x = 0;
358 overlayL.src_rect.y = 0;
359 overlayL.src_rect.w = lCropWidth;
360 overlayL.src_rect.h = gr_fb.height;
361 overlayL.dst_rect.x = 0;
362 overlayL.dst_rect.y = 0;
363 overlayL.dst_rect.w = lWidth;
364 overlayL.dst_rect.h = height;
365 overlayL.alpha = 0xFF;
xadro7509bc52016-01-30 21:30:12 +0100366#ifdef BOARD_HAS_FLIPPED_SCREEN
367 overlayL.flags = MDP_ROT_180;
368#endif
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100369 overlayL.transp_mask = MDP_TRANSP_NOP;
370 overlayL.id = MSMFB_NEW_REQUEST;
371 ret = ioctl(fd, MSMFB_OVERLAY_SET, &overlayL);
372 if (ret < 0) {
373 perror("OverlayL Set Failed");
374 return ret;
375 }
376 overlayL_id = overlayL.id;
377 }
378 if (MSMFB_NEW_REQUEST == overlayR_id) {
379 struct mdp_overlay overlayR;
380
381 memset(&overlayR, 0 , sizeof (struct mdp_overlay));
382
383 /* Fill OverlayR Data */
384 overlayR.src.width = ALIGN(gr_fb.width, 32);
385 overlayR.src.height = gr_fb.height;
386 overlayR.src.format = map_mdp_pixel_format();
387 overlayR.src_rect.x = lCropWidth;
388 overlayR.src_rect.y = 0;
389 overlayR.src_rect.w = gr_fb.width - lCropWidth;
390 overlayR.src_rect.h = gr_fb.height;
391 overlayR.dst_rect.x = 0;
392 overlayR.dst_rect.y = 0;
393 overlayR.dst_rect.w = rWidth;
394 overlayR.dst_rect.h = height;
395 overlayR.alpha = 0xFF;
xadro7509bc52016-01-30 21:30:12 +0100396#ifdef BOARD_HAS_FLIPPED_SCREEN
397 overlayR.flags = MDSS_MDP_RIGHT_MIXER | MDP_ROT_180;
398#else
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100399 overlayR.flags = MDSS_MDP_RIGHT_MIXER;
xadro7509bc52016-01-30 21:30:12 +0100400#endif
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100401 overlayR.transp_mask = MDP_TRANSP_NOP;
402 overlayR.id = MSMFB_NEW_REQUEST;
403 ret = ioctl(fd, MSMFB_OVERLAY_SET, &overlayR);
404 if (ret < 0) {
405 perror("OverlayR Set Failed");
406 return ret;
407 }
408 overlayR_id = overlayR.id;
409 }
410
411 }
412 return 0;
413}
414
415int overlay_display_frame(int fd, void* data, size_t size)
416{
417 int ret = 0;
418 struct msmfb_overlay_data ovdataL, ovdataR;
419 struct mdp_display_commit ext_commit;
420
421 if (!isDisplaySplit()) {
422 if (overlayL_id == MSMFB_NEW_REQUEST) {
423 perror("display_frame failed, no overlay\n");
424 return -EINVAL;
425 }
426
427 memcpy(mem_info.mem_buf, data, size);
428
429 memset(&ovdataL, 0, sizeof(struct msmfb_overlay_data));
430
431 ovdataL.id = overlayL_id;
432 ovdataL.data.flags = 0;
433 ovdataL.data.offset = 0;
434 ovdataL.data.memory_id = mem_info.mem_fd;
435 ret = ioctl(fd, MSMFB_OVERLAY_PLAY, &ovdataL);
436 if (ret < 0) {
437 perror("overlay_display_frame failed, overlay play Failed\n");
438 printf("%i, %i, %i, %i\n", ret, fb_fd, fd, errno);
439 return ret;
440 }
441 } else {
442
443 if (overlayL_id == MSMFB_NEW_REQUEST) {
444 perror("display_frame failed, no overlayL \n");
445 return -EINVAL;
446 }
447
448 memcpy(mem_info.mem_buf, data, size);
449
450 memset(&ovdataL, 0, sizeof(struct msmfb_overlay_data));
451
452 ovdataL.id = overlayL_id;
453 ovdataL.data.flags = 0;
454 ovdataL.data.offset = 0;
455 ovdataL.data.memory_id = mem_info.mem_fd;
456 ret = ioctl(fd, MSMFB_OVERLAY_PLAY, &ovdataL);
457 if (ret < 0) {
458 perror("overlay_display_frame failed, overlayL play Failed\n");
459 return ret;
460 }
461
462 if (overlayR_id == MSMFB_NEW_REQUEST) {
463 perror("display_frame failed, no overlayR \n");
464 return -EINVAL;
465 }
466 memset(&ovdataR, 0, sizeof(struct msmfb_overlay_data));
467
468 ovdataR.id = overlayR_id;
469 ovdataR.data.flags = 0;
470 ovdataR.data.offset = 0;
471 ovdataR.data.memory_id = mem_info.mem_fd;
472 ret = ioctl(fd, MSMFB_OVERLAY_PLAY, &ovdataR);
473 if (ret < 0) {
474 perror("overlay_display_frame failed, overlayR play Failed\n");
475 return ret;
476 }
477 }
478 memset(&ext_commit, 0, sizeof(struct mdp_display_commit));
479 ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY;
480 ext_commit.wait_for_finish = 1;
481 ret = ioctl(fd, MSMFB_DISPLAY_COMMIT, &ext_commit);
482 if (ret < 0) {
483 perror("overlay_display_frame failed, overlay commit Failed\n!");
484 }
485
486 return ret;
487}
488
489static GRSurface* overlay_flip(minui_backend* backend __unused) {
490#if defined(RECOVERY_BGRA)
491 // In case of BGRA, do some byte swapping
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100492 unsigned char* ucfb_vaddr = (unsigned char*)gr_draw->data;
Simon Shifcfc6342019-01-16 13:27:01 +0800493 for (int idx = 0 ; idx < (gr_draw->height * gr_draw->row_bytes);
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100494 idx += 4) {
Simon Shifcfc6342019-01-16 13:27:01 +0800495 unsigned char tmp = ucfb_vaddr[idx];
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100496 ucfb_vaddr[idx ] = ucfb_vaddr[idx + 2];
497 ucfb_vaddr[idx + 2] = tmp;
498 }
499#endif
500 // Copy from the in-memory surface to the framebuffer.
501 overlay_display_frame(fb_fd, gr_draw->data, frame_size);
502 return gr_draw;
503}
504
505int free_overlay(int fd)
506{
507 int ret = 0;
508 struct mdp_display_commit ext_commit;
509
510 if (!isDisplaySplit()) {
511 if (overlayL_id != MSMFB_NEW_REQUEST) {
512 ret = ioctl(fd, MSMFB_OVERLAY_UNSET, &overlayL_id);
513 if (ret) {
514 perror("Overlay Unset Failed");
515 overlayL_id = MSMFB_NEW_REQUEST;
516 return ret;
517 }
518 }
519 } else {
520
521 if (overlayL_id != MSMFB_NEW_REQUEST) {
522 ret = ioctl(fd, MSMFB_OVERLAY_UNSET, &overlayL_id);
523 if (ret) {
524 perror("OverlayL Unset Failed");
525 }
526 }
527
528 if (overlayR_id != MSMFB_NEW_REQUEST) {
529 ret = ioctl(fd, MSMFB_OVERLAY_UNSET, &overlayR_id);
530 if (ret) {
531 perror("OverlayR Unset Failed");
532 overlayR_id = MSMFB_NEW_REQUEST;
533 return ret;
534 }
535 }
536 }
537 memset(&ext_commit, 0, sizeof(struct mdp_display_commit));
538 ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY;
539 ext_commit.wait_for_finish = 1;
540 ret = ioctl(fd, MSMFB_DISPLAY_COMMIT, &ext_commit);
541 if (ret < 0) {
542 perror("ERROR: Clear MSMFB_DISPLAY_COMMIT failed!");
543 overlayL_id = MSMFB_NEW_REQUEST;
544 overlayR_id = MSMFB_NEW_REQUEST;
545 return ret;
546 }
547 overlayL_id = MSMFB_NEW_REQUEST;
548 overlayR_id = MSMFB_NEW_REQUEST;
549
550 return 0;
551}
552
553static GRSurface* overlay_init(minui_backend* backend) {
554 int fd = open("/dev/graphics/fb0", O_RDWR);
555 if (fd == -1) {
556 perror("cannot open fb0");
557 return NULL;
558 }
559
560 fb_fix_screeninfo fi;
561 if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
562 perror("failed to get fb0 info");
563 close(fd);
564 return NULL;
565 }
566
567 if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) {
568 perror("failed to get fb0 info");
569 close(fd);
570 return NULL;
571 }
572
573 // We print this out for informational purposes only, but
574 // throughout we assume that the framebuffer device uses an RGBX
575 // pixel format. This is the case for every development device I
576 // have access to. For some of those devices (eg, hammerhead aka
577 // Nexus 5), FBIOGET_VSCREENINFO *reports* that it wants a
578 // different format (XBGR) but actually produces the correct
579 // results on the display when you write RGBX.
580 //
581 // If you have a device that actually *needs* another pixel format
582 // (ie, BGRX, or 565), patches welcome...
583
584 printf("fb0 reports (possibly inaccurate):\n"
585 " vi.bits_per_pixel = %d\n"
586 " vi.red.offset = %3d .length = %3d\n"
587 " vi.green.offset = %3d .length = %3d\n"
588 " vi.blue.offset = %3d .length = %3d\n",
589 vi.bits_per_pixel,
590 vi.red.offset, vi.red.length,
591 vi.green.offset, vi.green.length,
592 vi.blue.offset, vi.blue.length);
593
594 gr_framebuffer.width = vi.xres;
595 gr_framebuffer.height = vi.yres;
596 gr_framebuffer.row_bytes = fi.line_length;
597 gr_framebuffer.pixel_bytes = vi.bits_per_pixel / 8;
598 //gr_framebuffer.data = reinterpret_cast<uint8_t*>(bits);
599 if (vi.bits_per_pixel == 16) {
600 printf("setting GGL_PIXEL_FORMAT_RGB_565\n");
601 gr_framebuffer.format = GGL_PIXEL_FORMAT_RGB_565;
Ziyan4fea38a2016-01-28 01:19:35 +0100602 } else if (vi.red.offset == 8 || vi.red.offset == 16) {
Ethan Yonkerfbb43532015-12-28 21:54:50 +0100603 printf("setting GGL_PIXEL_FORMAT_BGRA_8888\n");
604 gr_framebuffer.format = GGL_PIXEL_FORMAT_BGRA_8888;
605 } else if (vi.red.offset == 0) {
606 printf("setting GGL_PIXEL_FORMAT_RGBA_8888\n");
607 gr_framebuffer.format = GGL_PIXEL_FORMAT_RGBA_8888;
608 } else if (vi.red.offset == 24) {
609 printf("setting GGL_PIXEL_FORMAT_RGBX_8888\n");
610 gr_framebuffer.format = GGL_PIXEL_FORMAT_RGBX_8888;
611 } else {
612 if (vi.red.length == 8) {
613 printf("No valid pixel format detected, trying GGL_PIXEL_FORMAT_RGBX_8888\n");
614 gr_framebuffer.format = GGL_PIXEL_FORMAT_RGBX_8888;
615 } else {
616 printf("No valid pixel format detected, trying GGL_PIXEL_FORMAT_RGB_565\n");
617 gr_framebuffer.format = GGL_PIXEL_FORMAT_RGB_565;
618 }
619 }
620
621 frame_size = fi.line_length * vi.yres;
622
623 gr_framebuffer.data = reinterpret_cast<uint8_t*>(calloc(frame_size, 1));
624 if (gr_framebuffer.data == NULL) {
625 perror("failed to calloc framebuffer");
626 close(fd);
627 return NULL;
628 }
629
630 gr_draw = &gr_framebuffer;
631 fb_fd = fd;
632
633 printf("framebuffer: %d (%d x %d)\n", fb_fd, gr_draw->width, gr_draw->height);
634
635 overlay_blank(backend, true);
636 overlay_blank(backend, false);
637
638 if (!alloc_ion_mem(frame_size))
639 allocate_overlay(fb_fd, gr_framebuffer);
640
641 return gr_draw;
642}
643
644static void overlay_exit(minui_backend* backend __unused) {
645 free_overlay(fb_fd);
646 free_ion_mem();
647
648 close(fb_fd);
649 fb_fd = -1;
650
651 if (gr_draw) {
652 free(gr_draw->data);
653 free(gr_draw);
654 }
655 gr_draw = NULL;
656}
657#else // MSM_BSP
658static GRSurface* overlay_flip(minui_backend* backend __unused) {
659 return NULL;
660}
661
662static GRSurface* overlay_init(minui_backend* backend __unused) {
663 return NULL;
664}
665
666static void overlay_exit(minui_backend* backend __unused) {
667 return;
668}
669#endif // MSM_BSP