[Mesa-dev] [PATCH 1/2] st/mesa: unify window-system renderbuffer initialization
Marek Olšák
maraeo at gmail.com
Tue Jan 8 15:57:32 UTC 2019
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/state_tracker/st_cb_eglimage.c | 11 +--------
src/mesa/state_tracker/st_manager.c | 32 ++++++++++++++++---------
src/mesa/state_tracker/st_manager.h | 6 +++++
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c
index d6b93c3dbe8..f79df5a38ca 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -152,34 +152,25 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
surf_tmpl.format = stimg.format;
surf_tmpl.u.tex.level = stimg.level;
surf_tmpl.u.tex.first_layer = stimg.layer;
surf_tmpl.u.tex.last_layer = stimg.layer;
ps = pipe->create_surface(pipe, stimg.texture, &surf_tmpl);
pipe_resource_reference(&stimg.texture, NULL);
if (!ps)
return;
- strb->Base.Width = ps->width;
- strb->Base.Height = ps->height;
strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format);
strb->Base.InternalFormat = strb->Base._BaseFormat;
- struct pipe_surface **psurf =
- util_format_is_srgb(ps->format) ? &strb->surface_srgb :
- &strb->surface_linear;
-
- pipe_surface_reference(psurf, ps);
- strb->surface = *psurf;
- pipe_resource_reference(&strb->texture, ps->texture);
-
+ st_set_ws_renderbuffer_surface(strb, ps);
pipe_surface_reference(&ps, NULL);
}
}
static void
st_bind_egl_image(struct gl_context *ctx,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage,
struct st_egl_image *stimg)
{
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 73729d74545..7a3d9777101 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -166,20 +166,40 @@ st_context_validate(struct st_context *st,
st->dirty |= ST_NEW_FRAMEBUFFER;
_mesa_resize_framebuffer(st->ctx, &stread->Base,
stread->Base.Width,
stread->Base.Height);
}
st->read_stamp = stread->stamp;
}
}
+void
+st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb,
+ struct pipe_surface *surf)
+{
+ pipe_surface_reference(&strb->surface_srgb, NULL);
+ pipe_surface_reference(&strb->surface_linear, NULL);
+
+ if (util_format_is_srgb(surf->format))
+ pipe_surface_reference(&strb->surface_srgb, surf);
+ else
+ pipe_surface_reference(&strb->surface_linear, surf);
+
+ strb->surface = surf; /* just assign, don't ref */
+ pipe_resource_reference(&strb->texture, surf->texture);
+
+ strb->Base.Width = surf->width;
+ strb->Base.Height = surf->height;
+}
+
+
/**
* Validate a framebuffer to make sure up-to-date pipe_textures are used.
* The context is only used for creating pipe surfaces and for calling
* _mesa_resize_framebuffer().
* (That should probably be rethought, since those surfaces become
* drawable state, not context state, and can be freed by another pipe
* context).
*/
static void
st_framebuffer_validate(struct st_framebuffer *stfb,
@@ -227,35 +247,25 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
assert(strb);
if (strb->texture == textures[i]) {
pipe_resource_reference(&textures[i], NULL);
continue;
}
u_surface_default_template(&surf_tmpl, textures[i]);
ps = st->pipe->create_surface(st->pipe, textures[i], &surf_tmpl);
if (ps) {
- struct pipe_surface **psurf =
- util_format_is_srgb(ps->format) ? &strb->surface_srgb :
- &strb->surface_linear;
-
- pipe_surface_reference(psurf, ps);
- strb->surface = *psurf;
- pipe_resource_reference(&strb->texture, ps->texture);
- /* ownership transfered */
+ st_set_ws_renderbuffer_surface(strb, ps);
pipe_surface_reference(&ps, NULL);
changed = TRUE;
- strb->Base.Width = strb->surface->width;
- strb->Base.Height = strb->surface->height;
-
width = strb->Base.Width;
height = strb->Base.Height;
}
pipe_resource_reference(&textures[i], NULL);
}
if (changed) {
++stfb->stamp;
_mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height);
diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h
index 162dcc2ca57..581e858229b 100644
--- a/src/mesa/state_tracker/st_manager.h
+++ b/src/mesa/state_tracker/st_manager.h
@@ -28,20 +28,22 @@
#ifndef ST_MANAGER_H
#define ST_MANAGER_H
#include "main/menums.h"
#include "pipe/p_compiler.h"
struct st_context;
struct st_framebuffer;
struct st_framebuffer_interface;
+struct st_renderbuffer;
+struct pipe_surface;
void
st_manager_flush_frontbuffer(struct st_context *st);
void
st_manager_validate_framebuffers(struct st_context *st);
boolean
st_manager_add_color_renderbuffer(struct st_context *st, struct gl_framebuffer *fb,
gl_buffer_index idx);
@@ -49,11 +51,15 @@ st_manager_add_color_renderbuffer(struct st_context *st, struct gl_framebuffer *
void
st_framebuffer_reference(struct st_framebuffer **ptr,
struct st_framebuffer *stfb);
void
st_framebuffer_interface_destroy(struct st_framebuffer_interface *stfbi);
void
st_manager_flush_swapbuffers(void);
+void
+st_set_ws_renderbuffer_surface(struct st_renderbuffer *strb,
+ struct pipe_surface *surf);
+
#endif /* ST_MANAGER_H */
--
2.17.1
More information about the mesa-dev
mailing list