Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdbool.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 21 | #include <errno.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | #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 | |
| 34 | #include "minui.h" |
| 35 | |
| 36 | #ifdef BOARD_USE_CUSTOM_RECOVERY_FONT |
| 37 | #include BOARD_USE_CUSTOM_RECOVERY_FONT |
| 38 | #else |
| 39 | #include "font_10x18.h" |
| 40 | #endif |
| 41 | |
| 42 | #ifdef RECOVERY_BGRA |
| 43 | #define PIXEL_FORMAT GGL_PIXEL_FORMAT_BGRA_8888 |
| 44 | #define PIXEL_SIZE 4 |
| 45 | #endif |
| 46 | #ifdef RECOVERY_RGBX |
| 47 | #define PIXEL_FORMAT GGL_PIXEL_FORMAT_RGBX_8888 |
| 48 | #define PIXEL_SIZE 4 |
| 49 | #endif |
| 50 | #ifndef PIXEL_FORMAT |
| 51 | #define PIXEL_FORMAT GGL_PIXEL_FORMAT_RGB_565 |
| 52 | #define PIXEL_SIZE 2 |
| 53 | #endif |
| 54 | |
Hiemanshu Sharma | acf6a9b | 2012-11-21 11:28:36 -0600 | [diff] [blame] | 55 | #define NUM_BUFFERS 2 |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 56 | #define MAX_DISPLAY_DIM 2048 |
Hiemanshu Sharma | acf6a9b | 2012-11-21 11:28:36 -0600 | [diff] [blame] | 57 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 58 | // #define PRINT_SCREENINFO 1 // Enables printing of screen info to log |
| 59 | |
| 60 | typedef struct { |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 61 | int type; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 62 | GGLSurface texture; |
| 63 | unsigned offset[97]; |
| 64 | unsigned cheight; |
| 65 | unsigned ascent; |
| 66 | } GRFont; |
| 67 | |
| 68 | static GRFont *gr_font = 0; |
| 69 | static GGLContext *gr_context = 0; |
| 70 | static GGLSurface gr_font_texture; |
Hiemanshu Sharma | acf6a9b | 2012-11-21 11:28:36 -0600 | [diff] [blame] | 71 | static GGLSurface gr_framebuffer[NUM_BUFFERS]; |
Vojtech Bocek | 03fd6c5 | 2014-03-13 18:46:34 +0100 | [diff] [blame] | 72 | GGLSurface gr_mem_surface; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | static unsigned gr_active_fb = 0; |
Hiemanshu Sharma | 94f6c88 | 2012-11-21 11:25:22 -0600 | [diff] [blame] | 74 | static unsigned double_buffering = 0; |
Vojtech Bocek | 1a4744a | 2014-02-06 19:52:28 +0100 | [diff] [blame] | 75 | static int gr_is_curr_clr_opaque = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
| 77 | static int gr_fb_fd = -1; |
| 78 | static int gr_vt_fd = -1; |
| 79 | |
Vojtech Bocek | 03fd6c5 | 2014-03-13 18:46:34 +0100 | [diff] [blame] | 80 | struct fb_var_screeninfo vi; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | static struct fb_fix_screeninfo fi; |
| 82 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 83 | static bool has_overlay = false; |
| 84 | static int leftSplit = 0; |
| 85 | static int rightSplit = 0; |
| 86 | |
| 87 | bool target_has_overlay(char *version); |
| 88 | int free_ion_mem(void); |
| 89 | int alloc_ion_mem(unsigned int size); |
| 90 | int allocate_overlay(int fd, GGLSurface gr_fb[]); |
| 91 | int free_overlay(int fd); |
| 92 | int overlay_display_frame(int fd, GGLubyte* data, size_t size); |
| 93 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 94 | #ifdef PRINT_SCREENINFO |
| 95 | static void print_fb_var_screeninfo() |
| 96 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 97 | printf("vi.xres: %d\n", vi.xres); |
| 98 | printf("vi.yres: %d\n", vi.yres); |
| 99 | printf("vi.xres_virtual: %d\n", vi.xres_virtual); |
| 100 | printf("vi.yres_virtual: %d\n", vi.yres_virtual); |
| 101 | printf("vi.xoffset: %d\n", vi.xoffset); |
| 102 | printf("vi.yoffset: %d\n", vi.yoffset); |
| 103 | printf("vi.bits_per_pixel: %d\n", vi.bits_per_pixel); |
| 104 | printf("vi.grayscale: %d\n", vi.grayscale); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | } |
| 106 | #endif |
| 107 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 108 | #ifdef MSM_BSP |
| 109 | int getLeftSplit(void) { |
| 110 | //Default even split for all displays with high res |
| 111 | int lSplit = vi.xres / 2; |
| 112 | |
| 113 | //Override if split published by driver |
| 114 | if (leftSplit) |
| 115 | lSplit = leftSplit; |
| 116 | |
| 117 | return lSplit; |
| 118 | } |
| 119 | |
| 120 | int getRightSplit(void) { |
| 121 | return rightSplit; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void setDisplaySplit(void) { |
| 126 | char split[64] = {0}; |
| 127 | FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r"); |
| 128 | if (fp) { |
| 129 | //Format "left right" space as delimiter |
| 130 | if(fread(split, sizeof(char), 64, fp)) { |
| 131 | leftSplit = atoi(split); |
| 132 | printf("Left Split=%d\n",leftSplit); |
| 133 | char *rght = strpbrk(split, " "); |
| 134 | if (rght) |
| 135 | rightSplit = atoi(rght + 1); |
| 136 | printf("Right Split=%d\n", rightSplit); |
| 137 | } |
| 138 | } else { |
| 139 | printf("Failed to open mdss_fb_split node\n"); |
| 140 | } |
| 141 | if (fp) |
| 142 | fclose(fp); |
| 143 | } |
| 144 | |
| 145 | bool isDisplaySplit(void) { |
| 146 | if (vi.xres > MAX_DISPLAY_DIM) |
| 147 | return true; |
| 148 | //check if right split is set by driver |
| 149 | if (getRightSplit()) |
| 150 | return true; |
| 151 | |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | int getFbXres(void) { |
| 156 | return vi.xres; |
| 157 | } |
| 158 | |
| 159 | int getFbYres (void) { |
| 160 | return vi.yres; |
| 161 | } |
| 162 | #endif // MSM_BSP |
| 163 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 164 | static int get_framebuffer(GGLSurface *fb) |
| 165 | { |
| 166 | int fd; |
| 167 | void *bits; |
| 168 | |
| 169 | fd = open("/dev/graphics/fb0", O_RDWR); |
| 170 | if (fd < 0) { |
| 171 | perror("cannot open fb0"); |
| 172 | return -1; |
| 173 | } |
| 174 | |
| 175 | if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) { |
| 176 | perror("failed to get fb0 info"); |
| 177 | close(fd); |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | fprintf(stderr, "Pixel format: %dx%d @ %dbpp\n", vi.xres, vi.yres, vi.bits_per_pixel); |
| 182 | |
| 183 | vi.bits_per_pixel = PIXEL_SIZE * 8; |
| 184 | if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_BGRA_8888) { |
| 185 | fprintf(stderr, "Pixel format: BGRA_8888\n"); |
| 186 | if (PIXEL_SIZE != 4) fprintf(stderr, "E: Pixel Size mismatch!\n"); |
| 187 | vi.red.offset = 8; |
| 188 | vi.red.length = 8; |
| 189 | vi.green.offset = 16; |
| 190 | vi.green.length = 8; |
| 191 | vi.blue.offset = 24; |
| 192 | vi.blue.length = 8; |
| 193 | vi.transp.offset = 0; |
| 194 | vi.transp.length = 8; |
| 195 | } else if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_RGBX_8888) { |
| 196 | fprintf(stderr, "Pixel format: RGBX_8888\n"); |
| 197 | if (PIXEL_SIZE != 4) fprintf(stderr, "E: Pixel Size mismatch!\n"); |
| 198 | vi.red.offset = 24; |
| 199 | vi.red.length = 8; |
| 200 | vi.green.offset = 16; |
| 201 | vi.green.length = 8; |
| 202 | vi.blue.offset = 8; |
| 203 | vi.blue.length = 8; |
| 204 | vi.transp.offset = 0; |
| 205 | vi.transp.length = 8; |
| 206 | } else if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_RGB_565) { |
| 207 | #ifdef RECOVERY_RGB_565 |
| 208 | fprintf(stderr, "Pixel format: RGB_565\n"); |
| 209 | vi.blue.offset = 0; |
| 210 | vi.green.offset = 5; |
| 211 | vi.red.offset = 11; |
| 212 | #else |
| 213 | fprintf(stderr, "Pixel format: BGR_565\n"); |
| 214 | vi.blue.offset = 11; |
| 215 | vi.green.offset = 5; |
| 216 | vi.red.offset = 0; |
| 217 | #endif |
| 218 | if (PIXEL_SIZE != 2) fprintf(stderr, "E: Pixel Size mismatch!\n"); |
| 219 | vi.blue.length = 5; |
| 220 | vi.green.length = 6; |
| 221 | vi.red.length = 5; |
| 222 | vi.blue.msb_right = 0; |
| 223 | vi.green.msb_right = 0; |
| 224 | vi.red.msb_right = 0; |
| 225 | vi.transp.offset = 0; |
| 226 | vi.transp.length = 0; |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | perror("unknown pixel format"); |
| 231 | close(fd); |
| 232 | return -1; |
| 233 | } |
| 234 | |
| 235 | vi.vmode = FB_VMODE_NONINTERLACED; |
| 236 | vi.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; |
| 237 | |
| 238 | if (ioctl(fd, FBIOPUT_VSCREENINFO, &vi) < 0) { |
| 239 | perror("failed to put fb0 info"); |
| 240 | close(fd); |
| 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) { |
| 245 | perror("failed to get fb0 info"); |
| 246 | close(fd); |
| 247 | return -1; |
| 248 | } |
| 249 | |
Dees Troy | b042538 | 2014-04-03 00:10:03 +0000 | [diff] [blame] | 250 | #ifdef MSM_BSP |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 251 | has_overlay = target_has_overlay(fi.id); |
| 252 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 253 | if (isTargetMdp5()) |
| 254 | setDisplaySplit(); |
Dees Troy | b042538 | 2014-04-03 00:10:03 +0000 | [diff] [blame] | 255 | #else |
| 256 | has_overlay = false; |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 257 | #endif |
| 258 | |
| 259 | if (!has_overlay) { |
| 260 | printf("Not using qualcomm overlay, '%s'\n", fi.id); |
| 261 | bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 262 | if (bits == MAP_FAILED) { |
| 263 | perror("failed to mmap framebuffer"); |
| 264 | close(fd); |
| 265 | return -1; |
| 266 | } |
| 267 | } else { |
| 268 | printf("Using qualcomm overlay\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | #ifdef RECOVERY_GRAPHICS_USE_LINELENGTH |
| 272 | vi.xres_virtual = fi.line_length / PIXEL_SIZE; |
| 273 | #endif |
| 274 | |
| 275 | fb->version = sizeof(*fb); |
| 276 | fb->width = vi.xres; |
| 277 | fb->height = vi.yres; |
| 278 | #ifdef BOARD_HAS_JANKY_BACKBUFFER |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 279 | printf("setting JANKY BACKBUFFER\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 280 | fb->stride = fi.line_length/2; |
| 281 | #else |
| 282 | fb->stride = vi.xres_virtual; |
| 283 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 284 | fb->format = PIXEL_FORMAT; |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 285 | if (!has_overlay) { |
| 286 | fb->data = bits; |
| 287 | memset(fb->data, 0, vi.yres * fb->stride * PIXEL_SIZE); |
| 288 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 289 | |
| 290 | fb++; |
| 291 | |
Hiemanshu Sharma | 94f6c88 | 2012-11-21 11:25:22 -0600 | [diff] [blame] | 292 | /* check if we can use double buffering */ |
| 293 | if (vi.yres * fi.line_length * 2 > fi.smem_len) |
| 294 | return fd; |
| 295 | |
| 296 | double_buffering = 1; |
| 297 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 298 | fb->version = sizeof(*fb); |
| 299 | fb->width = vi.xres; |
| 300 | fb->height = vi.yres; |
| 301 | #ifdef BOARD_HAS_JANKY_BACKBUFFER |
| 302 | fb->stride = fi.line_length/2; |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 303 | fb->data = (GGLubyte*) (((unsigned long) bits) + vi.yres * fi.line_length); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 304 | #else |
| 305 | fb->stride = vi.xres_virtual; |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 306 | fb->data = (GGLubyte*) (((unsigned long) bits) + vi.yres * fb->stride * PIXEL_SIZE); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 307 | #endif |
| 308 | fb->format = PIXEL_FORMAT; |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 309 | if (!has_overlay) { |
| 310 | memset(fb->data, 0, vi.yres * fb->stride * PIXEL_SIZE); |
| 311 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 312 | |
| 313 | #ifdef PRINT_SCREENINFO |
| 314 | print_fb_var_screeninfo(); |
| 315 | #endif |
| 316 | |
| 317 | return fd; |
| 318 | } |
| 319 | |
| 320 | static void get_memory_surface(GGLSurface* ms) { |
| 321 | ms->version = sizeof(*ms); |
| 322 | ms->width = vi.xres; |
| 323 | ms->height = vi.yres; |
| 324 | ms->stride = vi.xres_virtual; |
| 325 | ms->data = malloc(vi.xres_virtual * vi.yres * PIXEL_SIZE); |
| 326 | ms->format = PIXEL_FORMAT; |
| 327 | } |
| 328 | |
| 329 | static void set_active_framebuffer(unsigned n) |
| 330 | { |
Hiemanshu Sharma | 94f6c88 | 2012-11-21 11:25:22 -0600 | [diff] [blame] | 331 | if (n > 1 || !double_buffering) return; |
Hiemanshu Sharma | acf6a9b | 2012-11-21 11:28:36 -0600 | [diff] [blame] | 332 | vi.yres_virtual = vi.yres * NUM_BUFFERS; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 333 | vi.yoffset = n * vi.yres; |
| 334 | // vi.bits_per_pixel = PIXEL_SIZE * 8; |
| 335 | if (ioctl(gr_fb_fd, FBIOPUT_VSCREENINFO, &vi) < 0) { |
| 336 | perror("active fb swap failed"); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void gr_flip(void) |
| 341 | { |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 342 | if (-EINVAL == overlay_display_frame(gr_fb_fd, gr_mem_surface.data, |
| 343 | (fi.line_length * vi.yres))) { |
| 344 | GGLContext *gl = gr_context; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 345 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 346 | /* swap front and back buffers */ |
| 347 | if (double_buffering) |
| 348 | gr_active_fb = (gr_active_fb + 1) & 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 349 | |
| 350 | #ifdef BOARD_HAS_FLIPPED_SCREEN |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 351 | /* flip buffer 180 degrees for devices with physicaly inverted screens */ |
| 352 | unsigned int i; |
| 353 | unsigned int j; |
Bogdan Seniuc | d1372f7 | 2015-01-23 08:22:39 -0800 | [diff] [blame] | 354 | for (i = 0; i < vi.yres; i++) { |
| 355 | for (j = 0; j < vi.xres; j++) { |
| 356 | memcpy(gr_framebuffer[gr_active_fb].data + (i * vi.xres_virtual + j) * PIXEL_SIZE, |
| 357 | gr_mem_surface.data + ((vi.yres - i - 1) * vi.xres_virtual + vi.xres - j - 1) * PIXEL_SIZE, PIXEL_SIZE); |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 358 | } |
| 359 | } |
Bogdan Seniuc | d1372f7 | 2015-01-23 08:22:39 -0800 | [diff] [blame] | 360 | #else |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 361 | /* copy data from the in-memory surface to the buffer we're about |
| 362 | * to make active. */ |
| 363 | memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data, |
| 364 | vi.xres_virtual * vi.yres * PIXEL_SIZE); |
Bogdan Seniuc | d1372f7 | 2015-01-23 08:22:39 -0800 | [diff] [blame] | 365 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 366 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 367 | /* inform the display driver */ |
| 368 | set_active_framebuffer(gr_active_fb); |
| 369 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) |
| 373 | { |
| 374 | GGLContext *gl = gr_context; |
| 375 | GGLint color[4]; |
| 376 | color[0] = ((r << 8) | r) + 1; |
| 377 | color[1] = ((g << 8) | g) + 1; |
| 378 | color[2] = ((b << 8) | b) + 1; |
| 379 | color[3] = ((a << 8) | a) + 1; |
| 380 | gl->color4xv(gl, color); |
Vojtech Bocek | 1a4744a | 2014-02-06 19:52:28 +0100 | [diff] [blame] | 381 | |
| 382 | gr_is_curr_clr_opaque = (a == 255); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | int gr_measureEx(const char *s, void* font) |
| 386 | { |
| 387 | GRFont* fnt = (GRFont*) font; |
| 388 | int total = 0; |
| 389 | unsigned pos; |
| 390 | unsigned off; |
| 391 | |
| 392 | if (!fnt) fnt = gr_font; |
| 393 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 394 | #ifndef TW_DISABLE_TTF |
| 395 | if(fnt->type == FONT_TYPE_TTF) |
| 396 | return gr_ttf_measureEx(s, font); |
| 397 | #endif |
| 398 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 399 | while ((off = *s++)) |
| 400 | { |
| 401 | off -= 32; |
| 402 | if (off < 96) |
| 403 | total += (fnt->offset[off+1] - fnt->offset[off]); |
| 404 | } |
| 405 | return total; |
| 406 | } |
| 407 | |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 408 | int gr_maxExW(const char *s, void* font, int max_width) |
| 409 | { |
| 410 | GRFont* fnt = (GRFont*) font; |
| 411 | int total = 0; |
| 412 | unsigned pos; |
| 413 | unsigned off; |
| 414 | |
| 415 | if (!fnt) fnt = gr_font; |
| 416 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 417 | #ifndef TW_DISABLE_TTF |
| 418 | if(fnt->type == FONT_TYPE_TTF) |
| 419 | return gr_ttf_maxExW(s, font, max_width); |
| 420 | #endif |
| 421 | |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 422 | while ((off = *s++)) |
| 423 | { |
| 424 | off -= 32; |
| 425 | if (off < 96) { |
| 426 | max_width -= (fnt->offset[off+1] - fnt->offset[off]); |
| 427 | if (max_width > 0) { |
| 428 | total++; |
| 429 | } else { |
| 430 | return total; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | return total; |
| 435 | } |
| 436 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 437 | int gr_textEx(int x, int y, const char *s, void* pFont) |
| 438 | { |
| 439 | GGLContext *gl = gr_context; |
| 440 | GRFont *font = (GRFont*) pFont; |
| 441 | unsigned off; |
| 442 | unsigned cwidth; |
| 443 | |
| 444 | /* Handle default font */ |
| 445 | if (!font) font = gr_font; |
| 446 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 447 | #ifndef TW_DISABLE_TTF |
| 448 | if(font->type == FONT_TYPE_TTF) |
| 449 | return gr_ttf_textExWH(gl, x, y, s, pFont, -1, -1); |
| 450 | #endif |
| 451 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | gl->bindTexture(gl, &font->texture); |
| 453 | gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); |
| 454 | gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 455 | gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 456 | gl->enable(gl, GGL_TEXTURE_2D); |
| 457 | |
| 458 | while((off = *s++)) { |
| 459 | off -= 32; |
| 460 | cwidth = 0; |
| 461 | if (off < 96) { |
| 462 | cwidth = font->offset[off+1] - font->offset[off]; |
| 463 | gl->texCoord2i(gl, (font->offset[off]) - x, 0 - y); |
| 464 | gl->recti(gl, x, y, x + cwidth, y + font->cheight); |
| 465 | x += cwidth; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | return x; |
| 470 | } |
| 471 | |
| 472 | int gr_textExW(int x, int y, const char *s, void* pFont, int max_width) |
| 473 | { |
| 474 | GGLContext *gl = gr_context; |
| 475 | GRFont *font = (GRFont*) pFont; |
| 476 | unsigned off; |
| 477 | unsigned cwidth; |
| 478 | |
| 479 | /* Handle default font */ |
| 480 | if (!font) font = gr_font; |
| 481 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 482 | #ifndef TW_DISABLE_TTF |
| 483 | if(font->type == FONT_TYPE_TTF) |
| 484 | return gr_ttf_textExWH(gl, x, y, s, pFont, max_width, -1); |
| 485 | #endif |
| 486 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 487 | gl->bindTexture(gl, &font->texture); |
| 488 | gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); |
| 489 | gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 490 | gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 491 | gl->enable(gl, GGL_TEXTURE_2D); |
| 492 | |
| 493 | while((off = *s++)) { |
| 494 | off -= 32; |
| 495 | cwidth = 0; |
| 496 | if (off < 96) { |
| 497 | cwidth = font->offset[off+1] - font->offset[off]; |
| 498 | if ((x + (int)cwidth) < max_width) { |
| 499 | gl->texCoord2i(gl, (font->offset[off]) - x, 0 - y); |
| 500 | gl->recti(gl, x, y, x + cwidth, y + font->cheight); |
| 501 | x += cwidth; |
| 502 | } else { |
| 503 | gl->texCoord2i(gl, (font->offset[off]) - x, 0 - y); |
| 504 | gl->recti(gl, x, y, max_width, y + font->cheight); |
| 505 | x = max_width; |
| 506 | return x; |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | return x; |
| 512 | } |
| 513 | |
| 514 | int gr_textExWH(int x, int y, const char *s, void* pFont, int max_width, int max_height) |
| 515 | { |
| 516 | GGLContext *gl = gr_context; |
| 517 | GRFont *font = (GRFont*) pFont; |
| 518 | unsigned off; |
| 519 | unsigned cwidth; |
| 520 | int rect_x, rect_y; |
| 521 | |
| 522 | /* Handle default font */ |
| 523 | if (!font) font = gr_font; |
| 524 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 525 | #ifndef TW_DISABLE_TTF |
| 526 | if(font->type == FONT_TYPE_TTF) |
| 527 | return gr_ttf_textExWH(gl, x, y, s, pFont, max_width, max_height); |
| 528 | #endif |
| 529 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | gl->bindTexture(gl, &font->texture); |
| 531 | gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); |
| 532 | gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 533 | gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 534 | gl->enable(gl, GGL_TEXTURE_2D); |
| 535 | |
| 536 | while((off = *s++)) { |
| 537 | off -= 32; |
| 538 | cwidth = 0; |
| 539 | if (off < 96) { |
| 540 | cwidth = font->offset[off+1] - font->offset[off]; |
| 541 | if ((x + (int)cwidth) < max_width) |
| 542 | rect_x = x + cwidth; |
| 543 | else |
| 544 | rect_x = max_width; |
Dees_Troy | f759675 | 2012-09-28 13:21:36 -0400 | [diff] [blame] | 545 | if (y + font->cheight < (unsigned int)(max_height)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 546 | rect_y = y + font->cheight; |
| 547 | else |
| 548 | rect_y = max_height; |
| 549 | |
| 550 | gl->texCoord2i(gl, (font->offset[off]) - x, 0 - y); |
| 551 | gl->recti(gl, x, y, rect_x, rect_y); |
| 552 | x += cwidth; |
| 553 | if (x > max_width) |
| 554 | return x; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | return x; |
| 559 | } |
| 560 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 561 | void gr_fill(int x, int y, int w, int h) |
| 562 | { |
| 563 | GGLContext *gl = gr_context; |
Vojtech Bocek | 1a4744a | 2014-02-06 19:52:28 +0100 | [diff] [blame] | 564 | |
| 565 | if(gr_is_curr_clr_opaque) |
| 566 | gl->disable(gl, GGL_BLEND); |
| 567 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 568 | gl->disable(gl, GGL_TEXTURE_2D); |
| 569 | gl->recti(gl, x, y, x + w, y + h); |
Vojtech Bocek | 1a4744a | 2014-02-06 19:52:28 +0100 | [diff] [blame] | 570 | |
| 571 | if(gr_is_curr_clr_opaque) |
| 572 | gl->enable(gl, GGL_BLEND); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) { |
Dees Troy | f171e10 | 2014-11-06 22:19:58 +0100 | [diff] [blame] | 576 | if (gr_context == NULL) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 577 | return; |
| 578 | } |
| 579 | |
| 580 | GGLContext *gl = gr_context; |
Vojtech Bocek | 6c694b6 | 2014-02-06 20:36:25 +0100 | [diff] [blame] | 581 | GGLSurface *surface = (GGLSurface*)source; |
| 582 | |
| 583 | if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888) |
| 584 | gl->disable(gl, GGL_BLEND); |
| 585 | |
| 586 | gl->bindTexture(gl, surface); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 587 | gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); |
| 588 | gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 589 | gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); |
| 590 | gl->enable(gl, GGL_TEXTURE_2D); |
| 591 | gl->texCoord2i(gl, sx - dx, sy - dy); |
| 592 | gl->recti(gl, dx, dy, dx + w, dy + h); |
Vojtech Bocek | 6c694b6 | 2014-02-06 20:36:25 +0100 | [diff] [blame] | 593 | |
| 594 | if(surface->format == GGL_PIXEL_FORMAT_RGBX_8888) |
Dees Troy | f171e10 | 2014-11-06 22:19:58 +0100 | [diff] [blame] | 595 | gl->enable(gl, GGL_BLEND); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | unsigned int gr_get_width(gr_surface surface) { |
| 599 | if (surface == NULL) { |
| 600 | return 0; |
| 601 | } |
| 602 | return ((GGLSurface*) surface)->width; |
| 603 | } |
| 604 | |
| 605 | unsigned int gr_get_height(gr_surface surface) { |
| 606 | if (surface == NULL) { |
| 607 | return 0; |
| 608 | } |
| 609 | return ((GGLSurface*) surface)->height; |
| 610 | } |
| 611 | |
| 612 | void* gr_loadFont(const char* fontName) |
| 613 | { |
| 614 | int fd; |
| 615 | GRFont *font = 0; |
| 616 | GGLSurface *ftex; |
| 617 | unsigned char *bits, *rle; |
| 618 | unsigned char *in, data; |
| 619 | unsigned width, height; |
| 620 | unsigned element; |
| 621 | |
| 622 | fd = open(fontName, O_RDONLY); |
| 623 | if (fd == -1) |
| 624 | { |
| 625 | char tmp[128]; |
| 626 | |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 627 | sprintf(tmp, TWRES "fonts/%s.dat", fontName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 628 | fd = open(tmp, O_RDONLY); |
| 629 | if (fd == -1) |
| 630 | return NULL; |
| 631 | } |
| 632 | |
| 633 | font = calloc(sizeof(*font), 1); |
| 634 | ftex = &font->texture; |
| 635 | |
| 636 | read(fd, &width, sizeof(unsigned)); |
| 637 | read(fd, &height, sizeof(unsigned)); |
| 638 | read(fd, font->offset, sizeof(unsigned) * 96); |
| 639 | font->offset[96] = width; |
| 640 | |
| 641 | bits = malloc(width * height); |
| 642 | memset(bits, 0, width * height); |
| 643 | |
| 644 | unsigned pos = 0; |
| 645 | while (pos < width * height) |
| 646 | { |
| 647 | int bit; |
| 648 | |
| 649 | read(fd, &data, 1); |
| 650 | for (bit = 0; bit < 8; bit++) |
| 651 | { |
| 652 | if (data & (1 << (7-bit))) bits[pos++] = 255; |
| 653 | else bits[pos++] = 0; |
| 654 | |
| 655 | if (pos == width * height) break; |
| 656 | } |
| 657 | } |
| 658 | close(fd); |
| 659 | |
| 660 | ftex->version = sizeof(*ftex); |
| 661 | ftex->width = width; |
| 662 | ftex->height = height; |
| 663 | ftex->stride = width; |
| 664 | ftex->data = (void*) bits; |
| 665 | ftex->format = GGL_PIXEL_FORMAT_A_8; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 666 | font->type = FONT_TYPE_TWRP; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 667 | font->cheight = height; |
| 668 | font->ascent = height - 2; |
| 669 | return (void*) font; |
| 670 | } |
| 671 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 672 | void gr_freeFont(void *font) |
| 673 | { |
| 674 | GRFont *f = font; |
| 675 | free(f->texture.data); |
| 676 | free(f); |
| 677 | } |
| 678 | |
| 679 | int gr_getMaxFontHeight(void *font) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 680 | { |
| 681 | GRFont *fnt = (GRFont*) font; |
| 682 | |
| 683 | if (!fnt) fnt = gr_font; |
| 684 | if (!fnt) return -1; |
| 685 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 686 | #ifndef TW_DISABLE_TTF |
| 687 | if(fnt->type == FONT_TYPE_TTF) |
| 688 | return gr_ttf_getMaxFontHeight(font); |
| 689 | #endif |
| 690 | |
| 691 | return fnt->cheight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void gr_init_font(void) |
| 695 | { |
| 696 | int fontRes; |
| 697 | GGLSurface *ftex; |
| 698 | unsigned char *bits, *rle; |
| 699 | unsigned char *in, data; |
| 700 | unsigned width, height; |
| 701 | unsigned element; |
| 702 | |
| 703 | gr_font = calloc(sizeof(*gr_font), 1); |
| 704 | ftex = &gr_font->texture; |
| 705 | |
| 706 | width = font.width; |
| 707 | height = font.height; |
| 708 | |
| 709 | bits = malloc(width * height); |
| 710 | rle = bits; |
| 711 | |
| 712 | in = font.rundata; |
| 713 | while((data = *in++)) |
| 714 | { |
| 715 | memset(rle, (data & 0x80) ? 255 : 0, data & 0x7f); |
| 716 | rle += (data & 0x7f); |
| 717 | } |
| 718 | for (element = 0; element < 97; element++) |
| 719 | { |
| 720 | gr_font->offset[element] = (element * font.cwidth); |
| 721 | } |
| 722 | |
| 723 | ftex->version = sizeof(*ftex); |
| 724 | ftex->width = width; |
| 725 | ftex->height = height; |
| 726 | ftex->stride = width; |
| 727 | ftex->data = (void*) bits; |
| 728 | ftex->format = GGL_PIXEL_FORMAT_A_8; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 729 | gr_font->type = FONT_TYPE_TWRP; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 730 | gr_font->cheight = height; |
| 731 | gr_font->ascent = height - 2; |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | int gr_init(void) |
| 736 | { |
| 737 | gglInit(&gr_context); |
| 738 | GGLContext *gl = gr_context; |
| 739 | |
| 740 | gr_init_font(); |
| 741 | gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC); |
| 742 | if (gr_vt_fd < 0) { |
| 743 | // This is non-fatal; post-Cupcake kernels don't have tty0. |
| 744 | } else if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) { |
| 745 | // However, if we do open tty0, we expect the ioctl to work. |
| 746 | perror("failed KDSETMODE to KD_GRAPHICS on tty0"); |
| 747 | gr_exit(); |
| 748 | return -1; |
| 749 | } |
| 750 | |
| 751 | gr_fb_fd = get_framebuffer(gr_framebuffer); |
| 752 | if (gr_fb_fd < 0) { |
| 753 | perror("Unable to get framebuffer.\n"); |
| 754 | gr_exit(); |
| 755 | return -1; |
| 756 | } |
| 757 | |
| 758 | get_memory_surface(&gr_mem_surface); |
| 759 | |
| 760 | fprintf(stderr, "framebuffer: fd %d (%d x %d)\n", |
| 761 | gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height); |
| 762 | |
| 763 | /* start with 0 as front (displayed) and 1 as back (drawing) */ |
| 764 | gr_active_fb = 0; |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 765 | if (!has_overlay) |
| 766 | set_active_framebuffer(0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 767 | gl->colorBuffer(gl, &gr_mem_surface); |
| 768 | |
| 769 | gl->activeTexture(gl, 0); |
| 770 | gl->enable(gl, GGL_BLEND); |
| 771 | gl->blendFunc(gl, GGL_SRC_ALPHA, GGL_ONE_MINUS_SRC_ALPHA); |
| 772 | |
xNUTx | cd56f8c | 2014-07-23 01:30:20 +0200 | [diff] [blame] | 773 | #ifdef TW_SCREEN_BLANK_ON_BOOT |
| 774 | printf("TW_SCREEN_BLANK_ON_BOOT := true\n"); |
| 775 | gr_fb_blank(true); |
| 776 | gr_fb_blank(false); |
| 777 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 778 | |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 779 | if (!alloc_ion_mem(fi.line_length * vi.yres)) |
| 780 | allocate_overlay(gr_fb_fd, gr_framebuffer); |
| 781 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | void gr_exit(void) |
| 786 | { |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 787 | free_overlay(gr_fb_fd); |
| 788 | free_ion_mem(); |
| 789 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 790 | close(gr_fb_fd); |
| 791 | gr_fb_fd = -1; |
| 792 | |
| 793 | free(gr_mem_surface.data); |
| 794 | |
| 795 | ioctl(gr_vt_fd, KDSETMODE, (void*) KD_TEXT); |
| 796 | close(gr_vt_fd); |
| 797 | gr_vt_fd = -1; |
| 798 | } |
| 799 | |
| 800 | int gr_fb_width(void) |
| 801 | { |
| 802 | return gr_framebuffer[0].width; |
| 803 | } |
| 804 | |
| 805 | int gr_fb_height(void) |
| 806 | { |
| 807 | return gr_framebuffer[0].height; |
| 808 | } |
| 809 | |
| 810 | gr_pixel *gr_fb_data(void) |
| 811 | { |
| 812 | return (unsigned short *) gr_mem_surface.data; |
| 813 | } |
| 814 | |
Dees_Troy | 70237dc | 2013-02-28 21:31:48 +0000 | [diff] [blame] | 815 | int gr_fb_blank(int blank) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 816 | { |
| 817 | int ret; |
Dees Troy | 05d18c9 | 2014-08-04 18:17:07 +0000 | [diff] [blame] | 818 | //if (blank) |
| 819 | //free_overlay(gr_fb_fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 820 | |
| 821 | ret = ioctl(gr_fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK); |
| 822 | if (ret < 0) |
| 823 | perror("ioctl(): blank"); |
Ethan Yonker | 4ee5ad7 | 2014-02-18 18:41:17 -0600 | [diff] [blame] | 824 | |
Dees Troy | 05d18c9 | 2014-08-04 18:17:07 +0000 | [diff] [blame] | 825 | //if (!blank) |
| 826 | //allocate_overlay(gr_fb_fd, gr_framebuffer); |
| 827 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | int gr_get_surface(gr_surface* surface) |
| 831 | { |
| 832 | GGLSurface* ms = malloc(sizeof(GGLSurface)); |
| 833 | if (!ms) return -1; |
| 834 | |
| 835 | // Allocate the data |
| 836 | get_memory_surface(ms); |
| 837 | |
| 838 | // Now, copy the data |
| 839 | memcpy(ms->data, gr_mem_surface.data, vi.xres * vi.yres * vi.bits_per_pixel / 8); |
| 840 | |
| 841 | *surface = (gr_surface*) ms; |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | int gr_free_surface(gr_surface surface) |
| 846 | { |
| 847 | if (!surface) |
| 848 | return -1; |
| 849 | |
| 850 | GGLSurface* ms = (GGLSurface*) surface; |
| 851 | free(ms->data); |
| 852 | free(ms); |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | void gr_write_frame_to_file(int fd) |
| 857 | { |
| 858 | write(fd, gr_mem_surface.data, vi.xres * vi.yres * vi.bits_per_pixel / 8); |
| 859 | } |