1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "pipe/p_defines.h"
30 #include "util/u_memory.h"
31 #include "pipe/p_context.h"
32 #include "util/u_inlines.h"
34 #include "fo_context.h"
35 #include "fo_winsys.h"
39 static void failover_destroy( struct pipe_context *pipe )
41 struct failover_context *failover = failover_context( pipe );
44 for (i = 0; i < failover->num_vertex_buffers; i++) {
45 pipe_resource_reference(&failover->vertex_buffers[i].buffer, NULL);
52 void failover_fail_over( struct failover_context *failover )
54 failover->dirty = TRUE;
55 failover->mode = FO_SW;
59 static void failover_draw_vbo( struct pipe_context *pipe,
60 const struct pipe_draw_info *info)
62 struct failover_context *failover = failover_context( pipe );
64 /* If there has been any statechange since last time, try hardware
67 if (failover->dirty) {
68 failover->mode = FO_HW;
73 if (failover->mode == FO_HW) {
74 failover->hw->draw_vbo( failover->hw, info );
77 /* Possibly try software:
79 if (failover->mode == FO_SW) {
81 if (failover->dirty) {
82 failover->hw->flush( failover->hw, NULL );
83 failover_state_emit( failover );
86 failover->sw->draw_vbo( failover->sw, info );
88 /* Be ready to switch back to hardware rendering without an
89 * intervening flush. Unlikely to be much performance impact to
92 failover->sw->flush( failover->sw, NULL );
96 struct pipe_context *failover_create( struct pipe_context *hw,
97 struct pipe_context *sw )
99 struct failover_context *failover = CALLOC_STRUCT(failover_context);
100 if (failover == NULL)
105 failover->pipe.winsys = hw->winsys;
106 failover->pipe.screen = hw->screen;
107 failover->pipe.destroy = failover_destroy;
109 failover->pipe.is_format_supported = hw->is_format_supported;
110 failover->pipe.get_name = hw->get_name;
111 failover->pipe.get_vendor = hw->get_vendor;
112 failover->pipe.get_param = hw->get_param;
113 failover->pipe.get_shader_param = hw->get_shader_param;
114 failover->pipe.get_paramf = hw->get_paramf;
117 failover->pipe.draw_vbo = failover_draw_vbo;
118 failover->pipe.clear = hw->clear;
119 failover->pipe.clear_render_target = hw->clear_render_target;
120 failover->pipe.clear_depth_stencil = hw->clear_depth_stencil;
122 /* No software occlusion fallback (or other optional functionality)
123 * at this point - if the hardware doesn't support it, don't
124 * advertise it to the application.
126 failover->pipe.begin_query = hw->begin_query;
127 failover->pipe.end_query = hw->end_query;
129 failover_init_state_functions( failover );
131 failover->pipe.resource_copy_region = hw->resource_copy_region;
134 failover->pipe.resource_create = hw->resource_create;
135 failover->pipe.resource_destroy = hw->resource_destroy;
136 failover->pipe.create_surface = hw->create_surface;
137 failover->pipe.surface_destroy = hw->surface_destroy;
140 failover->pipe.flush = hw->flush;
144 return &failover->pipe;