1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2016 Broadcom
3*4882a593Smuzhiyun * Copyright © 2009 Intel Corporation
4*4882a593Smuzhiyun * Copyright © 1998 Keith Packard
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
7*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
8*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
9*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
11*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
14*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
15*4882a593Smuzhiyun * Software.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23*4882a593Smuzhiyun * IN THE SOFTWARE.
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /**
27*4882a593Smuzhiyun * @file glamor_picture.c
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * Implements temporary uploads of GL_MEMORY Pixmaps to a texture that
30*4882a593Smuzhiyun * is swizzled appropriately for a given Render picture format.
31*4882a593Smuzhiyun * laid *
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * This is important because GTK likes to use SHM Pixmaps for Render
34*4882a593Smuzhiyun * blending operations, and we don't want a blend operation to fall
35*4882a593Smuzhiyun * back to software (readback is more expensive than the upload we do
36*4882a593Smuzhiyun * here, and you'd have to re-upload the fallback output anyway).
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun #include <stdlib.h>
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #include "glamor_priv.h"
42*4882a593Smuzhiyun #include "mipict.h"
43*4882a593Smuzhiyun
byte_swap_swizzle(GLenum * swizzle)44*4882a593Smuzhiyun static void byte_swap_swizzle(GLenum *swizzle)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun GLenum temp;
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun temp = swizzle[0];
49*4882a593Smuzhiyun swizzle[0] = swizzle[3];
50*4882a593Smuzhiyun swizzle[3] = temp;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun temp = swizzle[1];
53*4882a593Smuzhiyun swizzle[1] = swizzle[2];
54*4882a593Smuzhiyun swizzle[2] = temp;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /**
58*4882a593Smuzhiyun * Returns the GL format and type for uploading our bits to a given PictFormat.
59*4882a593Smuzhiyun *
60*4882a593Smuzhiyun * We may need to tell the caller to translate the bits to another
61*4882a593Smuzhiyun * format, as in PICT_a1 (which GL doesn't support). We may also need
62*4882a593Smuzhiyun * to tell the GL to swizzle the texture on sampling, because GLES3
63*4882a593Smuzhiyun * doesn't support the GL_UNSIGNED_INT_8_8_8_8{,_REV} types, so we
64*4882a593Smuzhiyun * don't have enough channel reordering options at upload time without
65*4882a593Smuzhiyun * it.
66*4882a593Smuzhiyun */
67*4882a593Smuzhiyun static Bool
glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,PictFormatShort format,PictFormatShort * temp_format,GLenum * tex_format,GLenum * tex_type,GLenum * swizzle)68*4882a593Smuzhiyun glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
69*4882a593Smuzhiyun PictFormatShort format,
70*4882a593Smuzhiyun PictFormatShort *temp_format,
71*4882a593Smuzhiyun GLenum *tex_format,
72*4882a593Smuzhiyun GLenum *tex_type,
73*4882a593Smuzhiyun GLenum *swizzle)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
76*4882a593Smuzhiyun Bool is_little_endian = IMAGE_BYTE_ORDER == LSBFirst;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun *temp_format = format;
79*4882a593Smuzhiyun swizzle[0] = GL_RED;
80*4882a593Smuzhiyun swizzle[1] = GL_GREEN;
81*4882a593Smuzhiyun swizzle[2] = GL_BLUE;
82*4882a593Smuzhiyun swizzle[3] = GL_ALPHA;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun switch (format) {
85*4882a593Smuzhiyun case PICT_a1:
86*4882a593Smuzhiyun *tex_format = glamor_priv->formats[8].format;
87*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_BYTE;
88*4882a593Smuzhiyun *temp_format = PICT_a8;
89*4882a593Smuzhiyun break;
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun case PICT_b8g8r8x8:
92*4882a593Smuzhiyun case PICT_b8g8r8a8:
93*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
94*4882a593Smuzhiyun *tex_format = GL_BGRA;
95*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_INT_8_8_8_8;
96*4882a593Smuzhiyun } else {
97*4882a593Smuzhiyun *tex_format = GL_RGBA;
98*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_BYTE;
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun swizzle[0] = GL_GREEN;
101*4882a593Smuzhiyun swizzle[1] = GL_BLUE;
102*4882a593Smuzhiyun swizzle[2] = GL_ALPHA;
103*4882a593Smuzhiyun swizzle[3] = GL_RED;
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun if (!is_little_endian)
106*4882a593Smuzhiyun byte_swap_swizzle(swizzle);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun break;
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun case PICT_x8r8g8b8:
111*4882a593Smuzhiyun case PICT_a8r8g8b8:
112*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
113*4882a593Smuzhiyun *tex_format = GL_BGRA;
114*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
115*4882a593Smuzhiyun } else {
116*4882a593Smuzhiyun *tex_format = GL_RGBA;
117*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_BYTE;
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun swizzle[0] = GL_BLUE;
120*4882a593Smuzhiyun swizzle[2] = GL_RED;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun if (!is_little_endian)
123*4882a593Smuzhiyun byte_swap_swizzle(swizzle);
124*4882a593Smuzhiyun break;
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun break;
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun case PICT_x8b8g8r8:
129*4882a593Smuzhiyun case PICT_a8b8g8r8:
130*4882a593Smuzhiyun *tex_format = GL_RGBA;
131*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
132*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
133*4882a593Smuzhiyun } else {
134*4882a593Smuzhiyun *tex_format = GL_RGBA;
135*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_BYTE;
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun if (!is_little_endian)
138*4882a593Smuzhiyun byte_swap_swizzle(swizzle);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun break;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun case PICT_x2r10g10b10:
143*4882a593Smuzhiyun case PICT_a2r10g10b10:
144*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
145*4882a593Smuzhiyun *tex_format = GL_BGRA;
146*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
147*4882a593Smuzhiyun } else {
148*4882a593Smuzhiyun return FALSE;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun break;
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun case PICT_x2b10g10r10:
153*4882a593Smuzhiyun case PICT_a2b10g10r10:
154*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
155*4882a593Smuzhiyun *tex_format = GL_RGBA;
156*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
157*4882a593Smuzhiyun } else {
158*4882a593Smuzhiyun return FALSE;
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun break;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun case PICT_r5g6b5:
163*4882a593Smuzhiyun *tex_format = GL_RGB;
164*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_5_6_5;
165*4882a593Smuzhiyun break;
166*4882a593Smuzhiyun case PICT_b5g6r5:
167*4882a593Smuzhiyun *tex_format = GL_RGB;
168*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
169*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
170*4882a593Smuzhiyun } else {
171*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_5_6_5;
172*4882a593Smuzhiyun swizzle[0] = GL_BLUE;
173*4882a593Smuzhiyun swizzle[2] = GL_RED;
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun break;
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun case PICT_x1b5g5r5:
178*4882a593Smuzhiyun case PICT_a1b5g5r5:
179*4882a593Smuzhiyun *tex_format = GL_RGBA;
180*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
181*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
182*4882a593Smuzhiyun } else {
183*4882a593Smuzhiyun return FALSE;
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun break;
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun case PICT_x1r5g5b5:
188*4882a593Smuzhiyun case PICT_a1r5g5b5:
189*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
190*4882a593Smuzhiyun *tex_format = GL_BGRA;
191*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
192*4882a593Smuzhiyun } else {
193*4882a593Smuzhiyun return FALSE;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun break;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun case PICT_a8:
198*4882a593Smuzhiyun *tex_format = glamor_priv->formats[8].format;
199*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_BYTE;
200*4882a593Smuzhiyun break;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun case PICT_x4r4g4b4:
203*4882a593Smuzhiyun case PICT_a4r4g4b4:
204*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
205*4882a593Smuzhiyun *tex_format = GL_BGRA;
206*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
207*4882a593Smuzhiyun } else {
208*4882a593Smuzhiyun /* XXX */
209*4882a593Smuzhiyun *tex_format = GL_RGBA;
210*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun break;
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun case PICT_x4b4g4r4:
215*4882a593Smuzhiyun case PICT_a4b4g4r4:
216*4882a593Smuzhiyun if (!glamor_priv->is_gles) {
217*4882a593Smuzhiyun *tex_format = GL_RGBA;
218*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
219*4882a593Smuzhiyun } else {
220*4882a593Smuzhiyun /* XXX */
221*4882a593Smuzhiyun *tex_format = GL_RGBA;
222*4882a593Smuzhiyun *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun break;
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun default:
227*4882a593Smuzhiyun return FALSE;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun if (!PICT_FORMAT_A(format))
231*4882a593Smuzhiyun swizzle[3] = GL_ONE;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun return TRUE;
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /**
237*4882a593Smuzhiyun * Takes a set of source bits with a given format and returns an
238*4882a593Smuzhiyun * in-memory pixman image of those bits in a destination format.
239*4882a593Smuzhiyun */
240*4882a593Smuzhiyun static pixman_image_t *
glamor_get_converted_image(PictFormatShort dst_format,PictFormatShort src_format,void * src_bits,int src_stride,int w,int h)241*4882a593Smuzhiyun glamor_get_converted_image(PictFormatShort dst_format,
242*4882a593Smuzhiyun PictFormatShort src_format,
243*4882a593Smuzhiyun void *src_bits,
244*4882a593Smuzhiyun int src_stride,
245*4882a593Smuzhiyun int w, int h)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun pixman_image_t *dst_image;
248*4882a593Smuzhiyun pixman_image_t *src_image;
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun dst_image = pixman_image_create_bits(dst_format, w, h, NULL, 0);
251*4882a593Smuzhiyun if (dst_image == NULL) {
252*4882a593Smuzhiyun return NULL;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun src_image = pixman_image_create_bits(src_format, w, h, src_bits, src_stride);
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (src_image == NULL) {
258*4882a593Smuzhiyun pixman_image_unref(dst_image);
259*4882a593Smuzhiyun return NULL;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun pixman_image_composite(PictOpSrc, src_image, NULL, dst_image,
263*4882a593Smuzhiyun 0, 0, 0, 0, 0, 0, w, h);
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun pixman_image_unref(src_image);
266*4882a593Smuzhiyun return dst_image;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /**
270*4882a593Smuzhiyun * Uploads a picture based on a GLAMOR_MEMORY pixmap to a texture in a
271*4882a593Smuzhiyun * temporary FBO.
272*4882a593Smuzhiyun */
273*4882a593Smuzhiyun Bool
glamor_upload_picture_to_texture(PicturePtr picture)274*4882a593Smuzhiyun glamor_upload_picture_to_texture(PicturePtr picture)
275*4882a593Smuzhiyun {
276*4882a593Smuzhiyun PixmapPtr pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
277*4882a593Smuzhiyun ScreenPtr screen = pixmap->drawable.pScreen;
278*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
279*4882a593Smuzhiyun glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
280*4882a593Smuzhiyun PictFormatShort converted_format;
281*4882a593Smuzhiyun void *bits = pixmap->devPrivate.ptr;
282*4882a593Smuzhiyun int stride = pixmap->devKind;
283*4882a593Smuzhiyun GLenum format, type;
284*4882a593Smuzhiyun GLenum swizzle[4];
285*4882a593Smuzhiyun GLenum iformat;
286*4882a593Smuzhiyun Bool ret = TRUE;
287*4882a593Smuzhiyun Bool needs_swizzle;
288*4882a593Smuzhiyun pixman_image_t *converted_image = NULL;
289*4882a593Smuzhiyun const struct glamor_format *f = glamor_format_for_pixmap(pixmap);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun assert(glamor_pixmap_is_memory(pixmap));
292*4882a593Smuzhiyun assert(!pixmap_priv->fbo);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun glamor_make_current(glamor_priv);
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /* No handling of large pixmap pictures here (would need to make
297*4882a593Smuzhiyun * an FBO array and split the uploads across it).
298*4882a593Smuzhiyun */
299*4882a593Smuzhiyun if (!glamor_check_fbo_size(glamor_priv,
300*4882a593Smuzhiyun pixmap->drawable.width,
301*4882a593Smuzhiyun pixmap->drawable.height)) {
302*4882a593Smuzhiyun return FALSE;
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun if (!glamor_get_tex_format_type_from_pictformat(screen,
306*4882a593Smuzhiyun picture->format,
307*4882a593Smuzhiyun &converted_format,
308*4882a593Smuzhiyun &format,
309*4882a593Smuzhiyun &type,
310*4882a593Smuzhiyun swizzle)) {
311*4882a593Smuzhiyun glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
312*4882a593Smuzhiyun return FALSE;
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun needs_swizzle = (swizzle[0] != GL_RED ||
316*4882a593Smuzhiyun swizzle[1] != GL_GREEN ||
317*4882a593Smuzhiyun swizzle[2] != GL_BLUE ||
318*4882a593Smuzhiyun swizzle[3] != GL_ALPHA);
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun if (!glamor_priv->has_texture_swizzle && needs_swizzle) {
321*4882a593Smuzhiyun glamor_fallback("Couldn't upload temporary picture due to missing "
322*4882a593Smuzhiyun "GL_ARB_texture_swizzle.\n");
323*4882a593Smuzhiyun return FALSE;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun if (converted_format != picture->format) {
327*4882a593Smuzhiyun converted_image = glamor_get_converted_image(converted_format,
328*4882a593Smuzhiyun picture->format,
329*4882a593Smuzhiyun bits, stride,
330*4882a593Smuzhiyun pixmap->drawable.width,
331*4882a593Smuzhiyun pixmap->drawable.height);
332*4882a593Smuzhiyun if (!converted_image)
333*4882a593Smuzhiyun return FALSE;
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun bits = pixman_image_get_data(converted_image);
336*4882a593Smuzhiyun stride = pixman_image_get_stride(converted_image);
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun if (!glamor_priv->is_gles)
340*4882a593Smuzhiyun iformat = f->internalformat;
341*4882a593Smuzhiyun else
342*4882a593Smuzhiyun iformat = format;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun if (!glamor_pixmap_ensure_fbo(pixmap, GLAMOR_CREATE_FBO_NO_FBO)) {
345*4882a593Smuzhiyun ret = FALSE;
346*4882a593Smuzhiyun goto fail;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun glamor_priv->suppress_gl_out_of_memory_logging = true;
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun /* We can't use glamor_pixmap_loop() because GLAMOR_MEMORY pixmaps
354*4882a593Smuzhiyun * don't have initialized boxes.
355*4882a593Smuzhiyun */
356*4882a593Smuzhiyun glBindTexture(GL_TEXTURE_2D, pixmap_priv->fbo->tex);
357*4882a593Smuzhiyun glTexImage2D(GL_TEXTURE_2D, 0, iformat,
358*4882a593Smuzhiyun pixmap->drawable.width, pixmap->drawable.height, 0,
359*4882a593Smuzhiyun format, type, bits);
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun if (needs_swizzle) {
362*4882a593Smuzhiyun glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzle[0]);
363*4882a593Smuzhiyun glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzle[1]);
364*4882a593Smuzhiyun glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzle[2]);
365*4882a593Smuzhiyun glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzle[3]);
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun glamor_priv->suppress_gl_out_of_memory_logging = false;
369*4882a593Smuzhiyun if (glGetError() == GL_OUT_OF_MEMORY) {
370*4882a593Smuzhiyun ret = FALSE;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun fail:
374*4882a593Smuzhiyun if (converted_image)
375*4882a593Smuzhiyun pixman_image_unref(converted_image);
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun return ret;
378*4882a593Smuzhiyun }
379