summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/failover/fo_context.c
blob: 37184eac7b17522b6862d6c6bf5680fab3c15b9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**************************************************************************
 * 
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/


#include "pipe/p_defines.h"
#include "pipe/internal/p_winsys_screen.h"
#include "util/u_memory.h"
#include "pipe/p_context.h"

#include "fo_context.h"
#include "fo_winsys.h"



static void failover_destroy( struct pipe_context *pipe )
{
   struct failover_context *failover = failover_context( pipe );

   free( failover );
}



static boolean failover_draw_elements( struct pipe_context *pipe,
				       struct pipe_buffer *indexBuffer,
				       unsigned indexSize,
				       unsigned prim, unsigned start, unsigned count)
{
   struct failover_context *failover = failover_context( pipe );

   /* If there has been any statechange since last time, try hardware
    * rendering again:
    */
   if (failover->dirty) {
      failover->mode = FO_HW;
   }

   /* Try hardware:
    */
   if (failover->mode == FO_HW) {
      if (!failover->hw->draw_elements( failover->hw, 
					indexBuffer, 
					indexSize, 
					prim, 
					start, 
					count )) {

	 failover->hw->flush( failover->hw, ~0, NULL );
	 failover->mode = FO_SW;
      }
   }

   /* Possibly try software:
    */
   if (failover->mode == FO_SW) {

      if (failover->dirty) 
	 failover_state_emit( failover );

      failover->sw->draw_elements( failover->sw, 
				   indexBuffer, 
				   indexSize, 
				   prim, 
				   start, 
				   count );

      /* Be ready to switch back to hardware rendering without an
       * intervening flush.  Unlikely to be much performance impact to
       * this:
       */
      failover->sw->flush( failover->sw, ~0, NULL );
   }

   return TRUE;
}


static boolean failover_draw_arrays( struct pipe_context *pipe,
				     unsigned prim, unsigned start, unsigned count)
{
   return failover_draw_elements(pipe, NULL, 0, prim, start, count);
}

static unsigned int
failover_is_texture_referenced( struct pipe_context *_pipe,
				struct pipe_texture *texture,
				unsigned face, unsigned level)
{
   struct failover_context *failover = failover_context( _pipe );
   struct pipe_context *pipe = (failover->mode == FO_HW) ?
      failover->hw : failover->sw;

   return pipe->is_texture_referenced(pipe, texture, face, level);
}

static unsigned int
failover_is_buffer_referenced( struct pipe_context *_pipe,
			       struct pipe_buffer *buf)
{
   struct failover_context *failover = failover_context( _pipe );
   struct pipe_context *pipe = (failover->mode == FO_HW) ?
      failover->hw : failover->sw;

   return pipe->is_buffer_referenced(pipe, buf);
}

struct pipe_context *failover_create( struct pipe_context *hw,
				      struct pipe_context *sw )
{
   struct failover_context *failover = CALLOC_STRUCT(failover_context);
   if (failover == NULL)
      return NULL;

   failover->hw = hw;
   failover->sw = sw;
   failover->pipe.winsys = hw->winsys;
   failover->pipe.screen = hw->screen;
   failover->pipe.destroy = failover_destroy;
#if 0
   failover->pipe.is_format_supported = hw->is_format_supported;
   failover->pipe.get_name = hw->get_name;
   failover->pipe.get_vendor = hw->get_vendor;
   failover->pipe.get_param = hw->get_param;
   failover->pipe.get_paramf = hw->get_paramf;
#endif

   failover->pipe.draw_arrays = failover_draw_arrays;
   failover->pipe.draw_elements = failover_draw_elements;
   failover->pipe.clear = hw->clear;

   /* No software occlusion fallback (or other optional functionality)
    * at this point - if the hardware doesn't support it, don't
    * advertise it to the application.
    */
   failover->pipe.begin_query = hw->begin_query;
   failover->pipe.end_query = hw->end_query;

   failover_init_state_functions( failover );

   failover->pipe.surface_copy = hw->surface_copy;
   failover->pipe.surface_fill = hw->surface_fill;

#if 0
   failover->pipe.texture_create = hw->texture_create;
   failover->pipe.texture_destroy = hw->texture_destroy;
   failover->pipe.get_tex_surface = hw->get_tex_surface;
   failover->pipe.texture_update = hw->texture_update;
#endif

   failover->pipe.flush = hw->flush;
   failover->pipe.is_texture_referenced = failover_is_texture_referenced;
   failover->pipe.is_buffer_referenced = failover_is_buffer_referenced;

   failover->dirty = 0;

   return &failover->pipe;
}