Improving Pixmap API
This commit is contained in:
parent
23a603dd0d
commit
380c41b766
3 changed files with 17 additions and 14 deletions
|
@ -32,8 +32,8 @@
|
||||||
#define PIXMAP_WIDTH 40
|
#define PIXMAP_WIDTH 40
|
||||||
#define PIXMAP_HEIGHT 10
|
#define PIXMAP_HEIGHT 10
|
||||||
|
|
||||||
static GDisplay *pix;
|
static GDisplay* pixmap;
|
||||||
static pixel_t *surface;
|
static pixel_t* surface;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
coord_t width, height;
|
coord_t width, height;
|
||||||
|
@ -47,8 +47,8 @@ int main(void) {
|
||||||
height = gdispGetHeight();
|
height = gdispGetHeight();
|
||||||
|
|
||||||
// Create a pixmap and get a pointer to the bits
|
// Create a pixmap and get a pointer to the bits
|
||||||
pix = gdispCreatePixmap(PIXMAP_WIDTH, PIXMAP_HEIGHT);
|
pixmap = gdispPixmapCreate(PIXMAP_WIDTH, PIXMAP_HEIGHT);
|
||||||
surface = gdispGetPixmapBits(pix);
|
surface = gdispPixmapGetBits(pixmap);
|
||||||
|
|
||||||
// A pixmap can be treated either as a virtual display or as a memory framebuffer surface.
|
// A pixmap can be treated either as a virtual display or as a memory framebuffer surface.
|
||||||
// We demonstrate writing to it using both methods.
|
// We demonstrate writing to it using both methods.
|
||||||
|
@ -59,7 +59,7 @@ int main(void) {
|
||||||
surface[j*PIXMAP_WIDTH + i] = RGB2COLOR(0, 255-i*(256/PIXMAP_WIDTH), j*(256/PIXMAP_HEIGHT));
|
surface[j*PIXMAP_WIDTH + i] = RGB2COLOR(0, 255-i*(256/PIXMAP_WIDTH), j*(256/PIXMAP_HEIGHT));
|
||||||
|
|
||||||
// Secondly, show drawing a line on it like a virtual display
|
// Secondly, show drawing a line on it like a virtual display
|
||||||
gdispGDrawLine(pix, 0, 0, gdispGGetWidth(pix)-1, gdispGGetHeight(pix)-1, White);
|
gdispGDrawLine(pixmap, 0, 0, gdispGGetWidth(pixmap)-1, gdispGGetHeight(pixmap)-1, White);
|
||||||
|
|
||||||
i = j = 0;
|
i = j = 0;
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
|
@ -79,5 +79,8 @@ int main(void) {
|
||||||
// Wait
|
// Wait
|
||||||
gfxSleepMilliseconds(100);
|
gfxSleepMilliseconds(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
gdispPixmapDelete(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ typedef struct pixmap {
|
||||||
color_t pixels[1]; // We really want pixels[0] but some compilers don't allow that even though it is C standard.
|
color_t pixels[1]; // We really want pixels[0] but some compilers don't allow that even though it is C standard.
|
||||||
} pixmap;
|
} pixmap;
|
||||||
|
|
||||||
GDisplay *gdispCreatePixmap(coord_t width, coord_t height) {
|
GDisplay *gdispPixmapCreate(coord_t width, coord_t height) {
|
||||||
GDisplay *g;
|
GDisplay *g;
|
||||||
pixmap *p;
|
pixmap *p;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -86,20 +86,20 @@ GDisplay *gdispCreatePixmap(coord_t width, coord_t height) {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdispDeletePixmap(GDisplay *g) {
|
void gdispPixmapDelete(GDisplay *g) {
|
||||||
if (gvmt(g) != GDISPVMT_pixmap)
|
if (gvmt(g) != GDISPVMT_pixmap)
|
||||||
return;
|
return;
|
||||||
gdriverUnRegister(&g->d);
|
gdriverUnRegister(&g->d);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_t *gdispGetPixmapBits(GDisplay *g) {
|
pixel_t *gdispPixmapGetBits(GDisplay *g) {
|
||||||
if (gvmt(g) != GDISPVMT_pixmap)
|
if (gvmt(g) != GDISPVMT_pixmap)
|
||||||
return 0;
|
return 0;
|
||||||
return ((pixmap *)g->priv)->pixels;
|
return ((pixmap *)g->priv)->pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GDISP_NEED_PIXMAP_IMAGE
|
#if GDISP_NEED_PIXMAP_IMAGE
|
||||||
void *gdispGetPixmapMemoryImage(GDisplay *g) {
|
void *gdispPixmapGetMemoryImage(GDisplay *g) {
|
||||||
if (gvmt(g) != GDISPVMT_pixmap)
|
if (gvmt(g) != GDISPVMT_pixmap)
|
||||||
return 0;
|
return 0;
|
||||||
return ((pixmap *)g->priv)->imghdr;
|
return ((pixmap *)g->priv)->imghdr;
|
||||||
|
|
|
@ -40,7 +40,7 @@ extern "C" {
|
||||||
* @note Because the RAM for the display area is allocated, on small micros only very small pixmaps should be considered.
|
* @note Because the RAM for the display area is allocated, on small micros only very small pixmaps should be considered.
|
||||||
* For example a 100x100 at 16 bits per pixel would be 20K of RAM (plus some overheads).
|
* For example a 100x100 at 16 bits per pixel would be 20K of RAM (plus some overheads).
|
||||||
*/
|
*/
|
||||||
GDisplay *gdispCreatePixmap(coord_t width, coord_t height);
|
GDisplay *gdispPixmapCreate(coord_t width, coord_t height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy an off-screen pixmap
|
* @brief Destroy an off-screen pixmap
|
||||||
|
@ -49,7 +49,7 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @note If a normal display is passed to this routine, it will be ignored.
|
* @note If a normal display is passed to this routine, it will be ignored.
|
||||||
*/
|
*/
|
||||||
void gdispDeletePixmap(GDisplay *g);
|
void gdispPixmapDelete(GDisplay *g);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a pointer to the pixels of the display surface.
|
* @brief Get a pointer to the pixels of the display surface.
|
||||||
|
@ -62,7 +62,7 @@ extern "C" {
|
||||||
* (although different pixmaps will have different pixel pointers). Once a pixmap is deleted, the pixel pointer
|
* (although different pixmaps will have different pixel pointers). Once a pixmap is deleted, the pixel pointer
|
||||||
* should not be used by the application.
|
* should not be used by the application.
|
||||||
*/
|
*/
|
||||||
pixel_t *gdispGetPixmapBits(GDisplay *g);
|
pixel_t *gdispPixmapGetBits(GDisplay *g);
|
||||||
|
|
||||||
#if GDISP_NEED_PIXMAP_IMAGE || defined(__DOXYGEN__)
|
#if GDISP_NEED_PIXMAP_IMAGE || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +78,7 @@ extern "C" {
|
||||||
* @note If you are just wanting to copy to a real display it is more efficient to use @p gdispGetPixmapBits() and @p gdispGBlitArea().
|
* @note If you are just wanting to copy to a real display it is more efficient to use @p gdispGetPixmapBits() and @p gdispGBlitArea().
|
||||||
* @note Like @p gdispGetPixmapBits(), the pointer returned is valid for the life of the pixmap.
|
* @note Like @p gdispGetPixmapBits(), the pointer returned is valid for the life of the pixmap.
|
||||||
*/
|
*/
|
||||||
void *gdispGetPixmapMemoryImage(GDisplay *g);
|
void *gdispPixmapGetMemoryImage(GDisplay *g);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Reference in a new issue