summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/drm/evas_drm.c
blob: 2a8ea571d8a133d8d492618e22bc1befe3e5603d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
#include "evas_engine.h"
#include <linux/vt.h>
#include <linux/kd.h>
#include <sys/mman.h>

/* NB: REALLY hate to store this here, but sigaction signal handlers cannot 
 * pass any 'user data' to the signal handlers :( */
static Evas_Engine_Info_Drm *siginfo;

static char *
_evas_drm_card_driver_get(const char *dev)
{
   struct stat st;
   int maj, min;
   char *path, path_link[PATH_MAX + 1] = "";
   char *drv;

   if (stat(dev, &st) < 0) return NULL;

   if (!S_ISCHR(st.st_mode)) return NULL;

   maj = major(st.st_rdev);
   min = minor(st.st_rdev);

   asprintf(&path, "/sys/dev/char/%d:%d/device/driver", maj, min);
   if (readlink(path, path_link, sizeof(path_link) - 1) < 0)
     {
        free(path);
        return NULL;
     }

   free(path);

   if (!(drv = strrchr(path_link, '/'))) return NULL;
   return strdup(drv + strlen("/"));
}

static int 
_evas_drm_card_open(int card)
{
   char dev[32], *driver;
   int fd = -1;
   uint64_t dumb;

   sprintf(dev, DRM_DEV_NAME, DRM_DIR_NAME, card);

   driver = _evas_drm_card_driver_get(dev);
   DBG("Drm Device Driver: %s", driver);

   if ((fd = drmOpen(driver, NULL)) < 0)
     {
        CRI("Could not open drm device %s: %m", dev);
        return -1;
     }

   /* if ((fd = open(dev, (O_RDWR | O_CLOEXEC))) < 0) */
   /*   { */
   /*      CRI("Could not open drm device %s: %m", dev); */
   /*      return -1; */
   /*   } */

   /* drmVersionPtr ver; */
   /* if ((ver = drmGetVersion(fd))) */
   /*   { */
   /*      DBG("Drm Driver Name: %s", ver->name); */
   /*      drmFreeVersion(ver); */
   /*   } */

   /* check for dumb buffer support
    * 
    * NB: This checks that we can at least support software rendering */
   if ((drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &dumb) < 0) || (!dumb))
     {
        CRI("Drm Device %s does not support software rendering", dev);

        /* close the card */
        close(fd);

        /* return failure */
        return -1;
     }

   DBG("Opened Drm Card %s: %d", dev, fd);

   /* return opened card */
   return fd;
}

static int 
_evas_drm_tty_open(Evas_Engine_Info_Drm *info)
{
   int tty = STDIN_FILENO;

   /* check if the current stdin is a valid tty */
   if (!isatty(tty))
     {
        /* if not, try to open the curren tty */
        if ((tty = open("/dev/tty", (O_RDWR | O_CLOEXEC))) < 0)
          {
             int tty0 = -1, num = -1;
             char name[16];

             /* if that fails, try tty0 */
             if ((tty0 = open("/dev/tty0", (O_WRONLY | O_CLOEXEC))) < 0)
               {
                  CRI("Could not open tty0: %m");
                  return -1;
               }

             /* try to find a non-opened tty */
             if ((ioctl(tty0, VT_OPENQRY, &num) < 0) || (num < 0))
               {
                  CRI("Could not find a non-opened tty");
                  close(tty0);
                  return -1;
               }

             snprintf(name, sizeof(name), "/dev/tty%d", num);

             /* try to open this tty */
             if ((tty = open(name, (O_RDWR | O_CLOEXEC))) < 0)
               {
                  CRI("Could not open tty: %s", name);
                  close(tty0);
                  return -1;
               }

             /* set flag that evas should close this tty */
             info->info.own_tty = EINA_TRUE;

             /* close /dev/tty0 */
             close(tty0);
          }
     }
   else
     {
        /* set flag that evas should close this tty */
        info->info.own_tty = EINA_TRUE;
     }

   DBG("Opened Tty %d", tty);

   return tty;
}

static int 
_evas_drm_crtc_find(int fd, drmModeRes *res, drmModeConnector *conn)
{
   int crtc = -1;
   drmModeEncoder *enc = NULL;

   /* if this connector already has an encoder, get it */
   if (conn->encoder_id) enc = drmModeGetEncoder(fd, conn->encoder_id);

   /* if this encoder already has a crtc, lets try to use that */
   if ((enc) && (enc->crtc_id)) crtc = enc->crtc_id;

   if (crtc < 0)
     {
        int i = 0, c = 0;

        /* if this connector has no encoder, we need to find one */
        for (; i < conn->count_encoders; ++i)
          {
             /* try to get this encoder */
             if (!(enc = drmModeGetEncoder(fd, conn->encoders[i])))
               continue;

             /* loop global crtcs */
             for (; c < res->count_crtcs; ++c)
               {
                  /* does this crtc work with this encoder ? */
                  if (!(enc->possible_crtcs & (1 << c))) continue;

                  /* FIXME: We could be more proactive here and check that 
                   * nobody else is using this crtc */

                  /* if it works, let's use it */
                  crtc = res->crtcs[c];
                  break;
               }

             if (crtc >= 0) break;
          }
     }

   /* free the encoder */
   if (enc) drmModeFreeEncoder(enc);

   return crtc;
}

static unsigned int 
_evas_drm_crtc_buffer_get(int fd, int crtc_id)
{
   drmModeCrtc *crtc;
   unsigned int id;

   if (!(crtc = drmModeGetCrtc(fd, crtc_id))) return 0;
   id = crtc->buffer_id;
   drmModeFreeCrtc(crtc);
   return id;
}

static void 
_evas_drm_tty_sigusr1(int x EINA_UNUSED, siginfo_t *info EINA_UNUSED, void *data EINA_UNUSED)
{
   Evas_Engine_Info_Drm *einfo;

   DBG("Caught SIGUSR1");

   if (!(einfo = siginfo)) return;

   /* TODO: set canvas to not render */

   DBG("\tDrop Master & Release VT");

   /* drop drm master */
   if (einfo->info.own_fd)
     {
        if (drmDropMaster(einfo->info.fd) != 0)
          WRN("Could not drop drm master: %m");
     }

   /* release vt */
   if (einfo->info.own_tty)
     {
        if (ioctl(einfo->info.tty, VT_RELDISP, 1) < 0)
          WRN("Could not release vt: %m");
     }
}

static void 
_evas_drm_tty_sigusr2(int x EINA_UNUSED, siginfo_t *info EINA_UNUSED, void *data EINA_UNUSED)
{
   Evas_Engine_Info_Drm *einfo;

   DBG("Caught SIGUSR2");

   if (!(einfo = siginfo)) return;

   /* TODO: set canvas to render again */

   DBG("\tAcquire VT & Set Master");

   /* acquire vt */
   if (einfo->info.own_tty)
     {
        if (ioctl(einfo->info.tty, VT_RELDISP, VT_ACKACQ) < 0)
          WRN("Could not acquire vt: %m");
     }

   /* set master */
   if (einfo->info.own_fd)
     {
        if (drmSetMaster(einfo->info.fd) != 0)
          WRN("Could not set drm master: %m");
     }
}

static Eina_Bool 
_evas_drm_tty_setup(Evas_Engine_Info_Drm *info)
{
   struct vt_mode vtmode = { 0 };
   struct sigaction sig;

   /* check for valid tty */
   if (info->info.tty < 0) return EINA_FALSE;

#if 0
   /* set vt to graphics mode */
   if (ioctl(info->info.tty, KDSETMODE, KD_GRAPHICS) < 0)
     {
        CRI("Could not set tty to graphics mode: %m");
        return EINA_FALSE;
     }
#endif

   /* setup tty rel/acq signals */
   vtmode.mode = VT_PROCESS;
   vtmode.waitv = 0;
   vtmode.relsig = SIGUSR1;
   vtmode.acqsig = SIGUSR2;
   if (ioctl(info->info.tty, VT_SETMODE, &vtmode) < 0)
     {
        CRI("Could not set tty mode: %m");
        return EINA_FALSE;
     }

   /* store info struct 
    * 
    * NB: REALLY hate to store this here, but sigaction signal handlers cannot 
    * pass any 'user data' to the signal handlers :(
    */
   siginfo = info;

   /* setup signal handlers for above signals */
   sig.sa_sigaction = _evas_drm_tty_sigusr1;
   sig.sa_flags = (SA_NODEFER | SA_SIGINFO | SA_RESTART);
   sigemptyset(&sig.sa_mask);
   sigaction(SIGUSR1, &sig, NULL);

   sig.sa_sigaction = _evas_drm_tty_sigusr2;
   sig.sa_flags = (SA_NODEFER | SA_SIGINFO | SA_RESTART);
   sigemptyset(&sig.sa_mask);
   sigaction(SIGUSR2, &sig, NULL);

   return EINA_TRUE;
}

static void 
_evas_drm_outbuf_page_flip(int fd EINA_UNUSED, unsigned int seq EINA_UNUSED, unsigned int tv_sec EINA_UNUSED, unsigned int tv_usec EINA_UNUSED, void *data)
{
   Outbuf *ob;

   /* get the output buffer from data */
   if (!(ob = data)) return;

   /* DBG("Page Flip Event"); */

   ob->priv.pending_flip = EINA_FALSE;
   ob->priv.curr = (ob->priv.curr + 1) % ob->priv.num;
}

/* static void  */
/* _evas_drm_outbuf_vblank(int fd EINA_UNUSED, unsigned int frame EINA_UNUSED, unsigned int sec EINA_UNUSED, unsigned int usec EINA_UNUSED, void *data) */
/* { */
/*    Outbuf *ob; */

/*    if (!(ob = data)) return; */

/*    DBG("VBlank Event"); */
/* } */

static Eina_Bool 
_evas_drm_outbuf_planes_setup(Outbuf *ob, drmModePlaneResPtr pres)
{
   drmModePlanePtr dplane;
   Plane *oplane;
   unsigned int p = 0;
   unsigned int f = 0;

   for (p = 0; p < pres->count_planes; p++)
     {
        /* try to get this plane */
        if (!(dplane = drmModeGetPlane(ob->priv.fd, pres->planes[p])))
          continue;

        /* try to allocate space for our plane */
        if (!(oplane = 
              malloc(sizeof(Plane)  + 
                     ((sizeof(unsigned int)) * dplane->count_formats))))
          {
             drmModeFreePlane(dplane);
             continue;
          }

        oplane->crtcs = dplane->possible_crtcs;
        oplane->id = dplane->plane_id;
        oplane->num_formats = dplane->count_formats;
        memcpy(oplane->formats, dplane->formats, 
               dplane->count_formats * sizeof(dplane->formats[0]));

        DBG("Plane %d, %d %d", p, dplane->x, dplane->y);
        DBG("\tFB: %d", dplane->fb_id);
        DBG("\tCrtc: %d, %d %d", dplane->crtc_id, 
            dplane->crtc_x, dplane->crtc_y);

        DBG("\tSupported Formats");
        for (f = 0; f < dplane->count_formats; f++)
          {
             DBG("\t\t%C%C%C%C", (dplane->formats[f] & 0xFF), 
                 ((dplane->formats[f] >> 8) & 0xFF),
                 ((dplane->formats[f] >> 16) & 0xFF), 
                 ((dplane->formats[f] >> 24) & 0xFF));
          }

        /* free this plane */
        drmModeFreePlane(dplane);

        /* append this plane */
        ob->priv.planes = eina_list_append(ob->priv.planes, oplane);
     }

   if (eina_list_count(ob->priv.planes) < 1) return EINA_FALSE;
   return EINA_TRUE;
}

Eina_Bool 
evas_drm_init(Evas_Engine_Info_Drm *info, int card)
{
   /* check for valid engine info */
   if (!info) return EINA_FALSE;

   setvbuf(stdout, NULL, _IONBF, 0);

   /* check if we already opened the card */
   if (info->info.fd < 0)
     {
        /* try to open the drm card */
        if ((info->info.fd = _evas_drm_card_open(card)) < 0) 
          return EINA_FALSE;

        /* set flag to indicate that evas opened the card and we should 
         * be the one to close it */
        info->info.own_fd = EINA_TRUE;
     }

   /* check if we already opened the tty */
   if (info->info.tty < 0)
     {
        /* try to open the current tty */
        if ((info->info.tty = _evas_drm_tty_open(info)) < 0) 
          {
             /* check if we already opened the card. if so, close it */
             if ((info->info.fd >= 0) && (info->info.own_fd))
               {
                  close(info->info.fd);
                  info->info.fd = -1;
               }

             return EINA_FALSE;
          }
     }

   /* with the tty opened, we need to set it up */
   if (!_evas_drm_tty_setup(info))
     {
        /* setup of tty failed, close it */
        if ((info->info.tty >= 0) && (info->info.own_tty))
          close(info->info.tty);

        /* FIXME: Close card also ?? */

        return EINA_FALSE;
     }

   return EINA_TRUE;
}

Eina_Bool 
evas_drm_shutdown(Evas_Engine_Info_Drm *info)
{
   /* check for valid engine info */
   if (!info) return EINA_TRUE;

   /* check if we already opened the tty. if so, close it */
   if ((info->info.tty >= 0) && (info->info.own_tty))
     {
        close(info->info.tty);
        info->info.tty = -1;
     }

   /* check if we already opened the card. if so, close it */
   if ((info->info.fd >= 0) && (info->info.own_fd))
     {
        close(info->info.fd);
        info->info.fd = -1;
     }

   return EINA_TRUE;
}

Eina_Bool 
evas_drm_outbuf_setup(Outbuf *ob)
{
   drmModeRes *res;
   drmModeConnector *conn;
   drmModePlaneResPtr pres;
   int i = 0;
   uint64_t dumb;

   /* check for valid Output buffer */
   if ((!ob) || (ob->priv.fd < 0)) return EINA_FALSE;

   /* setup drmHandleEvent context */
   memset(&ob->priv.ctx, 0, sizeof(ob->priv.ctx));
   ob->priv.ctx.version = DRM_EVENT_CONTEXT_VERSION;
   ob->priv.ctx.page_flip_handler = _evas_drm_outbuf_page_flip;
   /* ob->priv.ctx.vblank_handler = _evas_drm_outbuf_vblank; */

   /* try to get drm resources */
   if (!(res = drmModeGetResources(ob->priv.fd)))
     {
        CRI("Could not get drm resources: %m");
        return EINA_FALSE;
     }

   /* loop the connectors */
   for (; i < res->count_connectors; ++i)
     {
        int crtc = -1;
        int m = 0;

        /* try to get this connector */
        if (!(conn = drmModeGetConnector(ob->priv.fd, res->connectors[i])))
          {
             WRN("Could not get drm connector %d: %m", i);
             continue;
          }

        /* make sure this connector is actually connected */
        if (conn->connection != DRM_MODE_CONNECTED) 
          {
             /* free connector resources */
             drmModeFreeConnector(conn);
             continue;
          }

        /* make sure it has modes */
        if (conn->count_modes == 0)
          {
             /* free connector resources */
             drmModeFreeConnector(conn);
             continue;
          }

        /* try to find a crtc for this connector */
        if ((crtc = _evas_drm_crtc_find(ob->priv.fd, res, conn)) < 0) 
          {
             /* free connector resources */
             drmModeFreeConnector(conn);
             continue;
          }

        /* record the connector id */
        ob->priv.conn = conn->connector_id;

        /* record the crtc id */
        ob->priv.crtc = crtc;

        /* get the current framebuffer */
        ob->priv.fb = _evas_drm_crtc_buffer_get(ob->priv.fd, crtc);

        /* spew out connector properties for testing */
        /* drmModePropertyPtr props; */
        /* for (m = 0; m < conn->count_props; m++) */
        /*   { */
        /*      props = drmModeGetProperty(ob->priv.fd, conn->props[m]); */
        /*      if (!props) continue; */
        /*      DBG("Property Name: %s", props->name); */
        /*   } */

        /* record the current mode */
        memcpy(&ob->priv.mode, &conn->modes[0], sizeof(ob->priv.mode));

        for (m = 0; m < conn->count_modes; m++)
          {
             DBG("Output Available Mode: %d: %d %d %d", ob->priv.conn, 
                 conn->modes[m].hdisplay, conn->modes[m].vdisplay, 
                 conn->modes[m].vrefresh);

             /* try to find a mode which matches the requested size */
             if ((conn->modes[m].hdisplay == ob->w) && 
                 (conn->modes[m].vdisplay == ob->h) && 
                 (conn->modes[m].vrefresh == 60))
               {
                  memcpy(&ob->priv.mode, &conn->modes[m], 
                         sizeof(ob->priv.mode));
               }
          }

        DBG("Output Current Mode: %d: %d %d", ob->priv.conn, 
            ob->priv.mode.hdisplay, ob->priv.mode.vdisplay);

        if ((ob->priv.mode.hdisplay != conn->modes[0].hdisplay) || 
            (ob->priv.mode.vdisplay != conn->modes[0].vdisplay))
          {
             /* set new crtc mode */
             drmModeSetCrtc(ob->priv.fd, ob->priv.crtc, ob->priv.fb, 0, 0, 
                            &ob->priv.conn, 1, &ob->priv.mode);
          }

        /* free connector resources */
        drmModeFreeConnector(conn);

        break;
     }

   /* get any plane resource from the card */
   pres = drmModeGetPlaneResources(ob->priv.fd);

   /* if we have at least one plane, set it up */
   if (pres->count_planes > 0)
     {
        if (!_evas_drm_outbuf_planes_setup(ob, pres))
          WRN("Could not setup hardware planes");
     }

   /* free plane resources */
   drmModeFreePlaneResources(pres);

   /* free drm resources */
   drmModeFreeResources(res);

   return EINA_TRUE;
}

void 
evas_drm_outbuf_framebuffer_set(Outbuf *ob, Buffer *buffer)
{
   int ret;

   /* validate params */
   if ((!ob) || (!buffer)) return;

   /* DBG("Drm Framebuffer Set: %d", buffer->fb); */

   buffer->valid = EINA_FALSE;
   ret = drmModeSetCrtc(ob->priv.fd, ob->priv.crtc, buffer->fb, 0, 0, 
                        &ob->priv.conn, 1, &ob->priv.mode);

   if (ret) ERR("Failed to set crtc: %m");
   else buffer->valid = EINA_TRUE;
}

Eina_Bool 
evas_drm_framebuffer_create(int fd, Buffer *buffer, int depth)
{
   struct drm_mode_create_dumb carg;
   struct drm_mode_destroy_dumb darg;
   struct drm_mode_map_dumb marg;

   /* check for valid info */
   if (fd < 0) return EINA_FALSE;

   /* try to create a dumb buffer */
   memset(&carg, 0, sizeof(carg));
   carg.width = buffer->w;
   carg.height = buffer->h;
   carg.bpp = depth;

   if (drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg) < 0)
     {
        ERR("Could not create dumb buffer: %m");
        return EINA_FALSE;
     }

   buffer->stride = carg.pitch;
   buffer->size = carg.size;
   buffer->handle = carg.handle;

   DBG("Buffer: %d %d", buffer->w, buffer->h);
   DBG("Buffer Stride: %d", buffer->stride);
   DBG("Buffer Size: %d", buffer->size);

   /* try to create a framebuffer object */
   /* FIXME: Hardcoded bpp */
   if (drmModeAddFB(fd, buffer->w, buffer->h, 24, depth, buffer->stride, 
                    buffer->handle, &buffer->fb))
     {
        ERR("Could not create framebuffer object: %m");
        goto add_err;
     }

   DBG("Creating dumb buffer: %d %d %d %d", buffer->fb, 
       buffer->w, buffer->h, depth);

   /* try to mmap the buffer */
   memset(&marg, 0, sizeof(marg));
   marg.handle = buffer->handle;
   if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &marg))
     {
        ERR("Could not map dumb buffer: %m");
        goto map_err;
     }

   /* do actual mmap of memory */
   buffer->data = 
     mmap(NULL, buffer->size, (PROT_READ | PROT_WRITE), 
          MAP_SHARED, fd, marg.offset);
   if (buffer->data == MAP_FAILED)
     {
        ERR("Could not mmap dumb buffer: %m");
        goto map_err;
     }

   /* clear memory */
   memset(buffer->data, 0, buffer->size);

   return EINA_TRUE;

map_err:
   /* remove the framebuffer */
   drmModeRmFB(fd, buffer->fb);

add_err:
   /* destroy buffer */
   memset(&darg, 0, sizeof(darg));
   darg.handle = buffer->handle;
   drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);

   return EINA_FALSE;
}

void 
evas_drm_framebuffer_destroy(int fd, Buffer *buffer)
{
   struct drm_mode_destroy_dumb darg;

   /* check for valid info */
   if (fd < 0) return;

   /* unmap the buffer data */
   if (buffer->data) munmap(buffer->data, buffer->size);

   /* remove the framebuffer */
   drmModeRmFB(fd, buffer->fb);

   /* destroy buffer */
   memset(&darg, 0, sizeof(darg));
   darg.handle = buffer->handle;
   drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
}

Eina_Bool 
evas_drm_framebuffer_send(Outbuf *ob, Buffer *buffer)
{
   int ret;

   /* check for valid Output buffer */
   if ((!ob) || (ob->priv.fd < 0)) return EINA_FALSE;

   /* check for valid buffer */
   if (!buffer) return EINA_FALSE;

   if (ob->vsync)
     {
        if (drmModePageFlip(ob->priv.fd, ob->priv.crtc, 
                            buffer->fb, DRM_MODE_PAGE_FLIP_EVENT, ob) < 0)
          {
             ERR("Cannot flip crtc for connector %u: %m", ob->priv.conn);
             return EINA_FALSE;
          }

        ob->priv.pending_flip = EINA_TRUE;

        while (ob->priv.pending_flip)
          drmHandleEvent(ob->priv.fd, &ob->priv.ctx);
     }
   else
     {
        /* NB: We don't actually need to do this if we are not vsync
         * because we are drawing directly to the buffer anyway.
         * If we enable the sending of buffer to crtc, it causes vsync */

        /* send this buffer to the crtc */
        /* evas_drm_outbuf_framebuffer_set(ob, buffer); */

        /* increment buffer we are using */
        ob->priv.curr = (ob->priv.curr + 1) % ob->priv.num;
     }

   return EINA_TRUE;
}