[Mesa-dev] [PATCH 1/2] swrast: add an interface createNewContextForAPI

Feng, Haitao haitao.feng at intel.com
Thu Feb 3 17:50:41 PST 2011


Hi Kristian,

Thanks for your comments and getting this part into mesa master.

Thanks for letting me know the mesa development process. I will follow it in the future. 

Thanks
-Haitao

-----Original Message-----
From: hoegsberg at gmail.com [mailto:hoegsberg at gmail.com] On Behalf Of Kristian Høgsberg
Sent: 2011年2月4日 1:06
To: Feng, Haitao
Cc: mesa-dev at lists.freedesktop.org
Subject: Re: [Mesa-dev] [PATCH 1/2] swrast: add an interface createNewContextForAPI

On Sun, Jan 30, 2011 at 3:03 AM, Feng, Haitao <haitao.feng at intel.com> wrote:
> From 84b2c96eb2e477ac66b51022604286f555ff2f5b Mon Sep 17 00:00:00 2001
> From: Haitao Feng <haitao.feng at intel.com>
> Date: Sat, 29 Jan 2011 23:35:54 -0800
> Subject: [PATCH 1/2] swrast: add an interface createNewContextForAPI
>
> This new interface could set up context for OpenGL,
> OpenGL ES1 and OpenGL ES2. It will be used by egl_dri2
> driver.
>
> NOTE: this is a candidate for the 7.9 branch.

The convention of marking commits with the "candidate for the 7.9
branch" comment is used to indicate that the patch is for mesa master,
but should be cherry-picked back to a stable release, not that the
patch applies to 7.9.  We always commit to master first and the
cherry-pick back to release branches.  The patch applies with a minor
edit, though, and I committed it the mesa master.

Kristian

> Signed-off-by: Haitao Feng <haitao.feng at intel.com>
> ---
>  include/GL/internal/dri_interface.h      |    9 +++-
>  src/mesa/drivers/dri/common/drisw_util.c |   45 +++++++++++++++-
>  src/mesa/drivers/dri/swrast/swrast.c     |   85 ++++++++++++++++++++++++++---
>  3 files changed, 128 insertions(+), 11 deletions(-)
>
> diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
> index 9ee039b..d0fe193 100644
> --- a/include/GL/internal/dri_interface.h
> +++ b/include/GL/internal/dri_interface.h
> @@ -647,7 +647,7 @@ struct __DRIlegacyExtensionRec {
>  * conjunction with the core extension.
>  */
>  #define __DRI_SWRAST "DRI_SWRast"
> -#define __DRI_SWRAST_VERSION 1
> +#define __DRI_SWRAST_VERSION 2
>
>  struct __DRIswrastExtensionRec {
>     __DRIextension base;
> @@ -660,6 +660,13 @@ struct __DRIswrastExtensionRec {
>     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
>                                        const __DRIconfig *config,
>                                        void *loaderPrivate);
> +
> +   /* Since version 2 */
> +   __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
> +                                           int api,
> +                                           const __DRIconfig *config,
> +                                           __DRIcontext *shared,
> +                                           void *data);
>  };
>
>  /**
> diff --git a/src/mesa/drivers/dri/common/drisw_util.c b/src/mesa/drivers/dri/common/drisw_util.c
> index 1529c23..7506358 100644
> --- a/src/mesa/drivers/dri/common/drisw_util.c
> +++ b/src/mesa/drivers/dri/common/drisw_util.c
> @@ -121,6 +121,48 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
>     return pcp;
>  }
>
> +static __DRIcontext *
> +driCreateNewContextForAPI(__DRIscreen *psp, int api,
> +                          const __DRIconfig *config,
> +                          __DRIcontext *shared, void *data)
> +{
> +    __DRIcontext *pcp;
> +    void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
> +    gl_api mesa_api;
> +
> +    switch (api) {
> +    case __DRI_API_OPENGL:
> +            mesa_api = API_OPENGL;
> +            break;
> +    case __DRI_API_GLES:
> +            mesa_api = API_OPENGLES;
> +            break;
> +    case __DRI_API_GLES2:
> +            mesa_api = API_OPENGLES2;
> +            break;
> +    default:
> +            return NULL;
> +    }
> +
> +    pcp = CALLOC_STRUCT(__DRIcontextRec);
> +    if (!pcp)
> +        return NULL;
> +
> +    pcp->loaderPrivate = data;
> +
> +    pcp->driScreenPriv = psp;
> +    pcp->driDrawablePriv = NULL;
> +    pcp->driReadablePriv = NULL;
> +
> +    if (!driDriverAPI.CreateContext(mesa_api,
> +                            &config->modes, pcp, shareCtx)) {
> +        FREE(pcp);
> +        return NULL;
> +    }
> +
> +    return pcp;
> +}
> +
>  static void
>  driDestroyContext(__DRIcontext *pcp)
>  {
> @@ -269,5 +311,6 @@ const __DRIcoreExtension driCoreExtension = {
>  const __DRIswrastExtension driSWRastExtension = {
>     { __DRI_SWRAST, __DRI_SWRAST_VERSION },
>     driCreateNewScreen,
> -    driCreateNewDrawable
> +    driCreateNewDrawable,
> +    driCreateNewContextForAPI
>  };
> diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
> index ff53ffd..13445d2 100644
> --- a/src/mesa/drivers/dri/swrast/swrast.c
> +++ b/src/mesa/drivers/dri/swrast/swrast.c
> @@ -563,6 +563,60 @@ swrast_init_driver_functions(struct dd_function_table *driver)
>     driver->ChooseTextureFormat = swrastChooseTextureFormat;
>  }
>
> +static const char *es2_extensions[] = {
> +   /* Used by mesa internally (cf all_mesa_extensions in ../common/utils.c) */
> +   "GL_ARB_draw_buffers",
> +   "GL_ARB_multisample",
> +   "GL_ARB_texture_compression",
> +   "GL_ARB_transpose_matrix",
> +   "GL_ARB_vertex_buffer_object",
> +   "GL_ARB_window_pos",
> +   "GL_EXT_blend_func_separate",
> +   "GL_EXT_compiled_vertex_array",
> +   "GL_EXT_framebuffer_blit",
> +   "GL_EXT_multi_draw_arrays",
> +   "GL_EXT_polygon_offset",
> +   "GL_EXT_texture_object",
> +   "GL_EXT_vertex_array",
> +   "GL_IBM_multimode_draw_arrays",
> +   "GL_MESA_window_pos",
> +   "GL_NV_vertex_program",
> +
> +   /* Required by GLES2 */
> +   "GL_ARB_fragment_program",
> +   "GL_ARB_fragment_shader",
> +   "GL_ARB_multitexture",
> +   "GL_ARB_shader_objects",
> +   "GL_ARB_texture_cube_map",
> +   "GL_ARB_texture_mirrored_repeat",
> +   "GL_ARB_texture_non_power_of_two",
> +   "GL_ARB_vertex_shader",
> +   "GL_EXT_blend_color",
> +   "GL_EXT_blend_equation_separate",
> +   "GL_EXT_blend_minmax",
> +   "GL_EXT_blend_subtract",
> +   "GL_EXT_stencil_wrap",
> +
> +   /* Optional GLES2 */
> +   "GL_ARB_framebuffer_object",
> +   "GL_EXT_texture_filter_anisotropic",
> +   "GL_ARB_depth_texture",
> +   "GL_EXT_packed_depth_stencil",
> +   "GL_EXT_framebuffer_object",
> +   NULL,
> +};
> +
> +static void
> +InitExtensionsES2(GLcontext *ctx)
> +{
> +   int i;
> +
> +   /* Can't use driInitExtensions() since it uses extensions from
> + *     * main/remap_helper.h when called the first time. */
> +
> +   for (i = 0; es2_extensions[i]; i++)
> +      _mesa_enable_extension(ctx, es2_extensions[i]);
> +}
>
>  /**
>  * Context-related functions.
> @@ -599,7 +653,7 @@ dri_create_context(gl_api api,
>     mesaCtx = &ctx->Base;
>
>     /* basic context setup */
> -    if (!_mesa_initialize_context(mesaCtx, visual, sharedCtx, &functions, (void *) cPriv)) {
> +    if (!_mesa_initialize_context_for_api(mesaCtx, api, visual, sharedCtx, &functions, (void *) cPriv)) {
>        goto context_fail;
>     }
>
> @@ -619,16 +673,29 @@ dri_create_context(gl_api api,
>        tnl->Driver.RunPipeline = _tnl_run_pipeline;
>     }
>
> -    _mesa_enable_sw_extensions(mesaCtx);
> -    _mesa_enable_1_3_extensions(mesaCtx);
> -    _mesa_enable_1_4_extensions(mesaCtx);
> -    _mesa_enable_1_5_extensions(mesaCtx);
> -    _mesa_enable_2_0_extensions(mesaCtx);
> -    _mesa_enable_2_1_extensions(mesaCtx);
> -
>     _mesa_meta_init(mesaCtx);
> +    _mesa_enable_sw_extensions(mesaCtx);
>
> -    driInitExtensions( mesaCtx, NULL, GL_FALSE );
> +    switch (api) {
> +    case API_OPENGL:
> +        _mesa_enable_1_3_extensions(mesaCtx);
> +        _mesa_enable_1_4_extensions(mesaCtx);
> +        _mesa_enable_1_5_extensions(mesaCtx);
> +        _mesa_enable_2_0_extensions(mesaCtx);
> +        _mesa_enable_2_1_extensions(mesaCtx);
> +
> +        driInitExtensions( mesaCtx, NULL, GL_FALSE );
> +        break;
> +    case API_OPENGLES:
> +        _mesa_enable_1_3_extensions(mesaCtx);
> +        _mesa_enable_1_4_extensions(mesaCtx);
> +        _mesa_enable_1_5_extensions(mesaCtx);
> +
> +        break;
> +    case API_OPENGLES2:
> +        InitExtensionsES2( mesaCtx);
> +        break;
> +    }
>
>     return GL_TRUE;
>
> --
> 1.7.2.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>


More information about the mesa-dev mailing list