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
, ~0, 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
, ~0, NULL
);
97 failover_is_resource_referenced( struct pipe_context
*_pipe
,
98 struct pipe_resource
*resource
,
99 unsigned level
, int layer
)
101 struct failover_context
*failover
= failover_context( _pipe
);
102 struct pipe_context
*pipe
= (failover
->mode
== FO_HW
) ?
103 failover
->hw
: failover
->sw
;
105 return pipe
->is_resource_referenced(pipe
, resource
, level
, layer
);
108 struct pipe_context
*failover_create( struct pipe_context
*hw
,
109 struct pipe_context
*sw
)
111 struct failover_context
*failover
= CALLOC_STRUCT(failover_context
);
112 if (failover
== NULL
)
117 failover
->pipe
.winsys
= hw
->winsys
;
118 failover
->pipe
.screen
= hw
->screen
;
119 failover
->pipe
.destroy
= failover_destroy
;
121 failover
->pipe
.is_format_supported
= hw
->is_format_supported
;
122 failover
->pipe
.get_name
= hw
->get_name
;
123 failover
->pipe
.get_vendor
= hw
->get_vendor
;
124 failover
->pipe
.get_param
= hw
->get_param
;
125 failover
->pipe
.get_shader_param
= hw
->get_shader_param
;
126 failover
->pipe
.get_paramf
= hw
->get_paramf
;
129 failover
->pipe
.draw_vbo
= failover_draw_vbo
;
130 failover
->pipe
.clear
= hw
->clear
;
131 failover
->pipe
.clear_render_target
= hw
->clear_render_target
;
132 failover
->pipe
.clear_depth_stencil
= hw
->clear_depth_stencil
;
134 /* No software occlusion fallback (or other optional functionality)
135 * at this point - if the hardware doesn't support it, don't
136 * advertise it to the application.
138 failover
->pipe
.begin_query
= hw
->begin_query
;
139 failover
->pipe
.end_query
= hw
->end_query
;
141 failover_init_state_functions( failover
);
143 failover
->pipe
.resource_copy_region
= hw
->resource_copy_region
;
146 failover
->pipe
.resource_create
= hw
->resource_create
;
147 failover
->pipe
.resource_destroy
= hw
->resource_destroy
;
148 failover
->pipe
.create_surface
= hw
->create_surface
;
149 failover
->pipe
.surface_destroy
= hw
->surface_destroy
;
152 failover
->pipe
.flush
= hw
->flush
;
153 failover
->pipe
.is_resource_referenced
= failover_is_resource_referenced
;
157 return &failover
->pipe
;