From 92b50f59b214a92cf53ef1e881af3c6173994ab1 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 22 Feb 2014 01:32:30 +0800 Subject: [PATCH] st/dri, st/mesa: advertise sRGB-capability by default Applications tend to blindly assume that framebuffers are sRGB-capable. For GPUs that support rendering to sRGB framebuffers, we could assume the format is PIPE_FORMAT_B8G8R8X8_SRGB because, by default, GL_FRAMEBUFFER_SRGB is disabled and the format will be linearized. --- src/gallium/state_trackers/dri/common/dri_screen.c | 16 +++++++++++++--- src/mesa/state_tracker/st_cb_fbo.c | 4 ++++ src/mesa/state_tracker/st_manager.c | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index 7a6dcb2..de270ce 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -34,6 +34,7 @@ #include "dri_screen.h" +#include "util/u_format.h" #include "util/u_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_format.h" @@ -249,10 +250,19 @@ dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, return; if (mode->redBits == 8) { - if (mode->alphaBits == 8) - stvis->color_format = PIPE_FORMAT_BGRA8888_UNORM; - else + if (mode->alphaBits == 8) { + enum pipe_format linear_format = PIPE_FORMAT_BGRA8888_UNORM; + enum pipe_format srgb_format = util_format_srgb(linear_format); + + if (screen->base.screen->is_format_supported(screen->base.screen, + srgb_format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)) + stvis->color_format = srgb_format; + else + stvis->color_format = linear_format; + } + else { stvis->color_format = PIPE_FORMAT_BGRX8888_UNORM; + } } else { stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM; } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6449c62..ab6d9a0 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -358,6 +358,10 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw) case PIPE_FORMAT_R16G16B16A16_FLOAT: strb->Base.InternalFormat = GL_RGBA16F; break; + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_A8R8G8B8_SRGB: + strb->Base.InternalFormat = GL_SRGB8_ALPHA8; + break; default: _mesa_problem(NULL, "Unexpected format %s in st_new_renderbuffer_fb", diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index 6a776a8..76bf568 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -359,6 +359,8 @@ st_visual_to_context_mode(const struct st_visual *visual, mode->rgbBits = mode->redBits + mode->greenBits + mode->blueBits + mode->alphaBits; + + mode->sRGBCapable = util_format_is_srgb(visual->color_format); } if (visual->depth_stencil_format != PIPE_FORMAT_NONE) { -- 1.8.5.3