Merge branch 'gallium-nopointsizeminmax'
[mesa.git] / src / gallium / drivers / failover / fo_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_defines.h"
30 #include "util/u_simple_screen.h"
31 #include "util/u_memory.h"
32 #include "pipe/p_context.h"
33
34 #include "fo_context.h"
35 #include "fo_winsys.h"
36
37
38
39 static void failover_destroy( struct pipe_context *pipe )
40 {
41 struct failover_context *failover = failover_context( pipe );
42
43 free( failover );
44 }
45
46
47 void failover_fail_over( struct failover_context *failover )
48 {
49 failover->dirty = TRUE;
50 failover->mode = FO_SW;
51 }
52
53
54 static void failover_draw_elements( struct pipe_context *pipe,
55 struct pipe_buffer *indexBuffer,
56 unsigned indexSize,
57 unsigned prim,
58 unsigned start,
59 unsigned count)
60 {
61 struct failover_context *failover = failover_context( pipe );
62
63 /* If there has been any statechange since last time, try hardware
64 * rendering again:
65 */
66 if (failover->dirty) {
67 failover->mode = FO_HW;
68 }
69
70 /* Try hardware:
71 */
72 if (failover->mode == FO_HW) {
73 failover->hw->draw_elements( failover->hw,
74 indexBuffer,
75 indexSize,
76 prim,
77 start,
78 count );
79 }
80
81 /* Possibly try software:
82 */
83 if (failover->mode == FO_SW) {
84
85 if (failover->dirty) {
86 failover->hw->flush( failover->hw, ~0, NULL );
87 failover_state_emit( failover );
88 }
89
90 failover->sw->draw_elements( failover->sw,
91 indexBuffer,
92 indexSize,
93 prim,
94 start,
95 count );
96
97 /* Be ready to switch back to hardware rendering without an
98 * intervening flush. Unlikely to be much performance impact to
99 * this:
100 */
101 failover->sw->flush( failover->sw, ~0, NULL );
102 }
103 }
104
105
106 static void failover_draw_arrays( struct pipe_context *pipe,
107 unsigned prim, unsigned start, unsigned count)
108 {
109 failover_draw_elements(pipe, NULL, 0, prim, start, count);
110 }
111
112 static unsigned int
113 failover_is_texture_referenced( struct pipe_context *_pipe,
114 struct pipe_texture *texture,
115 unsigned face, unsigned level)
116 {
117 struct failover_context *failover = failover_context( _pipe );
118 struct pipe_context *pipe = (failover->mode == FO_HW) ?
119 failover->hw : failover->sw;
120
121 return pipe->is_texture_referenced(pipe, texture, face, level);
122 }
123
124 static unsigned int
125 failover_is_buffer_referenced( struct pipe_context *_pipe,
126 struct pipe_buffer *buf)
127 {
128 struct failover_context *failover = failover_context( _pipe );
129 struct pipe_context *pipe = (failover->mode == FO_HW) ?
130 failover->hw : failover->sw;
131
132 return pipe->is_buffer_referenced(pipe, buf);
133 }
134
135 struct pipe_context *failover_create( struct pipe_context *hw,
136 struct pipe_context *sw )
137 {
138 struct failover_context *failover = CALLOC_STRUCT(failover_context);
139 if (failover == NULL)
140 return NULL;
141
142 failover->hw = hw;
143 failover->sw = sw;
144 failover->pipe.winsys = hw->winsys;
145 failover->pipe.screen = hw->screen;
146 failover->pipe.destroy = failover_destroy;
147 #if 0
148 failover->pipe.is_format_supported = hw->is_format_supported;
149 failover->pipe.get_name = hw->get_name;
150 failover->pipe.get_vendor = hw->get_vendor;
151 failover->pipe.get_param = hw->get_param;
152 failover->pipe.get_paramf = hw->get_paramf;
153 #endif
154
155 failover->pipe.draw_arrays = failover_draw_arrays;
156 failover->pipe.draw_elements = failover_draw_elements;
157 failover->pipe.clear = hw->clear;
158
159 /* No software occlusion fallback (or other optional functionality)
160 * at this point - if the hardware doesn't support it, don't
161 * advertise it to the application.
162 */
163 failover->pipe.begin_query = hw->begin_query;
164 failover->pipe.end_query = hw->end_query;
165
166 failover_init_state_functions( failover );
167
168 failover->pipe.surface_copy = hw->surface_copy;
169 failover->pipe.surface_fill = hw->surface_fill;
170
171 #if 0
172 failover->pipe.texture_create = hw->texture_create;
173 failover->pipe.texture_destroy = hw->texture_destroy;
174 failover->pipe.get_tex_surface = hw->get_tex_surface;
175 failover->pipe.texture_update = hw->texture_update;
176 #endif
177
178 failover->pipe.flush = hw->flush;
179 failover->pipe.is_texture_referenced = failover_is_texture_referenced;
180 failover->pipe.is_buffer_referenced = failover_is_buffer_referenced;
181
182 failover->dirty = 0;
183
184 return &failover->pipe;
185 }
186