From f88fb21885709e627949437a414f4a6cef8bc5b0 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 21 Dec 2021 15:52:17 +1000 Subject: [PATCH] mesa/st: move DrawBufferAllocate into mesa. Little bit of refactoring here. Reviewed-by: Kristian H. Kristensen Part-of: --- src/mesa/main/buffers.c | 7 +++++-- src/mesa/main/framebuffer.c | 26 +++++++++++++++++++++++++- src/mesa/main/framebuffer.h | 3 +++ src/mesa/state_tracker/st_cb_fbo.c | 27 --------------------------- src/mesa/state_tracker/st_cb_fbo.h | 1 - 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index 82da74e46c1..9c4fb37a6cb 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -35,6 +35,7 @@ #include "context.h" #include "enums.h" #include "fbobject.h" +#include "framebuffer.h" #include "hash.h" #include "mtypes.h" #include "state.h" @@ -321,7 +322,8 @@ draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb, /* Call device driver function only if fb is the bound draw buffer */ if (fb == ctx->DrawBuffer) { - st_DrawBufferAllocate(ctx); + if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) + _mesa_draw_buffer_allocate(ctx); } } @@ -627,7 +629,8 @@ draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb, GLsizei n, * may not be valid. */ if (fb == ctx->DrawBuffer) { - st_DrawBufferAllocate(ctx); + if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) + _mesa_draw_buffer_allocate(ctx); } } diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 612da05de75..38723c8581b 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -49,6 +49,7 @@ #include "util/u_memory.h" #include "state_tracker/st_cb_fbo.h" +#include "state_tracker/st_manager.h" /** * Compute/set the _DepthMax field for the given framebuffer. @@ -581,6 +582,29 @@ update_color_read_buffer(struct gl_framebuffer *fb) } } +/** + * Called via glDrawBuffer. We only provide this driver function so that we + * can check if we need to allocate a new renderbuffer. Specifically, we + * don't usually allocate a front color buffer when using a double-buffered + * visual. But if the app calls glDrawBuffer(GL_FRONT) we need to allocate + * that buffer. Note, this is only for window system buffers, not user- + * created FBOs. + */ +void +_mesa_draw_buffer_allocate(struct gl_context *ctx) +{ + struct gl_framebuffer *fb = ctx->DrawBuffer; + assert(_mesa_is_winsys_fbo(fb)); + GLuint i; + /* add the renderbuffers on demand */ + for (i = 0; i < fb->_NumColorDrawBuffers; i++) { + gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i]; + + if (idx != BUFFER_NONE) { + st_manager_add_color_renderbuffer(st_context(ctx), fb, idx); + } + } +} /** * Update a gl_framebuffer's derived state. @@ -611,7 +635,7 @@ update_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb) /* Call device driver function if fb is the bound draw buffer. */ if (fb == ctx->DrawBuffer) { - st_DrawBufferAllocate(ctx); + _mesa_draw_buffer_allocate(ctx); } } else { diff --git a/src/mesa/main/framebuffer.h b/src/mesa/main/framebuffer.h index 4d54442a8f6..4f16130e32f 100644 --- a/src/mesa/main/framebuffer.h +++ b/src/mesa/main/framebuffer.h @@ -143,4 +143,7 @@ _mesa_is_multisample_enabled(const struct gl_context *ctx); extern bool _mesa_is_alpha_test_enabled(const struct gl_context *ctx); +void +_mesa_draw_buffer_allocate(struct gl_context *ctx); + #endif /* FRAMEBUFFER_H */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 107d83d1124..5eaca4ba6a9 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -536,33 +536,6 @@ st_update_renderbuffer_surface(struct st_context *st, rb->surface = *psurf; } -/** - * Called via glDrawBuffer. We only provide this driver function so that we - * can check if we need to allocate a new renderbuffer. Specifically, we - * don't usually allocate a front color buffer when using a double-buffered - * visual. But if the app calls glDrawBuffer(GL_FRONT) we need to allocate - * that buffer. Note, this is only for window system buffers, not user- - * created FBOs. - */ -void -st_DrawBufferAllocate(struct gl_context *ctx) -{ - struct st_context *st = st_context(ctx); - struct gl_framebuffer *fb = ctx->DrawBuffer; - - if (_mesa_is_winsys_fbo(fb)) { - GLuint i; - /* add the renderbuffers on demand */ - for (i = 0; i < fb->_NumColorDrawBuffers; i++) { - gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i]; - - if (idx != BUFFER_NONE) { - st_manager_add_color_renderbuffer(st, fb, idx); - } - } - } -} - /** * Called via ctx->Driver.MapRenderbuffer. */ diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 675d9cb59a2..58ac4330776 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -78,7 +78,6 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height); -void st_DrawBufferAllocate(struct gl_context *ctx); void st_MapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb,