diff options
author | José Fonseca <[email protected]> | 2011-11-09 19:29:37 +0000 |
---|---|---|
committer | José Fonseca <[email protected]> | 2011-11-14 10:06:01 +0000 |
commit | c88f3e0374620f18cf38d9fc3c45d14bc53f62b2 (patch) | |
tree | 05de7d375c47328da0097a62cbf239b442de85c4 /src/gallium/drivers/llvmpipe/lp_texture.c | |
parent | 9e29cdbe95810de8658dfd1cabf1a7d87264c2f7 (diff) |
llvmpipe: Make more resilient to out-of-memory situations.
Most of the code was alright, but we were missing a few paths.
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/drivers/llvmpipe/lp_texture.c')
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_texture.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index fa4ce5bf2ac..ca38571b2bc 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -163,6 +163,9 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen, lpr->num_slices_faces[level] = num_slices; lpr->layout[level] = alloc_layout_array(num_slices, width, height); + if (!lpr->layout[level]) { + goto fail; + } } /* Compute size of next mipmap level */ @@ -172,6 +175,15 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen, } return TRUE; + +fail: + for (level = 0; level <= pt->last_level; level++) { + if (lpr->layout[level]) { + FREE(lpr->layout[level]); + } + } + + return FALSE; } @@ -196,7 +208,9 @@ llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, lpr->img_stride[0] = 0; lpr->layout[0] = alloc_layout_array(1, width, height); - //lpr->layout[0][0] = LP_TEX_LAYOUT_LINEAR; + if (!lpr->layout[0]) { + return FALSE; + } lpr->dt = winsys->displaytarget_create(winsys, lpr->base.bind, @@ -437,13 +451,15 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen, struct winsys_handle *whandle) { struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; - struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource); + struct llvmpipe_resource *lpr; unsigned width, height, width_t, height_t; /* XXX Seems like from_handled depth textures doesn't work that well */ - if (!lpr) - return NULL; + lpr = CALLOC_STRUCT(llvmpipe_resource); + if (!lpr) { + goto no_lpr; + } lpr->base = *template; pipe_reference_init(&lpr->base.reference, 1); @@ -472,12 +488,15 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen, template, whandle, &lpr->row_stride[0]); - if (!lpr->dt) - goto fail; + if (!lpr->dt) { + goto no_dt; + } lpr->layout[0] = alloc_layout_array(1, lpr->base.width0, lpr->base.height0); + if (!lpr->layout[0]) { + goto no_layout_0; + } - assert(lpr->layout[0]); assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE); lpr->id = id_counter++; @@ -488,8 +507,11 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen, return &lpr->base; - fail: +no_layout_0: + winsys->displaytarget_destroy(winsys, lpr->dt); +no_dt: FREE(lpr); +no_lpr: return NULL; } |