[Mesa-dev] [PATCH 2/4] st/dri2: Notify on texture allocation failure
George Barrett
bob at bob131.so
Tue Nov 21 11:16:07 UTC 2017
Callers of dri_drawable->allocate_textures are unaware of failures
occurring in the provided allocation function, happily chugging along
with potentially invalid state. Update the interface and
{dri2,drisw}_allocate_textures to return a boolean indicating success.
---
src/gallium/state_trackers/dri/dri2.c | 20 ++++++++++++--------
src/gallium/state_trackers/dri/dri_drawable.c | 3 ++-
src/gallium/state_trackers/dri/dri_drawable.h | 8 ++++----
src/gallium/state_trackers/dri/drisw.c | 4 +++-
4 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index a70f37fe09..60d6ab28ee 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -565,7 +565,7 @@ dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv)
* Backend functions for st_framebuffer interface.
*/
-static void
+static boolean
dri2_allocate_textures(struct dri_context *ctx,
struct dri_drawable *drawable,
const enum st_attachment_type *statts,
@@ -589,16 +589,18 @@ dri2_allocate_textures(struct dri_context *ctx,
if (image) {
if (!dri_image_drawable_get_buffers(drawable, &images,
statts, statts_count))
- return;
+ return FALSE;
}
else {
buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
- if (!buffers || (drawable->old_num == num_buffers &&
- drawable->old_w == dri_drawable->w &&
- drawable->old_h == dri_drawable->h &&
- memcmp(drawable->old, buffers,
- sizeof(__DRIbuffer) * num_buffers) == 0))
- return;
+ if (!buffers)
+ return FALSE;
+ else if (drawable->old_num == num_buffers &&
+ drawable->old_w == dri_drawable->w &&
+ drawable->old_h == dri_drawable->h &&
+ memcmp(drawable->old, buffers,
+ sizeof(__DRIbuffer) * num_buffers) == 0)
+ return TRUE;
}
/* Second clean useless resources*/
@@ -837,6 +839,8 @@ dri2_allocate_textures(struct dri_context *ctx,
drawable->old_h = dri_drawable->h;
memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * num_buffers);
}
+
+ return TRUE;
}
static void
diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c
index d586b7564e..8a59c34c7e 100644
--- a/src/gallium/state_trackers/dri/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/dri_drawable.c
@@ -82,7 +82,8 @@ dri_st_framebuffer_validate(struct st_context_iface *stctx,
if (new_stamp && drawable->update_drawable_info)
drawable->update_drawable_info(drawable);
- drawable->allocate_textures(ctx, drawable, statts, count);
+ if (!drawable->allocate_textures(ctx, drawable, statts, count))
+ return FALSE;
/* add existing textures */
for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h
index 7c45004ba6..9f344fd3dc 100644
--- a/src/gallium/state_trackers/dri/dri_drawable.h
+++ b/src/gallium/state_trackers/dri/dri_drawable.h
@@ -71,10 +71,10 @@ struct dri_drawable
struct pipe_surface *drisw_surface;
/* hooks filled in by dri2 & drisw */
- void (*allocate_textures)(struct dri_context *ctx,
- struct dri_drawable *drawable,
- const enum st_attachment_type *statts,
- unsigned count);
+ boolean (*allocate_textures)(struct dri_context *ctx,
+ struct dri_drawable *drawable,
+ const enum st_attachment_type *statts,
+ unsigned count);
void (*update_drawable_info)(struct dri_drawable *drawable);
diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c
index eb5752386d..9f4a1197b8 100644
--- a/src/gallium/state_trackers/dri/drisw.c
+++ b/src/gallium/state_trackers/dri/drisw.c
@@ -258,7 +258,7 @@ drisw_flush_frontbuffer(struct dri_context *ctx,
* as they are requested. Unused attachments are not removed, not until the
* framebuffer is resized or destroyed.
*/
-static void
+static boolean
drisw_allocate_textures(struct dri_context *stctx,
struct dri_drawable *drawable,
const enum st_attachment_type *statts,
@@ -323,6 +323,8 @@ drisw_allocate_textures(struct dri_context *stctx,
drawable->old_w = width;
drawable->old_h = height;
+
+ return TRUE;
}
static void
--
2.14.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171121/1a42c37f/attachment-0001.sig>
More information about the mesa-dev
mailing list