コード例 #1
0
        private static BufferObject CreateCursor(IntPtr gbm, MouseCursor cursor)
        {
            if (cursor.Width > 64 || cursor.Height > 64)
            {
                Debug.Print("[KMS] Cursor size {0}x{1} unsupported. Maximum is 64x64.",
                            cursor.Width, cursor.Height);
                return(default(BufferObject));
            }

            int           width  = 64;
            int           height = 64;
            SurfaceFormat format = SurfaceFormat.ARGB8888;
            SurfaceFlags  usage  = SurfaceFlags.Cursor64x64 | SurfaceFlags.Write;

            Debug.Print("[KMS] Gbm.CreateBuffer({0:X}, {1}, {2}, {3}, {4}).",
                        gbm, width, height, format, usage);

            BufferObject bo = Gbm.CreateBuffer(
                gbm, width, height, format, usage);

            if (bo == BufferObject.Zero)
            {
                Debug.Print("[KMS] Failed to create buffer.");
                return(bo);
            }

            // Copy cursor.Data into a new buffer of the correct size
            byte[] cursor_data = new byte[width * height * 4];
            for (int y = 0; y < cursor.Height; y++)
            {
                int dst_offset = y * width * 4;
                int src_offset = y * cursor.Width * 4;
                int src_length = cursor.Width * 4;
                Array.Copy(
                    cursor.Data, src_offset,
                    cursor_data, dst_offset,
                    src_length);
            }
            bo.Write(cursor_data);

            return(bo);
        }