]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/genmem.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / genmem.c
1 /*
2  * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com>
3  *
4  * Screen Driver Utilities
5  * 
6  * Microwindows memory device routines
7  */
8 #include <assert.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "device.h"
12 #include "fb.h"
13 #include "genmem.h"
14
15 /* allocate a memory screen device*/
16 PSD 
17 gen_allocatememgc(PSD psd)
18 {
19         PSD     mempsd;
20
21         /* if driver doesn't have blit, fail*/
22         if((psd->flags & PSF_HAVEBLIT) == 0)
23                 return NULL;
24
25         mempsd = malloc(sizeof(SCREENDEVICE));
26         if (!mempsd)
27                 return NULL;
28
29         /* copy passed device get initial values*/
30         *mempsd = *psd;
31
32         /* initialize*/
33         mempsd->flags |= PSF_MEMORY;
34         mempsd->flags &= ~PSF_SCREEN;
35         mempsd->addr = NULL;
36
37         return mempsd;
38 }
39
40 /* initialize memory device with passed parms*/
41 void
42 initmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,int linelen,
43         int size,void *addr)
44 {
45         assert(mempsd->flags & PSF_MEMORY);
46
47         /* create mem psd w/h aligned with hw screen w/h*/
48         if (mempsd->portrait & (MWPORTRAIT_LEFT|MWPORTRAIT_RIGHT)) {
49                 mempsd->yres = w;
50                 mempsd->xres = h;
51         } else {
52                 mempsd->xres = w;
53                 mempsd->yres = h;               
54         }
55         mempsd->xvirtres = w;
56         mempsd->yvirtres = h;
57         mempsd->planes = planes;
58         mempsd->bpp = bpp;
59         mempsd->linelen = linelen;
60         mempsd->size = size;
61         mempsd->addr = addr;
62 }
63
64 void
65 gen_freememgc(PSD mempsd)
66 {
67         assert(mempsd->flags & PSF_MEMORY);
68
69         /* note: mempsd->addr must be freed elsewhere*/
70
71         free(mempsd);
72 }
73
74 void
75 gen_fillrect(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2,
76         MWPIXELVAL c)
77 {
78         while(y1 <= y2)
79                 psd->DrawHorzLine(psd, x1, x2, y1++, c);
80 }
81
82 /*
83  * Set subdriver entry points in screen device
84  * Initialize subdriver if init flag is TRUE
85  * Return 0 on fail
86  */
87 MWBOOL
88 set_subdriver(PSD psd, PSUBDRIVER subdriver, MWBOOL init)
89 {
90         /* set subdriver entry points in screen driver*/
91         psd->DrawPixel          = subdriver->DrawPixel;
92         psd->ReadPixel          = subdriver->ReadPixel;
93         psd->DrawHorzLine       = subdriver->DrawHorzLine;
94         psd->DrawVertLine       = subdriver->DrawVertLine;
95         psd->FillRect           = subdriver->FillRect;
96         psd->Blit               = subdriver->Blit;
97         psd->DrawArea           = subdriver->DrawArea;
98         psd->StretchBlit        = subdriver->StretchBlit;
99
100         /* call driver init procedure to calc map size and linelen*/
101         if (init && !subdriver->Init(psd))
102                 return 0;
103         return 1;
104 }
105
106 /* fill in a subdriver struct from passed screen device*/
107 void
108 get_subdriver(PSD psd, PSUBDRIVER subdriver)
109 {
110         /* set subdriver entry points in screen driver*/
111         subdriver->DrawPixel            = psd->DrawPixel;
112         subdriver->ReadPixel            = psd->ReadPixel;
113         subdriver->DrawHorzLine         = psd->DrawHorzLine;
114         subdriver->DrawVertLine         = psd->DrawVertLine;
115         subdriver->FillRect             = psd->FillRect;
116         subdriver->Blit                 = psd->Blit;
117         subdriver->DrawArea             = psd->DrawArea;
118         subdriver->StretchBlit          = psd->StretchBlit;
119 }