927addb834c9573bba0788f981f5fe2fc28b692a
[mesa.git] / src / gallium / winsys / drm / intel / egl / intel_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 #include "i915simple/i915_screen.h"
29
30 #include "intel_device.h"
31 #include "intel_context.h"
32 #include "intel_batchbuffer.h"
33
34 #include "state_tracker/st_public.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_context.h"
37 #include "intel_egl.h"
38 #include "utils.h"
39
40 #ifdef DEBUG
41 int __intel_debug = 0;
42 #endif
43
44
45 #define need_GL_ARB_multisample
46 #define need_GL_ARB_point_parameters
47 #define need_GL_ARB_texture_compression
48 #define need_GL_ARB_vertex_buffer_object
49 #define need_GL_ARB_vertex_program
50 #define need_GL_ARB_window_pos
51 #define need_GL_EXT_blend_color
52 #define need_GL_EXT_blend_equation_separate
53 #define need_GL_EXT_blend_func_separate
54 #define need_GL_EXT_blend_minmax
55 #define need_GL_EXT_cull_vertex
56 #define need_GL_EXT_fog_coord
57 #define need_GL_EXT_framebuffer_object
58 #define need_GL_EXT_multi_draw_arrays
59 #define need_GL_EXT_secondary_color
60 #define need_GL_NV_vertex_program
61 #include "extension_helper.h"
62
63
64 /**
65 * Extension strings exported by the intel driver.
66 *
67 * \note
68 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
69 * old i830-specific driver.
70 */
71 const struct dri_extension card_extensions[] = {
72 {"GL_ARB_multisample", GL_ARB_multisample_functions},
73 {"GL_ARB_multitexture", NULL},
74 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
75 {"GL_ARB_texture_border_clamp", NULL},
76 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
77 {"GL_ARB_texture_cube_map", NULL},
78 {"GL_ARB_texture_env_add", NULL},
79 {"GL_ARB_texture_env_combine", NULL},
80 {"GL_ARB_texture_env_dot3", NULL},
81 {"GL_ARB_texture_mirrored_repeat", NULL},
82 {"GL_ARB_texture_rectangle", NULL},
83 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
84 {"GL_ARB_pixel_buffer_object", NULL},
85 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
86 {"GL_ARB_window_pos", GL_ARB_window_pos_functions},
87 {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
88 {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions},
89 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
90 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
91 {"GL_EXT_blend_subtract", NULL},
92 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
93 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
94 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
95 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
96 {"GL_EXT_packed_depth_stencil", NULL},
97 {"GL_EXT_pixel_buffer_object", NULL},
98 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
99 {"GL_EXT_stencil_wrap", NULL},
100 {"GL_EXT_texture_edge_clamp", NULL},
101 {"GL_EXT_texture_env_combine", NULL},
102 {"GL_EXT_texture_env_dot3", NULL},
103 {"GL_EXT_texture_filter_anisotropic", NULL},
104 {"GL_EXT_texture_lod_bias", NULL},
105 {"GL_3DFX_texture_compression_FXT1", NULL},
106 {"GL_APPLE_client_storage", NULL},
107 {"GL_MESA_pack_invert", NULL},
108 {"GL_MESA_ycbcr_texture", NULL},
109 {"GL_NV_blend_square", NULL},
110 {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
111 {"GL_NV_vertex_program1_1", NULL},
112 {"GL_SGIS_generate_mipmap", NULL },
113 {NULL, NULL}
114 };
115
116
117 /*
118 * Hardware lock functions.
119 * Doesn't do anything in EGL
120 */
121
122 static void
123 intel_lock_hardware(struct intel_be_context *context)
124 {
125 (void)context;
126 }
127
128 static void
129 intel_unlock_hardware(struct intel_be_context *context)
130 {
131 (void)context;
132 }
133
134 static boolean
135 intel_locked_hardware(struct intel_be_context *context)
136 {
137 (void)context;
138 return FALSE;
139 }
140
141
142 /*
143 * Misc functions.
144 */
145
146 int
147 intel_create_context(struct egl_drm_context *egl_context, const __GLcontextModes *visual, void *sharedContextPrivate)
148 {
149 struct intel_context *intel = CALLOC_STRUCT(intel_context);
150 struct intel_device *device = (struct intel_device *)egl_context->device->priv;
151 struct pipe_context *pipe;
152 struct st_context *st_share = NULL;
153
154 egl_context->priv = intel;
155
156 intel->intel_device = device;
157 intel->egl_context = egl_context;
158 intel->egl_device = egl_context->device;
159
160 intel->base.hardware_lock = intel_lock_hardware;
161 intel->base.hardware_unlock = intel_unlock_hardware;
162 intel->base.hardware_locked = intel_locked_hardware;
163
164 intel_be_init_context(&intel->base, &device->base);
165
166 #if 0
167 pipe = intel_create_softpipe(intel, screen->winsys);
168 #else
169 pipe = i915_create_context(device->pipe, &device->base.base, &intel->base.base);
170 #endif
171
172 pipe->priv = intel;
173
174 intel->st = st_create_context(pipe, visual, st_share);
175
176 device->dummy = intel;
177
178 return TRUE;
179 }
180
181 int
182 intel_destroy_context(struct egl_drm_context *egl_context)
183 {
184 struct intel_context *intel = egl_context->priv;
185
186 if (intel->intel_device->dummy == intel)
187 intel->intel_device->dummy = NULL;
188
189 st_destroy_context(intel->st);
190 intel_be_destroy_context(&intel->base);
191 free(intel);
192 return TRUE;
193 }
194
195 void
196 intel_make_current(struct egl_drm_context *context, struct egl_drm_drawable *draw, struct egl_drm_drawable *read)
197 {
198 if (context) {
199 struct intel_context *intel = (struct intel_context *)context->priv;
200 struct intel_framebuffer *draw_fb = (struct intel_framebuffer *)draw->priv;
201 struct intel_framebuffer *read_fb = (struct intel_framebuffer *)read->priv;
202
203 assert(draw_fb->stfb);
204 assert(read_fb->stfb);
205
206 st_make_current(intel->st, draw_fb->stfb, read_fb->stfb);
207
208 intel->egl_drawable = draw;
209
210 st_resize_framebuffer(draw_fb->stfb, draw->w, draw->h);
211
212 if (draw != read)
213 st_resize_framebuffer(read_fb->stfb, read->w, read->h);
214
215 } else {
216 st_make_current(NULL, NULL, NULL);
217 }
218 }
219
220 void
221 intel_bind_frontbuffer(struct egl_drm_drawable *draw, struct egl_drm_frontbuffer *front)
222 {
223 struct intel_device *device = (struct intel_device *)draw->device->priv;
224 struct intel_framebuffer *draw_fb = (struct intel_framebuffer *)draw->priv;
225
226 if (draw_fb->front_buffer)
227 driBOUnReference(draw_fb->front_buffer);
228
229 draw_fb->front_buffer = NULL;
230 draw_fb->front = NULL;
231
232 /* to unbind just call this function with front == NULL */
233 if (!front)
234 return;
235
236 draw_fb->front = front;
237
238 driGenBuffers(device->base.staticPool, "front", 1, &draw_fb->front_buffer, 0, 0, 0);
239 driBOSetReferenced(draw_fb->front_buffer, front->handle);
240
241 st_resize_framebuffer(draw_fb->stfb, draw->w, draw->h);
242 }