graphics: first draft bits
authorAlan Cox <alan@linux.intel.com>
Tue, 31 Mar 2015 21:52:31 +0000 (22:52 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 31 Mar 2015 21:52:31 +0000 (22:52 +0100)
Kernel/README.GRAPHICS [new file with mode: 0644]
Kernel/include/graphics.h [new file with mode: 0644]

diff --git a/Kernel/README.GRAPHICS b/Kernel/README.GRAPHICS
new file mode 100644 (file)
index 0000000..77ed30b
--- /dev/null
@@ -0,0 +1,106 @@
+Graphics is still a prototype.
+
+The proposed method of operation is as follows
+
+Issue ioctl(ttyfd, GFXIOC_GETINFO , &display)
+
+An error means no graphics support, otherwise you get the display data for
+the default mode.
+
+If it reports GFX_PALETTE then you can get the palette entries and try
+and set them.
+
+If it reports GFX_MULTIMODE then you can call GFXIOC_GETMODE with a uint8_t
+set and get back a full buffer of the display for that mode.
+
+The formats defined so far are
+
+FMT_MONO_BW            Black with white monochrome bitmap. The data
+                       is on lines stride pixels wide, bit 7 is left
+FMT_MONO_WB            Ditto but white with black
+
+These are the most common small device modes and are defined this way to
+avoid needing palette support on the tiniest devices.
+
+FMT_COLOUR4            2bit packed pixel
+FMT_COLOUR16           4bit packed pixel
+FMT_SPECTRUM           ZX Spectrum
+FMT_VDP                        VDP display (which is mostly plain weird)
+
+Hardware types are defined for
+
+HW_UNACCEL             Just a framebuffer of some kind
+HW_VDP_9918            MSX1, MTX and similar
+HW_VDP_9938            MSX2
+
+It's assumed that for some stuff certain apps will want to go direct to GPU
+hence this information.
+
+The properties are
+
+GFX_MAPPABLE           Can be accessed if mapped as part of process memory
+                       (Mostly for 16/32bit platforms)
+GFX_PALETTE            Has a colour palette palette ioctls
+GFX_OFFSCREEN          It is meaningful to write or read memory in the full
+                       physical range not just the displayed window
+GFX_VBLANK             Supports wait for vblank
+GFX_ENABLE             Graphics mode must be enabled/disabled (ie its not
+                       just the text mode too)
+GFX_MULTIMODE          There are multiple display modes possible
+GFX_PALETTE_SET                The colour table is settable
+
+Memory holds the amount of RAM for hardware where this also matters (VDP
+primarily ?, otherwise 0)
+
+Commands are again organised to try and minimise size for small devices
+
+GFX_BLTAL_CG           Rectangular blit or byte aligned blocks from CPU to
+                       the screen
+GFX_BLTAL_GC           The reverse
+GFX_SETPIXEL           Plot a list of pixels
+GFX_HLINE              Horizontal line (on many devices even for software
+                       this can be done with optimised methods)
+GFX_VLINE              Similar for verticals
+GFX_LINE               Arbitrary line from A to B, for accelerator hardware
+GFX_BLT_GG             Arbitrary screen to screen memory copy. Mainly for
+                       things like VDP2
+GFX_BLT_CG             As the aligned blit but any alignment
+GFX_BLT_GC             Ditto in reverse
+GFX_RECT               Solid rectangle (or patterned if supported)
+GFX_RAW                        Direct command streams (eg VDP). Device specific
+GFX_RAWCOPY            For non mapped non accelerated screens, each command
+                       describes a block copy
+
+MODE_XOR               XOR drawing mode is supported
+MODE_PATTERN           8x8 Pattern fill is allowed
+
+There are things that need covering if they make sense
+- Sprite discovery, description, setup and movement
+- Blit with stencil
+
+The attributes describe colours and drawing modes.
+
+The basic idea is that a typical 8bit unaccelerated device need only support
+a few minimal operations and most ioctls can be completely ignored but we
+still can support smarter devices while having a direct route for accelerators
+for those cases they are needed (eg games)
+
+HLINE is worth having because in most cases that is faster if done by
+masking the ends and just setting/clearing/cpl the midstream bytes
+
+VLINE is a repeated operation while adding scanline of bytes
+
+RECT covers both and also the useful to optimise case of narrow rectangles
+where its a 1 or 2 byte wide drawing done akin to vline optimisations
+
+The BLTAL blit operations try and keep the logic simple and the code fast
+for the faster paths. It's sufficient for a lot of stuff including 8 pixel
+aligned font work, bitmaps, and double buffering work.
+
+
+Need to decide on the best approach for text and fonts
+
+Some hand optimised standard asm implementations of the rect/vline/hline and
+blits would also be worth having.
+
+
diff --git a/Kernel/include/graphics.h b/Kernel/include/graphics.h
new file mode 100644 (file)
index 0000000..256a9bc
--- /dev/null
@@ -0,0 +1,91 @@
+#ifndef _GRAPHICS_H
+#define _GRAPHICS_H
+
+/* We use the same structure for modes */
+struct display {
+  uint16_t width, height;      /* Logical display size */
+  uint16_t stride, lines;      /* Physical layout */
+  uint8_t vstep, hstep;                /* Scrolling step if supported or 0xFF */
+  uint8_t format;
+#define FMT_MONO_BW    0
+#define FMT_MONO_WB    1
+#define FMT_COLOUR4    2
+#define FMT_COLOUR16   3
+/* Those sufficiently funky */
+#define FMT_SPECTRUM   128
+#define FMT_VDP                129     /* VDP graphics engines */
+  uint8_t hardware;
+#define HW_UNACCEL     1       /* Simple display */
+#define HW_VDP_9918    128     /* Not neccessarily MSX... */
+#define HW_VDP_9938    129
+  uint16_t features;
+#define GFX_MAPPABLE   1       /* Can map into process memory */
+#define GFX_PALETTE    2       /* Has colour palette */
+#define GFX_OFFSCREEN  4       /* Offscreen memory */
+#define GFX_VBLANK     8
+#define GFX_ENABLE     16      /* Separate mode we enable/disable */
+#define GFX_MULTIMODE  32      /* Has multiple modes */
+#define GFX_PALETTE_SET        64      /* Has settable colour palette */
+  uint16_t memory;             /* Memory size in KB (may be 0 if not relevant) */
+  uint16_t commands;
+#define GFX_BLTAL_CG   1       /* Aligned blit CPU to graphics */
+#define GFX_BLTAL_GC   2       /* And the reverse */
+#define GFX_SETPIXEL   4       /* Driver supports set/clear pixel */
+#define GFX_HLINE      8       /* Horizontal line */
+#define GFX_VLINE      16      /* Vertical line */
+#define GFX_LINE       32      /* Arbitrary line */
+#define GFX_BLT_GG     64      /* Screen to screen blit */
+#define GFX_BLT_CG     128     /* Unaligned blits */
+#define GFX_BLT_GC     256
+#define GFX_RECT       512     /* Rectangles */
+#define GFX_RAW                1024    /* Raw command streams */
+#define GFX_RAWCOPY    1024    /* Raw command stream is copier format */
+  uint16_t drawmodes;
+#define MODE_XOR       1       /* XOR as well as set/clr */
+#define MODE_PATTERN   2       /* 8x8 pattern */
+};
+
+/* FIXME: need a way to describe/set modes if multiple supported */
+
+struct palette {
+  uint8_t n;
+  uint8_t r,g,b;
+};
+
+/* Do not fiddle with this struct idly - it has asm users */
+struct attribute {
+  uint8_t ink, paper;
+  uint8_t mode;
+#define        GFX_OP_COPY     0
+#define GFX_OP_SET     1
+#define GFX_OP_CLEAR   2
+#define GFX_OP_XOR     3
+  uint8_t flags;
+};
+
+#define GFX_BUFLEN             64      /* Default buffer length  (128 byte) */
+
+#define GFXIOC_GETINFO         0x0300  /* Query display info for this tty */
+#define GFXIOC_ENABLE          0x0301  /* Enter graphics mode */
+#define GFXIOC_DISABLE         0x0302  /* Exit graphics mode */
+#define GFXIOC_GETPALETTE      0x0303  /* Get a palette entry */
+#define GFXIOC_SETPALETTE      0x0304  /* Set a palette entry */
+#define GFXIOC_MAP             0x0305  /* Map into process if supported */
+#define GFXIOC_UNMAP           0x0306  /* Unmap from process */
+#define GFXIOC_SETATTR         0x0307  /* Set the drawing attributes */
+#define GFXIOC_SETPIXEL                0x0308  /* Set a pixel */
+#define GFXIOC_HLINE           0x0309  /* Horizontal line */
+#define GFXIOC_VLINE           0x030A  /* Vertical line */
+#define GFXIOC_RECT            0x030B  /* Draw rectangle */
+#define GFXIOC_BLTAL_CG                0x030C  /* Blit functions */
+#define GFXIOC_BLTAL_GC                0x030D
+#define GFXIOC_BLTCG           0x030E
+#define GFXIOC_BLTGC           0x030F
+#define GFXIOC_BLTGG           0x0310
+#define GFXIOC_CMD             0x0311  /* Raw command stream for a VDP */
+#define GFXIOC_PAN             0x0312  /* Panning */
+#define GFXIOC_WAITVB          0x0313  /* Wait for vblank */
+#define GFXIOC_GETPIXEL                0x0314  /* Read a pixel */
+#define GFXIOC_GETMODE         0x0315  /* Get info on a mode */
+#define GFXIOC_SETMODE         0x0315  /* Set video mode */
+#endif