diff --git a/src/Makefile b/src/Makefile index 393fa29..1e3d59c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ RESOURCES=../resources SPLASHSCREEN=splash-vmwcblk.png OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_upiwin_tmp.o ep_util.o \ - fbinit.o rect.o fontengine.o fbprimitive.o \ + fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o fbprimitive.o \ log.o gpio.o msg_queue.o time_func.o config.o splash.o LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm CFLAGS=-I/usr/include/python3.7m -I/usr/include/freetype2 -I/usr/include/libpng16 \ diff --git a/src/dc_screen.c b/src/dc_screen.c new file mode 100755 index 0000000..84fced2 --- /dev/null +++ b/src/dc_screen.c @@ -0,0 +1,5 @@ +#include "dc_screen.h" + +static COLORREF screen_set_pixel(PVOID privdata, INT32 x, INT32 y, COLORREF color, INT32 op) +{ +} diff --git a/src/dc_screen.h b/src/dc_screen.h new file mode 100755 index 0000000..4c4ad6e --- /dev/null +++ b/src/dc_screen.h @@ -0,0 +1,12 @@ +#ifndef __DC_SCREEN_H_INCLUDED +#define __DC_SCREEN_H_INCLUDED + +#include "wintype.h" +#include "gfxtype.h" + +typedef struct tagSCREENPRIVDATA { + UINT32 pix_per_row; + UINT16 *pdata; +} SCREENPRIVDATA, *PSCREENPRIVDATA; + +#endif /* __DC_SCREEN_H_INCLUDED */ diff --git a/src/devctxt.c b/src/devctxt.c new file mode 100755 index 0000000..982325a --- /dev/null +++ b/src/devctxt.c @@ -0,0 +1,9 @@ +#include "gfxtype.h" +#include "devctxt.h" + +COLORREF DC_SetPixel(PDCTXT pdctxt, INT32 x, INT32 y, COLORREF color) +{ + if (!G_coords_in_rect(&(pdctxt->cliprect), x, y)) + return (COLORREF)(-1); + return (*(pdctxt->funcs->set_pixel))(pdctxt->privdata, xm, y, colorref, pdctxt->rop2); +} diff --git a/src/devctxt.h b/src/devctxt.h new file mode 100755 index 0000000..2e8f528 --- /dev/null +++ b/src/devctxt.h @@ -0,0 +1,48 @@ +#ifndef __DEVCTXT_H_INCLUDED +#define __DEVCTXT_H_INCLUDED + +#include "wintype.h" +#include "gfxtype.h" +#include "gfxobj.h" + +#define DCTXT_SIG_WORD 0x78744344 /* "DCtx */ + +/* Raster operation codes */ +#define R2_BLACK 1 +#define R2_NOTMERGEPEN 2 +#define R2_MASKNOTPEN 3 +#define R2_NOTCOPYPEN 4 +#define R2_MASKPENNOT 5 +#define R2_NOT 6 +#define R2_XORPEN 7 +#define R2_NOTMASKPEN 8 +#define R2_MASKPEN 9 +#define R2_NOTXORPEN 10 +#define R2_NOP 11 +#define R2_MERGENOTPEN 12 +#define R2_COPYPEN 13 +#define R2_MERGEPENNOT 14 +#define R2_MERGEPEN 15 +#define R2_WHITE 16 + +typedef COLORREF (*DCtx_SetPixel)(PVOID privdata, INT32 x, INT32 y, COLORREF color, INT32 op); + +typedef struct tagDCFUNTABLE { + DCtx_SetPixel set_pixel; /* sets a single pixel on the display */ +} DCFUNTABLE; + +typedef const DCFUNTABLE *PDCFUNTABLE; + +typedef struct tagDCTXT { + GFXOBJECT hdr; /* the header of all objects */ + PDCFUNTABLE funcs; /* device context functions */ + PVOID privdata; /* private data for the type of DC */ + RECT cliprect; /* clipping rectangle */ + POINT pos; /* current position */ + UINT32 rop2; /* current raster operation */ + COLORREF color; /* current drawing color (XXX replace with pens later) */ +} DCTXT, *PDCTXT; + +extern COLORREF DC_SetPixel(PDCTXT pdctxt, INT32 x, INT32 y, COLORREF color); + +#endif /* __DEVCTXT_H_INCLUDED */ diff --git a/src/ep_backlight.c b/src/ep_backlight.c index bb37f07..e78cb58 100644 --- a/src/ep_backlight.c +++ b/src/ep_backlight.c @@ -24,7 +24,6 @@ PyObject *Epython_set_backlight(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "p", &new_state)) return NULL; pstate = (PUPIWIN_STATE)PyModule_GetState(UPIWIN_module); - Log(LDEBUG, "set_backlight: old=%d, new=%d (level=%u)", pstate->backlight_on, new_state, pstate->backlight_level); if (new_state && !(pstate->backlight_on)) Gpio_set_backlight(pstate->backlight_level); else if (!new_state && pstate->backlight_on) diff --git a/src/ep_msg.c b/src/ep_msg.c index c647533..9cf072b 100755 --- a/src/ep_msg.c +++ b/src/ep_msg.c @@ -68,3 +68,4 @@ PyObject *Epython_post_quit_message(PyObject *self, PyObject *args) Mq_post1(Sys_Queue, 0, WM_QUIT, exitcode); Py_RETURN_NONE; } + diff --git a/src/gfxobj.c b/src/gfxobj.c new file mode 100755 index 0000000..882ca1a --- /dev/null +++ b/src/gfxobj.c @@ -0,0 +1,30 @@ +#include +#include "gfxobj.h" + +void Go_unchain(PGFXOBJECT obj) +{ + if (!(obj->next || obj->prev)) + return; + if (obj->next) + obj->next->prev = obj->prev; + if (obj->prev) + obj->prev->next = obj->next; + obj->prev = obj->next = NULL; +} + +INT32 Go_addref(PGFXOBJECT obj) +{ + return ++(obj->refcnt); +} + +INT32 Go_release(PGFXOBJECT obj) +{ + int rc = --(obj->refcnt); + if (rc == 0) + { + if (obj->dtor) + (*(obj->dtor))(obj); + free(obj); + } + return rc; +} diff --git a/src/gfxobj.h b/src/gfxobj.h new file mode 100755 index 0000000..19d5926 --- /dev/null +++ b/src/gfxobj.h @@ -0,0 +1,23 @@ +#ifndef __GFXOBJ_H_INCLUDED +#define __GFXOBJ_H_INCLUDED + +#include "wintype.h" + +/* type definition for a graphics destructor */ +typedef void (*GFX_DTOR)(PVOID obj); + +/* A graphics object in memory always starts with this. */ +typedef struct tagGFXOBJECT { + UINT32 sig; /* signature so we know what something is */ + UINT32 size; /* size of total allocated memory in block */ + INT32 refcnt; /* reference count */ + GFX_DTOR dtor; /* destructor function called when we're no longer needed */ + struct tagGFXOBJECT *next; /* support double linked lists of obejcts */ + struct tagGFXOBJECT *prev; +} GFXOBJECT, *PGFXOBJECT; + +extern void Go_unchain(PGFXOBJECT obj); +extern INT32 Go_addref(PGFXOBJECT obj); +extern INT32 Go_release(PGFXOBJECT obj); + +#endif /* __GFXOBJ_H_INCLUDED */ diff --git a/src/gfxtype.h b/src/gfxtype.h index e992d9e..efc02db 100755 --- a/src/gfxtype.h +++ b/src/gfxtype.h @@ -18,14 +18,23 @@ typedef struct tagRECT { typedef const POINT *PCPOINT; typedef const RECT *PCRECT; +typedef UINT32 COLORREF; +typedef PUINT32 PCOLORREF; + extern BOOL G_set_rect(PRECT rect, int left, int top, int right, int bottom); extern BOOL G_set_rect_empty(PRECT rect); extern BOOL G_inflate_rect(PRECT rect, int dx, int dy); extern BOOL G_offset_rect(PRECT rect, int dx, int dy); extern BOOL G_is_rect_empty(PCRECT rect); +extern BOOL G_coords_in_rect(PCRECT rect, INT32 x, INT32 y); extern BOOL G_point_in_rect(PCRECT rect, PCPOINT pt); extern BOOL G_rect_equal(PCRECT rect1, PCRECT rect2); extern BOOL G_rect_intersect(PRECT dest, PCRECT src1, PCRECT src2); extern BOOL G_rect_union(PRECT dest, PCRECT src1, PCRECT src2); +#define RGB(r, g, b) ((((UINT32)(r)) & 0xFF) | ((((UINT32)(g)) & 0xFF) << 8) | ((((UINT32)(b)) & 0xFF) << 16)) +#define GetRValue(cr) ((UINT32)((cr) & 0xFF)) +#define GetGValue(cr) ((UINT32)(((cr) >> 8) & 0xFF)) +#define GetBValue(cr) ((UINT32)(((cr) >> 16) & 0xFF)) + #endif /* __GFXTYPE_H_INCLUDED */ diff --git a/src/rect.c b/src/rect.c index 2f1c318..eae408a 100755 --- a/src/rect.c +++ b/src/rect.c @@ -40,9 +40,14 @@ BOOL G_is_rect_empty(PCRECT rect) return (rect->right <= rect->left) || (rect->bottom <= rect->top); } +BOOL G_coords_in_rect(PCRECT rect, INT32 x, INT32 y) +{ + return (rect->left <= x) && (x < rect->right) && (rect->top <= y) && (y < rect->bottom); +} + BOOL G_point_in_rect(PCRECT rect, PCPOINT pt) { - return (rect->left <= pt->x) && (pt->x < rect->right) && (rect->top <= pt->y) && (pt->y < rect->bottom); + return G_coords_in_rect(rect, pt->x, pt->y); } BOOL G_rect_equal(PCRECT rect1, PCRECT rect2)