removed unused stuff from Painter and DrawingEngine, fixed the deadlock when trying to use the (20 times faster) DrawingEngine version of StringWidth, the font is now usually ignored when taking on a DrawState in Painter... should add a little speed overall

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15628 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-12-20 22:39:54 +00:00
parent bee1ec1ee0
commit 1f0a4ee8c7
5 changed files with 70 additions and 146 deletions
+2 -1
View File
@@ -99,7 +99,8 @@ public:
void FillRect(BRect r, const DrawState *d); void FillRect(BRect r, const DrawState *d);
// for debugging purposes? // for debugging purposes?
void StrokeRegion(BRegion &r, const DrawState *d); // void StrokeRegion(BRegion &r, const DrawState *d);
void FillRegion(BRegion &r, const DrawState *d); void FillRegion(BRegion &r, const DrawState *d);
void FillRegion(BRegion &r, const RGBColor& color); void FillRegion(BRegion &r, const RGBColor& color);
+2 -2
View File
@@ -1350,13 +1350,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
if (!stringArray[i] || lengthArray[i] <= 0) if (!stringArray[i] || lengthArray[i] <= 0)
widthArray[i] = 0.0; widthArray[i] = 0.0;
else { else {
//widthArray[i] = fDesktop->GetDrawingEngine()->StringWidth(stringArray[i], lengthArray[i], font); widthArray[i] = fDesktop->GetDrawingEngine()->StringWidth(stringArray[i], lengthArray[i], font);
// NOTE: The line below will return the exact same thing. However, // NOTE: The line below will return the exact same thing. However,
// the line above uses the AGG rendering backend, for which glyph caching // the line above uses the AGG rendering backend, for which glyph caching
// actually works. It is about 20 times faster! // actually works. It is about 20 times faster!
// TODO: I've disabled the AGG version for now, as it produces a dead lock // TODO: I've disabled the AGG version for now, as it produces a dead lock
// (font use), that I am currently too lazy to investigate... // (font use), that I am currently too lazy to investigate...
widthArray[i] = font.StringWidth(stringArray[i], lengthArray[i]); // widthArray[i] = font.StringWidth(stringArray[i], lengthArray[i]);
} }
} }
+34 -18
View File
@@ -127,6 +127,7 @@ DrawingEngine::SetHWInterface(HWInterface* interface)
fGraphicsCard = interface; fGraphicsCard = interface;
} }
// #pragma mark -
void void
DrawingEngine::ConstrainClippingRegion(const BRegion* region) DrawingEngine::ConstrainClippingRegion(const BRegion* region)
@@ -672,7 +673,7 @@ DrawingEngine::FillRect(BRect r, const DrawState *d)
WriteUnlock(); WriteUnlock();
} }
} }
/*
// StrokeRegion // StrokeRegion
void void
DrawingEngine::StrokeRegion(BRegion& r, const DrawState *d) DrawingEngine::StrokeRegion(BRegion& r, const DrawState *d)
@@ -700,7 +701,7 @@ DrawingEngine::StrokeRegion(BRegion& r, const DrawState *d)
Unlock(); Unlock();
} }
} }
*/
// FillRegion // FillRegion
void void
DrawingEngine::FillRegion(BRegion& r, const DrawState *d) DrawingEngine::FillRegion(BRegion& r, const DrawState *d)
@@ -757,10 +758,6 @@ DrawingEngine::FillRegion(BRegion& r, const RGBColor& color)
// NOTE: Write locking because we might use HW acceleration. // NOTE: Write locking because we might use HW acceleration.
// This needs to be investigated, I'm doing this because of // This needs to be investigated, I'm doing this because of
// gut feeling. // gut feeling.
// NOTE: this is used for internal app_server use and the
// region is expected to already be intersected with the
// current clipping... it would matter only if we can
// use hardware acceleration
if (WriteLock()) { if (WriteLock()) {
BRect clipped = fPainter->ClipRect(r.Frame()); BRect clipped = fPainter->ClipRect(r.Frame());
if (clipped.IsValid()) { if (clipped.IsValid()) {
@@ -769,6 +766,8 @@ DrawingEngine::FillRegion(BRegion& r, const RGBColor& color)
bool doInSoftware = true; bool doInSoftware = true;
// try hardware optimized version first // try hardware optimized version first
if ((fAvailableHWAccleration & HW_ACC_FILL_REGION) != 0) { if ((fAvailableHWAccleration & HW_ACC_FILL_REGION) != 0) {
// NOTE: region expected to be already clipped correctly
// r.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(r, color); fGraphicsCard->FillRegion(r, color);
doInSoftware = false; doInSoftware = false;
} }
@@ -980,6 +979,8 @@ DrawingEngine::StrokePoint(const BPoint& pt, DrawState *context)
StrokeLine(pt, pt, context); StrokeLine(pt, pt, context);
} }
// #pragma mark -
/* /*
// DrawString // DrawString
void void
@@ -1003,7 +1004,7 @@ DrawingEngine::DrawString(const char* string, int32 length,
BPoint penLocation = pt; BPoint penLocation = pt;
if (Lock()) { if (Lock()) {
FontLocker locker(d); FontLocker locker(d);
fPainter->SetDrawState(d); fPainter->SetDrawState(d, true);
//bigtime_t now = system_time(); //bigtime_t now = system_time();
// TODO: BoundingBox is quite slow!! Optimizing it will be beneficial. // TODO: BoundingBox is quite slow!! Optimizing it will be beneficial.
// Cursiously, the DrawString after it is actually faster!?! // Cursiously, the DrawString after it is actually faster!?!
@@ -1038,12 +1039,17 @@ DrawingEngine::StringWidth(const char* string, int32 length,
{ {
// TODO: use delta // TODO: use delta
float width = 0.0; float width = 0.0;
if (Lock()) { // if (Lock()) {
// NOTE: For now it is enough to block on the
// font style lock, this already prevents multiple
// threads from executing this code and avoids a
// deadlock in case another thread holds the font
// lock already and then tries to lock the drawing
// engine after it is already locked here (race condition)
FontLocker locker(d); FontLocker locker(d);
fPainter->SetDrawState(d); width = fPainter->StringWidth(string, length, d);
width = fPainter->StringWidth(string, length); // Unlock();
Unlock(); // }
}
return width; return width;
} }
@@ -1052,11 +1058,10 @@ float
DrawingEngine::StringWidth(const char* string, int32 length, DrawingEngine::StringWidth(const char* string, int32 length,
const ServerFont& font, escapement_delta* delta) const ServerFont& font, escapement_delta* delta)
{ {
// TODO: use delta
FontLocker locker(&font); FontLocker locker(&font);
static DrawState d; static DrawState d;
d.SetFont(font); d.SetFont(font);
return StringWidth(string, length, &d); return StringWidth(string, length, &d, delta);
} }
// StringHeight // StringHeight
@@ -1065,17 +1070,25 @@ DrawingEngine::StringHeight(const char *string, int32 length,
const DrawState *d) const DrawState *d)
{ {
float height = 0.0; float height = 0.0;
if (Lock()) { // if (Lock()) {
// NOTE: For now it is enough to block on the
// font style lock, this already prevents multiple
// threads from executing this code and avoids a
// deadlock in case another thread holds the font
// lock already and then tries to lock the drawing
// engine after it is already locked here (race condition)
FontLocker locker(d); FontLocker locker(d);
fPainter->SetDrawState(d); fPainter->SetDrawState(d, true);
static BPoint dummy1(0.0, 0.0); static BPoint dummy1(0.0, 0.0);
static BPoint dummy2(0.0, 0.0); static BPoint dummy2(0.0, 0.0);
height = fPainter->BoundingBox(string, length, dummy1, &dummy2).Height(); height = fPainter->BoundingBox(string, length, dummy1, &dummy2).Height();
Unlock(); // Unlock();
} // }
return height; return height;
} }
// #pragma mark -
// Lock // Lock
bool bool
DrawingEngine::Lock() DrawingEngine::Lock()
@@ -1104,6 +1117,8 @@ DrawingEngine::WriteUnlock()
fGraphicsCard->WriteUnlock(); fGraphicsCard->WriteUnlock();
} }
// #pragma mark -
// DumpToFile // DumpToFile
bool bool
DrawingEngine::DumpToFile(const char *path) DrawingEngine::DumpToFile(const char *path)
@@ -1130,6 +1145,7 @@ DrawingEngine::DumpToBitmap()
return NULL; return NULL;
} }
// #pragma mark -
BRect BRect
DrawingEngine::_CopyRect(BRect src, int32 xOffset, int32 yOffset) const DrawingEngine::_CopyRect(BRect src, int32 xOffset, int32 yOffset) const
+21 -98
View File
@@ -168,7 +168,7 @@ Painter::DetachFromBuffer()
// SetDrawState // SetDrawState
void void
Painter::SetDrawState(const DrawState* data) Painter::SetDrawState(const DrawState* data, bool updateFont)
{ {
// NOTE: The custom clipping in "data" is ignored, because it has already been // NOTE: The custom clipping in "data" is ignored, because it has already been
// taken into account elsewhere // taken into account elsewhere
@@ -177,7 +177,10 @@ Painter::SetDrawState(const DrawState* data)
// but for now... // but for now...
SetPenSize(data->PenSize()); SetPenSize(data->PenSize());
SetPenLocation(data->PenLocation()); SetPenLocation(data->PenLocation());
SetFont(data->Font());
if (updateFont)
SetFont(data->Font());
fTextRenderer->SetAntialiasing(!(data->ForceFontAliasing() || data->Font().Flags() & B_DISABLE_ANTIALIASING)); fTextRenderer->SetAntialiasing(!(data->ForceFontAliasing() || data->Font().Flags() & B_DISABLE_ANTIALIASING));
fSubpixelPrecise = data->SubPixelPrecise(); fSubpixelPrecise = data->SubPixelPrecise();
@@ -246,28 +249,6 @@ Painter::SetPenSize(float size)
} }
} }
// SetDrawingMode
void
Painter::SetDrawingMode(drawing_mode mode)
{
if (fDrawingMode != mode) {
fDrawingMode = mode;
_UpdateDrawingMode();
}
}
// SetBlendingMode
void
Painter::SetBlendingMode(source_alpha alphaSrcMode, alpha_function alphaFncMode)
{
if (fAlphaSrcMode != alphaSrcMode || fAlphaFncMode != alphaFncMode) {
fAlphaSrcMode = alphaSrcMode;
fAlphaFncMode = alphaFncMode;
if (fDrawingMode == B_OP_ALPHA)
_UpdateDrawingMode();
}
}
// SetPattern // SetPattern
void void
Painter::SetPattern(const pattern& p) Painter::SetPattern(const pattern& p)
@@ -299,15 +280,6 @@ Painter::SetFont(const ServerFont& font)
BRect BRect
Painter::StrokeLine(BPoint a, BPoint b, DrawState* context) Painter::StrokeLine(BPoint a, BPoint b, DrawState* context)
{ {
// this happens independent of wether we actually draw something
context->SetPenLocation(b);
// NOTE: penlocation should be converted to the local
// coordinate of the view for which we draw here, after
// we have been used. Updating it could also be done somewhere
// else in the app_server code, but DrawString() needs to
// do this as well, and it is probably hard to calculate
// the correct location outside of AGGTextRenderer...
CHECK_CLIPPING CHECK_CLIPPING
// "false" means not to do the pixel center offset, // "false" means not to do the pixel center offset,
@@ -331,11 +303,6 @@ Painter::StrokeLine(BPoint a, BPoint b, DrawState* context)
return touched; return touched;
} }
// SetHighColor(context->highcolor.GetColor32());
// SetLowColor(context->lowcolor.GetColor32());
// SetDrawingMode(context->draw_mode);
// SetBlendingMode(context->alphaSrcMode, context->alphaFncMode);
// fPatternHandler->SetPattern(context->patt);
SetDrawState(context); SetDrawState(context);
// first, try an optimized version // first, try an optimized version
@@ -912,34 +879,6 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius,
// #pragma mark - // #pragma mark -
// DrawChar
BRect
Painter::DrawChar(char aChar)
{
// TODO: to be moved elsewhere
return DrawChar(aChar, fPenLocation);
}
// DrawChar
BRect
Painter::DrawChar(char aChar, BPoint baseLine)
{
// TODO: to be moved elsewhere
char wrapper[2];
wrapper[0] = aChar;
wrapper[1] = 0;
return DrawString(wrapper, 1, baseLine);
}
// DrawString
BRect
Painter::DrawString(const char* utf8String, uint32 length,
const escapement_delta* delta)
{
// TODO: to be moved elsewhere
return DrawString(utf8String, length, fPenLocation, delta);
}
// DrawString // DrawString
BRect BRect
Painter::DrawString(const char* utf8String, uint32 length, Painter::DrawString(const char* utf8String, uint32 length,
@@ -965,21 +904,27 @@ Painter::DrawString(const char* utf8String, uint32 length,
return _Clipped(bounds); return _Clipped(bounds);
} }
// DrawString // BoundingBox
BRect BRect
Painter::DrawString(const char* utf8String, const escapement_delta* delta) Painter::BoundingBox(const char* utf8String, uint32 length,
const BPoint& baseLine, BPoint* penLocation,
const escapement_delta* delta) const
{ {
// TODO: to be moved elsewhere static BRect dummy;
return DrawString(utf8String, strlen(utf8String), fPenLocation, delta); return fTextRenderer->RenderString(utf8String,
length,
fFontRendererSolid,
fFontRendererBin,
baseLine, dummy, true, penLocation,
delta);
} }
// DrawString // StringWidth
BRect float
Painter::DrawString(const char* utf8String, BPoint baseLine, Painter::StringWidth(const char* utf8String, uint32 length, const DrawState* context)
const escapement_delta* delta)
{ {
// TODO: to be moved elsewhere SetFont(context->Font());
return DrawString(utf8String, strlen(utf8String), baseLine, delta); return fTextRenderer->StringWidth(utf8String, length);
} }
// #pragma mark - // #pragma mark -
@@ -1043,28 +988,6 @@ Painter::InvertRect(const BRect& r) const
return _Clipped(r); return _Clipped(r);
} }
// BoundingBox
BRect
Painter::BoundingBox(const char* utf8String, uint32 length,
const BPoint& baseLine, BPoint* penLocation,
const escapement_delta* delta) const
{
static BRect dummy;
return fTextRenderer->RenderString(utf8String,
length,
fFontRendererSolid,
fFontRendererBin,
baseLine, dummy, true, penLocation,
delta);
}
// StringWidth
float
Painter::StringWidth(const char* utf8String, uint32 length) const
{
return fTextRenderer->StringWidth(utf8String, length);
}
// #pragma mark - // #pragma mark -
// _MakeEmpty // _MakeEmpty
+11 -27
View File
@@ -61,7 +61,8 @@ class Painter {
const BRegion* ClippingRegion() const const BRegion* ClippingRegion() const
{ return fClippingRegion; } { return fClippingRegion; }
void SetDrawState(const DrawState* data); void SetDrawState(const DrawState* data,
bool updateFont = false);
// object settings // object settings
void SetHighColor(const rgb_color& color); void SetHighColor(const rgb_color& color);
@@ -74,9 +75,6 @@ class Painter {
{ SetLowColor(color.GetColor32()); } { SetLowColor(color.GetColor32()); }
void SetPenSize(float size); void SetPenSize(float size);
void SetDrawingMode(drawing_mode mode);
void SetBlendingMode(source_alpha alphaSrcMode,
alpha_function alphaFncMode);
void SetPattern(const pattern& p); void SetPattern(const pattern& p);
void SetPenLocation(const BPoint& location); void SetPenLocation(const BPoint& location);
@@ -175,26 +173,21 @@ class Painter {
float span) const; float span) const;
// strings // strings
BRect DrawChar( char aChar);
BRect DrawChar( char aChar,
BPoint baseLine);
BRect DrawString( const char* utf8String,
uint32 length,
const escapement_delta* delta = NULL);
BRect DrawString( const char* utf8String, BRect DrawString( const char* utf8String,
uint32 length, uint32 length,
BPoint baseLine, BPoint baseLine,
const escapement_delta* delta = NULL); const escapement_delta* delta = NULL);
BRect DrawString( const char* utf8String, BRect BoundingBox( const char* utf8String,
const escapement_delta* delta = NULL); uint32 length,
const BPoint& baseLine,
BPoint* penLocation,
const escapement_delta* delta = NULL) const;
float StringWidth( const char* utf8String,
uint32 length,
const DrawState* context);
BRect DrawString( const char* utf8String,
BPoint baseLine,
const escapement_delta* delta = NULL);
// bitmaps // bitmaps
BRect DrawBitmap( const ServerBitmap* bitmap, BRect DrawBitmap( const ServerBitmap* bitmap,
@@ -206,15 +199,6 @@ class Painter {
BRect InvertRect( const BRect& r) const; BRect InvertRect( const BRect& r) const;
BRect BoundingBox( const char* utf8String,
uint32 length,
const BPoint& baseLine,
BPoint* penLocation,
const escapement_delta* delta = NULL) const;
float StringWidth( const char* utf8String,
uint32 length) const;
inline BRect ClipRect(const BRect& rect) const inline BRect ClipRect(const BRect& rect) const
{ return _Clipped(rect); } { return _Clipped(rect); }