Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / drivers / i965simple / brw_context.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_context.h"
34 #include "brw_defines.h"
35 #include "brw_draw.h"
36 #include "brw_vs.h"
37 #include "brw_tex_layout.h"
38 #include "brw_winsys.h"
39
40 #include "pipe/internal/p_winsys_screen.h"
41 #include "pipe/p_context.h"
42 #include "util/u_memory.h"
43 #include "pipe/p_screen.h"
44
45
46 #ifndef BRW_DEBUG
47 int BRW_DEBUG = (0);
48 #endif
49
50
51 static void brw_destroy(struct pipe_context *pipe)
52 {
53 struct brw_context *brw = brw_context(pipe);
54
55 if(brw->winsys->destroy)
56 brw->winsys->destroy(brw->winsys);
57
58 FREE(brw);
59 }
60
61
62 static void brw_clear(struct pipe_context *pipe, struct pipe_surface *ps,
63 unsigned clearValue)
64 {
65 int x, y, w, h;
66 /* FIXME: corny... */
67
68 x = 0;
69 y = 0;
70 w = ps->width;
71 h = ps->height;
72
73 pipe->surface_fill(pipe, ps, x, y, w, h, clearValue);
74 }
75
76
77 struct pipe_context *brw_create(struct pipe_screen *screen,
78 struct brw_winsys *brw_winsys,
79 unsigned pci_id)
80 {
81 struct brw_context *brw;
82
83 debug_printf("%s: creating brw_context with pci id 0x%x\n",
84 __FUNCTION__, pci_id);
85
86 brw = CALLOC_STRUCT(brw_context);
87 if (brw == NULL)
88 return NULL;
89
90 brw->winsys = brw_winsys;
91 brw->pipe.winsys = screen->winsys;
92 brw->pipe.screen = screen;
93
94 brw->pipe.destroy = brw_destroy;
95 brw->pipe.clear = brw_clear;
96
97 brw_init_surface_functions(brw);
98 brw_init_texture_functions(brw);
99 brw_init_state_functions(brw);
100 brw_init_flush_functions(brw);
101 brw_init_draw_functions( brw );
102
103
104 brw_init_state( brw );
105
106 brw->pci_id = pci_id;
107 brw->dirty = ~0;
108 brw->hardware_dirty = ~0;
109
110 memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
111
112 return &brw->pipe;
113 }
114