intel_context.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 
00029 #include "i830_dri.h"
00030 
00031 #include "intel_screen.h"
00032 #include "intel_context.h"
00033 #include "intel_swapbuffers.h"
00034 #include "intel_batchbuffer.h"
00035 #include "intel_winsys_softpipe.h"
00036 
00037 #include "i915simple/i915_screen.h"
00038 
00039 #include "state_tracker/st_public.h"
00040 #include "state_tracker/st_context.h"
00041 #include "pipe/p_defines.h"
00042 #include "pipe/p_context.h"
00043 
00044 #include "utils.h"
00045 
00046 
00047 #ifdef DEBUG
00048 int __intel_debug = 0;
00049 #endif
00050 
00051 
00052 #define need_GL_ARB_multisample
00053 #define need_GL_ARB_point_parameters
00054 #define need_GL_ARB_texture_compression
00055 #define need_GL_ARB_vertex_buffer_object
00056 #define need_GL_ARB_vertex_program
00057 #define need_GL_ARB_window_pos
00058 #define need_GL_EXT_blend_color
00059 #define need_GL_EXT_blend_equation_separate
00060 #define need_GL_EXT_blend_func_separate
00061 #define need_GL_EXT_blend_minmax
00062 #define need_GL_EXT_cull_vertex
00063 #define need_GL_EXT_fog_coord
00064 #define need_GL_EXT_framebuffer_object
00065 #define need_GL_EXT_multi_draw_arrays
00066 #define need_GL_EXT_secondary_color
00067 #define need_GL_NV_vertex_program
00068 #include "extension_helper.h"
00069 
00070 
00078 const struct dri_extension card_extensions[] = {
00079    {"GL_ARB_multisample", GL_ARB_multisample_functions},
00080    {"GL_ARB_multitexture", NULL},
00081    {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
00082    {"GL_ARB_texture_border_clamp", NULL},
00083    {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
00084    {"GL_ARB_texture_cube_map", NULL},
00085    {"GL_ARB_texture_env_add", NULL},
00086    {"GL_ARB_texture_env_combine", NULL},
00087    {"GL_ARB_texture_env_dot3", NULL},
00088    {"GL_ARB_texture_mirrored_repeat", NULL},
00089    {"GL_ARB_texture_rectangle", NULL},
00090    {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
00091    {"GL_ARB_pixel_buffer_object", NULL},
00092    {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
00093    {"GL_ARB_window_pos", GL_ARB_window_pos_functions},
00094    {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
00095    {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions},
00096    {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
00097    {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
00098    {"GL_EXT_blend_subtract", NULL},
00099    {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
00100    {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
00101    {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
00102    {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
00103    {"GL_EXT_packed_depth_stencil", NULL},
00104    {"GL_EXT_pixel_buffer_object", NULL},
00105    {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
00106    {"GL_EXT_stencil_wrap", NULL},
00107    {"GL_EXT_texture_edge_clamp", NULL},
00108    {"GL_EXT_texture_env_combine", NULL},
00109    {"GL_EXT_texture_env_dot3", NULL},
00110    {"GL_EXT_texture_filter_anisotropic", NULL},
00111    {"GL_EXT_texture_lod_bias", NULL},
00112    {"GL_3DFX_texture_compression_FXT1", NULL},
00113    {"GL_APPLE_client_storage", NULL},
00114    {"GL_MESA_pack_invert", NULL},
00115    {"GL_MESA_ycbcr_texture", NULL},
00116    {"GL_NV_blend_square", NULL},
00117    {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
00118    {"GL_NV_vertex_program1_1", NULL},
00119    {"GL_SGIS_generate_mipmap", NULL },
00120    {NULL, NULL}
00121 };
00122 
00123 
00124 
00125 #ifdef DEBUG
00126 static const struct dri_debug_control debug_control[] = {
00127    {"ioctl", DEBUG_IOCTL},
00128    {"bat", DEBUG_BATCH},
00129    {"lock", DEBUG_LOCK},
00130    {"swap", DEBUG_SWAP},
00131    {NULL, 0}
00132 };
00133 #endif
00134 
00135 
00136 
00137 static void
00138 intel_lock_hardware(struct intel_be_context *context)
00139 {
00140    struct intel_context *intel = (struct intel_context *)context;
00141    LOCK_HARDWARE(intel);
00142 }
00143 
00144 static void
00145 intel_unlock_hardware(struct intel_be_context *context)
00146 {
00147    struct intel_context *intel = (struct intel_context *)context;
00148    UNLOCK_HARDWARE(intel);
00149 }
00150 
00151 static boolean
00152 intel_locked_hardware(struct intel_be_context *context)
00153 {
00154    struct intel_context *intel = (struct intel_context *)context;
00155    return intel->locked ? TRUE : FALSE;
00156 }
00157 
00158 GLboolean
00159 intelCreateContext(const __GLcontextModes * visual,
00160                    __DRIcontextPrivate * driContextPriv,
00161                    void *sharedContextPrivate)
00162 {
00163    struct intel_context *intel = CALLOC_STRUCT(intel_context);
00164    __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
00165    struct intel_screen *intelScreen = intel_screen(sPriv);
00166    drmI830Sarea *saPriv = intelScreen->sarea;
00167    int fthrottle_mode;
00168    GLboolean havePools;
00169    struct pipe_context *pipe;
00170    struct st_context *st_share = NULL;
00171 
00172    if (sharedContextPrivate) {
00173       st_share = ((struct intel_context *) sharedContextPrivate)->st;
00174    }
00175 
00176    driContextPriv->driverPrivate = intel;
00177    intel->intelScreen = intelScreen;
00178    intel->driScreen = sPriv;
00179    intel->sarea = saPriv;
00180 
00181    driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
00182                        intel->driScreen->myNum, "i915");
00183 
00184 
00185    /*
00186     * memory pools
00187     */
00188    DRM_LIGHT_LOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
00189    // ZZZ JB should be per screen and not be done per context
00190    havePools = intelCreatePools(sPriv);
00191    DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, driContextPriv->hHWContext);
00192    if (!havePools)
00193       return GL_FALSE;
00194 
00195 
00196    /* Dri stuff */
00197    intel->hHWContext = driContextPriv->hHWContext;
00198    intel->driFd = sPriv->fd;
00199    intel->driHwLock = (drmLock *) & sPriv->pSAREA->lock;
00200 
00201    fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
00202    intel->iw.irq_seq = -1;
00203    intel->irqsEmitted = 0;
00204 
00205    intel->last_swap_fence = NULL;
00206    intel->first_swap_fence = NULL;
00207 
00208 #ifdef DEBUG
00209    __intel_debug = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
00210 #endif
00211    intel->base.hardware_lock = intel_lock_hardware;
00212    intel->base.hardware_unlock = intel_unlock_hardware;
00213    intel->base.hardware_locked = intel_locked_hardware;
00214 
00215    intel_be_init_context(&intel->base, &intelScreen->base);
00216 
00217    /*
00218     * Pipe-related setup
00219     */
00220    if (getenv("INTEL_SP")) {
00221       /* use softpipe driver instead of hw */
00222       pipe = intel_create_softpipe( intel, &intelScreen->base.base );
00223    }
00224    else {
00225       switch (intel->intelScreen->deviceID) {
00226       case PCI_CHIP_I945_G:
00227       case PCI_CHIP_I945_GM:
00228       case PCI_CHIP_I945_GME:
00229       case PCI_CHIP_G33_G:
00230       case PCI_CHIP_Q33_G:
00231       case PCI_CHIP_Q35_G:
00232       case PCI_CHIP_I915_G:
00233       case PCI_CHIP_I915_GM:
00234          pipe = i915_create_context(intelScreen->base.screen,
00235                                     &intelScreen->base.base,
00236                                     &intel->base.base);
00237          break;
00238       default:
00239          fprintf(stderr, "Unknown PCIID %x in %s, using software driver\n",
00240                  intel->intelScreen->deviceID, __FUNCTION__);
00241 
00242          pipe = intel_create_softpipe( intel, &intelScreen->base.base );
00243          break;
00244       }
00245    }
00246 
00247    pipe->priv = intel;
00248 
00249    intel->st = st_create_context(pipe, visual, st_share);
00250 
00251    driInitExtensions( intel->st->ctx, card_extensions, GL_TRUE );
00252 
00253    return GL_TRUE;
00254 }
00255 
00256 
00257 void
00258 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
00259 {
00260    struct intel_context *intel = intel_context(driContextPriv);
00261 
00262    assert(intel);               /* should never be null */
00263    if (intel) {
00264       st_finish(intel->st);
00265 
00266       if (intel->last_swap_fence) {
00267          driFenceFinish(intel->last_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
00268          driFenceUnReference(&intel->last_swap_fence);
00269          intel->last_swap_fence = NULL;
00270       }
00271       if (intel->first_swap_fence) {
00272          driFenceFinish(intel->first_swap_fence, DRM_FENCE_TYPE_EXE, GL_TRUE);
00273          driFenceUnReference(&intel->first_swap_fence);
00274          intel->first_swap_fence = NULL;
00275       }
00276 
00277       if (intel->intelScreen->dummyContext == intel)
00278          intel->intelScreen->dummyContext = NULL;
00279 
00280       st_destroy_context(intel->st);
00281       intel_be_destroy_context(&intel->base);
00282       free(intel);
00283    }
00284 }
00285 
00286 
00287 GLboolean
00288 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
00289 {
00290    struct intel_context *intel = intel_context(driContextPriv);
00291    st_flush(intel->st, PIPE_FLUSH_RENDER_CACHE, NULL);
00292    /* XXX make_current(NULL)? */
00293    return GL_TRUE;
00294 }
00295 
00296 
00297 GLboolean
00298 intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
00299                  __DRIdrawablePrivate * driDrawPriv,
00300                  __DRIdrawablePrivate * driReadPriv)
00301 {
00302    if (driContextPriv) {
00303       struct intel_context *intel = intel_context(driContextPriv);
00304       struct intel_framebuffer *draw_fb = intel_framebuffer(driDrawPriv);
00305       struct intel_framebuffer *read_fb = intel_framebuffer(driReadPriv);
00306 
00307       assert(draw_fb->stfb);
00308       assert(read_fb->stfb);
00309 
00310       /* This is for situations in which we need a rendering context but
00311        * there may not be any currently bound.
00312        */
00313       intel->intelScreen->dummyContext = intel;
00314 
00315       st_make_current(intel->st, draw_fb->stfb, read_fb->stfb);
00316 
00317       if ((intel->driDrawable != driDrawPriv) ||
00318           (intel->lastStamp != driDrawPriv->lastStamp)) {
00319          intel->driDrawable = driDrawPriv;
00320          intelUpdateWindowSize(driDrawPriv);
00321          intel->lastStamp = driDrawPriv->lastStamp;
00322       }
00323 
00324       /* The size of the draw buffer will have been updated above.
00325        * If the readbuffer is a different window, check/update its size now.
00326        */
00327       if (driReadPriv != driDrawPriv) {
00328          intelUpdateWindowSize(driReadPriv);
00329       }
00330 
00331    }
00332    else {
00333       st_make_current(NULL, NULL, NULL);
00334    }
00335 
00336    return GL_TRUE;
00337 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4