fo_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 "pipe/p_defines.h"
00030 #include "pipe/p_winsys.h"
00031 #include "util/u_memory.h"
00032 #include "pipe/p_context.h"
00033 
00034 #include "fo_context.h"
00035 #include "fo_winsys.h"
00036 
00037 
00038 
00039 static void failover_destroy( struct pipe_context *pipe )
00040 {
00041    struct failover_context *failover = failover_context( pipe );
00042 
00043    free( failover );
00044 }
00045 
00046 
00047 
00048 static boolean failover_draw_elements( struct pipe_context *pipe,
00049                                        struct pipe_buffer *indexBuffer,
00050                                        unsigned indexSize,
00051                                        unsigned prim, unsigned start, unsigned count)
00052 {
00053    struct failover_context *failover = failover_context( pipe );
00054 
00055    /* If there has been any statechange since last time, try hardware
00056     * rendering again:
00057     */
00058    if (failover->dirty) {
00059       failover->mode = FO_HW;
00060    }
00061 
00062    /* Try hardware:
00063     */
00064    if (failover->mode == FO_HW) {
00065       if (!failover->hw->draw_elements( failover->hw, 
00066                                         indexBuffer, 
00067                                         indexSize, 
00068                                         prim, 
00069                                         start, 
00070                                         count )) {
00071 
00072          failover->hw->flush( failover->hw, ~0, NULL );
00073          failover->mode = FO_SW;
00074       }
00075    }
00076 
00077    /* Possibly try software:
00078     */
00079    if (failover->mode == FO_SW) {
00080 
00081       if (failover->dirty) 
00082          failover_state_emit( failover );
00083 
00084       failover->sw->draw_elements( failover->sw, 
00085                                    indexBuffer, 
00086                                    indexSize, 
00087                                    prim, 
00088                                    start, 
00089                                    count );
00090 
00091       /* Be ready to switch back to hardware rendering without an
00092        * intervening flush.  Unlikely to be much performance impact to
00093        * this:
00094        */
00095       failover->sw->flush( failover->sw, ~0, NULL );
00096    }
00097 
00098    return TRUE;
00099 }
00100 
00101 
00102 static boolean failover_draw_arrays( struct pipe_context *pipe,
00103                                      unsigned prim, unsigned start, unsigned count)
00104 {
00105    return failover_draw_elements(pipe, NULL, 0, prim, start, count);
00106 }
00107 
00108 
00109 
00110 struct pipe_context *failover_create( struct pipe_context *hw,
00111                                       struct pipe_context *sw )
00112 {
00113    struct failover_context *failover = CALLOC_STRUCT(failover_context);
00114    if (failover == NULL)
00115       return NULL;
00116 
00117    failover->hw = hw;
00118    failover->sw = sw;
00119    failover->pipe.winsys = hw->winsys;
00120    failover->pipe.screen = hw->screen;
00121    failover->pipe.destroy = failover_destroy;
00122 #if 0
00123    failover->pipe.is_format_supported = hw->is_format_supported;
00124    failover->pipe.get_name = hw->get_name;
00125    failover->pipe.get_vendor = hw->get_vendor;
00126    failover->pipe.get_param = hw->get_param;
00127    failover->pipe.get_paramf = hw->get_paramf;
00128 #endif
00129 
00130    failover->pipe.draw_arrays = failover_draw_arrays;
00131    failover->pipe.draw_elements = failover_draw_elements;
00132    failover->pipe.clear = hw->clear;
00133 
00134    /* No software occlusion fallback (or other optional functionality)
00135     * at this point - if the hardware doesn't support it, don't
00136     * advertise it to the application.
00137     */
00138    failover->pipe.begin_query = hw->begin_query;
00139    failover->pipe.end_query = hw->end_query;
00140 
00141    failover_init_state_functions( failover );
00142 
00143    failover->pipe.surface_copy = hw->surface_copy;
00144    failover->pipe.surface_fill = hw->surface_fill;
00145 
00146 #if 0
00147    failover->pipe.texture_create = hw->texture_create;
00148    failover->pipe.texture_release = hw->texture_release;
00149    failover->pipe.get_tex_surface = hw->get_tex_surface;
00150    failover->pipe.texture_update = hw->texture_update;
00151 #endif
00152 
00153    failover->pipe.flush = hw->flush;
00154 
00155    failover->dirty = 0;
00156 
00157    return &failover->pipe;
00158 }
00159 

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