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

View File

@ -99,7 +99,8 @@ public:
void FillRect(BRect r, const DrawState *d);
// 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 RGBColor& color);

View File

@ -1350,13 +1350,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
if (!stringArray[i] || lengthArray[i] <= 0)
widthArray[i] = 0.0;
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,
// the line above uses the AGG rendering backend, for which glyph caching
// actually works. It is about 20 times faster!
// 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...
widthArray[i] = font.StringWidth(stringArray[i], lengthArray[i]);
// widthArray[i] = font.StringWidth(stringArray[i], lengthArray[i]);
}
}

View File

@ -127,6 +127,7 @@ DrawingEngine::SetHWInterface(HWInterface* interface)
fGraphicsCard = interface;
}
// #pragma mark -
void
DrawingEngine::ConstrainClippingRegion(const BRegion* region)
@ -672,7 +673,7 @@ DrawingEngine::FillRect(BRect r, const DrawState *d)
WriteUnlock();
}
}
/*
// StrokeRegion
void
DrawingEngine::StrokeRegion(BRegion& r, const DrawState *d)
@ -700,7 +701,7 @@ DrawingEngine::StrokeRegion(BRegion& r, const DrawState *d)
Unlock();
}
}
*/
// FillRegion
void
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.
// This needs to be investigated, I'm doing this because of
// 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()) {
BRect clipped = fPainter->ClipRect(r.Frame());
if (clipped.IsValid()) {
@ -769,6 +766,8 @@ DrawingEngine::FillRegion(BRegion& r, const RGBColor& color)
bool doInSoftware = true;
// try hardware optimized version first
if ((fAvailableHWAccleration & HW_ACC_FILL_REGION) != 0) {
// NOTE: region expected to be already clipped correctly
// r.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(r, color);
doInSoftware = false;
}
@ -980,6 +979,8 @@ DrawingEngine::StrokePoint(const BPoint& pt, DrawState *context)
StrokeLine(pt, pt, context);
}
// #pragma mark -
/*
// DrawString
void
@ -1003,7 +1004,7 @@ DrawingEngine::DrawString(const char* string, int32 length,
BPoint penLocation = pt;
if (Lock()) {
FontLocker locker(d);
fPainter->SetDrawState(d);
fPainter->SetDrawState(d, true);
//bigtime_t now = system_time();
// TODO: BoundingBox is quite slow!! Optimizing it will be beneficial.
// Cursiously, the DrawString after it is actually faster!?!
@ -1038,12 +1039,17 @@ DrawingEngine::StringWidth(const char* string, int32 length,
{
// TODO: use delta
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);
fPainter->SetDrawState(d);
width = fPainter->StringWidth(string, length);
Unlock();
}
width = fPainter->StringWidth(string, length, d);
// Unlock();
// }
return width;
}
@ -1052,11 +1058,10 @@ float
DrawingEngine::StringWidth(const char* string, int32 length,
const ServerFont& font, escapement_delta* delta)
{
// TODO: use delta
FontLocker locker(&font);
static DrawState d;
d.SetFont(font);
return StringWidth(string, length, &d);
return StringWidth(string, length, &d, delta);
}
// StringHeight
@ -1065,17 +1070,25 @@ DrawingEngine::StringHeight(const char *string, int32 length,
const DrawState *d)
{
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);
fPainter->SetDrawState(d);
fPainter->SetDrawState(d, true);
static BPoint dummy1(0.0, 0.0);
static BPoint dummy2(0.0, 0.0);
height = fPainter->BoundingBox(string, length, dummy1, &dummy2).Height();
Unlock();
}
// Unlock();
// }
return height;
}
// #pragma mark -
// Lock
bool
DrawingEngine::Lock()
@ -1104,6 +1117,8 @@ DrawingEngine::WriteUnlock()
fGraphicsCard->WriteUnlock();
}
// #pragma mark -
// DumpToFile
bool
DrawingEngine::DumpToFile(const char *path)
@ -1130,6 +1145,7 @@ DrawingEngine::DumpToBitmap()
return NULL;
}
// #pragma mark -
BRect
DrawingEngine::_CopyRect(BRect src, int32 xOffset, int32 yOffset) const

View File

@ -168,7 +168,7 @@ Painter::DetachFromBuffer()
// SetDrawState
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
// taken into account elsewhere
@ -177,7 +177,10 @@ Painter::SetDrawState(const DrawState* data)
// but for now...
SetPenSize(data->PenSize());
SetPenLocation(data->PenLocation());
SetFont(data->Font());
if (updateFont)
SetFont(data->Font());
fTextRenderer->SetAntialiasing(!(data->ForceFontAliasing() || data->Font().Flags() & B_DISABLE_ANTIALIASING));
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
void
Painter::SetPattern(const pattern& p)
@ -299,15 +280,6 @@ Painter::SetFont(const ServerFont& font)
BRect
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
// "false" means not to do the pixel center offset,
@ -331,11 +303,6 @@ Painter::StrokeLine(BPoint a, BPoint b, DrawState* context)
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);
// first, try an optimized version
@ -912,34 +879,6 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius,
// #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
BRect
Painter::DrawString(const char* utf8String, uint32 length,
@ -965,21 +904,27 @@ Painter::DrawString(const char* utf8String, uint32 length,
return _Clipped(bounds);
}
// DrawString
// BoundingBox
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
return DrawString(utf8String, strlen(utf8String), fPenLocation, delta);
static BRect dummy;
return fTextRenderer->RenderString(utf8String,
length,
fFontRendererSolid,
fFontRendererBin,
baseLine, dummy, true, penLocation,
delta);
}
// DrawString
BRect
Painter::DrawString(const char* utf8String, BPoint baseLine,
const escapement_delta* delta)
// StringWidth
float
Painter::StringWidth(const char* utf8String, uint32 length, const DrawState* context)
{
// TODO: to be moved elsewhere
return DrawString(utf8String, strlen(utf8String), baseLine, delta);
SetFont(context->Font());
return fTextRenderer->StringWidth(utf8String, length);
}
// #pragma mark -
@ -1043,28 +988,6 @@ Painter::InvertRect(const BRect& r) const
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 -
// _MakeEmpty

View File

@ -61,7 +61,8 @@ class Painter {
const BRegion* ClippingRegion() const
{ return fClippingRegion; }
void SetDrawState(const DrawState* data);
void SetDrawState(const DrawState* data,
bool updateFont = false);
// object settings
void SetHighColor(const rgb_color& color);
@ -74,9 +75,6 @@ class Painter {
{ SetLowColor(color.GetColor32()); }
void SetPenSize(float size);
void SetDrawingMode(drawing_mode mode);
void SetBlendingMode(source_alpha alphaSrcMode,
alpha_function alphaFncMode);
void SetPattern(const pattern& p);
void SetPenLocation(const BPoint& location);
@ -175,26 +173,21 @@ class Painter {
float span) const;
// 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,
uint32 length,
BPoint baseLine,
const escapement_delta* delta = NULL);
BRect DrawString( const char* utf8String,
const escapement_delta* delta = NULL);
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 DrawState* context);
BRect DrawString( const char* utf8String,
BPoint baseLine,
const escapement_delta* delta = NULL);
// bitmaps
BRect DrawBitmap( const ServerBitmap* bitmap,
@ -206,15 +199,6 @@ class Painter {
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
{ return _Clipped(rect); }