i965: Use negative relocation deltas to minimse vertex uploads
[mesa.git] / src / mesa / drivers / dri / intel / intel_screen.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 "main/glheader.h"
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
32 #include "main/hash.h"
33 #include "main/fbobject.h"
34 #include "main/mfeatures.h"
35
36 #include "utils.h"
37 #include "xmlpool.h"
38
39 PUBLIC const char __driConfigOptions[] =
40 DRI_CONF_BEGIN
41 DRI_CONF_SECTION_PERFORMANCE
42 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
43 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
44 * DRI_CONF_BO_REUSE_ALL
45 */
46 DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
47 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
48 DRI_CONF_ENUM(0, "Disable buffer object reuse")
49 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
50 DRI_CONF_DESC_END
51 DRI_CONF_OPT_END
52
53 DRI_CONF_OPT_BEGIN(texture_tiling, bool, true)
54 DRI_CONF_DESC(en, "Enable texture tiling")
55 DRI_CONF_OPT_END
56
57 DRI_CONF_OPT_BEGIN(early_z, bool, false)
58 DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).")
59 DRI_CONF_OPT_END
60
61 DRI_CONF_OPT_BEGIN(fragment_shader, bool, true)
62 DRI_CONF_DESC(en, "Enable limited ARB_fragment_shader support on 915/945.")
63 DRI_CONF_OPT_END
64
65 DRI_CONF_SECTION_END
66 DRI_CONF_SECTION_QUALITY
67 DRI_CONF_FORCE_S3TC_ENABLE(false)
68 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
69 DRI_CONF_SECTION_END
70 DRI_CONF_SECTION_DEBUG
71 DRI_CONF_NO_RAST(false)
72 DRI_CONF_ALWAYS_FLUSH_BATCH(false)
73 DRI_CONF_ALWAYS_FLUSH_CACHE(false)
74
75 DRI_CONF_OPT_BEGIN(stub_occlusion_query, bool, false)
76 DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.")
77 DRI_CONF_OPT_END
78 DRI_CONF_SECTION_END
79 DRI_CONF_END;
80
81 const GLuint __driNConfigOptions = 11;
82
83 #include "intel_batchbuffer.h"
84 #include "intel_buffers.h"
85 #include "intel_bufmgr.h"
86 #include "intel_chipset.h"
87 #include "intel_fbo.h"
88 #include "intel_screen.h"
89 #include "intel_tex.h"
90 #include "intel_regions.h"
91
92 #include "i915_drm.h"
93
94 #ifdef USE_NEW_INTERFACE
95 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
96 #endif /*USE_NEW_INTERFACE */
97
98 static const __DRItexBufferExtension intelTexBufferExtension = {
99 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
100 intelSetTexBuffer,
101 intelSetTexBuffer2,
102 };
103
104 static void
105 intelDRI2Flush(__DRIdrawable *drawable)
106 {
107 GET_CURRENT_CONTEXT(ctx);
108 struct intel_context *intel = intel_context(ctx);
109
110 if (intel->gen < 4)
111 INTEL_FIREVERTICES(intel);
112
113 intel->need_throttle = GL_TRUE;
114
115 if (intel->batch.used)
116 intel_batchbuffer_flush(intel);
117 }
118
119 static const struct __DRI2flushExtensionRec intelFlushExtension = {
120 { __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
121 intelDRI2Flush,
122 dri2InvalidateDrawable,
123 };
124
125 static __DRIimage *
126 intel_create_image_from_name(__DRIscreen *screen,
127 int width, int height, int format,
128 int name, int pitch, void *loaderPrivate)
129 {
130 struct intel_screen *intelScreen = screen->private;
131 __DRIimage *image;
132 int cpp;
133
134 image = CALLOC(sizeof *image);
135 if (image == NULL)
136 return NULL;
137
138 switch (format) {
139 case __DRI_IMAGE_FORMAT_RGB565:
140 image->format = MESA_FORMAT_RGB565;
141 image->internal_format = GL_RGB;
142 image->data_type = GL_UNSIGNED_BYTE;
143 break;
144 case __DRI_IMAGE_FORMAT_XRGB8888:
145 image->format = MESA_FORMAT_XRGB8888;
146 image->internal_format = GL_RGB;
147 image->data_type = GL_UNSIGNED_BYTE;
148 break;
149 case __DRI_IMAGE_FORMAT_ARGB8888:
150 image->format = MESA_FORMAT_ARGB8888;
151 image->internal_format = GL_RGBA;
152 image->data_type = GL_UNSIGNED_BYTE;
153 break;
154 default:
155 free(image);
156 return NULL;
157 }
158
159 image->data = loaderPrivate;
160 cpp = _mesa_get_format_bytes(image->format);
161
162 image->region = intel_region_alloc_for_handle(intelScreen,
163 cpp, width, height,
164 pitch, name, "image");
165 if (image->region == NULL) {
166 FREE(image);
167 return NULL;
168 }
169
170 return image;
171 }
172
173 static __DRIimage *
174 intel_create_image_from_renderbuffer(__DRIcontext *context,
175 int renderbuffer, void *loaderPrivate)
176 {
177 __DRIimage *image;
178 struct intel_context *intel = context->driverPrivate;
179 struct gl_renderbuffer *rb;
180 struct intel_renderbuffer *irb;
181
182 rb = _mesa_lookup_renderbuffer(&intel->ctx, renderbuffer);
183 if (!rb) {
184 _mesa_error(&intel->ctx,
185 GL_INVALID_OPERATION, "glRenderbufferExternalMESA");
186 return NULL;
187 }
188
189 irb = intel_renderbuffer(rb);
190 image = CALLOC(sizeof *image);
191 if (image == NULL)
192 return NULL;
193
194 image->internal_format = rb->InternalFormat;
195 image->format = rb->Format;
196 image->data_type = rb->DataType;
197 image->data = loaderPrivate;
198 intel_region_reference(&image->region, irb->region);
199
200 return image;
201 }
202
203 static void
204 intel_destroy_image(__DRIimage *image)
205 {
206 intel_region_release(&image->region);
207 FREE(image);
208 }
209
210 static __DRIimage *
211 intel_create_image(__DRIscreen *screen,
212 int width, int height, int format,
213 unsigned int use,
214 void *loaderPrivate)
215 {
216 __DRIimage *image;
217 struct intel_screen *intelScreen = screen->private;
218 int cpp;
219
220 image = CALLOC(sizeof *image);
221 if (image == NULL)
222 return NULL;
223
224 switch (format) {
225 case __DRI_IMAGE_FORMAT_RGB565:
226 image->format = MESA_FORMAT_RGB565;
227 image->internal_format = GL_RGB;
228 image->data_type = GL_UNSIGNED_BYTE;
229 break;
230 case __DRI_IMAGE_FORMAT_XRGB8888:
231 image->format = MESA_FORMAT_XRGB8888;
232 image->internal_format = GL_RGB;
233 image->data_type = GL_UNSIGNED_BYTE;
234 break;
235 case __DRI_IMAGE_FORMAT_ARGB8888:
236 image->format = MESA_FORMAT_ARGB8888;
237 image->internal_format = GL_RGBA;
238 image->data_type = GL_UNSIGNED_BYTE;
239 break;
240 default:
241 free(image);
242 return NULL;
243 }
244
245 image->data = loaderPrivate;
246 cpp = _mesa_get_format_bytes(image->format);
247
248 image->region =
249 intel_region_alloc(intelScreen, I915_TILING_NONE,
250 cpp, width, height, GL_TRUE);
251 if (image->region == NULL) {
252 FREE(image);
253 return NULL;
254 }
255
256 return image;
257 }
258
259 static GLboolean
260 intel_query_image(__DRIimage *image, int attrib, int *value)
261 {
262 switch (attrib) {
263 case __DRI_IMAGE_ATTRIB_STRIDE:
264 *value = image->region->pitch * image->region->cpp;
265 return GL_TRUE;
266 case __DRI_IMAGE_ATTRIB_HANDLE:
267 *value = image->region->buffer->handle;
268 return GL_TRUE;
269 case __DRI_IMAGE_ATTRIB_NAME:
270 return intel_region_flink(image->region, (uint32_t *) value);
271 default:
272 return GL_FALSE;
273 }
274 }
275
276 static struct __DRIimageExtensionRec intelImageExtension = {
277 { __DRI_IMAGE, __DRI_IMAGE_VERSION },
278 intel_create_image_from_name,
279 intel_create_image_from_renderbuffer,
280 intel_destroy_image,
281 intel_create_image,
282 intel_query_image
283 };
284
285 static const __DRIextension *intelScreenExtensions[] = {
286 &driReadDrawableExtension,
287 &intelTexBufferExtension.base,
288 &intelFlushExtension.base,
289 &intelImageExtension.base,
290 &dri2ConfigQueryExtension.base,
291 NULL
292 };
293
294 static GLboolean
295 intel_get_param(__DRIscreen *psp, int param, int *value)
296 {
297 int ret;
298 struct drm_i915_getparam gp;
299
300 gp.param = param;
301 gp.value = value;
302
303 ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
304 if (ret) {
305 _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
306 return GL_FALSE;
307 }
308
309 return GL_TRUE;
310 }
311
312 static GLboolean
313 intel_get_boolean(__DRIscreen *psp, int param)
314 {
315 int value = 0;
316 return intel_get_param(psp, param, &value) && value;
317 }
318
319 static void
320 nop_callback(GLuint key, void *data, void *userData)
321 {
322 }
323
324 static void
325 intelDestroyScreen(__DRIscreen * sPriv)
326 {
327 struct intel_screen *intelScreen = sPriv->private;
328
329 dri_bufmgr_destroy(intelScreen->bufmgr);
330 driDestroyOptionInfo(&intelScreen->optionCache);
331
332 /* Some regions may still have references to them at this point, so
333 * flush the hash table to prevent _mesa_DeleteHashTable() from
334 * complaining about the hash not being empty; */
335 _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL);
336 _mesa_DeleteHashTable(intelScreen->named_regions);
337
338 FREE(intelScreen);
339 sPriv->private = NULL;
340 }
341
342
343 /**
344 * This is called when we need to set up GL rendering to a new X window.
345 */
346 static GLboolean
347 intelCreateBuffer(__DRIscreen * driScrnPriv,
348 __DRIdrawable * driDrawPriv,
349 const struct gl_config * mesaVis, GLboolean isPixmap)
350 {
351 struct intel_renderbuffer *rb;
352
353 if (isPixmap) {
354 return GL_FALSE; /* not implemented */
355 }
356 else {
357 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
358 mesaVis->depthBits != 24);
359 gl_format rgbFormat;
360
361 struct gl_framebuffer *fb = CALLOC_STRUCT(gl_framebuffer);
362
363 if (!fb)
364 return GL_FALSE;
365
366 _mesa_initialize_window_framebuffer(fb, mesaVis);
367
368 if (mesaVis->redBits == 5)
369 rgbFormat = MESA_FORMAT_RGB565;
370 else if (mesaVis->alphaBits == 0)
371 rgbFormat = MESA_FORMAT_XRGB8888;
372 else
373 rgbFormat = MESA_FORMAT_ARGB8888;
374
375 /* setup the hardware-based renderbuffers */
376 rb = intel_create_renderbuffer(rgbFormat);
377 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base);
378
379 if (mesaVis->doubleBufferMode) {
380 rb = intel_create_renderbuffer(rgbFormat);
381 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base);
382 }
383
384 if (mesaVis->depthBits == 24) {
385 assert(mesaVis->stencilBits == 8);
386 /* combined depth/stencil buffer */
387 struct intel_renderbuffer *depthStencilRb
388 = intel_create_renderbuffer(MESA_FORMAT_S8_Z24);
389 /* note: bind RB to two attachment points */
390 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthStencilRb->Base);
391 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depthStencilRb->Base);
392 }
393 else if (mesaVis->depthBits == 16) {
394 /* just 16-bit depth buffer, no hw stencil */
395 struct intel_renderbuffer *depthRb
396 = intel_create_renderbuffer(MESA_FORMAT_Z16);
397 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
398 }
399
400 /* now add any/all software-based renderbuffers we may need */
401 _mesa_add_soft_renderbuffers(fb,
402 GL_FALSE, /* never sw color */
403 GL_FALSE, /* never sw depth */
404 swStencil, mesaVis->accumRedBits > 0,
405 GL_FALSE, /* never sw alpha */
406 GL_FALSE /* never sw aux */ );
407 driDrawPriv->driverPrivate = fb;
408
409 return GL_TRUE;
410 }
411 }
412
413 static void
414 intelDestroyBuffer(__DRIdrawable * driDrawPriv)
415 {
416 struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
417
418 _mesa_reference_framebuffer(&fb, NULL);
419 }
420
421 /* There are probably better ways to do this, such as an
422 * init-designated function to register chipids and createcontext
423 * functions.
424 */
425 extern GLboolean i830CreateContext(const struct gl_config * mesaVis,
426 __DRIcontext * driContextPriv,
427 void *sharedContextPrivate);
428
429 extern GLboolean i915CreateContext(int api,
430 const struct gl_config * mesaVis,
431 __DRIcontext * driContextPriv,
432 void *sharedContextPrivate);
433 extern GLboolean brwCreateContext(int api,
434 const struct gl_config * mesaVis,
435 __DRIcontext * driContextPriv,
436 void *sharedContextPrivate);
437
438 static GLboolean
439 intelCreateContext(gl_api api,
440 const struct gl_config * mesaVis,
441 __DRIcontext * driContextPriv,
442 void *sharedContextPrivate)
443 {
444 __DRIscreen *sPriv = driContextPriv->driScreenPriv;
445 struct intel_screen *intelScreen = sPriv->private;
446
447 #ifdef I915
448 if (IS_9XX(intelScreen->deviceID)) {
449 if (!IS_965(intelScreen->deviceID)) {
450 return i915CreateContext(api, mesaVis, driContextPriv,
451 sharedContextPrivate);
452 }
453 } else {
454 intelScreen->no_vbo = GL_TRUE;
455 return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
456 }
457 #else
458 if (IS_965(intelScreen->deviceID))
459 return brwCreateContext(api, mesaVis,
460 driContextPriv, sharedContextPrivate);
461 #endif
462 fprintf(stderr, "Unrecognized deviceID 0x%x\n", intelScreen->deviceID);
463 return GL_FALSE;
464 }
465
466 static GLboolean
467 intel_init_bufmgr(struct intel_screen *intelScreen)
468 {
469 __DRIscreen *spriv = intelScreen->driScrnPriv;
470 int num_fences = 0;
471
472 intelScreen->no_hw = (getenv("INTEL_NO_HW") != NULL ||
473 getenv("INTEL_DEVID_OVERRIDE") != NULL);
474
475 intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
476 if (intelScreen->bufmgr == NULL) {
477 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
478 __func__, __LINE__);
479 return GL_FALSE;
480 }
481
482 if (!intel_get_param(spriv, I915_PARAM_NUM_FENCES_AVAIL, &num_fences) ||
483 num_fences == 0) {
484 fprintf(stderr, "[%s: %u] Kernel 2.6.29 required.\n", __func__, __LINE__);
485 return GL_FALSE;
486 }
487
488 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
489
490 intelScreen->named_regions = _mesa_NewHashTable();
491
492 intelScreen->relaxed_relocations = 0;
493 intelScreen->relaxed_relocations |=
494 intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA) << 0;
495
496 return GL_TRUE;
497 }
498
499 /**
500 * This is the driver specific part of the createNewScreen entry point.
501 * Called when using DRI2.
502 *
503 * \return the struct gl_config supported by this driver
504 */
505 static const
506 __DRIconfig **intelInitScreen2(__DRIscreen *psp)
507 {
508 struct intel_screen *intelScreen;
509 GLenum fb_format[3];
510 GLenum fb_type[3];
511 unsigned int api_mask;
512 char *devid_override;
513
514 static const GLenum back_buffer_modes[] = {
515 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
516 };
517 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
518 int color;
519 __DRIconfig **configs = NULL;
520
521 /* Allocate the private area */
522 intelScreen = CALLOC(sizeof *intelScreen);
523 if (!intelScreen) {
524 fprintf(stderr, "\nERROR! Allocating private area failed\n");
525 return GL_FALSE;
526 }
527 /* parse information in __driConfigOptions */
528 driParseOptionInfo(&intelScreen->optionCache,
529 __driConfigOptions, __driNConfigOptions);
530
531 intelScreen->driScrnPriv = psp;
532 psp->private = (void *) intelScreen;
533
534 /* Determine chipset ID */
535 if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
536 &intelScreen->deviceID))
537 return GL_FALSE;
538
539 /* Allow an override of the device ID for the purpose of making the
540 * driver produce dumps for debugging of new chipset enablement.
541 * This implies INTEL_NO_HW, to avoid programming your actual GPU
542 * incorrectly.
543 */
544 devid_override = getenv("INTEL_DEVID_OVERRIDE");
545 if (devid_override) {
546 intelScreen->deviceID = strtod(devid_override, NULL);
547 }
548
549 api_mask = (1 << __DRI_API_OPENGL);
550 #if FEATURE_ES1
551 api_mask |= (1 << __DRI_API_GLES);
552 #endif
553 #if FEATURE_ES2
554 api_mask |= (1 << __DRI_API_GLES2);
555 #endif
556
557 if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID))
558 psp->api_mask = api_mask;
559
560 if (!intel_init_bufmgr(intelScreen))
561 return GL_FALSE;
562
563 psp->extensions = intelScreenExtensions;
564
565 msaa_samples_array[0] = 0;
566
567 fb_format[0] = GL_RGB;
568 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
569
570 fb_format[1] = GL_BGR;
571 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
572
573 fb_format[2] = GL_BGRA;
574 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
575
576 depth_bits[0] = 0;
577 stencil_bits[0] = 0;
578
579 /* Generate a rich set of useful configs that do not include an
580 * accumulation buffer.
581 */
582 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
583 __DRIconfig **new_configs;
584 int depth_factor;
585
586 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
587 * buffer that has a diffferent number of bits per pixel than the color
588 * buffer. This isn't yet supported here.
589 */
590 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
591 depth_bits[1] = 16;
592 stencil_bits[1] = 0;
593 } else {
594 depth_bits[1] = 24;
595 stencil_bits[1] = 8;
596 }
597
598 depth_factor = 2;
599
600 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
601 depth_bits,
602 stencil_bits,
603 depth_factor,
604 back_buffer_modes,
605 ARRAY_SIZE(back_buffer_modes),
606 msaa_samples_array,
607 ARRAY_SIZE(msaa_samples_array),
608 GL_FALSE);
609 if (configs == NULL)
610 configs = new_configs;
611 else
612 configs = driConcatConfigs(configs, new_configs);
613 }
614
615 /* Generate the minimum possible set of configs that include an
616 * accumulation buffer.
617 */
618 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
619 __DRIconfig **new_configs;
620
621 if (fb_type[color] == GL_UNSIGNED_SHORT_5_6_5) {
622 depth_bits[0] = 16;
623 stencil_bits[0] = 0;
624 } else {
625 depth_bits[0] = 24;
626 stencil_bits[0] = 8;
627 }
628
629 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
630 depth_bits, stencil_bits, 1,
631 back_buffer_modes + 1, 1,
632 msaa_samples_array, 1,
633 GL_TRUE);
634 if (configs == NULL)
635 configs = new_configs;
636 else
637 configs = driConcatConfigs(configs, new_configs);
638 }
639
640 if (configs == NULL) {
641 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
642 __LINE__);
643 return NULL;
644 }
645
646 return (const __DRIconfig **)configs;
647 }
648
649 struct intel_buffer {
650 __DRIbuffer base;
651 struct intel_region *region;
652 };
653
654 static __DRIbuffer *
655 intelAllocateBuffer(__DRIscreen *screen,
656 unsigned attachment, unsigned format,
657 int width, int height)
658 {
659 struct intel_buffer *intelBuffer;
660 struct intel_screen *intelScreen = screen->private;
661
662 intelBuffer = CALLOC(sizeof *intelBuffer);
663 if (intelBuffer == NULL)
664 return NULL;
665
666 intelBuffer->region = intel_region_alloc(intelScreen, I915_TILING_NONE,
667 format / 8, width, height, GL_TRUE);
668
669 if (intelBuffer->region == NULL) {
670 FREE(intelBuffer);
671 return NULL;
672 }
673
674 intel_region_flink(intelBuffer->region, &intelBuffer->base.name);
675
676 intelBuffer->base.attachment = attachment;
677 intelBuffer->base.cpp = intelBuffer->region->cpp;
678 intelBuffer->base.pitch =
679 intelBuffer->region->pitch * intelBuffer->region->cpp;
680
681 return &intelBuffer->base;
682 }
683
684 static void
685 intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
686 {
687 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
688
689 intel_region_release(&intelBuffer->region);
690 free(intelBuffer);
691 }
692
693
694 const struct __DriverAPIRec driDriverAPI = {
695 .DestroyScreen = intelDestroyScreen,
696 .CreateContext = intelCreateContext,
697 .DestroyContext = intelDestroyContext,
698 .CreateBuffer = intelCreateBuffer,
699 .DestroyBuffer = intelDestroyBuffer,
700 .MakeCurrent = intelMakeCurrent,
701 .UnbindContext = intelUnbindContext,
702 .InitScreen2 = intelInitScreen2,
703 .AllocateBuffer = intelAllocateBuffer,
704 .ReleaseBuffer = intelReleaseBuffer
705 };
706
707 /* This is the table of extensions that the loader will dlsym() for. */
708 PUBLIC const __DRIextension *__driDriverExtensions[] = {
709 &driCoreExtension.base,
710 &driDRI2Extension.base,
711 NULL
712 };