示例#1
0
        private int GetFramebuffer(BufferObject bo)
        {
            if (bo == BufferObject.Zero)
            {
                goto fail;
            }

            int bo_handle = bo.Handle;

            if (bo_handle == 0)
            {
                Debug.Print("[KMS] Gbm.BOGetHandle({0:x}) failed.", bo);
                goto fail;
            }

            int width  = bo.Width;
            int height = bo.Height;
            int bpp    = Mode.ColorFormat.BitsPerPixel;
            int depth  = Mode.Depth;
            int stride = bo.Stride;

            if (width == 0 || height == 0 || bpp == 0)
            {
                Debug.Print("[KMS] Invalid framebuffer format: {0}x{1} {2} {3} {4}",
                            width, height, stride, bpp, depth);
                goto fail;
            }

            int buffer;
            int ret = Drm.ModeAddFB(
                fd, width, height,
                (byte)depth, (byte)bpp, stride, bo_handle,
                out buffer);

            if (ret != 0)
            {
                Debug.Print("[KMS] Drm.ModeAddFB({0}, {1}, {2}, {3}, {4}, {5}, {6}) failed. Error: {7}",
                            fd, width, height, depth, bpp, stride, bo_handle, ret);
                goto fail;
            }

            bo.SetUserData((IntPtr)buffer, DestroyFB);
            return(buffer);

fail:
            Debug.Print("[Error] Failed to create framebuffer.");
            return(-1);
        }