gallium: add flags parameter to pipe_screen::context_create
[mesa.git] / src / mesa / state_tracker / st_manager.c
index 706af7fd13d59265788c41377bfe1e447e2f1a2d..7abd128e719c0eee847bddd9ae2c959294217de2 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include "main/mtypes.h"
+#include "main/extensions.h"
 #include "main/context.h"
 #include "main/texobj.h"
 #include "main/teximage.h"
@@ -38,6 +39,7 @@
 #include "st_texture.h"
 
 #include "st_context.h"
+#include "st_extensions.h"
 #include "st_format.h"
 #include "st_cb_fbo.h"
 #include "st_cb_flush.h"
@@ -59,7 +61,7 @@
  * We'll only return non-null for window system framebuffers.
  * Note that this function may fail.
  */
-static INLINE struct st_framebuffer *
+static inline struct st_framebuffer *
 st_ws_framebuffer(struct gl_framebuffer *fb)
 {
    /* FBO cannot be casted.  See st_new_framebuffer */
@@ -71,7 +73,7 @@ st_ws_framebuffer(struct gl_framebuffer *fb)
 /**
  * Map an attachment to a buffer index.
  */
-static INLINE gl_buffer_index
+static inline gl_buffer_index
 attachment_to_buffer_index(enum st_attachment_type statt)
 {
    gl_buffer_index index;
@@ -107,7 +109,7 @@ attachment_to_buffer_index(enum st_attachment_type statt)
 /**
  * Map a buffer index to an attachment.
  */
-static INLINE enum st_attachment_type
+static inline enum st_attachment_type
 buffer_index_to_attachment(gl_buffer_index index)
 {
    enum st_attachment_type statt;
@@ -366,6 +368,7 @@ 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) {
@@ -450,7 +453,8 @@ st_framebuffer_create(struct st_context *st,
           st_pipe_format_to_mesa_format(srgb_format) != MESA_FORMAT_NONE &&
           screen->is_format_supported(screen, srgb_format,
                                       PIPE_TEXTURE_2D, stfbi->visual->samples,
-                                      PIPE_BIND_RENDER_TARGET))
+                                      (PIPE_BIND_DISPLAY_TARGET |
+                                       PIPE_BIND_RENDER_TARGET)))
          mode.sRGBCapable = GL_TRUE;
    }
 
@@ -653,7 +657,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       break;
    }
 
-   pipe = smapi->screen->context_create(smapi->screen, NULL);
+   pipe = smapi->screen->context_create(smapi->screen, NULL, 0);
    if (!pipe) {
       *error = ST_CONTEXT_ERROR_NO_MEMORY;
       return NULL;
@@ -677,12 +681,16 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
 
    if (attribs->flags & ST_CONTEXT_FLAG_FORWARD_COMPATIBLE)
       st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
+   if (attribs->flags & ST_CONTEXT_FLAG_ROBUST_ACCESS)
+      st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB;
+   if (attribs->flags & ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED)
+      st->ctx->Const.ResetStrategy = GL_LOSE_CONTEXT_ON_RESET_ARB;
 
    /* need to perform version check */
    if (attribs->major > 1 || attribs->minor > 0) {
       /* Is the actual version less than the requested version?
        */
-      if (st->ctx->Version < attribs->major * 10 + attribs->minor) {
+      if (st->ctx->Version < attribs->major * 10U + attribs->minor) {
         *error = ST_CONTEXT_ERROR_BAD_VERSION;
          st_destroy_context(st);
          return NULL;
@@ -910,6 +918,40 @@ st_manager_add_color_renderbuffer(struct st_context *st,
    return TRUE;
 }
 
+static unsigned get_version(struct pipe_screen *screen,
+                            struct st_config_options *options, gl_api api)
+{
+   struct gl_constants consts = {0};
+   struct gl_extensions extensions = {0};
+   GLuint version;
+
+   if (_mesa_override_gl_version_contextless(&consts, &api, &version)) {
+      return version;
+   }
+
+   _mesa_init_constants(&consts, api);
+   _mesa_init_extensions(&extensions);
+
+   st_init_limits(screen, &consts, &extensions);
+   st_init_extensions(screen, &consts, &extensions, options, GL_TRUE);
+
+   return _mesa_get_version(&extensions, &consts, api);
+}
+
+static void
+st_api_query_versions(struct st_api *stapi, struct st_manager *sm,
+                      struct st_config_options *options,
+                      int *gl_core_version,
+                      int *gl_compat_version,
+                      int *gl_es1_version,
+                      int *gl_es2_version)
+{
+   *gl_core_version = get_version(sm->screen, options, API_OPENGL_CORE);
+   *gl_compat_version = get_version(sm->screen, options, API_OPENGL_COMPAT);
+   *gl_es1_version = get_version(sm->screen, options, API_OPENGLES);
+   *gl_es2_version = get_version(sm->screen, options, API_OPENGLES2);
+}
+
 static const struct st_api st_gl_api = {
    "Mesa " PACKAGE_VERSION,
    ST_API_OPENGL,
@@ -920,6 +962,7 @@ static const struct st_api st_gl_api = {
    0,
    ST_API_FEATURE_MS_VISUALS_MASK,
    st_api_destroy,
+   st_api_query_versions,
    st_api_get_proc_address,
    st_api_create_context,
    st_api_make_current,