summaryrefslogtreecommitdiff
path: root/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2016-09-02 14:47:49 -0500
committerDerek Foreman <derekf@osg.samsung.com>2016-09-08 13:55:23 -0500
commit794798f55906d3704955ac3f108340eafdb06256 (patch)
tree31dc6fa4f891fcb4b0a0d1c58c2ff39dbe41d94e /src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
parent3d39c1e9b8647aebb12d4edfe426ec88e361c70d (diff)
ee_drm: Move all ticking into ecore_evas_drm and use new tick system
Combines all the gl_drm and drm ticking code into one set in ecore_evas_drm and uses the new evas tick register/unregister callbacks to set it up.
Diffstat (limited to 'src/modules/ecore_evas/engines/drm/ecore_evas_drm.c')
-rw-r--r--src/modules/ecore_evas/engines/drm/ecore_evas_drm.c117
1 files changed, 111 insertions, 6 deletions
diff --git a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
index 8289a76332..e53ffdab81 100644
--- a/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
+++ b/src/modules/ecore_evas/engines/drm/ecore_evas_drm.c
@@ -19,6 +19,8 @@
19# include <dlfcn.h> 19# include <dlfcn.h>
20#endif 20#endif
21 21
22#include <xf86drm.h>
23
22#ifdef EAPI 24#ifdef EAPI
23# undef EAPI 25# undef EAPI
24#endif 26#endif
@@ -49,14 +51,17 @@ typedef struct _Ecore_Evas_Engine_Drm_Data
49 int x, y, w, h; 51 int x, y, w, h;
50 int depth, bpp; 52 int depth, bpp;
51 unsigned int format; 53 unsigned int format;
54 drmEventContext ctx;
55 Ecore_Fd_Handler *hdlr;
52 Ecore_Drm2_Device *dev; 56 Ecore_Drm2_Device *dev;
53 Ecore_Drm2_Output *output; 57 Ecore_Drm2_Output *output;
58 Eina_Bool ticking : 1;
54} Ecore_Evas_Engine_Drm_Data; 59} Ecore_Evas_Engine_Drm_Data;
55 60
56static int _drm_init_count = 0; 61static int _drm_init_count = 0;
57 62
58static int 63static int
59_ecore_evas_drm_init(Ecore_Evas_Engine_Drm_Data *edata, const char *device) 64_ecore_evas_drm_init(Ecore_Evas *ee, Ecore_Evas_Engine_Drm_Data *edata, const char *device)
60{ 65{
61 if (++_drm_init_count != 1) return _drm_init_count; 66 if (++_drm_init_count != 1) return _drm_init_count;
62 67
@@ -92,8 +97,8 @@ _ecore_evas_drm_init(Ecore_Evas_Engine_Drm_Data *edata, const char *device)
92 } 97 }
93 98
94 edata->output = ecore_drm2_output_find(edata->dev, edata->x, edata->y); 99 edata->output = ecore_drm2_output_find(edata->dev, edata->x, edata->y);
95 if (!edata->output) 100 if (edata->output) ecore_drm2_output_user_data_set(edata->output, ee);
96 WRN("Could not find output at %d %d", edata->x, edata->y); 101 else WRN("Could not find output at %d %d", edata->x, edata->y);
97 102
98 ecore_event_evas_init(); 103 ecore_event_evas_init();
99 104
@@ -586,6 +591,97 @@ _ecore_evas_drm_interface_new(void)
586 return iface; 591 return iface;
587} 592}
588 593
594static Eina_Bool
595_cb_drm_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
596{
597 Ecore_Evas *ee;
598 Ecore_Evas_Engine_Drm_Data *edata;
599 int ret;
600
601 ee = data;
602 edata = ee->engine.data;
603 ret = drmHandleEvent(edata->fd, &edata->ctx);
604 if (ret)
605 {
606 WRN("drmHandleEvent failed to read an event");
607 return EINA_FALSE;
608 }
609
610 return EINA_TRUE;
611}
612
613static void
614_tick_schedule(int fd, Ecore_Evas *ee)
615{
616 Ecore_Evas_Engine_Drm_Data *edata;
617
618 edata = ee->engine.data;
619 if (!edata->ticking) return;
620
621 drmVBlank vbl =
622 {
623 .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
624 .request.sequence = 1,
625 .request.signal = (unsigned long)ee,
626 };
627
628 /* FIXME: On some systems this can fail, breaking ticking forever. */
629 drmWaitVBlank(fd, &vbl);
630}
631
632static void
633_cb_pageflip(int fd EINA_UNUSED, unsigned int frame EINA_UNUSED, unsigned int sec EINA_UNUSED, unsigned int usec EINA_UNUSED, void *data)
634{
635 Ecore_Evas *ee;
636 Ecore_Evas_Engine_Drm_Data *edata;
637 Ecore_Drm2_Fb *current, *next;
638
639 ee = data;
640 edata = ee->engine.data;
641
642 current = ecore_drm2_output_current_fb_get(edata->output);
643 if (current) ecore_drm2_fb_busy_set(current, EINA_FALSE);
644
645 next = ecore_drm2_output_next_fb_get(edata->output);
646 if (next)
647 {
648 ecore_drm2_output_next_fb_set(edata->output, NULL);
649 ecore_drm2_fb_flip(next, edata->output);
650 }
651}
652
653static void
654_cb_vblank(int fd, unsigned int frame EINA_UNUSED, unsigned int sec EINA_UNUSED, unsigned int usec EINA_UNUSED, void *data)
655{
656 Ecore_Evas *ee;
657 Ecore_Evas_Engine_Drm_Data *edata;
658
659 ee = data;
660 edata = ee->engine.data;
661
662 ecore_evas_animator_tick(ee, NULL);
663 if (edata->ticking) _tick_schedule(fd, ee);
664}
665
666static void
667_drm_animator_register(Ecore_Evas *ee)
668{
669 Ecore_Evas_Engine_Drm_Data *edata;
670
671 edata = ee->engine.data;
672 edata->ticking = EINA_TRUE;
673 _tick_schedule(edata->fd, ee);
674}
675
676static void
677_drm_animator_unregister(Ecore_Evas *ee)
678{
679 Ecore_Evas_Engine_Drm_Data *edata;
680
681 edata = ee->engine.data;
682 edata->ticking = EINA_FALSE;
683}
684
589static Ecore_Evas_Engine_Func _ecore_evas_drm_engine_func = 685static Ecore_Evas_Engine_Func _ecore_evas_drm_engine_func =
590{ 686{
591 _drm_free, 687 _drm_free,
@@ -662,8 +758,8 @@ static Ecore_Evas_Engine_Func _ecore_evas_drm_engine_func =
662 758
663 NULL, // aux_hints_set 759 NULL, // aux_hints_set
664 760
665 NULL, // animator_register 761 _drm_animator_register, // animator_register
666 NULL, // animator_unregister 762 _drm_animator_unregister, // animator_unregister
667 763
668 NULL // evas_changed 764 NULL // evas_changed
669}; 765};
@@ -700,7 +796,7 @@ _ecore_evas_new_internal(const char *device, int x, int y, int w, int h, Eina_Bo
700 edata->bpp = 32; // FIXME: Remove hardcode 796 edata->bpp = 32; // FIXME: Remove hardcode
701 edata->format = DRM_FORMAT_XRGB8888; 797 edata->format = DRM_FORMAT_XRGB8888;
702 798
703 if (_ecore_evas_drm_init(edata, device) < 1) 799 if (_ecore_evas_drm_init(ee, edata, device) < 1)
704 { 800 {
705 free(edata); 801 free(edata);
706 free(ee); 802 free(ee);
@@ -808,6 +904,15 @@ _ecore_evas_new_internal(const char *device, int x, int y, int w, int h, Eina_Bo
808 ecore_drm2_device_pointer_max_set(edata->dev, mw, mh); 904 ecore_drm2_device_pointer_max_set(edata->dev, mw, mh);
809 ecore_drm2_device_pointer_warp(edata->dev, mw / 2, mh / 2); 905 ecore_drm2_device_pointer_warp(edata->dev, mw / 2, mh / 2);
810 906
907 /* setup vblank handler */
908 memset(&edata->ctx, 0, sizeof(edata->ctx));
909 edata->ctx.version = DRM_EVENT_CONTEXT_VERSION;
910 edata->ctx.vblank_handler = _cb_vblank;
911 edata->ctx.page_flip_handler = _cb_pageflip;
912
913 edata->hdlr =
914 ecore_main_fd_handler_add(edata->fd, ECORE_FD_READ, _cb_drm_event, ee,
915 NULL, NULL);
811 return ee; 916 return ee;
812 917
813eng_err: 918eng_err: