gallium: rename clearRT / clearDS to clear_render_target / clear_depth_stencil
[profile/ivi/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_memory.h"
31 #include "pipe/p_context.h"
32
33 #include "fo_context.h"
34 #include "fo_winsys.h"
35
36
37
38 static void failover_destroy( struct pipe_context *pipe )
39 {
40    struct failover_context *failover = failover_context( pipe );
41
42    FREE( failover );
43 }
44
45
46 void failover_fail_over( struct failover_context *failover )
47 {
48    failover->dirty = TRUE;
49    failover->mode = FO_SW;
50 }
51
52
53 static void failover_draw_elements( struct pipe_context *pipe,
54                                     struct pipe_resource *indexResource,
55                                     unsigned indexSize,
56                                     int indexBias,
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                                    indexResource, 
75                                    indexSize, 
76                                    indexBias,
77                                    prim, 
78                                    start, 
79                                    count );
80    }
81
82    /* Possibly try software:
83     */
84    if (failover->mode == FO_SW) {
85
86       if (failover->dirty) {
87          failover->hw->flush( failover->hw, ~0, NULL );
88          failover_state_emit( failover );
89       }
90
91       failover->sw->draw_elements( failover->sw, 
92                                    indexResource, 
93                                    indexSize, 
94                                    indexBias,
95                                    prim, 
96                                    start, 
97                                    count );
98
99       /* Be ready to switch back to hardware rendering without an
100        * intervening flush.  Unlikely to be much performance impact to
101        * this:
102        */
103       failover->sw->flush( failover->sw, ~0, NULL );
104    }
105 }
106
107
108 static void failover_draw_arrays( struct pipe_context *pipe,
109                                      unsigned prim, unsigned start, unsigned count)
110 {
111    failover_draw_elements(pipe, NULL, 0, 0, prim, start, count);
112 }
113
114 static unsigned int
115 failover_is_resource_referenced( struct pipe_context *_pipe,
116                                  struct pipe_resource *resource,
117                                  unsigned face, unsigned level)
118 {
119    struct failover_context *failover = failover_context( _pipe );
120    struct pipe_context *pipe = (failover->mode == FO_HW) ?
121       failover->hw : failover->sw;
122
123    return pipe->is_resource_referenced(pipe, resource, face, level);
124 }
125
126 struct pipe_context *failover_create( struct pipe_context *hw,
127                                       struct pipe_context *sw )
128 {
129    struct failover_context *failover = CALLOC_STRUCT(failover_context);
130    if (failover == NULL)
131       return NULL;
132
133    failover->hw = hw;
134    failover->sw = sw;
135    failover->pipe.winsys = hw->winsys;
136    failover->pipe.screen = hw->screen;
137    failover->pipe.destroy = failover_destroy;
138 #if 0
139    failover->pipe.is_format_supported = hw->is_format_supported;
140    failover->pipe.get_name = hw->get_name;
141    failover->pipe.get_vendor = hw->get_vendor;
142    failover->pipe.get_param = hw->get_param;
143    failover->pipe.get_paramf = hw->get_paramf;
144 #endif
145
146    failover->pipe.draw_arrays = failover_draw_arrays;
147    failover->pipe.draw_elements = failover_draw_elements;
148    failover->pipe.clear = hw->clear;
149    failover->pipe.clear_render_target = hw->clear_render_target;
150    failover->pipe.clear_depth_stencil = hw->clear_depth_stencil;
151
152    /* No software occlusion fallback (or other optional functionality)
153     * at this point - if the hardware doesn't support it, don't
154     * advertise it to the application.
155     */
156    failover->pipe.begin_query = hw->begin_query;
157    failover->pipe.end_query = hw->end_query;
158
159    failover_init_state_functions( failover );
160
161    failover->pipe.resource_copy_region = hw->resource_copy_region;
162
163 #if 0
164    failover->pipe.texture_create = hw->texture_create;
165    failover->pipe.texture_destroy = hw->texture_destroy;
166    failover->pipe.get_tex_surface = hw->get_tex_surface;
167    failover->pipe.texture_update = hw->texture_update;
168 #endif
169
170    failover->pipe.flush = hw->flush;
171    failover->pipe.is_resource_referenced = failover_is_resource_referenced;
172
173    failover->dirty = 0;
174
175    return &failover->pipe;
176 }
177