* Fixed a few operator precedence bugs (&& ... & ... &&).

* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33931 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-11-07 09:14:01 +00:00
parent 4663f6d46a
commit d99900143c

View File

@ -1,11 +1,12 @@
/* /*
* Copyright 2001-2008, Haiku, Inc. * Copyright 2001-2009, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
*/ */
#include "DrawingEngine.h" #include "DrawingEngine.h"
#include <Bitmap.h> #include <Bitmap.h>
@ -22,13 +23,18 @@
#include "drawing_support.h" #include "drawing_support.h"
#define CRASH_IF_NOT_LOCKED
//#define CRASH_IF_NOT_LOCKED if (!IsParallelAccessLocked()) debugger("not parallel locked!");
#define CRASH_IF_NOT_EXCLUSIVE_LOCKED #if DEBUG
//#define CRASH_IF_NOT_EXCLUSIVE_LOCKED if (!IsExclusiveAccessLocked()) debugger("not exclusive locked!"); # define ASSERT_PARALLEL_LOCKED() \
{ if (!IsParallelAccessLocked()) debugger("not parallel locked!"); }
# define ASSERT_EXCLUSIVE_LOCKED() \
{ if (!IsExclusiveAccessLocked()) debugger("not exclusive locked!"); }
#else
# define ASSERT_PARALLEL_LOCKED()
# define ASSERT_EXCLUSIVE_LOCKED()
#endif
// make_rect_valid
static inline void static inline void
make_rect_valid(BRect& rect) make_rect_valid(BRect& rect)
{ {
@ -44,7 +50,7 @@ make_rect_valid(BRect& rect)
} }
} }
// extend_by_stroke_width
static inline void static inline void
extend_by_stroke_width(BRect& rect, float penSize) extend_by_stroke_width(BRect& rect, float penSize)
{ {
@ -57,14 +63,16 @@ extend_by_stroke_width(BRect& rect, float penSize)
class AutoFloatingOverlaysHider { class AutoFloatingOverlaysHider {
public: public:
AutoFloatingOverlaysHider(HWInterface* interface, const BRect& area) AutoFloatingOverlaysHider(HWInterface* interface, const BRect& area)
: fInterface(interface) :
, fHidden(interface->HideFloatingOverlays(area)) fInterface(interface),
fHidden(interface->HideFloatingOverlays(area))
{ {
} }
AutoFloatingOverlaysHider(HWInterface* interface) AutoFloatingOverlaysHider(HWInterface* interface)
: fInterface(interface) :
, fHidden(fInterface->HideFloatingOverlays()) fInterface(interface),
fHidden(fInterface->HideFloatingOverlays())
{ {
} }
@ -90,11 +98,12 @@ class AutoFloatingOverlaysHider {
DrawingEngine::DrawingEngine(HWInterface* interface) DrawingEngine::DrawingEngine(HWInterface* interface)
: fPainter(new Painter()), :
fGraphicsCard(NULL), fPainter(new Painter()),
fAvailableHWAccleration(0), fGraphicsCard(NULL),
fSuspendSyncLevel(0), fAvailableHWAccleration(0),
fCopyToFront(true) fSuspendSyncLevel(0),
fCopyToFront(true)
{ {
SetHWInterface(interface); SetHWInterface(interface);
} }
@ -144,8 +153,10 @@ DrawingEngine::UnlockExclusiveAccess()
fGraphicsCard->UnlockExclusiveAccess(); fGraphicsCard->UnlockExclusiveAccess();
} }
// #pragma mark - // #pragma mark -
void void
DrawingEngine::FrameBufferChanged() DrawingEngine::FrameBufferChanged()
{ {
@ -200,18 +211,20 @@ DrawingEngine::CopyToFront(/*const*/ BRegion& region)
// #pragma mark - // #pragma mark -
//! the DrawingEngine needs to be locked! //! the DrawingEngine needs to be locked!
void void
DrawingEngine::ConstrainClippingRegion(const BRegion* region) DrawingEngine::ConstrainClippingRegion(const BRegion* region)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
fPainter->ConstrainClipping(region); fPainter->ConstrainClipping(region);
} }
void void
DrawingEngine::SetDrawState(const DrawState* state, int32 xOffset, int32 yOffset) DrawingEngine::SetDrawState(const DrawState* state, int32 xOffset,
int32 yOffset)
{ {
fPainter->SetDrawState(state, xOffset, yOffset); fPainter->SetDrawState(state, xOffset, yOffset);
} }
@ -240,7 +253,7 @@ DrawingEngine::SetPenSize(float size)
void void
DrawingEngine::SetStrokeMode(cap_mode lineCap, join_mode joinMode, DrawingEngine::SetStrokeMode(cap_mode lineCap, join_mode joinMode,
float miterLimit) float miterLimit)
{ {
fPainter->SetStrokeMode(lineCap, joinMode, miterLimit); fPainter->SetStrokeMode(lineCap, joinMode, miterLimit);
} }
@ -295,7 +308,7 @@ DrawingEngine::SetFont(const DrawState* state)
void void
DrawingEngine::SuspendAutoSync() DrawingEngine::SuspendAutoSync()
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
fSuspendSyncLevel++; fSuspendSyncLevel++;
} }
@ -304,15 +317,17 @@ DrawingEngine::SuspendAutoSync()
void void
DrawingEngine::Sync() DrawingEngine::Sync()
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
fSuspendSyncLevel--; fSuspendSyncLevel--;
if (fSuspendSyncLevel == 0) if (fSuspendSyncLevel == 0)
fGraphicsCard->Sync(); fGraphicsCard->Sync();
} }
// #pragma mark - // #pragma mark -
// CopyRegion() does a topological sort of the rects in the // CopyRegion() does a topological sort of the rects in the
// region. The algorithm was suggested by Ingo Weinhold. // region. The algorithm was suggested by Ingo Weinhold.
// It compares each rect with each rect and builds a tree // It compares each rect with each rect and builds a tree
@ -368,42 +383,46 @@ DrawingEngine::Sync()
// and don't share the actual edge either (as is the case in BRegions). // and don't share the actual edge either (as is the case in BRegions).
struct node { struct node {
node() node()
{ {
pointers = NULL; pointers = NULL;
} }
node(const BRect& r, int32 maxPointers)
{
init(r, maxPointers);
}
~node()
{
delete [] pointers;
}
void init(const BRect& r, int32 maxPointers) node(const BRect& r, int32 maxPointers)
{ {
rect = r; init(r, maxPointers);
pointers = new node*[maxPointers]; }
in_degree = 0;
next_pointer = 0;
}
void push(node* node) ~node()
{ {
pointers[next_pointer] = node; delete [] pointers;
next_pointer++; }
}
node* top() void init(const BRect& r, int32 maxPointers)
{ {
return pointers[next_pointer]; rect = r;
} pointers = new node*[maxPointers];
node* pop() in_degree = 0;
{ next_pointer = 0;
node* ret = top(); }
next_pointer--;
return ret; void push(node* node)
} {
pointers[next_pointer] = node;
next_pointer++;
}
node* top()
{
return pointers[next_pointer];
}
node* pop()
{
node* ret = top();
next_pointer--;
return ret;
}
BRect rect; BRect rect;
int32 in_degree; int32 in_degree;
@ -411,23 +430,26 @@ struct node {
int32 next_pointer; int32 next_pointer;
}; };
static bool static bool
is_left_of(const BRect& a, const BRect& b) is_left_of(const BRect& a, const BRect& b)
{ {
return (a.right < b.left); return (a.right < b.left);
} }
static bool static bool
is_above(const BRect& a, const BRect& b) is_above(const BRect& a, const BRect& b)
{ {
return (a.bottom < b.top); return (a.bottom < b.top);
} }
// CopyRegion
void void
DrawingEngine::CopyRegion(/*const*/ BRegion* region, DrawingEngine::CopyRegion(/*const*/ BRegion* region, int32 xOffset,
int32 xOffset, int32 yOffset) int32 yOffset)
{ {
CRASH_IF_NOT_EXCLUSIVE_LOCKED ASSERT_EXCLUSIVE_LOCKED();
BRect frame = region->Frame(); BRect frame = region->Frame();
frame = frame | frame.OffsetByCopy(xOffset, yOffset); frame = frame | frame.OffsetByCopy(xOffset, yOffset);
@ -542,11 +564,11 @@ DrawingEngine::CopyRegion(/*const*/ BRegion* region,
delete[] sortedRectList; delete[] sortedRectList;
} }
// InvertRect
void void
DrawingEngine::InvertRect(BRect r) DrawingEngine::InvertRect(BRect r)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
r = fPainter->ClipRect(r); r = fPainter->ClipRect(r);
@ -567,12 +589,12 @@ DrawingEngine::InvertRect(BRect r)
_CopyToFront(r); _CopyToFront(r);
} }
// DrawBitmap
void void
DrawingEngine::DrawBitmap(ServerBitmap* bitmap, const BRect& bitmapRect, DrawingEngine::DrawBitmap(ServerBitmap* bitmap, const BRect& bitmapRect,
const BRect& viewRect, uint32 options) const BRect& viewRect, uint32 options)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect clipped = fPainter->ClipRect(viewRect); BRect clipped = fPainter->ClipRect(viewRect);
if (clipped.IsValid()) { if (clipped.IsValid()) {
@ -584,12 +606,12 @@ DrawingEngine::DrawBitmap(ServerBitmap* bitmap, const BRect& bitmapRect,
} }
} }
// DrawArc
void void
DrawingEngine::DrawArc(BRect r, const float& angle, const float& span, DrawingEngine::DrawArc(BRect r, const float& angle, const float& span,
bool filled) bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
fPainter->AlignEllipseRect(&r, filled); fPainter->AlignEllipseRect(&r, filled);
@ -617,11 +639,12 @@ DrawingEngine::DrawArc(BRect r, const float& angle, const float& span,
} }
} }
void void
DrawingEngine::FillArc(BRect r, const float& angle, const float& span, DrawingEngine::FillArc(BRect r, const float& angle, const float& span,
const BGradient& gradient) const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
fPainter->AlignEllipseRect(&r, true); fPainter->AlignEllipseRect(&r, true);
@ -647,7 +670,7 @@ DrawingEngine::FillArc(BRect r, const float& angle, const float& span,
void void
DrawingEngine::DrawBezier(BPoint* pts, bool filled) DrawingEngine::DrawBezier(BPoint* pts, bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// TODO: figure out bounds and hide cursor depending on that // TODO: figure out bounds and hide cursor depending on that
AutoFloatingOverlaysHider _(fGraphicsCard); AutoFloatingOverlaysHider _(fGraphicsCard);
@ -661,7 +684,7 @@ DrawingEngine::DrawBezier(BPoint* pts, bool filled)
void void
DrawingEngine::FillBezier(BPoint* pts, const BGradient& gradient) DrawingEngine::FillBezier(BPoint* pts, const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// TODO: figure out bounds and hide cursor depending on that // TODO: figure out bounds and hide cursor depending on that
AutoFloatingOverlaysHider _(fGraphicsCard); AutoFloatingOverlaysHider _(fGraphicsCard);
@ -675,7 +698,7 @@ DrawingEngine::FillBezier(BPoint* pts, const BGradient& gradient)
void void
DrawingEngine::DrawEllipse(BRect r, bool filled) DrawingEngine::DrawEllipse(BRect r, bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
BRect clipped = r; BRect clipped = r;
@ -704,7 +727,7 @@ DrawingEngine::DrawEllipse(BRect r, bool filled)
void void
DrawingEngine::FillEllipse(BRect r, const BGradient& gradient) DrawingEngine::FillEllipse(BRect r, const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
BRect clipped = r; BRect clipped = r;
@ -731,7 +754,7 @@ void
DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds, DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts, BRect bounds,
bool filled, bool closed) bool filled, bool closed)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(bounds); make_rect_valid(bounds);
if (!filled) if (!filled)
@ -751,7 +774,7 @@ void
DrawingEngine::FillPolygon(BPoint* ptlist, int32 numpts, BRect bounds, DrawingEngine::FillPolygon(BPoint* ptlist, int32 numpts, BRect bounds,
const BGradient& gradient, bool closed) const BGradient& gradient, bool closed)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(bounds); make_rect_valid(bounds);
bounds = fPainter->ClipRect(bounds); bounds = fPainter->ClipRect(bounds);
@ -774,15 +797,15 @@ DrawingEngine::StrokePoint(const BPoint& pt, const rgb_color& color)
StrokeLine(pt, pt, color); StrokeLine(pt, pt, color);
} }
// StrokeLine
// /*! This function is only used by Decorators,
// * this function is only used by Decorators it assumes a one pixel wide line
// * it assumes a one pixel wide line */
void void
DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end, DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end,
const rgb_color& color) const rgb_color& color)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect touched(start, end); BRect touched(start, end);
make_rect_valid(touched); make_rect_valid(touched);
@ -804,11 +827,12 @@ DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end,
_CopyToFront(touched); _CopyToFront(touched);
} }
// this function is used to draw a one pixel wide rect
//! This function is used to draw a one pixel wide rect
void void
DrawingEngine::StrokeRect(BRect r, const rgb_color &color) DrawingEngine::StrokeRect(BRect r, const rgb_color& color)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
BRect clipped = fPainter->ClipRect(r); BRect clipped = fPainter->ClipRect(r);
@ -825,7 +849,7 @@ DrawingEngine::StrokeRect(BRect r, const rgb_color &color)
void void
DrawingEngine::FillRect(BRect r, const rgb_color& color) DrawingEngine::FillRect(BRect r, const rgb_color& color)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// 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
@ -854,7 +878,7 @@ DrawingEngine::FillRect(BRect r, const rgb_color& color)
void void
DrawingEngine::FillRegion(BRegion& r, const rgb_color& color) DrawingEngine::FillRegion(BRegion& r, const rgb_color& color)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// NOTE: region expected to be already clipped correctly!! // NOTE: region expected to be already clipped correctly!!
BRect frame = r.Frame(); BRect frame = r.Frame();
@ -889,12 +913,14 @@ DrawingEngine::FillRegion(BRegion& r, const rgb_color& color)
_CopyToFront(frame); _CopyToFront(frame);
} }
// #pragma mark - DrawState // #pragma mark - DrawState
void void
DrawingEngine::StrokeRect(BRect r) DrawingEngine::StrokeRect(BRect r)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// support invalid rects // support invalid rects
make_rect_valid(r); make_rect_valid(r);
@ -914,7 +940,7 @@ DrawingEngine::StrokeRect(BRect r)
void void
DrawingEngine::FillRect(BRect r) DrawingEngine::FillRect(BRect r)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
r = fPainter->AlignAndClipRect(r); r = fPainter->AlignAndClipRect(r);
@ -934,24 +960,22 @@ DrawingEngine::FillRect(BRect r)
BRegion region(r); BRegion region(r);
region.IntersectWith(fPainter->ClippingRegion()); region.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(region, fPainter->HighColor(), fGraphicsCard->FillRegion(region, fPainter->HighColor(),
fSuspendSyncLevel == 0 fSuspendSyncLevel == 0 || overlaysHider.WasHidden());
|| overlaysHider.WasHidden());
doInSoftware = false; doInSoftware = false;
} else if (fPainter->Pattern() == B_SOLID_LOW } else if (fPainter->Pattern() == B_SOLID_LOW
&& fPainter->DrawingMode() == B_OP_COPY) { && fPainter->DrawingMode() == B_OP_COPY) {
BRegion region(r); BRegion region(r);
region.IntersectWith(fPainter->ClippingRegion()); region.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(region, fPainter->LowColor(), fGraphicsCard->FillRegion(region, fPainter->LowColor(),
fSuspendSyncLevel == 0 fSuspendSyncLevel == 0 || overlaysHider.WasHidden());
|| overlaysHider.WasHidden());
doInSoftware = false; doInSoftware = false;
} }
} }
} }
if (doInSoftware && fAvailableHWAccleration & HW_ACC_INVERT_REGION if (doInSoftware && (fAvailableHWAccleration & HW_ACC_INVERT_REGION) != 0
&& fPainter->Pattern() == B_SOLID_HIGH && fPainter->Pattern() == B_SOLID_HIGH
&& fPainter->DrawingMode() == B_OP_INVERT) { && fPainter->DrawingMode() == B_OP_INVERT) {
BRegion region(r); BRegion region(r);
region.IntersectWith(fPainter->ClippingRegion()); region.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->InvertRegion(region); fGraphicsCard->InvertRegion(region);
@ -968,7 +992,7 @@ DrawingEngine::FillRect(BRect r)
void void
DrawingEngine::FillRect(BRect r, const BGradient& gradient) DrawingEngine::FillRect(BRect r, const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
make_rect_valid(r); make_rect_valid(r);
r = fPainter->AlignAndClipRect(r); r = fPainter->AlignAndClipRect(r);
@ -986,7 +1010,7 @@ DrawingEngine::FillRect(BRect r, const BGradient& gradient)
void void
DrawingEngine::FillRegion(BRegion& r) DrawingEngine::FillRegion(BRegion& r)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect clipped = fPainter->ClipRect(r.Frame()); BRect clipped = fPainter->ClipRect(r.Frame());
if (!clipped.IsValid()) if (!clipped.IsValid())
@ -1002,29 +1026,26 @@ DrawingEngine::FillRegion(BRegion& r)
|| fPainter->DrawingMode() == B_OP_OVER)) { || fPainter->DrawingMode() == B_OP_OVER)) {
r.IntersectWith(fPainter->ClippingRegion()); r.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(r, fPainter->HighColor(), fGraphicsCard->FillRegion(r, fPainter->HighColor(),
fSuspendSyncLevel == 0 fSuspendSyncLevel == 0 || overlaysHider.WasHidden());
|| overlaysHider.WasHidden());
doInSoftware = false; doInSoftware = false;
} else if (fPainter->Pattern() == B_SOLID_LOW } else if (fPainter->Pattern() == B_SOLID_LOW
&& fPainter->DrawingMode() == B_OP_COPY) { && fPainter->DrawingMode() == B_OP_COPY) {
r.IntersectWith(fPainter->ClippingRegion()); r.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->FillRegion(r, fPainter->LowColor(), fGraphicsCard->FillRegion(r, fPainter->LowColor(),
fSuspendSyncLevel == 0 fSuspendSyncLevel == 0 || overlaysHider.WasHidden());
|| overlaysHider.WasHidden());
doInSoftware = false; doInSoftware = false;
} }
} }
if (doInSoftware && fAvailableHWAccleration & HW_ACC_INVERT_REGION if (doInSoftware && (fAvailableHWAccleration & HW_ACC_INVERT_REGION) != 0
&& fPainter->Pattern() == B_SOLID_HIGH && fPainter->Pattern() == B_SOLID_HIGH
&& fPainter->DrawingMode() == B_OP_INVERT) { && fPainter->DrawingMode() == B_OP_INVERT) {
r.IntersectWith(fPainter->ClippingRegion()); r.IntersectWith(fPainter->ClippingRegion());
fGraphicsCard->InvertRegion(r); fGraphicsCard->InvertRegion(r);
doInSoftware = false; doInSoftware = false;
} }
if (doInSoftware) { if (doInSoftware) {
BRect touched = fPainter->FillRect(r.RectAt(0)); BRect touched = fPainter->FillRect(r.RectAt(0));
int32 count = r.CountRects(); int32 count = r.CountRects();
@ -1039,7 +1060,7 @@ DrawingEngine::FillRegion(BRegion& r)
void void
DrawingEngine::FillRegion(BRegion& r, const BGradient& gradient) DrawingEngine::FillRegion(BRegion& r, const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect clipped = fPainter->ClipRect(r.Frame()); BRect clipped = fPainter->ClipRect(r.Frame());
if (!clipped.IsValid()) if (!clipped.IsValid())
@ -1060,7 +1081,7 @@ DrawingEngine::FillRegion(BRegion& r, const BGradient& gradient)
void void
DrawingEngine::DrawRoundRect(BRect r, float xrad, float yrad, bool filled) DrawingEngine::DrawRoundRect(BRect r, float xrad, float yrad, bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// NOTE: the stroke does not extend past "r" in R5, // NOTE: the stroke does not extend past "r" in R5,
// though I consider this unexpected behaviour. // though I consider this unexpected behaviour.
@ -1076,7 +1097,7 @@ DrawingEngine::DrawRoundRect(BRect r, float xrad, float yrad, bool filled)
AutoFloatingOverlaysHider _(fGraphicsCard, clipped); AutoFloatingOverlaysHider _(fGraphicsCard, clipped);
BRect touched = filled ? fPainter->FillRoundRect(r, xrad, yrad) BRect touched = filled ? fPainter->FillRoundRect(r, xrad, yrad)
: fPainter->StrokeRoundRect(r, xrad, yrad); : fPainter->StrokeRoundRect(r, xrad, yrad);
_CopyToFront(touched); _CopyToFront(touched);
} }
@ -1087,7 +1108,7 @@ void
DrawingEngine::FillRoundRect(BRect r, float xrad, float yrad, DrawingEngine::FillRoundRect(BRect r, float xrad, float yrad,
const BGradient& gradient) const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// NOTE: the stroke does not extend past "r" in R5, // NOTE: the stroke does not extend past "r" in R5,
// though I consider this unexpected behaviour. // though I consider this unexpected behaviour.
@ -1113,15 +1134,14 @@ void
DrawingEngine::DrawShape(const BRect& bounds, int32 opCount, DrawingEngine::DrawShape(const BRect& bounds, int32 opCount,
const uint32* opList, int32 ptCount, const BPoint* ptList, bool filled) const uint32* opList, int32 ptCount, const BPoint* ptList, bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// NOTE: hides cursor regardless of if and where // NOTE: hides cursor regardless of if and where
// shape is drawn on screen, TODO: optimize // shape is drawn on screen, TODO: optimize
AutoFloatingOverlaysHider _(fGraphicsCard); AutoFloatingOverlaysHider _(fGraphicsCard);
BRect touched = fPainter->DrawShape(opCount, opList, BRect touched = fPainter->DrawShape(opCount, opList, ptCount, ptList,
ptCount, ptList, filled);
filled);
_CopyToFront(touched); _CopyToFront(touched);
} }
@ -1132,14 +1152,14 @@ DrawingEngine::FillShape(const BRect& bounds, int32 opCount,
const uint32* opList, int32 ptCount, const BPoint* ptList, const uint32* opList, int32 ptCount, const BPoint* ptList,
const BGradient& gradient) const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
// NOTE: hides cursor regardless of if and where // NOTE: hides cursor regardless of if and where
// shape is drawn on screen, TODO: optimize // shape is drawn on screen, TODO: optimize
AutoFloatingOverlaysHider _(fGraphicsCard); AutoFloatingOverlaysHider _(fGraphicsCard);
BRect touched = fPainter->FillShape(opCount, opList, ptCount, BRect touched = fPainter->FillShape(opCount, opList, ptCount, ptList,
ptList, gradient); gradient);
_CopyToFront(touched); _CopyToFront(touched);
} }
@ -1148,7 +1168,7 @@ DrawingEngine::FillShape(const BRect& bounds, int32 opCount,
void void
DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds, bool filled) DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds, bool filled)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect clipped(bounds); BRect clipped(bounds);
if (!filled) if (!filled)
@ -1166,11 +1186,12 @@ DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds, bool filled)
} }
} }
void void
DrawingEngine::FillTriangle(BPoint* pts, const BRect& bounds, DrawingEngine::FillTriangle(BPoint* pts, const BRect& bounds,
const BGradient& gradient) const BGradient& gradient)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect clipped(bounds); BRect clipped(bounds);
clipped = fPainter->ClipRect(clipped); clipped = fPainter->ClipRect(clipped);
@ -1183,11 +1204,11 @@ DrawingEngine::FillTriangle(BPoint* pts, const BRect& bounds,
} }
} }
// StrokeLine
void void
DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end) DrawingEngine::StrokeLine(const BPoint& start, const BPoint& end)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BRect touched(start, end); BRect touched(start, end);
make_rect_valid(touched); make_rect_valid(touched);
@ -1202,29 +1223,29 @@ DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end)
} }
} }
// StrokeLineArray
void void
DrawingEngine::StrokeLineArray(int32 numLines, DrawingEngine::StrokeLineArray(int32 numLines,
const ViewLineArrayInfo *lineData) const ViewLineArrayInfo *lineData)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
if (!lineData || numLines <= 0) if (!lineData || numLines <= 0)
return; return;
// figure out bounding box for line array // figure out bounding box for line array
const ViewLineArrayInfo* data = (const ViewLineArrayInfo*)&(lineData[0]); const ViewLineArrayInfo* data = (const ViewLineArrayInfo*)&lineData[0];
BRect touched(min_c(data->startPoint.x, data->endPoint.x), BRect touched(min_c(data->startPoint.x, data->endPoint.x),
min_c(data->startPoint.y, data->endPoint.y), min_c(data->startPoint.y, data->endPoint.y),
max_c(data->startPoint.x, data->endPoint.x), max_c(data->startPoint.x, data->endPoint.x),
max_c(data->startPoint.y, data->endPoint.y)); max_c(data->startPoint.y, data->endPoint.y));
for (int32 i = 1; i < numLines; i++) { for (int32 i = 1; i < numLines; i++) {
data = (const ViewLineArrayInfo*)&(lineData[i]); data = (const ViewLineArrayInfo*)&lineData[i];
BRect box(min_c(data->startPoint.x, data->endPoint.x), BRect box(min_c(data->startPoint.x, data->endPoint.x),
min_c(data->startPoint.y, data->endPoint.y), min_c(data->startPoint.y, data->endPoint.y),
max_c(data->startPoint.x, data->endPoint.x), max_c(data->startPoint.x, data->endPoint.x),
max_c(data->startPoint.y, data->endPoint.y)); max_c(data->startPoint.y, data->endPoint.y));
touched = touched | box; touched = touched | box;
} }
extend_by_stroke_width(touched, fPainter->PenSize()); extend_by_stroke_width(touched, fPainter->PenSize());
@ -1257,13 +1278,15 @@ DrawingEngine::StrokeLineArray(int32 numLines,
} }
} }
// #pragma mark - // #pragma mark -
BPoint BPoint
DrawingEngine::DrawString(const char* string, int32 length, DrawingEngine::DrawString(const char* string, int32 length,
const BPoint& pt, escapement_delta* delta) const BPoint& pt, escapement_delta* delta)
{ {
CRASH_IF_NOT_LOCKED ASSERT_PARALLEL_LOCKED();
BPoint penLocation = pt; BPoint penLocation = pt;
@ -1310,15 +1333,15 @@ DrawingEngine::DrawString(const char* string, int32 length,
return penLocation; return penLocation;
} }
// StringWidth
float float
DrawingEngine::StringWidth(const char* string, int32 length, DrawingEngine::StringWidth(const char* string, int32 length,
escapement_delta* delta) escapement_delta* delta)
{ {
return fPainter->StringWidth(string, length, delta); return fPainter->StringWidth(string, length, delta);
} }
// StringWidth
float 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)
@ -1326,22 +1349,24 @@ DrawingEngine::StringWidth(const char* string, int32 length,
return font.StringWidth(string, length, delta); return font.StringWidth(string, length, delta);
} }
// #pragma mark - // #pragma mark -
// DumpToBitmap
ServerBitmap* ServerBitmap*
DrawingEngine::DumpToBitmap() DrawingEngine::DumpToBitmap()
{ {
return NULL; return NULL;
} }
status_t
DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
{
CRASH_IF_NOT_EXCLUSIVE_LOCKED
RenderingBuffer *buffer = fGraphicsCard->FrontBuffer(); status_t
if (!buffer) DrawingEngine::ReadBitmap(ServerBitmap* bitmap, bool drawCursor, BRect bounds)
{
ASSERT_EXCLUSIVE_LOCKED();
RenderingBuffer* buffer = fGraphicsCard->FrontBuffer();
if (buffer == NULL)
return B_ERROR; return B_ERROR;
BRect clip(0, 0, buffer->Width() - 1, buffer->Height() - 1); BRect clip(0, 0, buffer->Width() - 1, buffer->Height() - 1);
@ -1372,8 +1397,8 @@ DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
cursorPosition, BPoint(0, 0), cursorPosition, BPoint(0, 0),
cursorWidth, cursorHeight); cursorWidth, cursorHeight);
uint8 *bits = (uint8 *)cursorArea.Bits(); uint8* bits = (uint8*)cursorArea.Bits();
uint8 *cursorBits = (uint8 *)cursor->Bits(); uint8* cursorBits = (uint8*)cursor->Bits();
for (int32 i = 0; i < cursorHeight; i++) { for (int32 i = 0; i < cursorHeight; i++) {
for (int32 j = 0; j < cursorWidth; j++) { for (int32 j = 0; j < cursorWidth; j++) {
uint8 alpha = 255 - cursorBits[3]; uint8 alpha = 255 - cursorBits[3];
@ -1394,8 +1419,10 @@ DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
return result; return result;
} }
// #pragma mark - // #pragma mark -
BRect BRect
DrawingEngine::CopyRect(BRect src, int32 xOffset, int32 yOffset) const DrawingEngine::CopyRect(BRect src, int32 xOffset, int32 yOffset) const
{ {
@ -1505,5 +1532,3 @@ DrawingEngine::_CopyToFront(const BRect& frame)
if (fCopyToFront) if (fCopyToFront)
fGraphicsCard->Invalidate(frame); fGraphicsCard->Invalidate(frame);
} }