From: Toni Wilen Date: Sat, 1 Jan 2022 15:02:29 +0000 (+0200) Subject: epsonprinter: do not create separate print document from each page. X-Git-Tag: 4910~30 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1417186f310aa5422e03c3aaf68cbc0dbc92ddf0;p=francis%2Fwinuae.git epsonprinter: do not create separate print document from each page. --- diff --git a/epsonprinter.cpp b/epsonprinter.cpp index c97b1d95..7f7179cc 100644 --- a/epsonprinter.cpp +++ b/epsonprinter.cpp @@ -113,7 +113,7 @@ static int pins = 24; static void printCharBuffer(void); -static Bit8u colors[] = { +static const Bit8u colors[] = { 0x00, 0x00, 0x00, // 0 black 0xff, 0x00, 0xff, // 1 magenta (/green) 0x00, 0xff, 0xff, // 2 cyan (/red) @@ -713,194 +713,260 @@ STATIC_INLINE void getcolor (uae_u8 *Tpage, uae_u8 *Tcpage, int x, int y, int Tp *b = 255 - color_b; } +struct printdata +{ + volatile struct printdata *next; + volatile int page_w; + volatile int page_h; + volatile int page_pitch; + volatile uae_u8 *page; + volatile uae_u8 *cpage; + volatile int colorprinted; +}; + +static volatile struct printdata *queue; +static uae_sem_t queue_sem, queue_sem2; + static void prt_thread(void *p) { - Bit16u x, y; - HDC TprinterDC = printerDC; - HDC TmemHDC = memHDC; - int Tpage_w = page_w; - int Tpage_h = page_h; - int Tpage_pitch = page_pitch; - uae_u8 *Tpage = page; - uae_u8 *Tcpage = cpage; - int TcolorPrinter = colorPrinted; - - write_log (_T("EPSONPRINTER: background print thread started\n")); prt_thread_mode = 1; - SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_BELOW_NORMAL); + write_log(_T("EPSONPRINTER: background print thread started\n")); + while (prt_thread_mode) { - if (TprinterDC) - { - int hz = GetDeviceCaps (TprinterDC, PHYSICALWIDTH); - int vz = GetDeviceCaps (TprinterDC, PHYSICALHEIGHT); - int topmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETX); - int leftmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETY); - HDC dc = NULL; - - write_log (_T("EPSONPRINTER: HP=%d WP=%d TM=%d LM=%d W=%d H=%d\n"), - hz, vz, topmargin, leftmargin, Tpage_w, Tpage_h); - - if (TcolorPrinter) - dc = GetDC (NULL); - HBITMAP bitmap = CreateCompatibleBitmap (dc ? dc : TmemHDC, Tpage_w, Tpage_h); - SelectObject (TmemHDC, bitmap); - BitBlt (TmemHDC, 0, 0, Tpage_w, Tpage_h, NULL, 0, 0, WHITENESS); - - // Start new printer job? - if (outputHandle == NULL) - { - DOCINFO docinfo; - docinfo.cbSize = sizeof (docinfo); - docinfo.lpszDocName = _T("WinUAE Epson Printer"); - docinfo.lpszOutput = NULL; - docinfo.lpszDatatype = NULL; - docinfo.fwType = 0; - - StartDoc (TprinterDC, &docinfo); - multiPageCounter = 1; + uae_sem_wait(&queue_sem); + volatile struct printdata *pd = queue; + if (pd) { + queue = pd->next; } - - StartPage (TprinterDC); - - // this really needs to use something else than SetPixel().. - for (y=0; y 0) { + write_log(_T("EPSONPRINTER end document\n")); + EndDoc(printerDC); + } + DeleteDC(printerDC); + } + printerDC = NULL; + if (memHDC) + DeleteDC(memHDC); + memHDC = NULL; + multiPageCounter = 0; + break; } - } + Sleep(10); + } else if (pd) { + Bit16u x, y; + HDC TmemHDC = memHDC; + int Tpage_w = pd->page_w; + int Tpage_h = pd->page_h; + int Tpage_pitch = pd->page_pitch; + uae_u8 *Tpage = (uae_u8*)pd->page; + uae_u8 *Tcpage = (uae_u8*)pd->cpage; + int TcolorPrinter = pd->colorprinted; + + if (!multiPageCounter) { + DOCINFO docinfo; + docinfo.cbSize = sizeof(docinfo); + docinfo.lpszDocName = _T("WinUAE Epson Printer"); + docinfo.lpszOutput = NULL; + docinfo.lpszDatatype = NULL; + docinfo.fwType = 0; + + StartDoc(printerDC, &docinfo); + multiPageCounter = 1; + write_log(_T("EPSONPRINTER new document\n")); + } else { + multiPageCounter++; + } + HDC TprinterDC = printerDC; - BitBlt (TprinterDC, leftmargin, topmargin, Tpage_w, Tpage_h, TmemHDC, 0, 0, SRCCOPY); + if (TprinterDC) + { + int hz = GetDeviceCaps (TprinterDC, PHYSICALWIDTH); + int vz = GetDeviceCaps (TprinterDC, PHYSICALHEIGHT); + int topmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETX); + int leftmargin = GetDeviceCaps (TprinterDC, PHYSICALOFFSETY); + HDC dc = NULL; + + write_log (_T("EPSONPRINTER: page=%d, HP=%d WP=%d TM=%d LM=%d W=%d H=%d\n"), + multiPageCounter, + hz, vz, topmargin, leftmargin, Tpage_w, Tpage_h); + + if (TcolorPrinter) + dc = GetDC (NULL); + HBITMAP bitmap = CreateCompatibleBitmap (dc ? dc : TmemHDC, Tpage_w, Tpage_h); + SelectObject (TmemHDC, bitmap); + BitBlt (TmemHDC, 0, 0, Tpage_w, Tpage_h, NULL, 0, 0, WHITENESS); + + StartPage (TprinterDC); + + // this really needs to use something else than SetPixel().. + for (y=0; ypage_w = page_w; + pd->page_h = page_h; + pd->page_pitch = page_pitch; + pd->page = page; + pd->cpage = cpage; + pd->colorprinted = colorPrinted; + if (queue == NULL) { + queue = pd; + } else { + volatile struct printdata *pdx = queue; + while (pdx->next) { + pdx = pdx->next; + } + pdx->next = pd; + } page = NULL; cpage = NULL; - if (curFont) - DeleteObject (curFont); - curFont = NULL; } + uae_sem_post(&queue_sem); + + xfree(page); + page = NULL; + xfree(cpage); + cpage = NULL; + if (curFont) + DeleteObject (curFont); + curFont = NULL; } static void newPage(int save) @@ -909,10 +975,8 @@ static void newPage(int save) if (save) outputPage (); if (page == NULL) { - page = xcalloc (uae_u8, pagesize); - cpage = xcalloc (uae_u8, pagesize); - printerDC = CreateDC (NULL, epsonprintername, NULL, NULL); - memHDC = CreateCompatibleDC (NULL); + page = xcalloc(uae_u8, pagesize); + cpage = xcalloc(uae_u8, pagesize); } curY = topMargin; memset (page, 0, pagesize); @@ -966,6 +1030,8 @@ static void initPrinter(void) numHorizTabs = 32; numVertTabs = 255; + + uae_sem_init(&queue_sem, 0, 1); } static void resetPrinterHard(void) @@ -1068,12 +1134,9 @@ static void printer_close(void) if (curFont) DeleteObject (curFont); curFont = NULL; - if (printerDC) - DeleteDC(printerDC); - printerDC = NULL; - if (memHDC) - DeleteDC(memHDC); - memHDC = NULL; + if (prt_thread_mode) { + prt_thread_mode = -1; + } };