Removed the crash in ViewDriver when moving the cursor off the bottom edge of the screen

Replaced LayerData component of Decorator with DrawData
Fixed unfocused draw bug in DefaultDecorator::DrawBlendedRect
Added some copying methods to FBBitmap and ServerBitmap
Removed a lot of disabled code from ViewDriver file
Implemented and fixed font functions in DisplayDriver
Updates to the BitmapDriver to the reflect changes in DisplayDriver


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2004-02-15 20:27:26 +00:00
parent 14ef62299d
commit 67387a90b7
7 changed files with 516 additions and 1043 deletions
+255 -408
View File
@@ -118,212 +118,6 @@ void BitmapDriver::SetMode(const display_mode &mode)
// No need to reset a bitmap's color space
}
// This function is intended to eventually take care of most of the heavy lifting for
// DrawBitmap in 32-bit mode, with others coming later. Right now, it is *just* used for
// the
void BitmapDriver::BlitBitmap(ServerBitmap *sourcebmp,BRect sourcerect, BRect destrect, drawing_mode mode)
{
// Another internal function called from other functions.
if(!sourcebmp)
return;
if(sourcebmp->BitsPerPixel() != _target->BitsPerPixel())
return;
uint8 colorspace_size=sourcebmp->BitsPerPixel()/8;
// First, clip source rect to destination
if(sourcerect.Width() > destrect.Width())
sourcerect.right=sourcerect.left+destrect.Width();
if(sourcerect.Height() > destrect.Height())
sourcerect.bottom=sourcerect.top+destrect.Height();
// Second, check rectangle bounds against their own bitmaps
BRect work_rect;
work_rect=sourcebmp->Bounds();
if( !(work_rect.Contains(sourcerect)) )
{ // something in selection must be clipped
if(sourcerect.left < 0)
sourcerect.left = 0;
if(sourcerect.right > work_rect.right)
sourcerect.right = work_rect.right;
if(sourcerect.top < 0)
sourcerect.top = 0;
if(sourcerect.bottom > work_rect.bottom)
sourcerect.bottom = work_rect.bottom;
}
work_rect.Set(0,0,_target->Width()-1,_target->Height()-1);
// Check to see if we actually need to copy anything
if( (destrect.right<work_rect.left) || (destrect.left>work_rect.right) ||
(destrect.bottom<work_rect.top) || (destrect.top>work_rect.bottom) )
return;
// something in selection must be clipped
if(destrect.left < 0)
destrect.left = 0;
if(destrect.right > work_rect.right)
destrect.right = work_rect.right;
if(destrect.top < 0)
destrect.top = 0;
if(destrect.bottom > work_rect.bottom)
destrect.bottom = work_rect.bottom;
// Set pointers to the actual data
uint8 *src_bits = (uint8*) sourcebmp->Bits();
uint8 *dest_bits = (uint8*) _target->Bits();
// Get row widths for offset looping
uint32 src_width = uint32 (sourcebmp->BytesPerRow());
uint32 dest_width = uint32 (_target->BytesPerRow());
// Offset bitmap pointers to proper spot in each bitmap
src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) );
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
switch(mode)
{
case B_OP_OVER:
{
// uint32 srow_pixels=src_width>>2;
uint32 srow_pixels=((destrect.IntegerWidth()>=sourcerect.IntegerWidth())?src_width:destrect.IntegerWidth()+1)>>2;
uint8 *srow_index, *drow_index;
// This could later be optimized to use uint32's for faster copying
for (uint32 pos_y=0; pos_y!=lines; pos_y++)
{
srow_index=src_bits;
drow_index=dest_bits;
for(uint32 pos_x=0; pos_x!=srow_pixels;pos_x++)
{
// 32-bit RGBA32 mode byte order is BGRA
if(srow_index[3]>127)
{
*drow_index=*srow_index; drow_index++; srow_index++;
*drow_index=*srow_index; drow_index++; srow_index++;
*drow_index=*srow_index; drow_index++; srow_index++;
// we don't copy the alpha channel
drow_index++; srow_index++;
}
else
{
srow_index+=4;
drow_index+=4;
}
}
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
break;
}
default: // B_OP_COPY
{
for (uint32 pos_y = 0; pos_y != lines; pos_y++)
{
memcpy(dest_bits,src_bits,line_length);
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
break;
}
}
}
void BitmapDriver::ExtractToBitmap(ServerBitmap *destbmp,BRect destrect, BRect sourcerect)
{
// Another internal function called from other functions. Extracts data from
// the framebuffer to a target ServerBitmap
if(!destbmp)
return;
if(destbmp->BitsPerPixel() != _target->BitsPerPixel())
return;
uint8 colorspace_size=destbmp->BitsPerPixel()/8;
// First, clip source rect to destination
if(sourcerect.Width() > destrect.Width())
sourcerect.right=sourcerect.left+destrect.Width();
if(sourcerect.Height() > destrect.Height())
sourcerect.bottom=sourcerect.top+destrect.Height();
// Second, check rectangle bounds against their own bitmaps
BRect work_rect;
work_rect.Set( destbmp->Bounds().left,
destbmp->Bounds().top,
destbmp->Bounds().right,
destbmp->Bounds().bottom );
if( !(work_rect.Contains(destrect)) )
{ // something in selection must be clipped
if(destrect.left < 0)
destrect.left = 0;
if(destrect.right > work_rect.right)
destrect.right = work_rect.right;
if(destrect.top < 0)
destrect.top = 0;
if(destrect.bottom > work_rect.bottom)
destrect.bottom = work_rect.bottom;
}
work_rect.Set( 0,0,_target->Width()-1,_target->Height()-1);
if( !(work_rect.Contains(sourcerect)) )
{ // something in selection must be clipped
if(sourcerect.left < 0)
sourcerect.left = 0;
if(sourcerect.right > work_rect.right)
sourcerect.right = work_rect.right;
if(sourcerect.top < 0)
sourcerect.top = 0;
if(sourcerect.bottom > work_rect.bottom)
sourcerect.bottom = work_rect.bottom;
}
// Set pointers to the actual data
uint8 *dest_bits = (uint8*) destbmp->Bits();
uint8 *src_bits = (uint8*) _target->Bits();
// Get row widths for offset looping
uint32 dest_width = uint32 (destbmp->BytesPerRow());
uint32 src_width = uint32 (_target->BytesPerRow());
// Offset bitmap pointers to proper spot in each bitmap
src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) );
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
for (uint32 pos_y = 0; pos_y != lines; pos_y++)
{
memcpy(dest_bits,src_bits,line_length);
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
}
void BitmapDriver::InvertRect(const BRect &r)
{
Lock();
@@ -374,207 +168,6 @@ void BitmapDriver::InvertRect(const BRect &r)
Unlock();
}
/*
void BitmapDriver::BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d)
{
rgb_color color=d->highcolor.GetColor32();
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer, *destbuffer;
// index pointers which are incremented during the course of the blit
uint8 *srcindex, *destindex, *rowptr, value;
// increment values for the index pointers
int32 srcinc=src->pitch, destinc=_target->BytesPerRow();
int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows;
int32 x=(int32)pt.x,y=(int32)pt.y;
// starting point in source bitmap
srcbuffer=(uint8*)src->buffer;
if(y<0)
{
if(y<pt.y)
y++;
srcbuffer+=srcinc * (0-y);
srcheight-=srcinc;
destbuffer+=destinc * (0-y);
}
if(y+srcheight>_target->Height())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-_target->Height();
}
if(x+srcwidth>_target->Width())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-_target->Width();
}
if(x<0)
{
if(x<pt.x)
x++;
srcbuffer+=(0-x)>>3;
srcwidth-=0-x;
destbuffer+=(0-x)*4;
}
// starting point in destination bitmap
destbuffer=(uint8*)_target->Bits()+int32( (pt.y*_target->BytesPerRow())+(pt.x*4) );
srcindex=srcbuffer;
destindex=destbuffer;
for(i=0; i<srcheight; i++)
{
rowptr=destindex;
for(j=0;j<srcwidth;j++)
{
for(k=0; k<8; k++)
{
value=*(srcindex+j) & (1 << (7-k));
if(value)
{
rowptr[0]=color.blue;
rowptr[1]=color.green;
rowptr[2]=color.red;
rowptr[3]=color.alpha;
}
rowptr+=4;
}
}
srcindex+=srcinc;
destindex+=destinc;
}
}
void BitmapDriver::BlitGray2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d)
{
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer=NULL, *destbuffer=NULL;
// index pointers which are incremented during the course of the blit
uint8 *srcindex=NULL, *destindex=NULL, *rowptr=NULL;
rgb_color highcolor=d->highcolor.GetColor32(), lowcolor=d->lowcolor.GetColor32(); float rstep,gstep,bstep,astep;
rstep=float(highcolor.red-lowcolor.red)/255.0;
gstep=float(highcolor.green-lowcolor.green)/255.0;
bstep=float(highcolor.blue-lowcolor.blue)/255.0;
astep=float(highcolor.alpha-lowcolor.alpha)/255.0;
// increment values for the index pointers
int32 x=(int32)pt.x,
y=(int32)pt.y,
srcinc=src->pitch,
// destinc=dest->BytesPerRow(),
destinc=_target->BytesPerRow(),
srcwidth=src->width,
srcheight=src->rows,
incval=0;
int16 i,j;
// starting point in source bitmap
srcbuffer=(uint8*)src->buffer;
// starting point in destination bitmap
// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4));
destbuffer=(uint8*)_target->Bits()+(y*_target->BytesPerRow()+(x*4));
if(y<0)
{
if(y<pt.y)
y++;
incval=0-y;
srcbuffer+=incval * srcinc;
srcheight-=incval;
destbuffer+=incval * destinc;
}
if(y+srcheight>_target->Height())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-_target->Height();
}
if(x+srcwidth>_target->Width())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-_target->Width();
}
if(x<0)
{
if(x<pt.x)
x++;
incval=0-x;
srcbuffer+=incval;
srcwidth-=incval;
destbuffer+=incval*4;
}
int32 value;
srcindex=srcbuffer;
destindex=destbuffer;
for(i=0; i<srcheight; i++)
{
rowptr=destindex;
for(j=0;j<srcwidth;j++)
{
value=*(srcindex+j) ^ 255;
if(value!=255)
{
if(d->draw_mode==B_OP_COPY)
{
rowptr[0]=uint8(highcolor.blue-(value*bstep));
rowptr[1]=uint8(highcolor.green-(value*gstep));
rowptr[2]=uint8(highcolor.red-(value*rstep));
rowptr[3]=255;
}
else
if(d->draw_mode==B_OP_OVER)
{
if(highcolor.alpha>127)
{
rowptr[0]=uint8(highcolor.blue-(value*(float(highcolor.blue-rowptr[0])/255.0)));
rowptr[1]=uint8(highcolor.green-(value*(float(highcolor.green-rowptr[1])/255.0)));
rowptr[2]=uint8(highcolor.red-(value*(float(highcolor.red-rowptr[2])/255.0)));
rowptr[3]=255;
}
}
}
rowptr+=4;
}
srcindex+=srcinc;
destindex+=destinc;
}
}
*/
rgb_color BitmapDriver::GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high)
{
rgb_color returncolor={0,0,0,0};
@@ -1010,7 +603,261 @@ void BitmapDriver::FillPatternRect(int32 left, int32 top, int32 right, int32 bot
}
*/
void BitmapDriver::DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, DrawData *d)
void BitmapDriver::DrawBitmap(ServerBitmap *sourcebmp, const BRect &source,
const BRect &dest, DrawData *d)
{
// Another internal function called from other functions.
if(!sourcebmp | !d)
return;
if(sourcebmp->BitsPerPixel() != _target->BitsPerPixel())
return;
uint8 colorspace_size=sourcebmp->BitsPerPixel()/8;
BRect sourcerect(source),destrect(dest);
// First, clip source rect to destination
if(sourcerect.Width() > destrect.Width())
sourcerect.right=sourcerect.left+destrect.Width();
if(sourcerect.Height() > destrect.Height())
sourcerect.bottom=sourcerect.top+destrect.Height();
// Second, check rectangle bounds against their own bitmaps
BRect work_rect;
work_rect=sourcebmp->Bounds();
if( !(work_rect.Contains(sourcerect)) )
{ // something in selection must be clipped
if(sourcerect.left < 0)
sourcerect.left = 0;
if(sourcerect.right > work_rect.right)
sourcerect.right = work_rect.right;
if(sourcerect.top < 0)
sourcerect.top = 0;
if(sourcerect.bottom > work_rect.bottom)
sourcerect.bottom = work_rect.bottom;
}
work_rect.Set(0,0,_target->Width()-1,_target->Height()-1);
// Check to see if we actually need to copy anything
if( (destrect.right<work_rect.left) || (destrect.left>work_rect.right) ||
(destrect.bottom<work_rect.top) || (destrect.top>work_rect.bottom) )
return;
// something in selection must be clipped
if(destrect.left < 0)
destrect.left = 0;
if(destrect.right > work_rect.right)
destrect.right = work_rect.right;
if(destrect.top < 0)
destrect.top = 0;
if(destrect.bottom > work_rect.bottom)
destrect.bottom = work_rect.bottom;
// Set pointers to the actual data
uint8 *src_bits = (uint8*) sourcebmp->Bits();
uint8 *dest_bits = (uint8*) _target->Bits();
// Get row widths for offset looping
uint32 src_width = uint32 (sourcebmp->BytesPerRow());
uint32 dest_width = uint32 (_target->BytesPerRow());
// Offset bitmap pointers to proper spot in each bitmap
src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) );
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
switch(d->draw_mode)
{
case B_OP_OVER:
{
// uint32 srow_pixels=src_width>>2;
uint32 srow_pixels=((destrect.IntegerWidth()>=sourcerect.IntegerWidth())?src_width:destrect.IntegerWidth()+1)>>2;
uint8 *srow_index, *drow_index;
// This could later be optimized to use uint32's for faster copying
for (uint32 pos_y=0; pos_y!=lines; pos_y++)
{
srow_index=src_bits;
drow_index=dest_bits;
for(uint32 pos_x=0; pos_x!=srow_pixels;pos_x++)
{
// 32-bit RGBA32 mode byte order is BGRA
if(srow_index[3]>127)
{
*drow_index=*srow_index; drow_index++; srow_index++;
*drow_index=*srow_index; drow_index++; srow_index++;
*drow_index=*srow_index; drow_index++; srow_index++;
// we don't copy the alpha channel
drow_index++; srow_index++;
}
else
{
srow_index+=4;
drow_index+=4;
}
}
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
break;
}
default: // B_OP_COPY
{
for (uint32 pos_y = 0; pos_y != lines; pos_y++)
{
memcpy(dest_bits,src_bits,line_length);
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
break;
}
}
}
bool BitmapDriver::AcquireBuffer(FBBitmap *fbmp)
{
if(!fbmp)
return false;
fbmp->ServerBitmap::ShallowCopy(_target);
return true;
}
void BitmapDriver::ReleaseBuffer(void)
{
}
void BitmapDriver::Blit(const BRect &src, const BRect &dest, const DrawData *d)
{
}
void BitmapDriver::FillSolidRect(const BRect &rect, RGBColor &color)
{
}
void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d)
{
}
void BitmapDriver::StrokeSolidLine(const BPoint &start, const BPoint &end, RGBColor &color)
{
}
void BitmapDriver::StrokePatternLine(const BPoint &start, const BPoint &end, const DrawData *d)
{
}
void BitmapDriver::StrokeSolidRect(const BRect &rect, RGBColor &color)
{
}
void BitmapDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d)
{
}
void BitmapDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
{
if(!destbmp)
{
printf("CopyToBitmap returned - not init or NULL bitmap\n");
return;
}
if(((uint32)destbmp->ColorSpace() & 0x000F) != (_displaymode.space & 0x000F))
{
printf("CopyToBitmap returned - unequal buffer pixel depth\n");
return;
}
BRect destrect(destbmp->Bounds()), source(sourcerect);
uint8 colorspace_size=destbmp->BitsPerPixel()/8;
// First, clip source rect to destination
if(source.Width() > destrect.Width())
source.right=source.left+destrect.Width();
if(source.Height() > destrect.Height())
source.bottom=source.top+destrect.Height();
// Second, check rectangle bounds against their own bitmaps
BRect work_rect(destbmp->Bounds());
if( !(work_rect.Contains(destrect)) )
{
// something in selection must be clipped
if(destrect.left < 0)
destrect.left = 0;
if(destrect.right > work_rect.right)
destrect.right = work_rect.right;
if(destrect.top < 0)
destrect.top = 0;
if(destrect.bottom > work_rect.bottom)
destrect.bottom = work_rect.bottom;
}
work_rect.Set(0,0,_displaymode.virtual_width-1,_displaymode.virtual_height-1);
if(!work_rect.Contains(sourcerect))
return;
if( !(work_rect.Contains(source)) )
{
// something in selection must be clipped
if(source.left < 0)
source.left = 0;
if(source.right > work_rect.right)
source.right = work_rect.right;
if(source.top < 0)
source.top = 0;
if(source.bottom > work_rect.bottom)
source.bottom = work_rect.bottom;
}
// Set pointers to the actual data
uint8 *dest_bits = (uint8*) destbmp->Bits();
uint8 *src_bits = (uint8*) _target->Bits();
// Get row widths for offset looping
uint32 dest_width = uint32 (destbmp->BytesPerRow());
uint32 src_width = uint32 (_target->BytesPerRow());
// Offset bitmap pointers to proper spot in each bitmap
src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) );
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (source.bottom-source.top+1);
for (uint32 pos_y=0; pos_y<lines; pos_y++)
{
memcpy(dest_bits,src_bits,line_length);
// Increment offsets
src_bits += src_width;
dest_bits += dest_width;
}
}
+12 -1
View File
@@ -77,7 +77,18 @@ public:
virtual void SetMode(const display_mode &mode);
virtual void InvertRect(const BRect &rect);
protected:
void BlitBitmap(ServerBitmap *sourcebmp, BRect sourcerect, BRect destrect, drawing_mode mode=B_OP_COPY);
virtual bool AcquireBuffer(FBBitmap *bmp);
virtual void ReleaseBuffer(void);
virtual void Blit(const BRect &src, const BRect &dest, const DrawData *d);
virtual void FillSolidRect(const BRect &rect, RGBColor &color);
virtual void FillPatternRect(const BRect &rect, const DrawData *d);
virtual void StrokeSolidLine(const BPoint &start, const BPoint &end, RGBColor &color);
virtual void StrokePatternLine(const BPoint &start, const BPoint &end, const DrawData *d);
virtual void StrokeSolidRect(const BRect &rect, RGBColor &color);
virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d);
virtual void CopyToBitmap(ServerBitmap *target, const BRect &source);
void ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect);
rgb_color GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high=true);
void HLinePatternThick(int32 x1, int32 x2, int32 y);
+3 -3
View File
@@ -178,7 +178,7 @@ void Decorator::SetFont(ServerFont *font)
if(!font)
return;
_layerdata.font = *font;
_drawdata.font = *font;
}
/*!
@@ -307,7 +307,7 @@ int32 Decorator::_ClipTitle(float width)
if(_driver)
{
int32 strlength=_title_string->CountChars();
float pixwidth=_driver->StringWidth(_title_string->String(),strlength,&_layerdata);
float pixwidth=_driver->StringWidth(_title_string->String(),strlength,&_drawdata);
while(strlength>=0)
{
@@ -315,7 +315,7 @@ int32 Decorator::_ClipTitle(float width)
return strlength;
strlength--;
pixwidth=_driver->StringWidth(_title_string->String(),strlength,&_layerdata);
pixwidth=_driver->StringWidth(_title_string->String(),strlength,&_drawdata);
}
}
return 0;
+16 -43
View File
@@ -208,7 +208,7 @@ STRACE(("DefaultDecorator: Do Layout\n"));
if(strlen(GetTitle())>1)
{
if(_driver)
titlepixelwidth=_driver->StringWidth(GetTitle(),_TitleWidth(), &_layerdata);
titlepixelwidth=_driver->StringWidth(GetTitle(),_TitleWidth(), &_drawdata);
else
titlepixelwidth=10;
@@ -329,8 +329,8 @@ void DefaultDecorator::_DrawTitle(BRect r)
STRACE(("_DrawTitle(%f,%f,%f,%f)\n", r.left, r.top, r.right, r.bottom));
// Designed simply to redraw the title when it has changed on
// the client side.
_layerdata.highcolor=_colors->window_tab_text;
_layerdata.lowcolor=(GetFocus())?_colors->window_tab:_colors->inactive_window_tab;
_drawdata.highcolor=_colors->window_tab_text;
_drawdata.lowcolor=(GetFocus())?_colors->window_tab:_colors->inactive_window_tab;
int32 titlecount=_ClipTitle((_zoomrect.left-textoffset)-(_closerect.right+textoffset));
BString titlestr( GetTitle() );
@@ -346,10 +346,10 @@ void DefaultDecorator::_DrawTitle(BRect r)
// is a little different. If it isn't moved, title placement looks really funky
if(_look==B_FLOATING_WINDOW_LOOK)
_driver->DrawString(titlestr.String(),titlecount,
BPoint(_closerect.right+textoffset,_closerect.bottom+1),&_layerdata);
BPoint(_closerect.right+textoffset,_closerect.bottom+1),&_drawdata);
else
_driver->DrawString(titlestr.String(),titlecount,
BPoint(_closerect.right+textoffset,_closerect.bottom),&_layerdata);
BPoint(_closerect.right+textoffset,_closerect.bottom),&_drawdata);
}
void DefaultDecorator::_SetFocus(void)
@@ -452,34 +452,13 @@ void DefaultDecorator::DrawBlendedRect(BRect r, bool down)
{
// This bad boy is used to draw a rectangle with a gradient.
// Note that it is not part of the Decorator API - it's specific
// to just the DefaultDecorator. Called by DrawZoom and DrawClose
// to just the BeDecorator. Called by DrawZoom and DrawClose
RGBColor temprgbcol(175,123,0);
_driver->StrokeLine( r.LeftTop(),
BPoint( r.left, r.bottom - 1 ),
temprgbcol);
_driver->StrokeLine( r.LeftTop(),
BPoint( r.right - 1, r.top ),
temprgbcol);
_driver->StrokeLine( BPoint( r.right - 1, r.top + 2),
BPoint( r.right - 1, r.bottom - 1),
temprgbcol);
_driver->StrokeLine( BPoint( r.left + 2, r.bottom -1),
BPoint( r.right - 2, r.bottom - 1),
temprgbcol);
temprgbcol.SetColor(255,255,0);
_driver->StrokeRect( BRect( r.left + 1, r.top + 1,
r.right, r.bottom),
temprgbcol);
r.InsetBy( 2, 2 );
// Actually just draws a blended square
int32 w=r.IntegerWidth(), h=r.IntegerHeight();
RGBColor temprgbcol;
rgb_color halfcol, startcol, endcol;
// rgb_color tmpcol;
float rstep,gstep,bstep,i;
int steps=(w<h)?w:h;
@@ -503,11 +482,6 @@ void DefaultDecorator::DrawBlendedRect(BRect r, bool down)
for(i=0;i<=steps; i++)
{
/* SetRGBColor(&tmpcol, uint8(startcol.red-(i*rstep)),
uint8(startcol.green-(i*gstep)),
uint8(startcol.blue-(i*bstep)));
_layerdata.highcolor=tmpcol;
*/
temprgbcol.SetColor(uint8(startcol.red-(i*rstep)),
uint8(startcol.green-(i*gstep)),
uint8(startcol.blue-(i*bstep)));
@@ -515,11 +489,6 @@ void DefaultDecorator::DrawBlendedRect(BRect r, bool down)
_driver->StrokeLine(BPoint(r.left,r.top+i),
BPoint(r.left+i,r.top),temprgbcol);
/* SetRGBColor(&tmpcol, uint8(halfcol.red-(i*rstep)),
uint8(halfcol.green-(i*gstep)),
uint8(halfcol.blue-(i*bstep)));
_layerdata.highcolor=tmpcol;
*/
temprgbcol.SetColor(uint8(halfcol.red-(i*rstep)),
uint8(halfcol.green-(i*gstep)),
uint8(halfcol.blue-(i*bstep)));
@@ -527,6 +496,10 @@ void DefaultDecorator::DrawBlendedRect(BRect r, bool down)
_driver->StrokeLine(BPoint(r.left+steps,r.top+i),
BPoint(r.left+i,r.top+steps),temprgbcol);
}
// _layerdata.highcolor=startcol;
// _driver->FillRect(r,&_layerdata,pat_solidhigh);
_driver->StrokeRect(r,framecolors[3]);
}
void DefaultDecorator::_DrawFrame(BRect invalid)
@@ -537,8 +510,8 @@ STRACE(("_DrawFrame(%f,%f,%f,%f)\n", invalid.left, invalid.top,
// we must clip the lines drawn by this function to the invalid rectangle we are given
#ifdef USE_VIEW_FILL_HACK
_layerdata.highcolor = RGBColor( 192, 192, 192 );
_driver->FillRect(_frame,_layerdata.highcolor);
_drawdata.highcolor = RGBColor( 192, 192, 192 );
_driver->FillRect(_frame,_drawdata.highcolor);
#endif
if(_look == B_NO_BORDER_WINDOW_LOOK)
@@ -810,7 +783,7 @@ STRACE(("_DrawFrame(%f,%f,%f,%f)\n", invalid.left, invalid.top,
//do(draw) nothing!
}
else{
_driver->StrokeLineArray(points,numlines,&_layerdata,colors);
_driver->StrokeLineArray(points,numlines,&_drawdata,colors);
}
delete rightindices;
+175 -19
View File
@@ -31,6 +31,7 @@
#include "FontFamily.h"
#include <stdio.h>
#include "DisplayDriver.h"
#include "RectUtils.h"
#include "ServerCursor.h"
// TODO: Major cleanup is left. Public functions should be repsonsible for locking.
@@ -315,6 +316,16 @@ void DisplayDriver::DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect
{
}
void DisplayDriver::DrawString(const char *string, const int32 &length, const BPoint &pt, RGBColor &color, escapement_delta *delta)
{
DrawData d;
d.highcolor=color;
if(delta)
d.edelta=*delta;
DrawString(string,length,pt,&d);
}
/*!
\brief Utilizes the font engine to draw a string to the frame buffer
\param string String to be drawn. Always non-NULL.
@@ -482,16 +493,23 @@ void DisplayDriver::DrawString(const char *string, const int32 &length, const BP
void DisplayDriver::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawData *d)
{
/* rgb_color color=d->highcolor.GetColor32();
rgb_color color=d->highcolor.GetColor32();
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer, *destbuffer;
FBBitmap framebuffer;
if(!AcquireBuffer(&framebuffer))
{
printf("ERROR: Couldn't acquire framebuffer in BlitMono2RGB32\n");
return;
}
// index pointers which are incremented during the course of the blit
uint8 *srcindex, *destindex, *rowptr, value;
// increment values for the index pointers
int32 srcinc=src->pitch, destinc=framebuffer->BytesPerRow();
int32 srcinc=src->pitch, destinc=framebuffer.BytesPerRow();
int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows;
int32 x=(int32)pt.x,y=(int32)pt.y;
@@ -508,18 +526,18 @@ void DisplayDriver::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
destbuffer+=destinc * (0-y);
}
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
if(y+srcheight>framebuffer.Bounds().IntegerHeight())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
srcheight-=(y+srcheight-1)-framebuffer.Bounds().IntegerHeight();
}
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
if(x+srcwidth>framebuffer.Bounds().IntegerWidth())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
srcwidth-=(x+srcwidth-1)-framebuffer.Bounds().IntegerWidth();
}
if(x<0)
@@ -532,7 +550,7 @@ void DisplayDriver::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
}
// starting point in destination bitmap
destbuffer=(uint8*)framebuffer->Bits()+int32( (pt.y*framebuffer->BytesPerRow())+(pt.x*4) );
destbuffer=(uint8*)framebuffer.Bits()+int32( (pt.y*framebuffer.BytesPerRow())+(pt.x*4) );
srcindex=srcbuffer;
destindex=destbuffer;
@@ -562,13 +580,21 @@ void DisplayDriver::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
srcindex+=srcinc;
destindex+=destinc;
}
*/
Invalidate(BRect(0,0,srcwidth,srcheight));
ReleaseBuffer();
}
void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawData *d)
{
/* // pointers to the top left corner of the area to be copied in each bitmap
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer=NULL, *destbuffer=NULL;
FBBitmap framebuffer;
if(!AcquireBuffer(&framebuffer))
{
printf("Couldn't acquire framebuffer in DisplayDriver::BlitGray2RGB32");
return;
}
// index pointers which are incremented during the course of the blit
uint8 *srcindex=NULL, *destindex=NULL, *rowptr=NULL;
@@ -585,7 +611,7 @@ void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
y=(int32)pt.y,
srcinc=src->pitch,
// destinc=dest->BytesPerRow(),
destinc=framebuffer->BytesPerRow(),
destinc=framebuffer.BytesPerRow(),
srcwidth=src->width,
srcheight=src->rows,
incval=0;
@@ -596,8 +622,7 @@ void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
srcbuffer=(uint8*)src->buffer;
// starting point in destination bitmap
// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4));
destbuffer=(uint8*)framebuffer->Bits()+(y*framebuffer->BytesPerRow()+(x*4));
destbuffer=(uint8*)framebuffer.Bits()+(y*framebuffer.BytesPerRow()+(x*4));
if(y<0)
@@ -612,18 +637,18 @@ void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
destbuffer+=incval * destinc;
}
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
if(y+srcheight>framebuffer.Bounds().IntegerHeight())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
srcheight-=(y+srcheight-1)-framebuffer.Bounds().IntegerHeight();
}
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
if(x+srcwidth>framebuffer.Bounds().IntegerWidth())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
srcwidth-=(x+srcwidth-1)-framebuffer.Bounds().IntegerWidth();
}
if(x<0)
@@ -677,7 +702,8 @@ void DisplayDriver::BlitGray2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawD
srcindex+=srcinc;
destindex+=destinc;
}
*/
Invalidate(BRect(0,0,srcwidth,srcheight));
ReleaseBuffer();
}
bool DisplayDriver::AcquireBuffer(FBBitmap *bmp)
@@ -689,6 +715,10 @@ void DisplayDriver::ReleaseBuffer(void)
{
}
void DisplayDriver::Invalidate(const BRect &r)
{
}
void DisplayDriver::FillArc(const BRect &r, const float &angle, const float &span, RGBColor &color)
{
}
@@ -1679,6 +1709,12 @@ void DisplayDriver::InvertRect(const BRect &r)
*/
void DisplayDriver::ShowCursor(void)
{
if(!_cursor)
{
printf("ERROR: Call to ShowCursor and driver has no defined cursor\n");
return;
}
Lock();
_is_cursor_hidden=false;
@@ -2359,7 +2395,72 @@ ServerBitmap *DisplayDriver::DumpToBitmap(void)
*/
float DisplayDriver::StringWidth(const char *string, int32 length, const DrawData *d)
{
return 0.0;
if(!string || !d)
return 0.0;
Lock();
const ServerFont *font=&(d->font);
FontStyle *style=font->Style();
if(!style)
return 0.0;
FT_Face face;
FT_GlyphSlot slot;
FT_UInt glyph_index=0, previous=0;
FT_Vector pen,delta;
int16 error=0;
int32 strlength,i;
float returnval;
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
if(error)
{
Unlock();
return 0.0;
}
slot=face->glyph;
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
if(error)
{
Unlock();
return 0.0;
}
// set the pen position in 26.6 cartesian space coordinates
pen.x=0;
slot=face->glyph;
strlength=strlen(string);
if(length<strlength)
strlength=length;
for(i=0;i<strlength;i++)
{
// get kerning and move pen
if(use_kerning && previous && glyph_index)
{
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
pen.x+=delta.x;
}
error=FT_Load_Char(face,string[i],FT_LOAD_MONOCHROME);
// increment pen position
pen.x+=slot->advance.x;
previous=glyph_index;
}
FT_Done_Face(face);
Unlock();
returnval=pen.x>>6;
return returnval;
}
/*!
@@ -2376,7 +2477,61 @@ float DisplayDriver::StringWidth(const char *string, int32 length, const DrawDat
*/
float DisplayDriver::StringHeight(const char *string, int32 length, const DrawData *d)
{
return 0.0;
if(!string || !d)
return 0.0;
Lock();
const ServerFont *font=&(d->font);
FontStyle *style=font->Style();
if(!style)
{
Unlock();
return 0.0;
}
FT_Face face;
FT_GlyphSlot slot;
int16 error=0;
int32 strlength,i;
float returnval=0.0,ascent=0.0,descent=0.0;
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
if(error)
{
Unlock();
return 0.0;
}
slot=face->glyph;
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
if(error)
{
Unlock();
return 0.0;
}
slot=face->glyph;
strlength=strlen(string);
if(length<strlength)
strlength=length;
for(i=0;i<strlength;i++)
{
FT_Load_Char(face,string[i],FT_LOAD_RENDER);
if(slot->metrics.horiBearingY<slot->metrics.height)
descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent);
else
ascent=MAX(slot->bitmap.rows,ascent);
}
FT_Done_Face(face);
Unlock();
returnval=ascent+descent;
return returnval;
}
/*!
@@ -2710,6 +2865,7 @@ void DisplayDriver::HLinePatternThick(int32 x1, int32 x2, int32 y)
void DisplayDriver::VLinePatternThick(int32 x1, int32 x2, int32 y)
{
}
/*
void DisplayDriver::FillSolidRect(int32 left, int32 top, int32 right, int32 bottom)
{
+49 -567
View File
@@ -416,78 +416,7 @@ void VDWindow::MessageReceived(BMessage *msg)
view->serverlink->Flush();
break;
}
/* case VDWIN_SHOWCURSOR:
{
if(view->hide_cursor>0)
view->hide_cursor--;
if(view->hide_cursor==0)
view->Invalidate(view->cursorframe);
break;
}
case VDWIN_HIDECURSOR:
{
view->hide_cursor++;
if(view->hide_cursor==1)
view->Invalidate(view->cursorframe);
break;
}
case VDWIN_OBSCURECURSOR:
{
view->obscure_cursor=true;
view->Invalidate(view->cursorframe);
break;
}
case VDWIN_MOVECURSOR:
{
float x,y;
msg->FindFloat("x",&x);
msg->FindFloat("y",&y);
// this was changed because an extra message was
// sent even though the mouse was never moved
if(view->cursorframe.left!=x || view->cursorframe.top!=y)
{
if(view->obscure_cursor)
view->obscure_cursor=false;
view->oldcursorframe=view->cursorframe;
view->cursorframe.OffsetTo(x,y);
}
if(view->hide_cursor==0)
view->Invalidate(view->oldcursorframe);
break;
}
case VDWIN_SETCURSOR:
{
ServerBitmap *cdata;
msg->FindPointer("SCursor",(void**)&cdata);
if(cdata!=NULL)
{
BBitmap *bmp=new BBitmap(cdata->Bounds(), B_RGBA32);
// Copy the server bitmap in the cursor to a BBitmap
uint8 *sbmppos=(uint8*)cdata->Bits(),
*bbmppos=(uint8*)bmp->Bits();
int32 bytes=cdata->BytesPerRow(),
bbytes=bmp->BytesPerRow();
for(int i=0;i<cdata->Bounds().IntegerHeight();i++)
memcpy(bbmppos+(i*bbytes), sbmppos+(i*bytes), bytes);
// Replace the bitmap
delete view->cursor;
view->cursor=bmp;
view->Invalidate(view->cursorframe);
break;
}
break;
}
*/ default:
default:
BWindow::MessageReceived(msg);
break;
}
@@ -940,487 +869,6 @@ void ViewDriver::SetDrawData(const DrawData *d, bool set_font_data)
framebuffer->Unlock();
}
/*
float ViewDriver::StringWidth(const char *string, int32 length, DrawData *d)
{
if(!string || !d || !is_initialized)
return 0.0;
screenwin->Lock();
ServerFont *font=&(d->font);
FontStyle *style=font->Style();
if(!style)
return 0.0;
FT_Face face;
FT_GlyphSlot slot;
FT_UInt glyph_index=0, previous=0;
FT_Vector pen,delta;
int16 error=0;
int32 strlength,i;
float returnval;
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
if(error)
{
screenwin->Unlock();
return 0.0;
}
slot=face->glyph;
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
if(error)
{
screenwin->Unlock();
return 0.0;
}
// set the pen position in 26.6 cartesian space coordinates
pen.x=0;
slot=face->glyph;
strlength=strlen(string);
if(length<strlength)
strlength=length;
for(i=0;i<strlength;i++)
{
// get kerning and move pen
if(use_kerning && previous && glyph_index)
{
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
pen.x+=delta.x;
}
error=FT_Load_Char(face,string[i],FT_LOAD_MONOCHROME);
// increment pen position
pen.x+=slot->advance.x;
previous=glyph_index;
}
screenwin->Unlock();
FT_Done_Face(face);
returnval=pen.x>>6;
return returnval;
}
float ViewDriver::StringHeight(const char *string, int32 length, DrawData *d)
{
if(!string || !d || !is_initialized)
return 0.0;
screenwin->Lock();
ServerFont *font=&(d->font);
FontStyle *style=font->Style();
if(!style)
{
screenwin->Unlock();
return 0.0;
}
FT_Face face;
FT_GlyphSlot slot;
int16 error=0;
int32 strlength,i;
float returnval=0.0,ascent=0.0,descent=0.0;
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
if(error)
return 0.0;
slot=face->glyph;
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
if(error)
{
screenwin->Unlock();
return 0.0;
}
slot=face->glyph;
strlength=strlen(string);
if(length<strlength)
strlength=length;
for(i=0;i<strlength;i++)
{
FT_Load_Char(face,string[i],FT_LOAD_RENDER);
if(slot->metrics.horiBearingY<slot->metrics.height)
descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent);
else
ascent=MAX(slot->bitmap.rows,ascent);
}
screenwin->Unlock();
FT_Done_Face(face);
returnval=ascent+descent;
return returnval;
}
*/
/*
void ViewDriver::DrawString(const char *string, int32 length, BPoint pt, DrawData *d, escapement_delta *edelta)
{
if(!is_initialized)
return;
if(!string || !d )
return;
screenwin->Lock();
pt.y--; // because of Be's backward compatibility hack
ServerFont *font=&(d->font);
FontStyle *style=font->Style();
if(!style)
return;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix rmatrix,smatrix;
FT_UInt glyph_index=0, previous=0;
FT_Vector pen,delta,space,nonspace;
int16 error=0;
int32 strlength,i;
Angle rotation(font->Rotation()), shear(font->Shear());
// bool antialias=( (font->Size()<18 && font->Flags()& B_DISABLE_ANTIALIASING==0)
// || font->Flags()& B_FORCE_ANTIALIASING)?true:false;
bool antialias=(font->Flags()& B_DISABLE_ANTIALIASING==1)?false:true;
// Originally, I thought to do this shear checking here, but it really should be
// done in BFont::SetShear()
float shearangle=shear.Value();
if(shearangle>135)
shearangle=135;
if(shearangle<45)
shearangle=45;
if(shearangle>90)
shear=90+((180-shearangle)*2);
else
shear=90-(90-shearangle)*2;
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
if(error)
return;
slot=face->glyph;
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
if(error)
return;
// if we do any transformation, we do a call to FT_Set_Transform() here
// First, rotate
rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000);
rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000);
rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000);
rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000);
// Next, shear
smatrix.xx = (FT_Fixed)(0x10000);
smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000);
smatrix.yx = (FT_Fixed)(0);
smatrix.yy = (FT_Fixed)(0x10000);
FT_Matrix_Multiply(&rmatrix,&smatrix);
// Set up the increment value for escapement padding
space.x=int32(d->edelta.space * rotation.Cosine()*64);
space.y=int32(d->edelta.space * rotation.Sine()*64);
nonspace.x=int32(d->edelta.nonspace * rotation.Cosine()*64);
nonspace.y=int32(d->edelta.nonspace * rotation.Sine()*64);
// set the pen position in 26.6 cartesian space coordinates
pen.x=(int32)pt.x * 64;
pen.y=(int32)pt.y * 64;
slot=face->glyph;
strlength=strlen(string);
if(length<strlength)
strlength=length;
for(i=0;i<strlength;i++)
{
FT_Set_Transform(face,&smatrix,&pen);
// Handle escapement padding option
if((uint8)string[i]<=0x20)
{
pen.x+=space.x;
pen.y+=space.y;
}
else
{
pen.x+=nonspace.x;
pen.y+=nonspace.y;
}
// get kerning and move pen
if(use_kerning && previous && glyph_index)
{
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
pen.x+=delta.x;
pen.y+=delta.y;
}
error=FT_Load_Char(face,string[i],
((antialias)?FT_LOAD_RENDER:FT_LOAD_RENDER | FT_LOAD_MONOCHROME) );
if(!error)
{
if(antialias)
BlitGray2RGB32(&slot->bitmap,
BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d);
else
BlitMono2RGB32(&slot->bitmap,
BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d);
}
// increment pen position
pen.x+=slot->advance.x;
pen.y+=slot->advance.y;
previous=glyph_index;
}
// TODO: implement properly
// calculate the invalid rectangle
BRect r;
r.left=MIN(pt.x,pen.x>>6);
r.right=MAX(pt.x,pen.x>>6);
r.top=pt.y-face->height;
r.bottom=pt.y+face->height;
screenwin->view->Invalidate(r);
screenwin->Unlock();
FT_Done_Face(face);
}
*/
void ViewDriver::BlitMono2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d)
{
if(!is_initialized)
return;
rgb_color color=d->highcolor.GetColor32();
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer, *destbuffer;
// index pointers which are incremented during the course of the blit
uint8 *srcindex, *destindex, *rowptr, value;
// increment values for the index pointers
int32 srcinc=src->pitch, destinc=framebuffer->BytesPerRow();
int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows;
int32 x=(int32)pt.x,y=(int32)pt.y;
// starting point in source bitmap
srcbuffer=(uint8*)src->buffer;
if(y<0)
{
if(y<pt.y)
y++;
srcbuffer+=srcinc * (0-y);
srcheight-=srcinc;
destbuffer+=destinc * (0-y);
}
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
}
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
}
if(x<0)
{
if(x<pt.x)
x++;
srcbuffer+=(0-x)>>3;
srcwidth-=0-x;
destbuffer+=(0-x)*4;
}
// starting point in destination bitmap
destbuffer=(uint8*)framebuffer->Bits()+int32( (pt.y*framebuffer->BytesPerRow())+(pt.x*4) );
srcindex=srcbuffer;
destindex=destbuffer;
for(i=0; i<srcheight; i++)
{
rowptr=destindex;
for(j=0;j<srcwidth;j++)
{
for(k=0; k<8; k++)
{
value=*(srcindex+j) & (1 << (7-k));
if(value)
{
rowptr[0]=color.blue;
rowptr[1]=color.green;
rowptr[2]=color.red;
rowptr[3]=color.alpha;
}
rowptr+=4;
}
}
srcindex+=srcinc;
destindex+=destinc;
}
}
void ViewDriver::BlitGray2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d)
{
if(!is_initialized)
return;
// pointers to the top left corner of the area to be copied in each bitmap
uint8 *srcbuffer=NULL, *destbuffer=NULL;
// index pointers which are incremented during the course of the blit
uint8 *srcindex=NULL, *destindex=NULL, *rowptr=NULL;
rgb_color highcolor=d->highcolor.GetColor32(), lowcolor=d->lowcolor.GetColor32(); float rstep,gstep,bstep,astep;
rstep=float(highcolor.red-lowcolor.red)/255.0;
gstep=float(highcolor.green-lowcolor.green)/255.0;
bstep=float(highcolor.blue-lowcolor.blue)/255.0;
astep=float(highcolor.alpha-lowcolor.alpha)/255.0;
// increment values for the index pointers
int32 x=(int32)pt.x,
y=(int32)pt.y,
srcinc=src->pitch,
// destinc=dest->BytesPerRow(),
destinc=framebuffer->BytesPerRow(),
srcwidth=src->width,
srcheight=src->rows,
incval=0;
int16 i,j;
// starting point in source bitmap
srcbuffer=(uint8*)src->buffer;
// starting point in destination bitmap
// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4));
destbuffer=(uint8*)framebuffer->Bits()+(y*framebuffer->BytesPerRow()+(x*4));
if(y<0)
{
if(y<pt.y)
y++;
incval=0-y;
srcbuffer+=incval * srcinc;
srcheight-=incval;
destbuffer+=incval * destinc;
}
if(y+srcheight>framebuffer->Bounds().IntegerHeight())
{
if(y>pt.y)
y--;
srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight();
}
if(x+srcwidth>framebuffer->Bounds().IntegerWidth())
{
if(x>pt.x)
x--;
srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth();
}
if(x<0)
{
if(x<pt.x)
x++;
incval=0-x;
srcbuffer+=incval;
srcwidth-=incval;
destbuffer+=incval*4;
}
int32 value;
srcindex=srcbuffer;
destindex=destbuffer;
for(i=0; i<srcheight; i++)
{
rowptr=destindex;
for(j=0;j<srcwidth;j++)
{
value=*(srcindex+j) ^ 255;
if(value!=255)
{
if(d->draw_mode==B_OP_COPY)
{
rowptr[0]=uint8(highcolor.blue-(value*bstep));
rowptr[1]=uint8(highcolor.green-(value*gstep));
rowptr[2]=uint8(highcolor.red-(value*rstep));
rowptr[3]=255;
}
else
if(d->draw_mode==B_OP_OVER)
{
if(highcolor.alpha>127)
{
rowptr[0]=uint8(highcolor.blue-(value*(float(highcolor.blue-rowptr[0])/255.0)));
rowptr[1]=uint8(highcolor.green-(value*(float(highcolor.green-rowptr[1])/255.0)));
rowptr[2]=uint8(highcolor.red-(value*(float(highcolor.red-rowptr[2])/255.0)));
rowptr[3]=255;
}
}
}
rowptr+=4;
}
srcindex+=srcinc;
destindex+=destinc;
}
}
rgb_color ViewDriver::GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high)
{
rgb_color returncolor={0,0,0,0};
@@ -1701,9 +1149,6 @@ void ViewDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRe
void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
{
// TODO: BUG: CRASH: There is a crash on memcpy whenever the cursor is saved and it
// is clipped to the bottom edge of the screen.
if(!is_initialized || !destbmp)
{
printf("CopyToBitmap returned - not init or NULL bitmap\n");
@@ -1729,14 +1174,11 @@ void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
// Second, check rectangle bounds against their own bitmaps
BRect work_rect;
work_rect.Set( destbmp->Bounds().left,
destbmp->Bounds().top,
destbmp->Bounds().right,
destbmp->Bounds().bottom );
BRect work_rect(destbmp->Bounds());
if( !(work_rect.Contains(destrect)) )
{ // something in selection must be clipped
{
// something in selection must be clipped
if(destrect.left < 0)
destrect.left = 0;
if(destrect.right > work_rect.right)
@@ -1749,8 +1191,12 @@ void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
work_rect.Set(0,0,_displaymode.virtual_width-1,_displaymode.virtual_height-1);
if(!work_rect.Contains(sourcerect))
return;
if( !(work_rect.Contains(source)) )
{ // something in selection must be clipped
{
// something in selection must be clipped
if(source.left < 0)
source.left = 0;
if(source.right > work_rect.right)
@@ -1772,10 +1218,11 @@ void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
// Offset bitmap pointers to proper spot in each bitmap
src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) );
dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) );
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (destrect.bottom-destrect.top+1);
uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size);
uint32 lines = uint32 (source.bottom-source.top+1);
for (uint32 pos_y=0; pos_y<lines; pos_y++)
{
memcpy(dest_bits,src_bits,line_length);
@@ -1786,3 +1233,38 @@ void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect)
}
}
bool ViewDriver::AcquireBuffer(FBBitmap *fbmp)
{
if(!fbmp || !is_initialized)
return false;
screenwin->Lock();
framebuffer->Lock();
fbmp->SetBytesPerRow(framebuffer->BytesPerRow());
fbmp->SetSpace(framebuffer->ColorSpace());
fbmp->SetSize(framebuffer->Bounds().IntegerWidth(), framebuffer->Bounds().IntegerHeight());
fbmp->SetBuffer(framebuffer->Bits());
fbmp->SetBitsPerPixel(framebuffer->ColorSpace(),framebuffer->BytesPerRow());
return true;
}
void ViewDriver::ReleaseBuffer(void)
{
if(!is_initialized)
return;
framebuffer->Unlock();
screenwin->Unlock();
}
void ViewDriver::Invalidate(const BRect &r)
{
if(!is_initialized)
return;
screenwin->Lock();
screenwin->view->Invalidate();
screenwin->Unlock();
}
+6 -2
View File
@@ -138,8 +138,12 @@ protected:
void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d);
void CopyToBitmap(ServerBitmap *target, const BRect &source);
void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
bool AcquireBuffer(FBBitmap *fbmp);
void ReleaseBuffer(void);
void Invalidate(const BRect &r);
// void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
// void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d);
rgb_color GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high=true);
int hide_cursor;
bool obscure_cursor;