Example #1
0
 public void PageFlip()
 {
     if (_bo != IntPtr.Zero)
     {
         Gbm.SurfaceReleaseBuffer(_gbmSurface, _bo);
     }
     SetCrtc();
 }
Example #2
0
        public override void EnterMessageLoop(bool runInBackground)
        {
            bool running = true;

            SizeChanged?.Invoke(this, _width, _height);
            Activated?.Invoke(this);

            IntPtr bo         = Gbm.SurfaceLockFrontBuffer(_gbmSurface);
            uint   fb         = GetFbForBo(bo);
            IntPtr connectors = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(uint));

            System.Runtime.InteropServices.Marshal.WriteInt32(connectors, (int)_drmConnectorId);
            int rc = Drm.ModeSetCrtc(_drmFd, _drmEncoderCrtcId, fb, 0, 0, connectors, 1, ref _drmMode);

            System.Runtime.InteropServices.Marshal.FreeHGlobal(connectors);
            if (rc != 0)
            {
                throw new Exception("Failed to create DRM Mode");
            }

            while (running)
            {
                LibEvdev.HandleEvents();
                Render?.Invoke(this);

                IntPtr prevBo = bo;
                bo = Gbm.SurfaceLockFrontBuffer(_gbmSurface);
                fb = GetFbForBo(bo);

                Drm.ModePageFlip(_drmFd, _drmEncoderCrtcId, fb, Drm.MODE_PAGE_FLIP_EVENT, IntPtr.Zero);

                LibC.PollFd fd = new LibC.PollFd();
                fd.fd     = _drmFd;
                fd.events = LibC.POLLIN | LibC.POLLPRI;
                LibC.PollFd[] fds = new LibC.PollFd[] { fd };
                LibC.Poll(fds, -1);
                Drm.EventContext evctx = new Drm.EventContext();
                evctx.version = 2;
                Drm.HandleEvent(_drmFd, ref evctx);

                if (prevBo != IntPtr.Zero)
                {
                    Gbm.SurfaceReleaseBuffer(_gbmSurface, prevBo);
                }
            }
        }