dri2.c revision 221c678329fd1c073d5f8dcf387129cd426ecf07
1/*
2 * Mesa 3-D graphics library
3 * Version:  7.9
4 *
5 * Copyright 2009, VMware, Inc.
6 * All Rights Reserved.
7 * Copyright (C) 2010 LunarG Inc.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 *    Keith Whitwell <keithw@vmware.com>
28 *    Jakob Bornecrantz <wallbraker@gmail.com>
29 *    Chia-I Wu <olv@lunarg.com>
30 */
31
32#include "util/u_memory.h"
33#include "util/u_inlines.h"
34#include "util/u_format.h"
35#include "util/u_debug.h"
36#include "state_tracker/drm_driver.h"
37
38#include "dri_screen.h"
39#include "dri_context.h"
40#include "dri_drawable.h"
41#include "dri2_buffer.h"
42
43/**
44 * DRI2 flush extension.
45 */
46static void
47dri2_flush_drawable(__DRIdrawable *dPriv)
48{
49   struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
50   struct dri_drawable *drawable = dri_drawable(dPriv);
51
52   struct pipe_resource *ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
53
54   if (ctx) {
55      if (ptex && ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
56         pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
57
58      ctx->st->flush(ctx->st, 0, NULL);
59   }
60}
61
62static void
63dri2_invalidate_drawable(__DRIdrawable *dPriv)
64{
65   struct dri_drawable *drawable = dri_drawable(dPriv);
66
67   dri2InvalidateDrawable(dPriv);
68   drawable->dPriv->lastStamp = drawable->dPriv->dri2.stamp;
69
70   p_atomic_inc(&drawable->base.stamp);
71}
72
73static const __DRI2flushExtension dri2FlushExtension = {
74    { __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
75    dri2_flush_drawable,
76    dri2_invalidate_drawable,
77};
78
79/**
80 * Retrieve __DRIbuffer from the DRI loader.
81 */
82static __DRIbuffer *
83dri2_drawable_get_buffers(struct dri_drawable *drawable,
84                          const enum st_attachment_type *statts,
85                          unsigned *count)
86{
87   __DRIdrawable *dri_drawable = drawable->dPriv;
88   struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader;
89   boolean with_format;
90   __DRIbuffer *buffers;
91   int num_buffers;
92   unsigned attachments[10];
93   unsigned num_attachments, i;
94
95   assert(loader);
96   with_format = dri_with_format(drawable->sPriv);
97
98   num_attachments = 0;
99
100   /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
101   if (!with_format)
102      attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT;
103
104   for (i = 0; i < *count; i++) {
105      enum pipe_format format;
106      unsigned bind;
107      int att, depth;
108
109      dri_drawable_get_format(drawable, statts[i], &format, &bind);
110      if (format == PIPE_FORMAT_NONE)
111         continue;
112
113      switch (statts[i]) {
114      case ST_ATTACHMENT_FRONT_LEFT:
115         /* already added */
116         if (!with_format)
117            continue;
118         att = __DRI_BUFFER_FRONT_LEFT;
119         break;
120      case ST_ATTACHMENT_BACK_LEFT:
121         att = __DRI_BUFFER_BACK_LEFT;
122         break;
123      case ST_ATTACHMENT_FRONT_RIGHT:
124         att = __DRI_BUFFER_FRONT_RIGHT;
125         break;
126      case ST_ATTACHMENT_BACK_RIGHT:
127         att = __DRI_BUFFER_BACK_RIGHT;
128         break;
129      case ST_ATTACHMENT_DEPTH_STENCIL:
130         att = __DRI_BUFFER_DEPTH_STENCIL;
131         break;
132      default:
133         att = -1;
134         break;
135      }
136
137      /*
138       * In this switch statement we must support all formats that
139       * may occur as the stvis->color_format or
140       * stvis->depth_stencil_format.
141       */
142      switch(format) {
143      case PIPE_FORMAT_B8G8R8A8_UNORM:
144	 depth = 32;
145	 break;
146      case PIPE_FORMAT_B8G8R8X8_UNORM:
147	 depth = 24;
148	 break;
149      case PIPE_FORMAT_B5G6R5_UNORM:
150	 depth = 16;
151	 break;
152      case PIPE_FORMAT_Z16_UNORM:
153	 att = __DRI_BUFFER_DEPTH;
154	 depth = 16;
155	 break;
156      case PIPE_FORMAT_Z24X8_UNORM:
157      case PIPE_FORMAT_X8Z24_UNORM:
158	 att = __DRI_BUFFER_DEPTH;
159	 depth = 24;
160	 break;
161      case PIPE_FORMAT_Z24_UNORM_S8_UINT:
162      case PIPE_FORMAT_S8_UINT_Z24_UNORM:
163	 depth = 32;
164	 break;
165      case PIPE_FORMAT_Z32_UNORM:
166	 att = __DRI_BUFFER_DEPTH;
167	 depth = 32;
168	 break;
169      default:
170	 depth = util_format_get_blocksizebits(format);
171	 assert(!"Unexpected format in dri2_drawable_get_buffers()");
172      }
173
174      if (att >= 0) {
175         attachments[num_attachments++] = att;
176         if (with_format) {
177            attachments[num_attachments++] = depth;
178         }
179      }
180   }
181
182   if (with_format) {
183      num_attachments /= 2;
184      buffers = loader->getBuffersWithFormat(dri_drawable,
185            &dri_drawable->w, &dri_drawable->h,
186            attachments, num_attachments,
187            &num_buffers, dri_drawable->loaderPrivate);
188   }
189   else {
190      buffers = loader->getBuffers(dri_drawable,
191            &dri_drawable->w, &dri_drawable->h,
192            attachments, num_attachments,
193            &num_buffers, dri_drawable->loaderPrivate);
194   }
195
196   if (buffers)
197      *count = num_buffers;
198
199   return buffers;
200}
201
202/**
203 * Process __DRIbuffer and convert them into pipe_resources.
204 */
205static void
206dri2_drawable_process_buffers(struct dri_drawable *drawable,
207                              __DRIbuffer *buffers, unsigned count)
208{
209   struct dri_screen *screen = dri_screen(drawable->sPriv);
210   __DRIdrawable *dri_drawable = drawable->dPriv;
211   struct pipe_resource templ;
212   struct winsys_handle whandle;
213   boolean have_depth = FALSE;
214   unsigned i, bind;
215
216   if (drawable->old_num == count &&
217       drawable->old_w == dri_drawable->w &&
218       drawable->old_h == dri_drawable->h &&
219       memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0)
220      return;
221
222   for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
223      pipe_resource_reference(&drawable->textures[i], NULL);
224
225   memset(&templ, 0, sizeof(templ));
226   templ.target = screen->target;
227   templ.last_level = 0;
228   templ.width0 = dri_drawable->w;
229   templ.height0 = dri_drawable->h;
230   templ.depth0 = 1;
231   templ.array_size = 1;
232
233   memset(&whandle, 0, sizeof(whandle));
234
235   for (i = 0; i < count; i++) {
236      __DRIbuffer *buf = &buffers[i];
237      enum st_attachment_type statt;
238      enum pipe_format format;
239
240      switch (buf->attachment) {
241      case __DRI_BUFFER_FRONT_LEFT:
242         if (!screen->auto_fake_front) {
243            statt = ST_ATTACHMENT_INVALID;
244            break;
245         }
246         /* fallthrough */
247      case __DRI_BUFFER_FAKE_FRONT_LEFT:
248         statt = ST_ATTACHMENT_FRONT_LEFT;
249         break;
250      case __DRI_BUFFER_BACK_LEFT:
251         statt = ST_ATTACHMENT_BACK_LEFT;
252         break;
253      case __DRI_BUFFER_DEPTH:
254      case __DRI_BUFFER_DEPTH_STENCIL:
255      case __DRI_BUFFER_STENCIL:
256         /* use only the first depth/stencil buffer */
257         if (!have_depth) {
258            have_depth = TRUE;
259            statt = ST_ATTACHMENT_DEPTH_STENCIL;
260         }
261         else {
262            statt = ST_ATTACHMENT_INVALID;
263         }
264         break;
265      default:
266         statt = ST_ATTACHMENT_INVALID;
267         break;
268      }
269
270      dri_drawable_get_format(drawable, statt, &format, &bind);
271      if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE)
272         continue;
273
274      templ.format = format;
275      templ.bind = bind;
276      whandle.handle = buf->name;
277      whandle.stride = buf->pitch;
278
279      drawable->textures[statt] =
280         screen->base.screen->resource_from_handle(screen->base.screen,
281               &templ, &whandle);
282   }
283
284   drawable->old_num = count;
285   drawable->old_w = dri_drawable->w;
286   drawable->old_h = dri_drawable->h;
287   memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count);
288}
289
290static __DRIbuffer *
291dri2_allocate_buffer(__DRIscreen *sPriv,
292                     unsigned attachment, unsigned format,
293                     int width, int height)
294{
295   struct dri_screen *screen = dri_screen(sPriv);
296   struct dri2_buffer *buffer;
297   struct pipe_resource templ;
298   enum pipe_format pf;
299   unsigned bind = 0;
300   struct winsys_handle whandle;
301
302   switch (attachment) {
303      case __DRI_BUFFER_FRONT_LEFT:
304      case __DRI_BUFFER_FAKE_FRONT_LEFT:
305         bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
306         break;
307      case __DRI_BUFFER_BACK_LEFT:
308         bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
309         break;
310      case __DRI_BUFFER_DEPTH:
311      case __DRI_BUFFER_DEPTH_STENCIL:
312      case __DRI_BUFFER_STENCIL:
313            bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
314         break;
315   }
316
317   switch (format) {
318      case 32:
319         pf = PIPE_FORMAT_B8G8R8X8_UNORM;
320         break;
321      case 16:
322         pf = PIPE_FORMAT_Z16_UNORM;
323         break;
324      default:
325         return NULL;
326   }
327
328   buffer = CALLOC_STRUCT(dri2_buffer);
329   if (!buffer)
330      return NULL;
331
332   memset(&templ, 0, sizeof(templ));
333   templ.bind = bind;
334   templ.format = pf;
335   templ.target = PIPE_TEXTURE_2D;
336   templ.last_level = 0;
337   templ.width0 = width;
338   templ.height0 = height;
339   templ.depth0 = 1;
340   templ.array_size = 1;
341
342   buffer->resource =
343      screen->base.screen->resource_create(screen->base.screen, &templ);
344   if (!buffer->resource) {
345      FREE(buffer);
346      return NULL;
347   }
348
349   memset(&whandle, 0, sizeof(whandle));
350   whandle.type = DRM_API_HANDLE_TYPE_SHARED;
351   screen->base.screen->resource_get_handle(screen->base.screen,
352         buffer->resource, &whandle);
353
354   buffer->base.attachment = attachment;
355   buffer->base.name = whandle.handle;
356   buffer->base.cpp = util_format_get_blocksize(pf);
357   buffer->base.pitch = whandle.stride;
358
359   return &buffer->base;
360}
361
362static void
363dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv)
364{
365   struct dri2_buffer *buffer = dri2_buffer(bPriv);
366
367   pipe_resource_reference(&buffer->resource, NULL);
368   FREE(buffer);
369}
370
371/*
372 * Backend functions for st_framebuffer interface.
373 */
374
375static void
376dri2_allocate_textures(struct dri_drawable *drawable,
377                       const enum st_attachment_type *statts,
378                       unsigned count)
379{
380   __DRIbuffer *buffers;
381   unsigned num_buffers = count;
382
383   buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
384   if (buffers)
385      dri2_drawable_process_buffers(drawable, buffers, num_buffers);
386}
387
388static void
389dri2_flush_frontbuffer(struct dri_drawable *drawable,
390                       enum st_attachment_type statt)
391{
392   __DRIdrawable *dri_drawable = drawable->dPriv;
393   struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader;
394
395   if (loader->flushFrontBuffer == NULL)
396      return;
397
398   if (statt == ST_ATTACHMENT_FRONT_LEFT) {
399      loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate);
400   }
401}
402
403static void
404dri2_update_tex_buffer(struct dri_drawable *drawable,
405                       struct dri_context *ctx,
406                       struct pipe_resource *res)
407{
408   /* no-op */
409}
410
411static __DRIimage *
412dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
413{
414   __DRIimageLookupExtension *loader = screen->sPriv->dri2.image;
415   __DRIimage *img;
416
417   if (!loader->lookupEGLImage)
418      return NULL;
419
420   img = loader->lookupEGLImage(screen->sPriv,
421				handle, screen->sPriv->loaderPrivate);
422
423   return img;
424}
425
426static __DRIimage *
427dri2_create_image_from_name(__DRIscreen *_screen,
428                            int width, int height, int format,
429                            int name, int pitch, void *loaderPrivate)
430{
431   struct dri_screen *screen = dri_screen(_screen);
432   __DRIimage *img;
433   struct pipe_resource templ;
434   struct winsys_handle whandle;
435   unsigned tex_usage;
436   enum pipe_format pf;
437
438   tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
439
440   switch (format) {
441   case __DRI_IMAGE_FORMAT_RGB565:
442      pf = PIPE_FORMAT_B5G6R5_UNORM;
443      break;
444   case __DRI_IMAGE_FORMAT_XRGB8888:
445      pf = PIPE_FORMAT_B8G8R8X8_UNORM;
446      break;
447   case __DRI_IMAGE_FORMAT_ARGB8888:
448      pf = PIPE_FORMAT_B8G8R8A8_UNORM;
449      break;
450   case __DRI_IMAGE_FORMAT_ABGR8888:
451      pf = PIPE_FORMAT_R8G8B8A8_UNORM;
452      break;
453   default:
454      pf = PIPE_FORMAT_NONE;
455      break;
456   }
457   if (pf == PIPE_FORMAT_NONE)
458      return NULL;
459
460   img = CALLOC_STRUCT(__DRIimageRec);
461   if (!img)
462      return NULL;
463
464   memset(&templ, 0, sizeof(templ));
465   templ.bind = tex_usage;
466   templ.format = pf;
467   templ.target = screen->target;
468   templ.last_level = 0;
469   templ.width0 = width;
470   templ.height0 = height;
471   templ.depth0 = 1;
472   templ.array_size = 1;
473
474   memset(&whandle, 0, sizeof(whandle));
475   whandle.handle = name;
476   whandle.stride = pitch * util_format_get_blocksize(pf);
477
478   img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
479         &templ, &whandle);
480   if (!img->texture) {
481      FREE(img);
482      return NULL;
483   }
484
485   img->level = 0;
486   img->layer = 0;
487   img->loader_private = loaderPrivate;
488
489   return img;
490}
491
492static __DRIimage *
493dri2_create_image_from_renderbuffer(__DRIcontext *context,
494				    int renderbuffer, void *loaderPrivate)
495{
496   struct dri_context *ctx = dri_context(context);
497
498   if (!ctx->st->get_resource_for_egl_image)
499      return NULL;
500
501   /* TODO */
502   return NULL;
503}
504
505static __DRIimage *
506dri2_create_image(__DRIscreen *_screen,
507                   int width, int height, int format,
508                   unsigned int use, void *loaderPrivate)
509{
510   struct dri_screen *screen = dri_screen(_screen);
511   __DRIimage *img;
512   struct pipe_resource templ;
513   unsigned tex_usage;
514   enum pipe_format pf;
515
516   tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
517   if (use & __DRI_IMAGE_USE_SCANOUT)
518      tex_usage |= PIPE_BIND_SCANOUT;
519   if (use & __DRI_IMAGE_USE_SHARE)
520      tex_usage |= PIPE_BIND_SHARED;
521   if (use & __DRI_IMAGE_USE_CURSOR) {
522      if (width != 64 || height != 64)
523         return NULL;
524      tex_usage |= PIPE_BIND_CURSOR;
525   }
526
527   switch (format) {
528   case __DRI_IMAGE_FORMAT_RGB565:
529      pf = PIPE_FORMAT_B5G6R5_UNORM;
530      break;
531   case __DRI_IMAGE_FORMAT_XRGB8888:
532      pf = PIPE_FORMAT_B8G8R8X8_UNORM;
533      break;
534   case __DRI_IMAGE_FORMAT_ARGB8888:
535      pf = PIPE_FORMAT_B8G8R8A8_UNORM;
536      break;
537   case __DRI_IMAGE_FORMAT_ABGR8888:
538      pf = PIPE_FORMAT_R8G8B8A8_UNORM;
539      break;
540   default:
541      pf = PIPE_FORMAT_NONE;
542      break;
543   }
544   if (pf == PIPE_FORMAT_NONE)
545      return NULL;
546
547   img = CALLOC_STRUCT(__DRIimageRec);
548   if (!img)
549      return NULL;
550
551   memset(&templ, 0, sizeof(templ));
552   templ.bind = tex_usage;
553   templ.format = pf;
554   templ.target = PIPE_TEXTURE_2D;
555   templ.last_level = 0;
556   templ.width0 = width;
557   templ.height0 = height;
558   templ.depth0 = 1;
559   templ.array_size = 1;
560
561   img->texture = screen->base.screen->resource_create(screen->base.screen, &templ);
562   if (!img->texture) {
563      FREE(img);
564      return NULL;
565   }
566
567   img->level = 0;
568   img->layer = 0;
569
570   img->loader_private = loaderPrivate;
571   return img;
572}
573
574static GLboolean
575dri2_query_image(__DRIimage *image, int attrib, int *value)
576{
577   struct winsys_handle whandle;
578   memset(&whandle, 0, sizeof(whandle));
579
580   switch (attrib) {
581   case __DRI_IMAGE_ATTRIB_STRIDE:
582      image->texture->screen->resource_get_handle(image->texture->screen,
583            image->texture, &whandle);
584      *value = whandle.stride;
585      return GL_TRUE;
586   case __DRI_IMAGE_ATTRIB_HANDLE:
587      whandle.type = DRM_API_HANDLE_TYPE_KMS;
588      image->texture->screen->resource_get_handle(image->texture->screen,
589         image->texture, &whandle);
590      *value = whandle.handle;
591      return GL_TRUE;
592   case __DRI_IMAGE_ATTRIB_NAME:
593      whandle.type = DRM_API_HANDLE_TYPE_SHARED;
594      image->texture->screen->resource_get_handle(image->texture->screen,
595         image->texture, &whandle);
596      *value = whandle.handle;
597      return GL_TRUE;
598   default:
599      return GL_FALSE;
600   }
601}
602
603static __DRIimage *
604dri2_dup_image(__DRIimage *image, void *loaderPrivate)
605{
606   __DRIimage *img;
607
608   img = CALLOC_STRUCT(__DRIimageRec);
609   if (!img)
610      return NULL;
611
612   img->texture = NULL;
613   pipe_resource_reference(&img->texture, image->texture);
614   img->level = image->level;
615   img->layer = image->layer;
616   img->loader_private = loaderPrivate;
617
618   return img;
619}
620
621static void
622dri2_destroy_image(__DRIimage *img)
623{
624   pipe_resource_reference(&img->texture, NULL);
625   FREE(img);
626}
627
628static struct __DRIimageExtensionRec dri2ImageExtension = {
629    { __DRI_IMAGE, 1 },
630    dri2_create_image_from_name,
631    dri2_create_image_from_renderbuffer,
632    dri2_destroy_image,
633    dri2_create_image,
634    dri2_query_image,
635    dri2_dup_image,
636};
637
638/*
639 * Backend function init_screen.
640 */
641
642static const __DRIextension *dri_screen_extensions[] = {
643   &driTexBufferExtension.base,
644   &dri2FlushExtension.base,
645   &dri2ImageExtension.base,
646   &dri2ConfigQueryExtension.base,
647   NULL
648};
649
650static const __DRIextension *dri_screen_extensions_throttle[] = {
651   &driTexBufferExtension.base,
652   &dri2FlushExtension.base,
653   &dri2ImageExtension.base,
654   &dri2ConfigQueryExtension.base,
655   &dri2ThrottleExtension.base,
656   NULL
657};
658
659/**
660 * This is the driver specific part of the createNewScreen entry point.
661 *
662 * Returns the struct gl_config supported by this driver.
663 */
664static const __DRIconfig **
665dri2_init_screen(__DRIscreen * sPriv)
666{
667   const __DRIconfig **configs;
668   struct dri_screen *screen;
669   struct pipe_screen *pscreen;
670   const struct drm_conf_ret *throttle_ret = NULL;
671
672   screen = CALLOC_STRUCT(dri_screen);
673   if (!screen)
674      return NULL;
675
676   screen->sPriv = sPriv;
677   screen->fd = sPriv->fd;
678
679   sPriv->driverPrivate = (void *)screen;
680
681   pscreen = driver_descriptor.create_screen(screen->fd);
682   if (driver_descriptor.configuration)
683      throttle_ret = driver_descriptor.configuration(DRM_CONF_THROTTLE);
684
685   if (throttle_ret && throttle_ret->val.val_int != -1) {
686      sPriv->extensions = dri_screen_extensions_throttle;
687      screen->default_throttle_frames = throttle_ret->val.val_int;
688   } else
689      sPriv->extensions = dri_screen_extensions;
690
691   /* dri_init_screen_helper checks pscreen for us */
692
693   configs = dri_init_screen_helper(screen, pscreen, 32);
694   if (!configs)
695      goto fail;
696
697   sPriv->api_mask = 0;
698   if (screen->st_api->profile_mask & ST_PROFILE_DEFAULT_MASK)
699      sPriv->api_mask |= 1 << __DRI_API_OPENGL;
700   if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES1_MASK)
701      sPriv->api_mask |= 1 << __DRI_API_GLES;
702   if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES2_MASK)
703      sPriv->api_mask |= 1 << __DRI_API_GLES2;
704
705   screen->auto_fake_front = dri_with_format(sPriv);
706   screen->broken_invalidate = !sPriv->dri2.useInvalidate;
707   screen->lookup_egl_image = dri2_lookup_egl_image;
708
709   return configs;
710fail:
711   dri_destroy_screen_helper(screen);
712   FREE(screen);
713   return NULL;
714}
715
716static boolean
717dri2_create_buffer(__DRIscreen * sPriv,
718                   __DRIdrawable * dPriv,
719                   const struct gl_config * visual, boolean isPixmap)
720{
721   struct dri_drawable *drawable = NULL;
722
723   if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap))
724      return FALSE;
725
726   drawable = dPriv->driverPrivate;
727
728   drawable->allocate_textures = dri2_allocate_textures;
729   drawable->flush_frontbuffer = dri2_flush_frontbuffer;
730   drawable->update_tex_buffer = dri2_update_tex_buffer;
731
732   return TRUE;
733}
734
735/**
736 * DRI driver virtual function table.
737 *
738 * DRI versions differ in their implementation of init_screen and swap_buffers.
739 */
740const struct __DriverAPIRec driDriverAPI = {
741   .InitScreen = dri2_init_screen,
742   .DestroyScreen = dri_destroy_screen,
743   .CreateContext = dri_create_context,
744   .DestroyContext = dri_destroy_context,
745   .CreateBuffer = dri2_create_buffer,
746   .DestroyBuffer = dri_destroy_buffer,
747   .MakeCurrent = dri_make_current,
748   .UnbindContext = dri_unbind_context,
749
750   .AllocateBuffer = dri2_allocate_buffer,
751   .ReleaseBuffer  = dri2_release_buffer,
752};
753
754/* This is the table of extensions that the loader will dlsym() for. */
755PUBLIC const __DRIextension *__driDriverExtensions[] = {
756    &driCoreExtension.base,
757    &driDRI2Extension.base,
758    NULL
759};
760
761/* vim: set sw=3 ts=8 sts=3 expandtab: */
762