ReactOS  0.4.14-dev-390-g34947ad
paint.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS VGA display driver
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: win32ss/drivers/displays/vga/objects/paint.c
5  * PURPOSE:
6  * PROGRAMMERS:
7  */
8 
9 #include <vgaddi.h>
10 
11 #include "brush.h"
12 
13 BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
14 {
15  int x, y, x2, y2, w, h, j;
16  ULONG orgx, pre1, midpre1, tmppre1;
17  //ULONG offset, orgpre1;
18  int ileftpix, imidpix, irightpix;
19 /* double leftpix, midpix, rightpix;*/
20 
21  /* Swap dimensions so that x, y are at topmost left */
22  if ( Dimensions.right < Dimensions.left )
23  {
24  x = Dimensions.right;
25  x2 = Dimensions.left;
26  }
27  else
28  {
29  x2 = Dimensions.right;
30  x = Dimensions.left;
31  }
32  if ( Dimensions.bottom < Dimensions.top )
33  {
34  y = Dimensions.bottom;
35  y2 = Dimensions.top;
36  }
37  else
38  {
39  y2 = Dimensions.bottom;
40  y = Dimensions.top;
41  }
42 
43  /* Calculate the width and height */
44  w = x2 - x;
45  h = y2 - y;
46 
47  DPRINT("VGADDIFillSolid: x:%d, y:%d, w:%d, h:%d\n", x, y, w, h);
48 
49  /* Calculate the starting offset */
50  //offset = xconv[x]+y80[y];
51 
52  /* Make a note of original x */
53  orgx = x;
54 
55  /* Calculate the left mask pixels, middle bytes and right mask pixel */
56  ileftpix = 7 - mod8(x-1);
57  irightpix = mod8(x+w);
58  imidpix = (w-ileftpix-irightpix) / 8;
59 
60  pre1 = xconv[(x-1)&~7] + y80[y];
61  //orgpre1=pre1;
62 
63  /* check for overlap ( very horizontally skinny rect ) */
64  if ( (ileftpix+irightpix) > w )
65  {
66  int mask = startmasks[ileftpix] & endmasks[irightpix];
67 
68  WRITE_PORT_UCHAR((PUCHAR)GRA_I,0x08); // set the mask
70 
71  tmppre1 = pre1;
72  for ( j = y; j < y+h; j++ )
73  {
74  READ_REGISTER_UCHAR ( vidmem+tmppre1 );
75  WRITE_REGISTER_UCHAR ( vidmem+tmppre1, iColor );
76  tmppre1 += 80;
77  }
78  return TRUE;
79  }
80 
81  if ( ileftpix > 0 )
82  {
83  /* Write left pixels */
84  WRITE_PORT_UCHAR((PUCHAR)GRA_I,0x08); // set the mask
86 
87  tmppre1 = pre1;
88  for ( j = y; j < y+h; j++ )
89  {
90  READ_REGISTER_UCHAR(vidmem + tmppre1);
92  tmppre1 += 80;
93  }
94 
95  /* Prepare new x for the middle */
96  x = orgx + 8;
97  }
98 
99  if ( imidpix > 0 )
100  {
101  midpre1=xconv[x] + y80[y];
102 
103  /* Set mask to all pixels in byte */
104  WRITE_PORT_UCHAR((PUCHAR)GRA_I, 0x08);
105 
106  WRITE_PORT_UCHAR((PUCHAR)GRA_D, 0xff);
107 
108  for ( j = y; j < y+h; j++ )
109  {
110  memset(vidmem+midpre1, iColor, imidpix); // write middle pixels, no need to read in latch because of the width
111  midpre1 += 80;
112  }
113  }
114 
115  x = orgx + w - irightpix;
116  pre1 = xconv[x] + y80[y];
117 
118  /* Write right pixels */
119  WRITE_PORT_UCHAR((PUCHAR)GRA_I,0x08); // set the mask bits
120  WRITE_PORT_UCHAR((PUCHAR)GRA_D,endmasks[irightpix]);
121 
122  for ( j = y; j < y+h; j++ )
123  {
124  READ_REGISTER_UCHAR(vidmem + pre1);
126  pre1 += 80;
127  }
128 
129  return TRUE;
130 }
131 
133  IN SURFOBJ *Surface,
134  IN CLIPOBJ *ClipRegion,
135  IN ULONG iColor,
136  IN MIX Mix,
137  IN BRUSHINST *BrushInst,
138  IN POINTL *BrushPoint)
139 {
140  RECT_ENUM RectEnum;
141  BOOL EnumMore;
142 
143  DPRINT("VGADDIPaintRgn: iMode: %d, iDComplexity: %d\n Color:%d\n", ClipRegion->iMode, ClipRegion->iDComplexity, iColor);
144  switch(ClipRegion->iMode)
145  {
146  case TC_RECTANGLES:
147 
148  /* Rectangular clipping can be handled without enumeration.
149  Note that trivial clipping is not possible, since the clipping
150  region defines the area to fill */
151 
152  if (ClipRegion->iDComplexity == DC_RECT)
153  {
154  DPRINT("VGADDIPaintRgn Rect:%d %d %d %d\n", ClipRegion->rclBounds.left, ClipRegion->rclBounds.top, ClipRegion->rclBounds.right, ClipRegion->rclBounds.bottom);
155  VGADDIFillSolid(Surface, ClipRegion->rclBounds, iColor);
156  }
157  else
158  {
159  /* Enumerate all the rectangles and draw them */
160 
161  CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, CD_ANY, 0);
162 
163  do
164  {
165  UINT i;
166  EnumMore = CLIPOBJ_bEnum(ClipRegion, sizeof(RectEnum), (PVOID) &RectEnum);
167  DPRINT("EnumMore: %d, count: %d\n", EnumMore, RectEnum.c);
168  for( i=0; i<RectEnum.c; i++)
169  {
170  DPRINT("VGADDI enum Rect:%d %d %d %d\n", RectEnum.arcl[i].left, RectEnum.arcl[i].top, RectEnum.arcl[i].right, RectEnum.arcl[i].bottom);
171  VGADDIFillSolid(Surface, RectEnum.arcl[i], iColor);
172  }
173  } while (EnumMore);
174  }
175  return TRUE;
176 
177  default:
178  return FALSE;
179  }
180 }
181 
182 
185  IN SURFOBJ *Surface,
186  IN CLIPOBJ *ClipRegion,
187  IN BRUSHOBJ *Brush,
188  IN POINTL *BrushOrigin,
189  IN MIX Mix)
190 {
191  ULONG iSolidColor;
192 
193  iSolidColor = Brush->iSolidColor; // FIXME: Realizations and the like
194 
195  // If the foreground and background Mixes are the same,
196  // (LATER or if there's no brush mask)
197  // then see if we can use the solid brush accelerators
198 
199  // FIXME: Put in the mix switch below
200  // Brush color parameter doesn't matter for these rops
201  return(VGADDIPaintRgn(Surface, ClipRegion, iSolidColor, Mix, NULL, BrushOrigin));
202 
203  if ((Mix & 0xFF) == ((Mix >> 8) & 0xFF))
204  {
205  switch (Mix & 0xFF)
206  {
207  case 0:
208  break;
209 
210  // FIXME: Implement all these millions of ROPs
211  // For now we don't support brushes -- everything is solid
212 
213  case R2_MASKNOTPEN:
214  case R2_NOTCOPYPEN:
215  case R2_XORPEN:
216  case R2_MASKPEN:
217  case R2_NOTXORPEN:
218  case R2_MERGENOTPEN:
219  case R2_COPYPEN:
220  case R2_MERGEPEN:
221  case R2_NOTMERGEPEN:
222  case R2_MASKPENNOT:
223  case R2_NOTMASKPEN:
224  case R2_MERGEPENNOT:
225 
226  // Rops that are implicit solid colors
227  case R2_NOT:
228  case R2_WHITE:
229  case R2_BLACK:
230 
231 
232  // FIXME: The Paint region belongs HERE
233 
234  case R2_NOP:
235  return TRUE;
236 
237  default:
238  break;
239  }
240  }
241 
242 /*
243 doBitBlt:
244 
245  // If VGADDIPaint can't do it, VGADDIBitBlt can.. or it might just loop back
246  // here and we have a nice infinite loop
247 
248  return( VGADDIBitBlt(Surface, (SURFOBJ *)NULL, (SURFOBJ *)NULL, ClipRegion,
249  (XLATEOBJ *)NULL, &ClipRegion->rclBounds,
250  NULL, (POINTL *)NULL, Brush, BrushOrigin,
251  NULL) ); UNIMPLEMENTED */
252 }
#define R2_MERGEPEN
Definition: wingdi.h:343
int y80[480]
Definition: vgavideo.c:13
#define IN
Definition: typedefs.h:38
PBYTE vidmem
Definition: vgavideo.c:18
#define TRUE
Definition: types.h:120
BOOL APIENTRY DrvPaint(IN SURFOBJ *Surface, IN CLIPOBJ *ClipRegion, IN BRUSHOBJ *Brush, IN POINTL *BrushOrigin, IN MIX Mix)
Definition: paint.c:184
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
ULONG MIX
Definition: winddi.h:129
#define R2_NOT
Definition: wingdi.h:346
#define R2_MASKNOTPEN
Definition: wingdi.h:339
#define TC_RECTANGLES
Definition: winddi.h:269
#define R2_NOTMERGEPEN
Definition: wingdi.h:349
unsigned char * PUCHAR
Definition: retypes.h:3
#define GRA_I
Definition: vgavideo.h:59
long bottom
Definition: polytest.cpp:53
#define R2_NOP
Definition: wingdi.h:345
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define R2_COPYPEN
Definition: wingdi.h:338
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
int endmasks[8]
Definition: vgavideo.c:17
long right
Definition: polytest.cpp:53
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLenum GLint GLuint mask
Definition: glext.h:6028
unsigned int BOOL
Definition: ntddk_ex.h:94
long top
Definition: polytest.cpp:53
smooth NULL
Definition: ftsmooth.c:416
#define CT_RECTANGLES
Definition: winddi.h:1317
void DPRINT(...)
Definition: polytest.cpp:61
#define R2_XORPEN
Definition: wingdi.h:352
long left
Definition: polytest.cpp:53
BOOL VGADDIFillSolid(SURFOBJ *Surface, RECTL Dimensions, ULONG iColor)
Definition: paint.c:13
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define R2_WHITE
Definition: wingdi.h:351
#define R2_MASKPEN
Definition: wingdi.h:340
int xconv[640]
Definition: vgavideo.c:14
#define DC_RECT
Definition: winddi.h:260
#define mod8(n)
Definition: vgavideo.h:70
ENGAPI ULONG APIENTRY CLIPOBJ_cEnumStart(_Inout_ CLIPOBJ *pco, _In_ BOOL bAll, _In_ ULONG iType, _In_ ULONG iDirection, _In_ ULONG cLimit)
Definition: clip.c:255
#define R2_MASKPENNOT
Definition: wingdi.h:341
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG _In_ LONG y2
Definition: winddi.h:3706
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)
BOOL VGADDIPaintRgn(IN SURFOBJ *Surface, IN CLIPOBJ *ClipRegion, IN ULONG iColor, IN MIX Mix, IN BRUSHINST *BrushInst, IN POINTL *BrushPoint)
Definition: paint.c:132
#define R2_NOTCOPYPEN
Definition: wingdi.h:347
#define R2_MERGEPENNOT
Definition: wingdi.h:344
#define GRA_D
Definition: vgavideo.h:60
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
int startmasks[8]
Definition: vgavideo.c:16
unsigned int ULONG
Definition: retypes.h:1
#define R2_NOTXORPEN
Definition: wingdi.h:350
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#define memset(x, y, z)
Definition: compat.h:39
#define R2_NOTMASKPEN
Definition: wingdi.h:348
ENGAPI BOOL APIENTRY CLIPOBJ_bEnum(_In_ CLIPOBJ *pco, _In_ ULONG cj, _Out_bytecap_(cj) ULONG *pul)
Definition: clip.c:319
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)
#define R2_BLACK
Definition: wingdi.h:337
#define APIENTRY
Definition: api.h:79
#define CD_ANY
Definition: winddi.h:1326
_In_ ULONG iColor
Definition: xlateobj.h:17
#define R2_MERGENOTPEN
Definition: wingdi.h:342