Memory Devices
Memory devices can be used in a variety of situations, mainly to prevent the display from flickering when using drawing operations for overlapping items. The basic idea is quite simple. Without the use of a memory device, drawing operations write directly to the display. The screen is updated as drawing operations are executed, which gives it a flickering appearance as the various updates are made. For example, if you wanted to draw a bitmap in the background and some transparent text in the foreground, you would first have to draw the bitmap and then the text. The effect would be a flickering of the text.
If a memory device is used for such a procedure, however, all drawing operations are executed in memory. The final result is displayed on the screen only when all operations have been carried out, with the advantage of no flickering. This difference can be seen in the example in the following section, which illustrates a sequence of drawing operations both with and without the use of a memory device.
The distinction may be summarized as follows: If no memory device is used, the effects of drawing operations can be seen step by step, with the disadvantage of a flickering display. With a memory device, the effects of all routines are made visible as a single operation. No intermediate steps can actually be seen. The advantage, as explained above, is that display flickering is completely eliminated, and this is often desirable. Memory devices are an additional (optional) software item and are not shipped with the emWin basic package. The software for memory devices is located in the subdirectory Memdev of the GUI directory.
Using memory devices: an illustration
The following table shows screen shots of the same operations handled with and without a memory device. The objective in both cases is identical: a work piece is to be rotated and labeled with the respective angle of rotation (here, 10 degrees). In the first case (without a memory device) the screen is first cleared, then the polygon is redrawn in the new position and a string with the new label is written. In the second case (with a memory device) the same operations are performed in memory, but the screen is not updated during this time. The only update occurs when the routine GUI_MEMDEV_CopyToLCD is called, and this update reflects all the operations at once. Note that the initial states and final outputs of both procedures are identical.
| API function | Without memory device | With memory device |
| Step 0: Initial state | ![]() | ![]() |
| Step 1: GUI_Clear | ![]() | ![]() |
| Step 2: GUI_DrawPolygon | ![]() | ![]() |
| Step 3: GUI_DispString | ![]() | ![]() |
Step 4: GUI_MEMDEV_CopyToLCD (only when using memory device) | ![]() |
Basic functions
The following routines are those that are typically used with memory devices. Basic usage is rather simple:
- Create the memory device (using GUI_MEMDEV_Create).
- Activate it (using GUI_MEMDEV_Select).
- Execute drawing operations.
- Copy the result into the display (using GUI_MEMDEV_CopyToLCD).
- Delete the memory device (if you no longer need it).
Banding memory device
The size of available memory is normally not enough to cover the whole drawing area. A banding memory device divides the drawing area into bands. One band covers as many lines as possible with the currently available memory.
Take a look at the c-code and download the demo file here.
Auto device object
An auto device object is often preferred for applications such as moving pointers, in which only a small part of the display is updated at a time. The device automatically distinguishes which parts of the display consist of fixed items and which parts consist of moving or changing items. When the drawing function for the auto device object is called for the first time, it draws all items. Each further call updates only the space used by the moving or changing objects. The actual drawing operation uses the banding memory device, but only within the necessary area. The main advantage of using an auto device object is that it saves computation time, since it does not keep updating the entire display.
Take a look at the c-code and download the demo file here.
Memory devices and the window manager
The window manager works seamlessly with memory devices. Every window has a flag which tells the window manager if a memory device should be used for rendering. This flag can be specified when creating the window or set/reset at any time. If the memory device flag is set for a particular window, the WM automatically uses a memory device when drawing the window. It creates a memory device before drawing a window and deletes it after the drawing operation.
If enough memory is available, the whole window fits into the size of the memory device created by the WM. If not enough memory is available for the complete window in one memory device, the WM uses 'banding' for drawing the window. The memory used for the drawing operation is only allocated during the drawing operation. If there is not enough memory available when (re-)drawing the window, the window is redrawn without memory device.
Performance
Using memory devices typically does no significantly affect performance. When memory devices are used, the work of the driver is easier: It simply transfers bitmaps to the display controller. On systems with slow drivers (for example displays connected via serial interface), the performance is better if memory devices are used; on systems with a fast driver (such as memory mapped display memory, LCDLin driver and others) the use of memory devices costs some performance. If 'banding' is needed, the used time to draw a window increases with the number of bands. The more memory available for memory devices, the better the performance.
Memory device API
The table below lists the available routines of the emWin memory device API. All functions are listed in alphabetical order within their respective categories.
| Routine | Explanation |
|---|---|
| GUI_MEMDEV_CopyToLCDAA() | Copies the contents of memory device antialiased. |
| GUI_MEMDEV_CopyToLCDAt() | Copies contents of memory device to LCD at the given position. |
| GUI_MEMDEV_Create() | Creates the memory device (first step). |
| GUI_MEMDEV_CreateEx() | Creates the memory device with additional creation flags. |
| GUI_MEMDEV_CreateFixed() | Creates a memory device with a given color depth. |
| GUI_MEMDEV_Delete() | Frees the memory used by the memory device. |
| GUI_MEMDEV_DrawPerspectiveX() | Draws the given memory device perspectively distorted into the current selected device. |
| GUI_MEMDEV_GetDataPtr() | Returns a pointer to the data area for direct manipulation. |
| GUI_MEMDEV_GetXSize() | Returns the X-size (width) of memory device. |
| GUI_MEMDEV_GetYSize() | Returns the Y-size (height) of memory device. |
| GUI_MEMDEV_MarkDirty() | Marks the given area as containing pixels to be drawn. |
| GUI_MEMDEV_ReduceYSize() | Reduces Y-size of memory device. |
| GUI_MEMDEV_Rotate() | Rotates and scales a memory device and writes the result into a memory device using the ’nearest neighbour’ method. |
| GUI_MEMDEV_RotateHQ() | Rotates and scales a memory device and writes the result into a memory device using the ’high quality’ method. |
| GUI_MEMDEV_Select() | Selects a memory device as target for drawing operations. |
| GUI_MEMDEV_SetOrg() | Changes the origin of the memory device on the LCD. |
| UI_MEMDEV_Write() | Writes the contents of a memory device into a memory device. |
| GUI_MEMDEV_WriteAlpha() | Writes the contents of a memory device into a memory device using alpha blending. |
| GUI_MEMDEV_WriteAlphaAt() | Writes the contents of a memory device into a memory device using the given position and alpha blending. |
| GUI_MEMDEV_WriteAt() | Writes the contents of a memory device into a memory device to the given position. |
| GUI_MEMEDV_WriteEx() | Writes the contents of a memory device into a memory device using alpha blending and scaling. |
| GUI_MEMDEV_WriteExAt() | Writes the contents of a memory device into a memory device to the given position using alpha blending and scaling. |
| GUI_SelectLCD() | Selects the LCD as target for drawing operations. |
| Banding memory device | |
| GUI_MEMDEV_Draw() | Use a memory device for drawing |
| Auto device object functions | |
| GUI_MEMDEV_CreateAuto | Creates an auto device object |
| GUI_MEMDEV_DeleteAuto | Deletes an auto device object |
| GUI_MEMDEV_DrawAuto | Uses a GUI_AUTODEV object for drawing |
| Measurement device object functions | |
| GUI_MEASDEV_ClearRect() | Clears the measurement rectangle |
| GUI_MEASDEV_Create() | Creates a measurement device |
| GUI_MEASDEV_Delete() | Deletes a measurement device |
| GUI_MEASDEV_GetRect() | Retrieves the measurement result |
| GUI_MEASDEV_Select() | Selects a measurement device as target for drawing operations |
Memory Devices
Head office Germany
US office 




