blob: 34c9c82ba29f3710a2b1ab4c5a22861a49d97c0e [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
17#include <stdlib.h>
Elliott Hughescd3c55a2015-01-29 20:50:08 -080018#include <string.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080019#include <unistd.h>
20
21#include <fcntl.h>
22#include <stdio.h>
23
24#include <sys/ioctl.h>
25#include <sys/mman.h>
26#include <sys/types.h>
27
28#include <linux/fb.h>
29#include <linux/kd.h>
30
Doug Zongker19faefa2009-03-27 17:06:24 -070031#include <png.h>
32
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080033#include "minui.h"
34
Doug Zongker16f97c32014-03-06 16:16:05 -080035#define SURFACE_DATA_ALIGNMENT 8
36
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070037static GRSurface* malloc_surface(size_t data_size) {
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070038 size_t size = sizeof(GRSurface) + data_size + SURFACE_DATA_ALIGNMENT;
39 unsigned char* temp = reinterpret_cast<unsigned char*>(malloc(size));
Doug Zongker16f97c32014-03-06 16:16:05 -080040 if (temp == NULL) return NULL;
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -070041 GRSurface* surface = reinterpret_cast<GRSurface*>(temp);
Doug Zongker16f97c32014-03-06 16:16:05 -080042 surface->data = temp + sizeof(GRSurface) +
43 (SURFACE_DATA_ALIGNMENT - (sizeof(GRSurface) % SURFACE_DATA_ALIGNMENT));
44 return surface;
Doug Zongker19faefa2009-03-27 17:06:24 -070045}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080046
Doug Zongkera418aa72014-03-17 12:10:02 -070047static int open_png(const char* name, png_structp* png_ptr, png_infop* info_ptr,
48 png_uint_32* width, png_uint_32* height, png_byte* channels) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080049 char resPath[256];
Doug Zongker19faefa2009-03-27 17:06:24 -070050 unsigned char header[8];
Doug Zongkera418aa72014-03-17 12:10:02 -070051 int result = 0;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070052 int color_type, bit_depth;
53 size_t bytesRead;
Doug Zongker6809c512011-03-01 14:04:34 -080054
Doug Zongker19faefa2009-03-27 17:06:24 -070055 snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056 resPath[sizeof(resPath)-1] = '\0';
Doug Zongker19faefa2009-03-27 17:06:24 -070057 FILE* fp = fopen(resPath, "rb");
58 if (fp == NULL) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080059 result = -1;
60 goto exit;
61 }
Doug Zongker19faefa2009-03-27 17:06:24 -070062
Elliott Hughes07cfb8f2015-04-10 13:12:05 -070063 bytesRead = fread(header, 1, sizeof(header), fp);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080064 if (bytesRead != sizeof(header)) {
65 result = -2;
66 goto exit;
67 }
Doug Zongker19faefa2009-03-27 17:06:24 -070068
69 if (png_sig_cmp(header, 0, sizeof(header))) {
70 result = -3;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080071 goto exit;
72 }
Doug Zongker19faefa2009-03-27 17:06:24 -070073
Doug Zongkera418aa72014-03-17 12:10:02 -070074 *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
75 if (!*png_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080076 result = -4;
77 goto exit;
78 }
Doug Zongker19faefa2009-03-27 17:06:24 -070079
Doug Zongkera418aa72014-03-17 12:10:02 -070080 *info_ptr = png_create_info_struct(*png_ptr);
81 if (!*info_ptr) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080082 result = -5;
83 goto exit;
84 }
Doug Zongker19faefa2009-03-27 17:06:24 -070085
Doug Zongkera418aa72014-03-17 12:10:02 -070086 if (setjmp(png_jmpbuf(*png_ptr))) {
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080087 result = -6;
88 goto exit;
89 }
Doug Zongker19faefa2009-03-27 17:06:24 -070090
Doug Zongkera418aa72014-03-17 12:10:02 -070091 png_init_io(*png_ptr, fp);
92 png_set_sig_bytes(*png_ptr, sizeof(header));
93 png_read_info(*png_ptr, *info_ptr);
Doug Zongker19faefa2009-03-27 17:06:24 -070094
Doug Zongkera418aa72014-03-17 12:10:02 -070095 png_get_IHDR(*png_ptr, *info_ptr, width, height, &bit_depth,
John Reck94fd07b2013-08-26 16:45:33 -070096 &color_type, NULL, NULL, NULL);
97
Doug Zongkera418aa72014-03-17 12:10:02 -070098 *channels = png_get_channels(*png_ptr, *info_ptr);
John Reck94fd07b2013-08-26 16:45:33 -070099
Doug Zongkera418aa72014-03-17 12:10:02 -0700100 if (bit_depth == 8 && *channels == 3 && color_type == PNG_COLOR_TYPE_RGB) {
101 // 8-bit RGB images: great, nothing to do.
102 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_GRAY) {
103 // 1-, 2-, 4-, or 8-bit gray images: expand to 8-bit gray.
104 png_set_expand_gray_1_2_4_to_8(*png_ptr);
Doug Zongker577a1302014-03-20 08:27:01 -0700105 } else if (bit_depth <= 8 && *channels == 1 && color_type == PNG_COLOR_TYPE_PALETTE) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700106 // paletted images: expand to 8-bit RGB. Note that we DON'T
107 // currently expand the tRNS chunk (if any) to an alpha
108 // channel, because minui doesn't support alpha channels in
109 // general.
110 png_set_palette_to_rgb(*png_ptr);
111 *channels = 3;
112 } else {
113 fprintf(stderr, "minui doesn't support PNG depth %d channels %d color_type %d\n",
Doug Zongkera388a762014-03-17 16:51:47 -0700114 bit_depth, *channels, color_type);
Doug Zongkera418aa72014-03-17 12:10:02 -0700115 result = -7;
Doug Zongker19faefa2009-03-27 17:06:24 -0700116 goto exit;
117 }
118
Doug Zongkera418aa72014-03-17 12:10:02 -0700119 return result;
Doug Zongker55a36ac2013-03-04 15:49:02 -0800120
Doug Zongkera418aa72014-03-17 12:10:02 -0700121 exit:
122 if (result < 0) {
123 png_destroy_read_struct(png_ptr, info_ptr, NULL);
124 }
125 if (fp != NULL) {
126 fclose(fp);
127 }
128
129 return result;
130}
131
132// "display" surfaces are transformed into the framebuffer's required
133// pixel format (currently only RGBX is supported) at load time, so
134// gr_blit() can be nothing more than a memcpy() for each row. The
135// next two functions are the only ones that know anything about the
136// framebuffer pixel format; they need to be modified if the
137// framebuffer format changes (but nothing else should).
138
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700139// Allocate and return a GRSurface* sufficient for storing an image of
Doug Zongkera418aa72014-03-17 12:10:02 -0700140// the indicated size in the framebuffer pixel format.
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700141static GRSurface* init_display_surface(png_uint_32 width, png_uint_32 height) {
142 GRSurface* surface = malloc_surface(width * height * 4);
Doug Zongkera418aa72014-03-17 12:10:02 -0700143 if (surface == NULL) return NULL;
144
145 surface->width = width;
146 surface->height = height;
147 surface->row_bytes = width * 4;
148 surface->pixel_bytes = 4;
149
150 return surface;
151}
152
153// Copy 'input_row' to 'output_row', transforming it to the
154// framebuffer pixel format. The input format depends on the value of
155// 'channels':
156//
157// 1 - input is 8-bit grayscale
158// 3 - input is 24-bit RGB
159// 4 - input is 32-bit RGBA/RGBX
160//
161// 'width' is the number of pixels in the row.
162static void transform_rgb_to_draw(unsigned char* input_row,
163 unsigned char* output_row,
164 int channels, int width) {
165 int x;
166 unsigned char* ip = input_row;
167 unsigned char* op = output_row;
168
169 switch (channels) {
170 case 1:
171 // expand gray level to RGBX
172 for (x = 0; x < width; ++x) {
173 *op++ = *ip;
174 *op++ = *ip;
175 *op++ = *ip;
176 *op++ = 0xff;
177 ip++;
178 }
179 break;
180
181 case 3:
182 // expand RGBA to RGBX
183 for (x = 0; x < width; ++x) {
184 *op++ = *ip++;
185 *op++ = *ip++;
186 *op++ = *ip++;
187 *op++ = 0xff;
188 }
189 break;
190
191 case 4:
192 // copy RGBA to RGBX
193 memcpy(output_row, input_row, width*4);
194 break;
195 }
196}
197
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700198int res_create_display_surface(const char* name, GRSurface** pSurface) {
199 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700200 int result = 0;
201 png_structp png_ptr = NULL;
202 png_infop info_ptr = NULL;
203 png_uint_32 width, height;
204 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700205 unsigned char* p_row;
206 unsigned int y;
Doug Zongkera418aa72014-03-17 12:10:02 -0700207
208 *pSurface = NULL;
209
210 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
211 if (result < 0) return result;
212
213 surface = init_display_surface(width, height);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800214 if (surface == NULL) {
Doug Zongker19faefa2009-03-27 17:06:24 -0700215 result = -8;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800216 goto exit;
217 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800218
Tony Kuofd778e32015-02-05 21:25:56 +0800219#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
220 png_set_bgr(png_ptr);
221#endif
222
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700223 p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700224 for (y = 0; y < height; ++y) {
225 png_read_row(png_ptr, p_row, NULL);
226 transform_rgb_to_draw(p_row, surface->data + y * surface->row_bytes, channels, width);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800227 }
Doug Zongkera418aa72014-03-17 12:10:02 -0700228 free(p_row);
Doug Zongker19faefa2009-03-27 17:06:24 -0700229
Doug Zongkera418aa72014-03-17 12:10:02 -0700230 *pSurface = surface;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800231
Doug Zongkera418aa72014-03-17 12:10:02 -0700232 exit:
Doug Zongker19faefa2009-03-27 17:06:24 -0700233 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700234 if (result < 0 && surface != NULL) free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800235 return result;
236}
237
Tao Baob723f4f2015-12-11 15:18:51 -0800238int res_create_multi_display_surface(const char* name, int* frames, int* fps,
239 GRSurface*** pSurface) {
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700240 GRSurface** surface = NULL;
Doug Zongker469954f2014-03-07 09:21:25 -0800241 int result = 0;
Doug Zongker469954f2014-03-07 09:21:25 -0800242 png_structp png_ptr = NULL;
243 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700244 png_uint_32 width, height;
245 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700246 png_textp text;
247 int num_text;
248 unsigned char* p_row;
249 unsigned int y;
Doug Zongker469954f2014-03-07 09:21:25 -0800250
251 *pSurface = NULL;
252 *frames = -1;
253
Doug Zongkera418aa72014-03-17 12:10:02 -0700254 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
255 if (result < 0) return result;
Doug Zongker469954f2014-03-07 09:21:25 -0800256
257 *frames = 1;
Tao Baob723f4f2015-12-11 15:18:51 -0800258 *fps = 20;
Doug Zongker469954f2014-03-07 09:21:25 -0800259 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
Tao Baob723f4f2015-12-11 15:18:51 -0800260 for (int i = 0; i < num_text; ++i) {
Doug Zongker469954f2014-03-07 09:21:25 -0800261 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
262 *frames = atoi(text[i].text);
Tao Baob723f4f2015-12-11 15:18:51 -0800263 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
264 *fps = atoi(text[i].text);
Doug Zongker469954f2014-03-07 09:21:25 -0800265 }
266 }
267 printf(" found frames = %d\n", *frames);
Tao Baob723f4f2015-12-11 15:18:51 -0800268 printf(" found fps = %d\n", *fps);
269 }
270
271 if (frames <= 0 || fps <= 0) {
272 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
273 result = -10;
274 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800275 }
276
277 if (height % *frames != 0) {
278 printf("bad height (%d) for frame count (%d)\n", height, *frames);
279 result = -9;
280 goto exit;
281 }
282
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700283 surface = reinterpret_cast<GRSurface**>(malloc(*frames * sizeof(GRSurface*)));
Doug Zongker469954f2014-03-07 09:21:25 -0800284 if (surface == NULL) {
285 result = -8;
286 goto exit;
287 }
Tao Baob723f4f2015-12-11 15:18:51 -0800288 for (int i = 0; i < *frames; ++i) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700289 surface[i] = init_display_surface(width, height / *frames);
290 if (surface[i] == NULL) {
291 result = -8;
292 goto exit;
Doug Zongker469954f2014-03-07 09:21:25 -0800293 }
294 }
295
Tony Kuofd778e32015-02-05 21:25:56 +0800296#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
297 png_set_bgr(png_ptr);
298#endif
299
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700300 p_row = reinterpret_cast<unsigned char*>(malloc(width * 4));
Doug Zongkera418aa72014-03-17 12:10:02 -0700301 for (y = 0; y < height; ++y) {
302 png_read_row(png_ptr, p_row, NULL);
303 int frame = y % *frames;
304 unsigned char* out_row = surface[frame]->data +
305 (y / *frames) * surface[frame]->row_bytes;
306 transform_rgb_to_draw(p_row, out_row, channels, width);
307 }
308 free(p_row);
309
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700310 *pSurface = reinterpret_cast<GRSurface**>(surface);
Doug Zongker469954f2014-03-07 09:21:25 -0800311
312exit:
313 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
314
Doug Zongker469954f2014-03-07 09:21:25 -0800315 if (result < 0) {
316 if (surface) {
Tao Baob723f4f2015-12-11 15:18:51 -0800317 for (int i = 0; i < *frames; ++i) {
Doug Zongker469954f2014-03-07 09:21:25 -0800318 if (surface[i]) free(surface[i]);
319 }
320 free(surface);
321 }
322 }
323 return result;
324}
325
Ethan Yonker534d4e02016-08-26 10:05:03 -0500326int res_create_multi_display_surface(const char* name, int* frames,
327 GRSurface*** pSurface) {
328 int fps = 0;
329 return res_create_multi_display_surface(name, frames, &fps, pSurface);
330}
331
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700332int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
333 GRSurface* surface = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700334 int result = 0;
335 png_structp png_ptr = NULL;
336 png_infop info_ptr = NULL;
337 png_uint_32 width, height;
338 png_byte channels;
339
340 *pSurface = NULL;
341
342 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
343 if (result < 0) return result;
344
345 if (channels != 1) {
346 result = -7;
347 goto exit;
348 }
349
350 surface = malloc_surface(width * height);
351 if (surface == NULL) {
352 result = -8;
353 goto exit;
354 }
355 surface->width = width;
356 surface->height = height;
357 surface->row_bytes = width;
358 surface->pixel_bytes = 1;
359
Tony Kuofd778e32015-02-05 21:25:56 +0800360#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
361 png_set_bgr(png_ptr);
362#endif
363
Doug Zongkera418aa72014-03-17 12:10:02 -0700364 unsigned char* p_row;
365 unsigned int y;
366 for (y = 0; y < height; ++y) {
367 p_row = surface->data + y * surface->row_bytes;
368 png_read_row(png_ptr, p_row, NULL);
369 }
370
371 *pSurface = surface;
372
373 exit:
374 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
375 if (result < 0 && surface != NULL) free(surface);
376 return result;
377}
378
Tianjie Xu2430e292016-04-19 15:02:41 -0700379// This function tests if a locale string stored in PNG (prefix) matches
380// the locale string provided by the system (locale).
381bool matches_locale(const char* prefix, const char* locale) {
382 if (locale == NULL) return false;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700383
Tianjie Xu2430e292016-04-19 15:02:41 -0700384 // Return true if the whole string of prefix matches the top part of
385 // locale. For instance, prefix == "en" matches locale == "en_US";
386 // and prefix == "zh_CN" matches locale == "zh_CN_#Hans".
Doug Zongker02ec6b82012-08-22 17:26:40 -0700387
Tianjie Xu2430e292016-04-19 15:02:41 -0700388 return (strncmp(prefix, locale, strlen(prefix)) == 0);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700389}
390
Doug Zongkera418aa72014-03-17 12:10:02 -0700391int res_create_localized_alpha_surface(const char* name,
392 const char* locale,
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700393 GRSurface** pSurface) {
394 GRSurface* surface = NULL;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700395 int result = 0;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700396 png_structp png_ptr = NULL;
397 png_infop info_ptr = NULL;
Doug Zongkera418aa72014-03-17 12:10:02 -0700398 png_uint_32 width, height;
399 png_byte channels;
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700400 unsigned char* row;
401 png_uint_32 y;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700402
403 *pSurface = NULL;
404
Doug Zongkera418aa72014-03-17 12:10:02 -0700405 if (locale == NULL) {
406 surface = malloc_surface(0);
407 surface->width = 0;
408 surface->height = 0;
409 surface->row_bytes = 0;
410 surface->pixel_bytes = 1;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700411 goto exit;
412 }
413
Doug Zongkera418aa72014-03-17 12:10:02 -0700414 result = open_png(name, &png_ptr, &info_ptr, &width, &height, &channels);
415 if (result < 0) return result;
416
417 if (channels != 1) {
418 result = -7;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700419 goto exit;
420 }
421
Elliott Hughes07cfb8f2015-04-10 13:12:05 -0700422 row = reinterpret_cast<unsigned char*>(malloc(width));
Doug Zongker02ec6b82012-08-22 17:26:40 -0700423 for (y = 0; y < height; ++y) {
424 png_read_row(png_ptr, row, NULL);
425 int w = (row[1] << 8) | row[0];
426 int h = (row[3] << 8) | row[2];
427 int len = row[4];
Doug Zongker469954f2014-03-07 09:21:25 -0800428 char* loc = (char*)row+5;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700429
Doug Zongkera418aa72014-03-17 12:10:02 -0700430 if (y+1+h >= height || matches_locale(loc, locale)) {
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700431 printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
432
Doug Zongker16f97c32014-03-06 16:16:05 -0800433 surface = malloc_surface(w*h);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700434 if (surface == NULL) {
435 result = -8;
436 goto exit;
437 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700438 surface->width = w;
439 surface->height = h;
Doug Zongker16f97c32014-03-06 16:16:05 -0800440 surface->row_bytes = w;
441 surface->pixel_bytes = 1;
Doug Zongker02ec6b82012-08-22 17:26:40 -0700442
443 int i;
444 for (i = 0; i < h; ++i, ++y) {
445 png_read_row(png_ptr, row, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700446 memcpy(surface->data + i*w, row, w);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700447 }
448
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700449 *pSurface = reinterpret_cast<GRSurface*>(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700450 break;
451 } else {
Doug Zongker02ec6b82012-08-22 17:26:40 -0700452 int i;
453 for (i = 0; i < h; ++i, ++y) {
454 png_read_row(png_ptr, row, NULL);
455 }
456 }
457 }
458
459exit:
460 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
Doug Zongkera418aa72014-03-17 12:10:02 -0700461 if (result < 0 && surface != NULL) free(surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700462 return result;
463}
464
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700465void res_free_surface(GRSurface* surface) {
Doug Zongker16f97c32014-03-06 16:16:05 -0800466 free(surface);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800467}