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