* renamed HWInterface locking to LockParallelAccess() and

LockExclusiveAccess() (meaning more or less access to the
  frame buffer)
* extracted the AGGTextRenderer to be a global instance used
  by each Painter instance (currently, it is thread safe because
  of the global font lock, so there is some work left in this
  regard)
* gave every ServerWindow it's own DrawingEngine instance, this
  is work in progress. So far, there doesn't seem to be a regression,
  but less fighting over the exclusive access to the frame buffer, now
  each ServerWindow thread can draw in parallel. There is room for
  improvement, plus I think I'm leaking the DrawingEngine...
* changed the locking for the software cursor. ShowSoftwareCursor()
  can only be called if HideSoftwareCursor(BRect) returned true, or
  if you called the generic HideSoftwareCursor(), since it needs
  to keep the cursor lock and unlocks in Show...!
* some clean up and renaming in Decorator and friends
* moved PatternHandler.h to live along with the .cpp


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19427 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-12-04 22:25:17 +00:00
parent c31e5df06c
commit 2cfe93e780
23 changed files with 819 additions and 786 deletions
+4 -4
View File
@@ -31,10 +31,10 @@
#define ANGLE_PI 3.14159265358979323846 #define ANGLE_PI 3.14159265358979323846
#endif #endif
bool sTablesInitialized = false; static bool sTablesInitialized = false;
float sSinTable[360]; static float sSinTable[360];
float sCosTable[360]; static float sCosTable[360];
float sTanTable[360]; static float sTanTable[360];
/*! /*!
\brief Constructor \brief Constructor
+1 -1
View File
@@ -92,7 +92,7 @@ DecorInfo::Instantiate(Desktop* desktop, BRect rect, const char *title,
desktop->UnlockSingleWindow(); desktop->UnlockSingleWindow();
decorator->SetDriver(desktop->GetDrawingEngine()); decorator->SetDrawingEngine(desktop->GetDrawingEngine());
decorator->SetTitle(title); decorator->SetTitle(title);
return decorator; return decorator;
+39 -39
View File
@@ -30,19 +30,19 @@
Decorator::Decorator(DesktopSettings& settings, BRect rect, Decorator::Decorator(DesktopSettings& settings, BRect rect,
window_look look, uint32 flags) window_look look, uint32 flags)
: :
_driver(NULL), fDrawingEngine(NULL),
fDrawState(), fDrawState(),
fLook(look), fLook(look),
fFlags(flags), fFlags(flags),
_zoomrect(), fZoomRect(),
_closerect(), fCloseRect(),
_minimizerect(), fMinimizeRect(),
_tabrect(), fTabRect(),
_frame(rect), fFrame(rect),
_resizerect(), fResizeRect(),
_borderrect(), fBorderRect(),
fClosePressed(false), fClosePressed(false),
fZoomPressed(false), fZoomPressed(false),
@@ -68,12 +68,12 @@ Decorator::~Decorator()
\param driver A valid DrawingEngine object \param driver A valid DrawingEngine object
*/ */
void void
Decorator::SetDriver(DrawingEngine *driver) Decorator::SetDrawingEngine(DrawingEngine* engine)
{ {
_driver = driver; fDrawingEngine = engine;
// lots of subclasses will depend on the driver for text support, so call // lots of subclasses will depend on the driver for text support, so call
// _DoLayout() after we have it // _DoLayout() after we have it
if (_driver) { if (fDrawingEngine) {
_DoLayout(); _DoLayout();
} }
} }
@@ -227,7 +227,7 @@ Decorator::Title() const
BRect BRect
Decorator::BorderRect() const Decorator::BorderRect() const
{ {
return _borderrect; return fBorderRect;
} }
@@ -238,7 +238,7 @@ Decorator::BorderRect() const
BRect BRect
Decorator::TabRect() const Decorator::TabRect() const
{ {
return _tabrect; return fTabRect;
} }
/*! /*!
@@ -373,14 +373,14 @@ Decorator::MoveBy(float x, float y)
void void
Decorator::MoveBy(BPoint pt) Decorator::MoveBy(BPoint pt)
{ {
_zoomrect.OffsetBy(pt); fZoomRect.OffsetBy(pt);
_closerect.OffsetBy(pt); fCloseRect.OffsetBy(pt);
_minimizerect.OffsetBy(pt); fMinimizeRect.OffsetBy(pt);
_minimizerect.OffsetBy(pt); fMinimizeRect.OffsetBy(pt);
_tabrect.OffsetBy(pt); fTabRect.OffsetBy(pt);
_frame.OffsetBy(pt); fFrame.OffsetBy(pt);
_resizerect.OffsetBy(pt); fResizeRect.OffsetBy(pt);
_borderrect.OffsetBy(pt); fBorderRect.OffsetBy(pt);
} }
/*! /*!
@@ -389,7 +389,7 @@ Decorator::MoveBy(BPoint pt)
\param dy y offset \param dy y offset
This is a required function for subclasses to implement - the default does nothing. This is a required function for subclasses to implement - the default does nothing.
Note that window resize flags should be followed and _frame should be resized Note that window resize flags should be followed and fFrame should be resized
accordingly. It would also be a wise idea to ensure that the window's rectangles accordingly. It would also be a wise idea to ensure that the window's rectangles
are not inverted. are not inverted.
*/ */
@@ -423,62 +423,62 @@ Decorator::GetSettings(BMessage* settings) const
void void
Decorator::Draw(BRect r) Decorator::Draw(BRect r)
{ {
_DrawFrame(r & _frame); _DrawFrame(r & fFrame);
_DrawTab(r & _tabrect); _DrawTab(r & fTabRect);
} }
//! Forces a complete decorator update //! Forces a complete decorator update
void void
Decorator::Draw() Decorator::Draw()
{ {
_DrawFrame(_frame); _DrawFrame(fFrame);
_DrawTab(_tabrect); _DrawTab(fTabRect);
} }
//! Draws the close button //! Draws the close button
void void
Decorator::DrawClose() Decorator::DrawClose()
{ {
_DrawClose(_closerect); _DrawClose(fCloseRect);
} }
//! draws the frame //! draws the frame
void void
Decorator::DrawFrame() Decorator::DrawFrame()
{ {
_DrawFrame(_frame); _DrawFrame(fFrame);
} }
//! draws the minimize button //! draws the minimize button
void void
Decorator::DrawMinimize(void) Decorator::DrawMinimize(void)
{ {
_DrawTab(_minimizerect); _DrawTab(fMinimizeRect);
} }
//! draws the tab, title, and buttons //! draws the tab, title, and buttons
void void
Decorator::DrawTab() Decorator::DrawTab()
{ {
_DrawTab(_tabrect); _DrawTab(fTabRect);
_DrawZoom(_zoomrect); _DrawZoom(fZoomRect);
_DrawMinimize(_minimizerect); _DrawMinimize(fMinimizeRect);
_DrawTitle(_tabrect); _DrawTitle(fTabRect);
_DrawClose(_closerect); _DrawClose(fCloseRect);
} }
// draws the title // draws the title
void void
Decorator::DrawTitle() Decorator::DrawTitle()
{ {
_DrawTitle(_tabrect); _DrawTitle(fTabRect);
} }
//! draws the zoom button //! draws the zoom button
void void
Decorator::DrawZoom(void) Decorator::DrawZoom(void)
{ {
_DrawZoom(_zoomrect); _DrawZoom(fZoomRect);
} }
@@ -501,16 +501,16 @@ Decorator::_ClipTitle(float width)
{ {
// TODO: eventually, use ServerFont::TruncateString() // TODO: eventually, use ServerFont::TruncateString()
// when it exists (if it doesn't already) // when it exists (if it doesn't already)
if (_driver) { if (fDrawingEngine) {
int32 strlength = fTitle.CountChars(); int32 strlength = fTitle.CountChars();
float pixwidth=_driver->StringWidth(fTitle.String(),strlength,&fDrawState); float pixwidth=fDrawingEngine->StringWidth(fTitle.String(),strlength,&fDrawState);
while (strlength >= 0) { while (strlength >= 0) {
if (pixwidth < width) if (pixwidth < width)
return strlength; return strlength;
strlength--; strlength--;
pixwidth=_driver->StringWidth(fTitle.String(), strlength, &fDrawState); pixwidth=fDrawingEngine->StringWidth(fTitle.String(), strlength, &fDrawState);
} }
} }
return 0; return 0;
+12 -10
View File
@@ -50,7 +50,9 @@ class Decorator {
window_look look, uint32 flags); window_look look, uint32 flags);
virtual ~Decorator(); virtual ~Decorator();
void SetDriver(DrawingEngine *driver); void SetDrawingEngine(DrawingEngine *driver);
inline DrawingEngine* GetDrawingEngine() const
{ return fDrawingEngine; }
void SetFont(ServerFont *font); void SetFont(ServerFont *font);
virtual void SetLook(DesktopSettings& settings, virtual void SetLook(DesktopSettings& settings,
@@ -68,7 +70,7 @@ class Decorator {
const char* Title() const; const char* Title() const;
// we need to know its border(frame). WinBorder's _frame rect // we need to know its border(frame). WinBorder's fFrame rect
// must expand to include Decorator borders. Otherwise we can't // must expand to include Decorator borders. Otherwise we can't
// draw the border. We also add TabRect because I feel we'll need it // draw the border. We also add TabRect because I feel we'll need it
BRect BorderRect() const; BRect BorderRect() const;
@@ -138,19 +140,19 @@ class Decorator {
virtual void _SetFocus(); virtual void _SetFocus();
DrawingEngine* _driver; DrawingEngine* fDrawingEngine;
DrawState fDrawState; DrawState fDrawState;
window_look fLook; window_look fLook;
uint32 fFlags; uint32 fFlags;
BRect _zoomrect; BRect fZoomRect;
BRect _closerect; BRect fCloseRect;
BRect _minimizerect; BRect fMinimizeRect;
BRect _tabrect; BRect fTabRect;
BRect _frame; BRect fFrame;
BRect _resizerect; BRect fResizeRect;
BRect _borderrect; BRect fBorderRect;
private: private:
bool fClosePressed; bool fClosePressed;
+143 -143
View File
@@ -207,12 +207,12 @@ DefaultDecorator::MoveBy(BPoint pt)
{ {
STRACE(("DefaultDecorator: Move By (%.1f, %.1f)\n",pt.x,pt.y)); STRACE(("DefaultDecorator: Move By (%.1f, %.1f)\n",pt.x,pt.y));
// Move all internal rectangles the appropriate amount // Move all internal rectangles the appropriate amount
_frame.OffsetBy(pt); fFrame.OffsetBy(pt);
_closerect.OffsetBy(pt); fCloseRect.OffsetBy(pt);
_tabrect.OffsetBy(pt); fTabRect.OffsetBy(pt);
_resizerect.OffsetBy(pt); fResizeRect.OffsetBy(pt);
_zoomrect.OffsetBy(pt); fZoomRect.OffsetBy(pt);
_borderrect.OffsetBy(pt); fBorderRect.OffsetBy(pt);
fLeftBorder.OffsetBy(pt); fLeftBorder.OffsetBy(pt);
fRightBorder.OffsetBy(pt); fRightBorder.OffsetBy(pt);
@@ -226,15 +226,15 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty)
{ {
STRACE(("DefaultDecorator: Resize By (%.1f, %.1f)\n", pt.x, pt.y)); STRACE(("DefaultDecorator: Resize By (%.1f, %.1f)\n", pt.x, pt.y));
// Move all internal rectangles the appropriate amount // Move all internal rectangles the appropriate amount
_frame.right += pt.x; fFrame.right += pt.x;
_frame.bottom += pt.y; fFrame.bottom += pt.y;
// handle invalidation of resize rect // handle invalidation of resize rect
if (dirty && !(fFlags & B_NOT_RESIZABLE)) { if (dirty && !(fFlags & B_NOT_RESIZABLE)) {
BRect realResizeRect; BRect realResizeRect;
switch (fLook) { switch (fLook) {
case B_DOCUMENT_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK:
realResizeRect = _resizerect; realResizeRect = fResizeRect;
// resize rect at old location // resize rect at old location
dirty->Include(realResizeRect); dirty->Include(realResizeRect);
realResizeRect.OffsetBy(pt); realResizeRect.OffsetBy(pt);
@@ -266,10 +266,10 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty)
} }
} }
_resizerect.OffsetBy(pt); fResizeRect.OffsetBy(pt);
_borderrect.right += pt.x; fBorderRect.right += pt.x;
_borderrect.bottom += pt.y; fBorderRect.bottom += pt.y;
fLeftBorder.bottom += pt.y; fLeftBorder.bottom += pt.y;
fTopBorder.right += pt.x; fTopBorder.right += pt.x;
@@ -307,8 +307,8 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty)
} }
// resize tab and layout tab items // resize tab and layout tab items
if (_tabrect.IsValid()) { if (fTabRect.IsValid()) {
BRect oldTabRect(_tabrect); BRect oldTabRect(fTabRect);
float tabSize; float tabSize;
float maxLocation; float maxLocation;
@@ -325,30 +325,30 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty)
float delta = tabOffset - fTabOffset; float delta = tabOffset - fTabOffset;
fTabOffset = (uint32)tabOffset; fTabOffset = (uint32)tabOffset;
if (fLook != kLeftTitledWindowLook) if (fLook != kLeftTitledWindowLook)
_tabrect.OffsetBy(delta, 0.0); fTabRect.OffsetBy(delta, 0.0);
else else
_tabrect.OffsetBy(0.0, delta); fTabRect.OffsetBy(0.0, delta);
if (tabSize < fMinTabSize) if (tabSize < fMinTabSize)
tabSize = fMinTabSize; tabSize = fMinTabSize;
if (tabSize > fMaxTabSize) if (tabSize > fMaxTabSize)
tabSize = fMaxTabSize; tabSize = fMaxTabSize;
if (fLook != kLeftTitledWindowLook && tabSize != _tabrect.Width()) { if (fLook != kLeftTitledWindowLook && tabSize != fTabRect.Width()) {
_tabrect.right = _tabrect.left + tabSize; fTabRect.right = fTabRect.left + tabSize;
} else if (fLook == kLeftTitledWindowLook && tabSize != _tabrect.Height()) { } else if (fLook == kLeftTitledWindowLook && tabSize != fTabRect.Height()) {
_tabrect.bottom = _tabrect.top + tabSize; fTabRect.bottom = fTabRect.top + tabSize;
} }
if (oldTabRect != _tabrect) { if (oldTabRect != fTabRect) {
_LayoutTabItems(_tabrect); _LayoutTabItems(fTabRect);
if (dirty) { if (dirty) {
// NOTE: the tab rect becoming smaller only would // NOTE: the tab rect becoming smaller only would
// handled be the Desktop anyways, so it is sufficient // handled be the Desktop anyways, so it is sufficient
// to include it into the dirty region in it's // to include it into the dirty region in it's
// final state // final state
BRect redraw(_tabrect); BRect redraw(fTabRect);
if (delta != 0.0) { if (delta != 0.0) {
redraw = redraw | oldTabRect; redraw = redraw | oldTabRect;
if (fLook != kLeftTitledWindowLook) if (fLook != kLeftTitledWindowLook)
@@ -367,13 +367,13 @@ bool
DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion) DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion)
{ {
STRACE(("DefaultDecorator: Set Tab Location(%.1f)\n", location)); STRACE(("DefaultDecorator: Set Tab Location(%.1f)\n", location));
if (!_tabrect.IsValid()) if (!fTabRect.IsValid())
return false; return false;
if (location < 0) if (location < 0)
location = 0; location = 0;
float maxLocation = fRightBorder.right - fLeftBorder.left - _tabrect.Width(); float maxLocation = fRightBorder.right - fLeftBorder.left - fTabRect.Width();
if (location > maxLocation) if (location > maxLocation)
location = maxLocation; location = maxLocation;
@@ -382,18 +382,18 @@ DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion)
return false; return false;
// redraw old rect (1 pix on the border also must be updated) // redraw old rect (1 pix on the border also must be updated)
BRect trect(_tabrect); BRect trect(fTabRect);
trect.bottom++; trect.bottom++;
updateRegion->Include(trect); updateRegion->Include(trect);
_tabrect.OffsetBy(delta, 0); fTabRect.OffsetBy(delta, 0);
fTabOffset = (int32)location; fTabOffset = (int32)location;
_LayoutTabItems(_tabrect); _LayoutTabItems(fTabRect);
fTabLocation = maxLocation > 0.0 ? fTabOffset / maxLocation : 0.0; fTabLocation = maxLocation > 0.0 ? fTabOffset / maxLocation : 0.0;
// redraw new rect as well // redraw new rect as well
trect = _tabrect; trect = fTabRect;
trect.bottom++; trect.bottom++;
updateRegion->Include(trect); updateRegion->Include(trect);
return true; return true;
@@ -414,7 +414,7 @@ DefaultDecorator::SetSettings(const BMessage& settings, BRegion* updateRegion)
bool bool
DefaultDecorator::GetSettings(BMessage* settings) const DefaultDecorator::GetSettings(BMessage* settings) const
{ {
if (!_tabrect.IsValid()) if (!fTabRect.IsValid())
return false; return false;
return settings->AddFloat("tab location", (float)fTabOffset) == B_OK; return settings->AddFloat("tab location", (float)fTabOffset) == B_OK;
@@ -445,7 +445,7 @@ DefaultDecorator::Draw()
// things // things
_DrawFrame(BRect(fTopBorder.LeftTop(), fBottomBorder.RightBottom())); _DrawFrame(BRect(fTopBorder.LeftTop(), fBottomBorder.RightBottom()));
_DrawTab(_tabrect); _DrawTab(fTabRect);
} }
// GetSizeLimits // GetSizeLimits
@@ -453,10 +453,10 @@ void
DefaultDecorator::GetSizeLimits(int32* minWidth, int32* minHeight, DefaultDecorator::GetSizeLimits(int32* minWidth, int32* minHeight,
int32* maxWidth, int32* maxHeight) const int32* maxWidth, int32* maxHeight) const
{ {
if (_tabrect.IsValid()) if (fTabRect.IsValid())
*minWidth = (int32)roundf(max_c(*minWidth, fMinTabSize - 2 * fBorderWidth)); *minWidth = (int32)roundf(max_c(*minWidth, fMinTabSize - 2 * fBorderWidth));
if (_resizerect.IsValid()) if (fResizeRect.IsValid())
*minHeight = (int32)roundf(max_c(*minHeight, _resizerect.Height() - fBorderWidth)); *minHeight = (int32)roundf(max_c(*minHeight, fResizeRect.Height() - fBorderWidth));
} }
// GetFootprint // GetFootprint
@@ -483,12 +483,12 @@ DefaultDecorator::GetFootprint(BRegion *region)
if (fLook == B_BORDERED_WINDOW_LOOK) if (fLook == B_BORDERED_WINDOW_LOOK)
return; return;
region->Include(_tabrect); region->Include(fTabRect);
if (fLook == B_DOCUMENT_WINDOW_LOOK) { if (fLook == B_DOCUMENT_WINDOW_LOOK) {
// include the rectangular resize knob on the bottom right // include the rectangular resize knob on the bottom right
region->Include(BRect(_frame.right - 13.0f, _frame.bottom - 13.0f, region->Include(BRect(fFrame.right - 13.0f, fFrame.bottom - 13.0f,
_frame.right, _frame.bottom)); fFrame.right, fFrame.bottom));
} }
} }
@@ -511,19 +511,19 @@ DefaultDecorator::Clicked(BPoint pt, int32 buttons, int32 modifiers)
// In checking for hit test stuff, we start with the smallest rectangles the user might // In checking for hit test stuff, we start with the smallest rectangles the user might
// be clicking on and gradually work our way out into larger rectangles. // be clicking on and gradually work our way out into larger rectangles.
if (!(fFlags & B_NOT_CLOSABLE) && _closerect.Contains(pt)) if (!(fFlags & B_NOT_CLOSABLE) && fCloseRect.Contains(pt))
return DEC_CLOSE; return DEC_CLOSE;
if (!(fFlags & B_NOT_ZOOMABLE) && _zoomrect.Contains(pt)) if (!(fFlags & B_NOT_ZOOMABLE) && fZoomRect.Contains(pt))
return DEC_ZOOM; return DEC_ZOOM;
if (fLook == B_DOCUMENT_WINDOW_LOOK && _resizerect.Contains(pt)) if (fLook == B_DOCUMENT_WINDOW_LOOK && fResizeRect.Contains(pt))
return DEC_RESIZE; return DEC_RESIZE;
bool clicked = false; bool clicked = false;
// Clicking in the tab? // Clicking in the tab?
if (_tabrect.Contains(pt)) { if (fTabRect.Contains(pt)) {
// tab sliding in any case if either shift key is held down // tab sliding in any case if either shift key is held down
// except sliding up-down by moving mouse left-right would look strange // except sliding up-down by moving mouse left-right would look strange
if ((modifiers & B_SHIFT_KEY) && (fLook != kLeftTitledWindowLook)) if ((modifiers & B_SHIFT_KEY) && (fLook != kLeftTitledWindowLook))
@@ -610,26 +610,26 @@ DefaultDecorator::_DoLayout()
fDrawState.Font().GetHeight(fontHeight); fDrawState.Font().GetHeight(fontHeight);
if (fLook != kLeftTitledWindowLook) { if (fLook != kLeftTitledWindowLook) {
_tabrect.Set(_frame.left - fBorderWidth, fTabRect.Set(fFrame.left - fBorderWidth,
_frame.top - fBorderWidth - ceilf(fontHeight.ascent + fontHeight.descent + 7.0), fFrame.top - fBorderWidth - ceilf(fontHeight.ascent + fontHeight.descent + 7.0),
((_frame.right - _frame.left) < 35.0 ? ((fFrame.right - fFrame.left) < 35.0 ?
_frame.left + 35.0 : _frame.right) + fBorderWidth, fFrame.left + 35.0 : fFrame.right) + fBorderWidth,
_frame.top - fBorderWidth); fFrame.top - fBorderWidth);
} else { } else {
_tabrect.Set(_frame.left - fBorderWidth - ceilf(fontHeight.ascent + fontHeight.descent + 5.0), fTabRect.Set(fFrame.left - fBorderWidth - ceilf(fontHeight.ascent + fontHeight.descent + 5.0),
_frame.top - fBorderWidth, _frame.left - fBorderWidth, fFrame.top - fBorderWidth, fFrame.left - fBorderWidth,
_frame.bottom + fBorderWidth); fFrame.bottom + fBorderWidth);
} }
// format tab rect for a floating window - make the rect smaller // format tab rect for a floating window - make the rect smaller
if (fLook == B_FLOATING_WINDOW_LOOK) { if (fLook == B_FLOATING_WINDOW_LOOK) {
_tabrect.InsetBy(0, 2); fTabRect.InsetBy(0, 2);
_tabrect.OffsetBy(0, 2); fTabRect.OffsetBy(0, 2);
} }
float offset; float offset;
float size; float size;
_GetButtonSizeAndOffset(_tabrect, &offset, &size); _GetButtonSizeAndOffset(fTabRect, &offset, &size);
// fMinTabSize contains just the room for the buttons // fMinTabSize contains just the room for the buttons
fMinTabSize = 4.0 + fTextOffset; fMinTabSize = 4.0 + fTextOffset;
@@ -639,13 +639,13 @@ DefaultDecorator::_DoLayout()
fMinTabSize += offset + size; fMinTabSize += offset + size;
// fMaxTabSize contains fMinWidth + the width required for the title // fMaxTabSize contains fMinWidth + the width required for the title
fMaxTabSize = _driver ? ceilf(_driver->StringWidth(Title(), strlen(Title()), fMaxTabSize = fDrawingEngine ? ceilf(fDrawingEngine->StringWidth(Title(), strlen(Title()),
&fDrawState)) : 0.0; &fDrawState)) : 0.0;
if (fMaxTabSize > 0.0) if (fMaxTabSize > 0.0)
fMaxTabSize += fTextOffset; fMaxTabSize += fTextOffset;
fMaxTabSize += fMinTabSize; fMaxTabSize += fMinTabSize;
float tabSize = fLook != kLeftTitledWindowLook ? _frame.Width() : _frame.Height(); float tabSize = fLook != kLeftTitledWindowLook ? fFrame.Width() : fFrame.Height();
if (tabSize < fMinTabSize) if (tabSize < fMinTabSize)
tabSize = fMinTabSize; tabSize = fMinTabSize;
if (tabSize > fMaxTabSize) if (tabSize > fMaxTabSize)
@@ -653,33 +653,33 @@ DefaultDecorator::_DoLayout()
// layout buttons and truncate text // layout buttons and truncate text
if (fLook != kLeftTitledWindowLook) if (fLook != kLeftTitledWindowLook)
_tabrect.right = _tabrect.left + tabSize; fTabRect.right = fTabRect.left + tabSize;
else else
_tabrect.bottom = _tabrect.top + tabSize; fTabRect.bottom = fTabRect.top + tabSize;
} else { } else {
// no tab // no tab
fMinTabSize = 0.0; fMinTabSize = 0.0;
fMaxTabSize = 0.0; fMaxTabSize = 0.0;
_tabrect.Set(0.0, 0.0, -1.0, -1.0); fTabRect.Set(0.0, 0.0, -1.0, -1.0);
_closerect.Set(0.0, 0.0, -1.0, -1.0); fCloseRect.Set(0.0, 0.0, -1.0, -1.0);
_zoomrect.Set(0.0, 0.0, -1.0, -1.0); fZoomRect.Set(0.0, 0.0, -1.0, -1.0);
} }
// calculate left/top/right/bottom borders // calculate left/top/right/bottom borders
if (fBorderWidth > 0) { if (fBorderWidth > 0) {
// NOTE: no overlapping, the left and right border rects // NOTE: no overlapping, the left and right border rects
// don't include the corners! // don't include the corners!
fLeftBorder.Set(_frame.left - fBorderWidth, _frame.top, fLeftBorder.Set(fFrame.left - fBorderWidth, fFrame.top,
_frame.left - 1, _frame.bottom); fFrame.left - 1, fFrame.bottom);
fRightBorder.Set(_frame.right + 1, _frame.top , fRightBorder.Set(fFrame.right + 1, fFrame.top ,
_frame.right + fBorderWidth, _frame.bottom); fFrame.right + fBorderWidth, fFrame.bottom);
fTopBorder.Set(_frame.left - fBorderWidth, _frame.top - fBorderWidth, fTopBorder.Set(fFrame.left - fBorderWidth, fFrame.top - fBorderWidth,
_frame.right + fBorderWidth, _frame.top - 1); fFrame.right + fBorderWidth, fFrame.top - 1);
fBottomBorder.Set(_frame.left - fBorderWidth, _frame.bottom + 1, fBottomBorder.Set(fFrame.left - fBorderWidth, fFrame.bottom + 1,
_frame.right + fBorderWidth, _frame.bottom + fBorderWidth); fFrame.right + fBorderWidth, fFrame.bottom + fBorderWidth);
} else { } else {
// no border // no border
fLeftBorder.Set(0.0, 0.0, -1.0, -1.0); fLeftBorder.Set(0.0, 0.0, -1.0, -1.0);
@@ -689,21 +689,21 @@ DefaultDecorator::_DoLayout()
} }
// calculate resize rect // calculate resize rect
_resizerect.Set(fBottomBorder.right - 18.0, fBottomBorder.bottom - 18.0, fResizeRect.Set(fBottomBorder.right - 18.0, fBottomBorder.bottom - 18.0,
fBottomBorder.right, fBottomBorder.bottom); fBottomBorder.right, fBottomBorder.bottom);
if (hasTab) { if (hasTab) {
// make sure fTabOffset is within limits and apply it to // make sure fTabOffset is within limits and apply it to
// the _tabrect // the fTabRect
if (fTabOffset < 0) if (fTabOffset < 0)
fTabOffset = 0; fTabOffset = 0;
if (fTabLocation != 0.0 if (fTabLocation != 0.0
&& fTabOffset > (fRightBorder.right - fLeftBorder.left - _tabrect.Width())) && fTabOffset > (fRightBorder.right - fLeftBorder.left - fTabRect.Width()))
fTabOffset = uint32(fRightBorder.right - fLeftBorder.left - _tabrect.Width()); fTabOffset = uint32(fRightBorder.right - fLeftBorder.left - fTabRect.Width());
_tabrect.OffsetBy(fTabOffset, 0); fTabRect.OffsetBy(fTabOffset, 0);
// finally, layout the buttons and text within the tab rect // finally, layout the buttons and text within the tab rect
_LayoutTabItems(_tabrect); _LayoutTabItems(fTabRect);
} }
} }
@@ -733,21 +733,21 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// top // top
if (invalid.Intersects(fTopBorder)) { if (invalid.Intersects(fTopBorder)) {
for (int8 i = 0; i < 5; i++) { for (int8 i = 0; i < 5; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.top + i),
BPoint(r.right - i, r.top + i), BPoint(r.right - i, r.top + i),
fFrameColors[i]); fFrameColors[i]);
} }
if (_tabrect.IsValid()) { if (fTabRect.IsValid()) {
// grey along the bottom of the tab (overwrites "white" from frame) // grey along the bottom of the tab (overwrites "white" from frame)
_driver->StrokeLine(BPoint(_tabrect.left + 2, _tabrect.bottom + 1), fDrawingEngine->StrokeLine(BPoint(fTabRect.left + 2, fTabRect.bottom + 1),
BPoint(_tabrect.right - 2, _tabrect.bottom + 1), BPoint(fTabRect.right - 2, fTabRect.bottom + 1),
fFrameColors[2]); fFrameColors[2]);
} }
} }
// left // left
if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) { if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) {
for (int8 i = 0; i < 5; i++) { for (int8 i = 0; i < 5; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.top + i),
BPoint(r.left + i, r.bottom - i), BPoint(r.left + i, r.bottom - i),
fFrameColors[i]); fFrameColors[i]);
} }
@@ -755,7 +755,7 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// bottom // bottom
if (invalid.Intersects(fBottomBorder)) { if (invalid.Intersects(fBottomBorder)) {
for (int8 i = 0; i < 5; i++) { for (int8 i = 0; i < 5; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.bottom - i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.bottom - i),
BPoint(r.right - i, r.bottom - i), BPoint(r.right - i, r.bottom - i),
fFrameColors[(4 - i) == 4 ? 5 : (4 - i)]); fFrameColors[(4 - i) == 4 ? 5 : (4 - i)]);
} }
@@ -763,7 +763,7 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// right // right
if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) { if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) {
for (int8 i = 0; i < 5; i++) { for (int8 i = 0; i < 5; i++) {
_driver->StrokeLine(BPoint(r.right - i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.right - i, r.top + i),
BPoint(r.right - i, r.bottom - i), BPoint(r.right - i, r.bottom - i),
fFrameColors[(4 - i) == 4 ? 5 : (4 - i)]); fFrameColors[(4 - i) == 4 ? 5 : (4 - i)]);
} }
@@ -777,35 +777,35 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// top // top
if (invalid.Intersects(fTopBorder)) { if (invalid.Intersects(fTopBorder)) {
for (int8 i = 0; i < 3; i++) { for (int8 i = 0; i < 3; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.top + i),
BPoint(r.right - i, r.top + i), BPoint(r.right - i, r.top + i),
fFrameColors[i * 2]); fFrameColors[i * 2]);
} }
if (_tabrect.IsValid() && fLook != kLeftTitledWindowLook) { if (fTabRect.IsValid() && fLook != kLeftTitledWindowLook) {
// grey along the bottom of the tab (overwrites "white" from frame) // grey along the bottom of the tab (overwrites "white" from frame)
_driver->StrokeLine(BPoint(_tabrect.left + 2, _tabrect.bottom + 1), fDrawingEngine->StrokeLine(BPoint(fTabRect.left + 2, fTabRect.bottom + 1),
BPoint(_tabrect.right - 2, _tabrect.bottom + 1), BPoint(fTabRect.right - 2, fTabRect.bottom + 1),
fFrameColors[2]); fFrameColors[2]);
} }
} }
// left // left
if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) { if (invalid.Intersects(fLeftBorder.InsetByCopy(0, -fBorderWidth))) {
for (int8 i = 0; i < 3; i++) { for (int8 i = 0; i < 3; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.top + i),
BPoint(r.left + i, r.bottom - i), BPoint(r.left + i, r.bottom - i),
fFrameColors[i * 2]); fFrameColors[i * 2]);
} }
if (fLook == kLeftTitledWindowLook && _tabrect.IsValid()) { if (fLook == kLeftTitledWindowLook && fTabRect.IsValid()) {
// grey along the right side of the tab (overwrites "white" from frame) // grey along the right side of the tab (overwrites "white" from frame)
_driver->StrokeLine(BPoint(_tabrect.right + 1, _tabrect.top + 2), fDrawingEngine->StrokeLine(BPoint(fTabRect.right + 1, fTabRect.top + 2),
BPoint(_tabrect.right + 1, _tabrect.bottom - 2), BPoint(fTabRect.right + 1, fTabRect.bottom - 2),
fFrameColors[2]); fFrameColors[2]);
} }
} }
// bottom // bottom
if (invalid.Intersects(fBottomBorder)) { if (invalid.Intersects(fBottomBorder)) {
for (int8 i = 0; i < 3; i++) { for (int8 i = 0; i < 3; i++) {
_driver->StrokeLine(BPoint(r.left + i, r.bottom - i), fDrawingEngine->StrokeLine(BPoint(r.left + i, r.bottom - i),
BPoint(r.right - i, r.bottom - i), BPoint(r.right - i, r.bottom - i),
fFrameColors[(2 - i) == 2 ? 5 : (2 - i) * 2]); fFrameColors[(2 - i) == 2 ? 5 : (2 - i) * 2]);
} }
@@ -813,7 +813,7 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// right // right
if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) { if (invalid.Intersects(fRightBorder.InsetByCopy(0, -fBorderWidth))) {
for (int8 i = 0; i < 3; i++) { for (int8 i = 0; i < 3; i++) {
_driver->StrokeLine(BPoint(r.right - i, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.right - i, r.top + i),
BPoint(r.right - i, r.bottom - i), BPoint(r.right - i, r.bottom - i),
fFrameColors[(2 - i) == 2 ? 5 : (2 - i) * 2]); fFrameColors[(2 - i) == 2 ? 5 : (2 - i) * 2]);
} }
@@ -822,7 +822,7 @@ DefaultDecorator::_DrawFrame(BRect invalid)
} }
case B_BORDERED_WINDOW_LOOK: case B_BORDERED_WINDOW_LOOK:
_driver->StrokeRect(r, fFrameColors[5]); fDrawingEngine->StrokeRect(r, fFrameColors[5]);
break; break;
default: default:
@@ -832,7 +832,7 @@ DefaultDecorator::_DrawFrame(BRect invalid)
// Draw the resize thumb if we're supposed to // Draw the resize thumb if we're supposed to
if (!(fFlags & B_NOT_RESIZABLE)) { if (!(fFlags & B_NOT_RESIZABLE)) {
r = _resizerect; r = fResizeRect;
switch (fLook) { switch (fLook) {
case B_DOCUMENT_WINDOW_LOOK: case B_DOCUMENT_WINDOW_LOOK:
@@ -843,14 +843,14 @@ DefaultDecorator::_DrawFrame(BRect invalid)
float x = r.right - 3; float x = r.right - 3;
float y = r.bottom - 3; float y = r.bottom - 3;
_driver->FillRect(BRect(x - 13, y - 13, x, y), fFrameColors[2]); fDrawingEngine->FillRect(BRect(x - 13, y - 13, x, y), fFrameColors[2]);
_driver->StrokeLine(BPoint(x - 15, y - 15), BPoint(x - 15, y - 2), fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), BPoint(x - 15, y - 2),
fFrameColors[0]); fFrameColors[0]);
_driver->StrokeLine(BPoint(x - 14, y - 14), BPoint(x - 14, y - 1), fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), BPoint(x - 14, y - 1),
fFrameColors[1]); fFrameColors[1]);
_driver->StrokeLine(BPoint(x - 15, y - 15), BPoint(x - 2, y - 15), fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), BPoint(x - 2, y - 15),
fFrameColors[0]); fFrameColors[0]);
_driver->StrokeLine(BPoint(x - 14, y - 14), BPoint(x - 1, y - 14), fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), BPoint(x - 1, y - 14),
fFrameColors[1]); fFrameColors[1]);
if (!IsFocus()) if (!IsFocus())
@@ -860,8 +860,8 @@ DefaultDecorator::_DrawFrame(BRect invalid)
for (int8 j = 1; j <= i; j++) { for (int8 j = 1; j <= i; j++) {
BPoint pt1(x - (3 * j) + 1, y - (3 * (5 - i)) + 1); BPoint pt1(x - (3 * j) + 1, y - (3 * (5 - i)) + 1);
BPoint pt2(x - (3 * j) + 2, y - (3 * (5 - i)) + 2); BPoint pt2(x - (3 * j) + 2, y - (3 * (5 - i)) + 2);
_driver->StrokePoint(pt1, fFrameColors[0]); fDrawingEngine->StrokePoint(pt1, fFrameColors[0]);
_driver->StrokePoint(pt2, fFrameColors[1]); fDrawingEngine->StrokePoint(pt2, fFrameColors[1]);
} }
} }
break; break;
@@ -877,10 +877,10 @@ DefaultDecorator::_DrawFrame(BRect invalid)
fBottomBorder.bottom - 1))) fBottomBorder.bottom - 1)))
break; break;
_driver->StrokeLine(BPoint(fRightBorder.left, fBottomBorder.bottom - 22), fDrawingEngine->StrokeLine(BPoint(fRightBorder.left, fBottomBorder.bottom - 22),
BPoint(fRightBorder.right - 1, fBottomBorder.bottom - 22), BPoint(fRightBorder.right - 1, fBottomBorder.bottom - 22),
fFrameColors[0]); fFrameColors[0]);
_driver->StrokeLine(BPoint(fRightBorder.right - 22, fBottomBorder.top), fDrawingEngine->StrokeLine(BPoint(fRightBorder.right - 22, fBottomBorder.top),
BPoint(fRightBorder.right - 22, fBottomBorder.bottom - 1), BPoint(fRightBorder.right - 22, fBottomBorder.bottom - 1),
fFrameColors[0]); fFrameColors[0]);
break; break;
@@ -901,7 +901,7 @@ DefaultDecorator::_DrawTab(BRect invalid)
invalid.left, invalid.top, invalid.right, invalid.bottom)); invalid.left, invalid.top, invalid.right, invalid.bottom));
// If a window has a tab, this will draw it and any buttons which are // If a window has a tab, this will draw it and any buttons which are
// in it. // in it.
if (!_tabrect.IsValid() || !invalid.Intersects(_tabrect)) if (!fTabRect.IsValid() || !invalid.Intersects(fTabRect))
return; return;
// TODO: cache these // TODO: cache these
@@ -911,45 +911,45 @@ DefaultDecorator::_DrawTab(BRect invalid)
B_DARKEN_2_TINT)); B_DARKEN_2_TINT));
// outer frame // outer frame
_driver->StrokeLine(_tabrect.LeftTop(), _tabrect.LeftBottom(), fFrameColors[0]); fDrawingEngine->StrokeLine(fTabRect.LeftTop(), fTabRect.LeftBottom(), fFrameColors[0]);
_driver->StrokeLine(_tabrect.LeftTop(), _tabrect.RightTop(), fFrameColors[0]); fDrawingEngine->StrokeLine(fTabRect.LeftTop(), fTabRect.RightTop(), fFrameColors[0]);
if (fLook != kLeftTitledWindowLook) if (fLook != kLeftTitledWindowLook)
_driver->StrokeLine(_tabrect.RightTop(),_tabrect.RightBottom(), fFrameColors[5]); fDrawingEngine->StrokeLine(fTabRect.RightTop(),fTabRect.RightBottom(), fFrameColors[5]);
else else
_driver->StrokeLine(_tabrect.LeftBottom(),_tabrect.RightBottom(), fFrameColors[5]); fDrawingEngine->StrokeLine(fTabRect.LeftBottom(),fTabRect.RightBottom(), fFrameColors[5]);
// bevel // bevel
_driver->StrokeLine(BPoint(_tabrect.left + 1, _tabrect.top + 1), fDrawingEngine->StrokeLine(BPoint(fTabRect.left + 1, fTabRect.top + 1),
BPoint(_tabrect.left + 1, _tabrect.bottom - (fLook == kLeftTitledWindowLook ? 1 : 0)), BPoint(fTabRect.left + 1, fTabRect.bottom - (fLook == kLeftTitledWindowLook ? 1 : 0)),
tabColorLight); tabColorLight);
_driver->StrokeLine(BPoint(_tabrect.left + 1, _tabrect.top + 1), fDrawingEngine->StrokeLine(BPoint(fTabRect.left + 1, fTabRect.top + 1),
BPoint(_tabrect.right - (fLook == kLeftTitledWindowLook ? 0 : 1), _tabrect.top + 1), BPoint(fTabRect.right - (fLook == kLeftTitledWindowLook ? 0 : 1), fTabRect.top + 1),
tabColorLight); tabColorLight);
if (fLook != kLeftTitledWindowLook) { if (fLook != kLeftTitledWindowLook) {
_driver->StrokeLine(BPoint(_tabrect.right - 1, _tabrect.top + 2), fDrawingEngine->StrokeLine(BPoint(fTabRect.right - 1, fTabRect.top + 2),
BPoint(_tabrect.right - 1, _tabrect.bottom), tabColorShadow); BPoint(fTabRect.right - 1, fTabRect.bottom), tabColorShadow);
} else { } else {
_driver->StrokeLine(BPoint(_tabrect.left + 2, _tabrect.bottom - 1), fDrawingEngine->StrokeLine(BPoint(fTabRect.left + 2, fTabRect.bottom - 1),
BPoint(_tabrect.right, _tabrect.bottom - 1), tabColorShadow); BPoint(fTabRect.right, fTabRect.bottom - 1), tabColorShadow);
} }
// fill // fill
if (fLook != kLeftTitledWindowLook) { if (fLook != kLeftTitledWindowLook) {
_driver->FillRect(BRect(_tabrect.left + 2, _tabrect.top + 2, fDrawingEngine->FillRect(BRect(fTabRect.left + 2, fTabRect.top + 2,
_tabrect.right - 2, _tabrect.bottom), fTabColor); fTabRect.right - 2, fTabRect.bottom), fTabColor);
} else { } else {
_driver->FillRect(BRect(_tabrect.left + 2, _tabrect.top + 2, fDrawingEngine->FillRect(BRect(fTabRect.left + 2, fTabRect.top + 2,
_tabrect.right, _tabrect.bottom - 2), fTabColor); fTabRect.right, fTabRect.bottom - 2), fTabColor);
} }
_DrawTitle(_tabrect); _DrawTitle(fTabRect);
// Draw the buttons if we're supposed to // Draw the buttons if we're supposed to
if (!(fFlags & B_NOT_CLOSABLE) && invalid.Intersects(_closerect)) if (!(fFlags & B_NOT_CLOSABLE) && invalid.Intersects(fCloseRect))
_DrawClose(_closerect); _DrawClose(fCloseRect);
if (!(fFlags & B_NOT_ZOOMABLE) && invalid.Intersects(_zoomrect)) if (!(fFlags & B_NOT_ZOOMABLE) && invalid.Intersects(fZoomRect))
_DrawZoom(_zoomrect); _DrawZoom(fZoomRect);
} }
// _DrawClose // _DrawClose
@@ -976,18 +976,18 @@ DefaultDecorator::_DrawTitle(BRect r)
BPoint titlePos; BPoint titlePos;
if (fLook != kLeftTitledWindowLook) { if (fLook != kLeftTitledWindowLook) {
titlePos.x = _closerect.IsValid() ? _closerect.right + fTextOffset titlePos.x = fCloseRect.IsValid() ? fCloseRect.right + fTextOffset
: _tabrect.left + fTextOffset; : fTabRect.left + fTextOffset;
titlePos.y = floorf(((_tabrect.top + 2.0) + _tabrect.bottom + fontHeight.ascent titlePos.y = floorf(((fTabRect.top + 2.0) + fTabRect.bottom + fontHeight.ascent
+ fontHeight.descent) / 2.0 - fontHeight.descent + 0.5); + fontHeight.descent) / 2.0 - fontHeight.descent + 0.5);
} else { } else {
titlePos.x = floorf(((_tabrect.left + 2.0) + _tabrect.right + fontHeight.ascent titlePos.x = floorf(((fTabRect.left + 2.0) + fTabRect.right + fontHeight.ascent
+ fontHeight.descent) / 2.0 - fontHeight.descent + 0.5); + fontHeight.descent) / 2.0 - fontHeight.descent + 0.5);
titlePos.y = _zoomrect.IsValid() ? _zoomrect.top - fTextOffset titlePos.y = fZoomRect.IsValid() ? fZoomRect.top - fTextOffset
: _tabrect.bottom - fTextOffset; : fTabRect.bottom - fTextOffset;
} }
_driver->DrawString(fTruncatedTitle.String(), fTruncatedTitleLength, titlePos, &fDrawState); fDrawingEngine->DrawString(fTruncatedTitle.String(), fTruncatedTitleLength, titlePos, &fDrawState);
} }
// _DrawZoom // _DrawZoom
@@ -1088,17 +1088,17 @@ DefaultDecorator::_DrawBlendedRect(BRect r, bool down)
uint8(startColor.green - (i * gstep)), uint8(startColor.green - (i * gstep)),
uint8(startColor.blue - (i * bstep))); uint8(startColor.blue - (i * bstep)));
_driver->StrokeLine(BPoint(r.left, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left, r.top + i),
BPoint(r.left + i, r.top), temprgbcol); BPoint(r.left + i, r.top), temprgbcol);
temprgbcol.SetColor(uint8(halfColor.red - (i * rstep)), temprgbcol.SetColor(uint8(halfColor.red - (i * rstep)),
uint8(halfColor.green - (i * gstep)), uint8(halfColor.green - (i * gstep)),
uint8(halfColor.blue - (i * bstep))); uint8(halfColor.blue - (i * bstep)));
_driver->StrokeLine(BPoint(r.left + steps, r.top + i), fDrawingEngine->StrokeLine(BPoint(r.left + steps, r.top + i),
BPoint(r.left + i, r.top + steps), temprgbcol); BPoint(r.left + i, r.top + steps), temprgbcol);
} }
_driver->StrokeRect(r, fFrameColors[3]); fDrawingEngine->StrokeRect(r, fFrameColors[3]);
} }
// _GetButtonSizeAndOffset // _GetButtonSizeAndOffset
@@ -1126,29 +1126,29 @@ DefaultDecorator::_LayoutTabItems(const BRect& tabRect)
// calulate close rect based on the tab rectangle // calulate close rect based on the tab rectangle
if (fLook != kLeftTitledWindowLook) { if (fLook != kLeftTitledWindowLook) {
_closerect.Set(tabRect.left + offset, tabRect.top + offset, fCloseRect.Set(tabRect.left + offset, tabRect.top + offset,
tabRect.left + offset + size, tabRect.top + offset + size); tabRect.left + offset + size, tabRect.top + offset + size);
_zoomrect.Set(tabRect.right - offset - size, tabRect.top + offset, fZoomRect.Set(tabRect.right - offset - size, tabRect.top + offset,
tabRect.right - offset, tabRect.top + offset + size); tabRect.right - offset, tabRect.top + offset + size);
// hidden buttons have no width // hidden buttons have no width
if ((Flags() & B_NOT_CLOSABLE) != 0) if ((Flags() & B_NOT_CLOSABLE) != 0)
_closerect.right = _closerect.left - offset; fCloseRect.right = fCloseRect.left - offset;
if ((Flags() & B_NOT_ZOOMABLE) != 0) if ((Flags() & B_NOT_ZOOMABLE) != 0)
_zoomrect.left = _zoomrect.right + offset; fZoomRect.left = fZoomRect.right + offset;
} else { } else {
_closerect.Set(tabRect.left + offset, tabRect.top + offset, fCloseRect.Set(tabRect.left + offset, tabRect.top + offset,
tabRect.left + offset + size, tabRect.top + offset + size); tabRect.left + offset + size, tabRect.top + offset + size);
_zoomrect.Set(tabRect.left + offset, tabRect.bottom - offset - size, fZoomRect.Set(tabRect.left + offset, tabRect.bottom - offset - size,
tabRect.left + size + offset, tabRect.bottom - offset); tabRect.left + size + offset, tabRect.bottom - offset);
// hidden buttons have no height // hidden buttons have no height
if ((Flags() & B_NOT_CLOSABLE) != 0) if ((Flags() & B_NOT_CLOSABLE) != 0)
_closerect.bottom = _closerect.top - offset; fCloseRect.bottom = fCloseRect.top - offset;
if ((Flags() & B_NOT_ZOOMABLE) != 0) if ((Flags() & B_NOT_ZOOMABLE) != 0)
_zoomrect.top = _zoomrect.bottom + offset; fZoomRect.top = fZoomRect.bottom + offset;
} }
// calculate room for title // calculate room for title
@@ -1156,9 +1156,9 @@ DefaultDecorator::_LayoutTabItems(const BRect& tabRect)
// truncated for no apparent reason - OTOH the title does // truncated for no apparent reason - OTOH the title does
// also not appear perfectly in the middle // also not appear perfectly in the middle
if (fLook != kLeftTitledWindowLook) if (fLook != kLeftTitledWindowLook)
size = (_zoomrect.left - _closerect.right) - fTextOffset * 2 + 2; size = (fZoomRect.left - fCloseRect.right) - fTextOffset * 2 + 2;
else else
size = (_zoomrect.top - _closerect.bottom) - fTextOffset * 2 + 2; size = (fZoomRect.top - fCloseRect.bottom) - fTextOffset * 2 + 2;
fTruncatedTitle = Title(); fTruncatedTitle = Title();
fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END, size); fDrawState.Font().TruncateString(&fTruncatedTitle, B_TRUNCATE_END, size);
+2 -2
View File
@@ -2315,11 +2315,11 @@ Desktop::_SetBackground(BRegion& background)
dirtyBackground.IntersectWith(&background); dirtyBackground.IntersectWith(&background);
fBackgroundRegion = background; fBackgroundRegion = background;
if (dirtyBackground.Frame().IsValid()) { if (dirtyBackground.Frame().IsValid()) {
if (GetDrawingEngine()->Lock()) { if (GetDrawingEngine()->LockParallelAccess()) {
GetDrawingEngine()->FillRegion(dirtyBackground, GetDrawingEngine()->FillRegion(dirtyBackground,
fWorkspaces[fCurrentWorkspace].Color()); fWorkspaces[fCurrentWorkspace].Color());
GetDrawingEngine()->Unlock(); GetDrawingEngine()->UnlockParallelAccess();
} }
} }
} }
+1
View File
@@ -10,6 +10,7 @@ UseFreeTypeHeaders ;
Server app_server : Server app_server :
Angle.cpp Angle.cpp
AppServer.cpp AppServer.cpp
BitfieldRegion.cpp
BitmapManager.cpp BitmapManager.cpp
ClientMemoryAllocator.cpp ClientMemoryAllocator.cpp
CursorData.cpp CursorData.cpp
+10 -2
View File
@@ -115,19 +115,27 @@ class AutoReadLocker {
AutoReadLocker(MultiLocker* lock) AutoReadLocker(MultiLocker* lock)
: fLock(*lock) : fLock(*lock)
{ {
fLock.ReadLock(); fLocked = fLock.ReadLock();
} }
AutoReadLocker(MultiLocker& lock) AutoReadLocker(MultiLocker& lock)
: fLock(lock) : fLock(lock)
{ {
fLock.ReadLock(); fLocked = fLock.ReadLock();
} }
~AutoReadLocker() ~AutoReadLocker()
{ {
Unlock();
}
void Unlock()
{
if (fLocked) {
fLock.ReadUnlock(); fLock.ReadUnlock();
fLocked = false;
}
} }
private: private:
MultiLocker& fLock; MultiLocker& fLock;
bool fLocked;
}; };
+2 -2
View File
@@ -39,11 +39,11 @@ OffscreenWindowLayer::OffscreenWindowLayer(ServerBitmap* bitmap,
OffscreenWindowLayer::~OffscreenWindowLayer() OffscreenWindowLayer::~OffscreenWindowLayer()
{ {
fHWInterface->WriteLock(); fHWInterface->LockExclusiveAccess();
// Unlike normal Layers, we own the DrawingEngine instance // Unlike normal Layers, we own the DrawingEngine instance
delete GetDrawingEngine(); delete GetDrawingEngine();
fHWInterface->Shutdown(); fHWInterface->Shutdown();
fHWInterface->WriteUnlock(); fHWInterface->UnlockExclusiveAccess();
delete fHWInterface; delete fHWInterface;
} }
+7 -8
View File
@@ -1966,10 +1966,8 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li
return; return;
} }
// prevent other ServerWindows from messing with the drawing engine drawingEngine->LockParallelAccess();
// as long as each uses the same instance... TODO: remove the locking // TODO: avoid setting the region each time
// when each has its own
drawingEngine->Lock();
drawingEngine->ConstrainClippingRegion(&fCurrentDrawingRegion); drawingEngine->ConstrainClippingRegion(&fCurrentDrawingRegion);
switch (code) { switch (code) {
@@ -2288,7 +2286,7 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li
break; break;
} }
drawingEngine->Unlock(); drawingEngine->UnlockParallelAccess();
} }
@@ -2698,7 +2696,8 @@ ServerWindow::MakeWindowLayer(BRect frame, const char* name,
{ {
// The non-offscreen ServerWindow uses the DrawingEngine instance from the desktop. // The non-offscreen ServerWindow uses the DrawingEngine instance from the desktop.
return new (nothrow) WindowLayer(frame, name, look, feel, flags, return new (nothrow) WindowLayer(frame, name, look, feel, flags,
workspace, this, fDesktop->GetDrawingEngine()); // workspace, this, fDesktop->GetDrawingEngine());
workspace, this, new DrawingEngine(fDesktop->HWInterface()));
} }
@@ -2830,7 +2829,7 @@ ServerWindow::_SetCurrentLayer(ViewLayer* layer)
#if DELAYED_BACKGROUND_CLEARING #if DELAYED_BACKGROUND_CLEARING
if (fCurrentLayer && fCurrentLayer->IsBackgroundDirty() && fWindowLayer->InUpdate()) { if (fCurrentLayer && fCurrentLayer->IsBackgroundDirty() && fWindowLayer->InUpdate()) {
DrawingEngine* drawingEngine = fWindowLayer->GetDrawingEngine(); DrawingEngine* drawingEngine = fWindowLayer->GetDrawingEngine();
if (drawingEngine->Lock()) { if (drawingEngine->LockParallelAccess()) {
fWindowLayer->GetEffectiveDrawingRegion(fCurrentLayer, fCurrentDrawingRegion); fWindowLayer->GetEffectiveDrawingRegion(fCurrentLayer, fCurrentDrawingRegion);
fCurrentDrawingRegionValid = true; fCurrentDrawingRegionValid = true;
@@ -2841,7 +2840,7 @@ ServerWindow::_SetCurrentLayer(ViewLayer* layer)
fCurrentLayer->Draw(drawingEngine, &dirty, &content, false); fCurrentLayer->Draw(drawingEngine, &dirty, &content, false);
drawingEngine->Unlock(); drawingEngine->UnlockParallelAccess();
} }
} }
#endif #endif
+6 -1
View File
@@ -1354,7 +1354,12 @@ ViewLayer::AddTokensForLayersInRegion(BPrivate::PortLink& link,
if (!fVisible) if (!fVisible)
return; return;
if (region.Intersects(ScreenClipping(windowContentClipping).Frame())) // if (region.Intersects(ScreenClipping(windowContentClipping).Frame()))
IntRect screenBounds(Bounds());
ConvertToScreen(&screenBounds);
if (!region.Intersects((clipping_rect)screenBounds))
return;
link.Attach<int32>(fToken); link.Attach<int32>(fToken);
for (ViewLayer* child = FirstChild(); child; child = child->NextSibling()) for (ViewLayer* child = FirstChild(); child; child = child->NextSibling())
+33 -17
View File
@@ -796,8 +796,9 @@ WindowLayer::MouseDown(BMessage* message, BPoint where, int32* _viewToken)
GetBorderRegion(visibleBorder); GetBorderRegion(visibleBorder);
visibleBorder->IntersectWith(&VisibleRegion()); visibleBorder->IntersectWith(&VisibleRegion());
fDrawingEngine->Lock(); DrawingEngine* engine = fDecorator->GetDrawingEngine();
fDrawingEngine->ConstrainClippingRegion(visibleBorder); engine->LockExclusiveAccess();
engine->ConstrainClippingRegion(visibleBorder);
if (fIsZooming) { if (fIsZooming) {
fDecorator->SetZoom(true); fDecorator->SetZoom(true);
@@ -807,7 +808,7 @@ WindowLayer::MouseDown(BMessage* message, BPoint where, int32* _viewToken)
fDecorator->SetMinimize(true); fDecorator->SetMinimize(true);
} }
fDrawingEngine->Unlock(); engine->UnlockExclusiveAccess();
fRegionPool.Recycle(visibleBorder); fRegionPool.Recycle(visibleBorder);
@@ -872,8 +873,9 @@ WindowLayer::MouseUp(BMessage* message, BPoint where, int32* _viewToken)
GetBorderRegion(visibleBorder); GetBorderRegion(visibleBorder);
visibleBorder->IntersectWith(&VisibleRegion()); visibleBorder->IntersectWith(&VisibleRegion());
fDrawingEngine->Lock(); DrawingEngine* engine = fDecorator->GetDrawingEngine();
fDrawingEngine->ConstrainClippingRegion(visibleBorder); engine->LockExclusiveAccess();
engine->ConstrainClippingRegion(visibleBorder);
if (fIsZooming) { if (fIsZooming) {
fIsZooming = false; fIsZooming = false;
@@ -900,7 +902,7 @@ WindowLayer::MouseUp(BMessage* message, BPoint where, int32* _viewToken)
} }
} }
fDrawingEngine->Unlock(); engine->UnlockExclusiveAccess();
fRegionPool.Recycle(visibleBorder); fRegionPool.Recycle(visibleBorder);
} }
@@ -959,8 +961,9 @@ WindowLayer::MouseMoved(BMessage *message, BPoint where, int32* _viewToken,
GetBorderRegion(visibleBorder); GetBorderRegion(visibleBorder);
visibleBorder->IntersectWith(&VisibleRegion()); visibleBorder->IntersectWith(&VisibleRegion());
fDrawingEngine->Lock(); DrawingEngine* engine = fDecorator->GetDrawingEngine();
fDrawingEngine->ConstrainClippingRegion(visibleBorder); engine->LockExclusiveAccess();
engine->ConstrainClippingRegion(visibleBorder);
if (fIsZooming) { if (fIsZooming) {
fDecorator->SetZoom(_ActionFor(message) == DEC_ZOOM); fDecorator->SetZoom(_ActionFor(message) == DEC_ZOOM);
@@ -970,7 +973,7 @@ WindowLayer::MouseMoved(BMessage *message, BPoint where, int32* _viewToken,
fDecorator->SetMinimize(_ActionFor(message) == DEC_MINIMIZE); fDecorator->SetMinimize(_ActionFor(message) == DEC_MINIMIZE);
} }
fDrawingEngine->Unlock(); engine->UnlockExclusiveAccess();
fRegionPool.Recycle(visibleBorder); fRegionPool.Recycle(visibleBorder);
} }
@@ -1737,14 +1740,14 @@ WindowLayer::_TriggerContentRedraw(BRegion& dirtyContentRegion)
backgroundClearingRegion = &fPendingUpdateSession.DirtyRegion(); backgroundClearingRegion = &fPendingUpdateSession.DirtyRegion();
} }
if (fDrawingEngine->Lock()) { if (fDrawingEngine->LockParallelAccess()) {
fDrawingEngine->SuspendAutoSync(); fDrawingEngine->SuspendAutoSync();
fTopLayer->Draw(fDrawingEngine, backgroundClearingRegion, fTopLayer->Draw(fDrawingEngine, backgroundClearingRegion,
&fContentRegion, true); &fContentRegion, true);
fDrawingEngine->Sync(); fDrawingEngine->Sync();
fDrawingEngine->Unlock(); fDrawingEngine->UnlockParallelAccess();
} }
} }
} }
@@ -1771,16 +1774,20 @@ WindowLayer::_DrawBorder()
// intersect with the dirty region // intersect with the dirty region
dirtyBorderRegion->IntersectWith(&fDirtyRegion); dirtyBorderRegion->IntersectWith(&fDirtyRegion);
if (dirtyBorderRegion->CountRects() > 0 && fDrawingEngine->Lock()) { DrawingEngine* engine = fDecorator->GetDrawingEngine();
fDrawingEngine->ConstrainClippingRegion(dirtyBorderRegion); if (dirtyBorderRegion->CountRects() > 0 && engine->LockExclusiveAccess()) {
engine->ConstrainClippingRegion(dirtyBorderRegion);
fDecorator->Draw(dirtyBorderRegion->Frame()); fDecorator->Draw(dirtyBorderRegion->Frame());
fDrawingEngine->Unlock(); engine->UnlockExclusiveAccess();
} }
fRegionPool.Recycle(dirtyBorderRegion); fRegionPool.Recycle(dirtyBorderRegion);
} }
//static rgb_color sPendingColor;
//static rgb_color sCurrentColor;
/*! /*!
pre: the clipping is readlocked (this function is pre: the clipping is readlocked (this function is
only called from _TriggerContentRedraw()), which only called from _TriggerContentRedraw()), which
@@ -1793,7 +1800,7 @@ WindowLayer::_TransferToUpdateSession(BRegion* contentDirtyRegion)
if (contentDirtyRegion->CountRects() <= 0) if (contentDirtyRegion->CountRects() <= 0)
return; return;
//fDrawingEngine->FillRegion(*contentDirtyRegion, RGBColor(255, 255, 0, 255)); //fDrawingEngine->FillRegion(*contentDirtyRegion, RGBColor(sPendingColor));
//snooze(10000); //snooze(10000);
// add to pending // add to pending
@@ -1873,6 +1880,15 @@ WindowLayer::BeginUpdate(BPrivate::PortLink& link)
dirty->IntersectWith(&VisibleContentRegion()); dirty->IntersectWith(&VisibleContentRegion());
//sCurrentColor.red = rand() % 255;
//sCurrentColor.green = rand() % 255;
//sCurrentColor.blue = rand() % 255;
//sPendingColor.red = rand() % 255;
//sPendingColor.green = rand() % 255;
//sPendingColor.blue = rand() % 255;
//fDrawingEngine->FillRegion(*dirty, RGBColor(sCurrentColor));
//snooze(10000);
link.StartMessage(B_OK); link.StartMessage(B_OK);
// append the current window geometry to the // append the current window geometry to the
// message, the client will need it // message, the client will need it
@@ -1888,7 +1904,7 @@ WindowLayer::BeginUpdate(BPrivate::PortLink& link)
link.Attach<int32>(B_NULL_TOKEN); link.Attach<int32>(B_NULL_TOKEN);
link.Flush(); link.Flush();
if (!fCurrentUpdateSession.IsExpose() && fDrawingEngine->Lock()) { if (!fCurrentUpdateSession.IsExpose() && fDrawingEngine->LockParallelAccess()) {
//fDrawingEngine->FillRegion(dirty, RGBColor(255, 0, 0, 255)); //fDrawingEngine->FillRegion(dirty, RGBColor(255, 0, 0, 255));
fDrawingEngine->SuspendAutoSync(); fDrawingEngine->SuspendAutoSync();
@@ -1896,7 +1912,7 @@ WindowLayer::BeginUpdate(BPrivate::PortLink& link)
&fContentRegion, true); &fContentRegion, true);
fDrawingEngine->Sync(); fDrawingEngine->Sync();
fDrawingEngine->Unlock(); fDrawingEngine->UnlockParallelAccess();
} // else the background was cleared already } // else the background was cleared already
fRegionPool.Recycle(dirty); fRegionPool.Recycle(dirty);
@@ -545,9 +545,9 @@ AccelerantHWInterface::SetMode(const display_mode& mode)
void void
AccelerantHWInterface::GetMode(display_mode *mode) AccelerantHWInterface::GetMode(display_mode *mode)
{ {
if (mode && ReadLock()) { if (mode && LockParallelAccess()) {
*mode = fDisplayMode; *mode = fDisplayMode;
ReadUnlock(); UnlockParallelAccess();
} }
} }
@@ -997,13 +997,13 @@ void
AccelerantHWInterface::SetCursor(ServerCursor* cursor) AccelerantHWInterface::SetCursor(ServerCursor* cursor)
{ {
HWInterface::SetCursor(cursor); HWInterface::SetCursor(cursor);
// if (WriteLock()) { // if (LockExclusiveAccess()) {
// TODO: implement setting the hard ware cursor // TODO: implement setting the hard ware cursor
// NOTE: cursor should be always B_RGBA32 // NOTE: cursor should be always B_RGBA32
// NOTE: The HWInterface implementation should // NOTE: The HWInterface implementation should
// still be called, since it takes ownership of // still be called, since it takes ownership of
// the cursor. // the cursor.
// WriteUnlock(); // UnlockExclusiveAccess();
// } // }
} }
@@ -1012,9 +1012,9 @@ void
AccelerantHWInterface::SetCursorVisible(bool visible) AccelerantHWInterface::SetCursorVisible(bool visible)
{ {
HWInterface::SetCursorVisible(visible); HWInterface::SetCursorVisible(visible);
// if (WriteLock()) { // if (LockExclusiveAccess()) {
// TODO: update graphics hardware // TODO: update graphics hardware
// WriteUnlock(); // UnlockExclusiveAccess();
// } // }
} }
@@ -1023,9 +1023,9 @@ void
AccelerantHWInterface::MoveCursorTo(const float& x, const float& y) AccelerantHWInterface::MoveCursorTo(const float& x, const float& y)
{ {
HWInterface::MoveCursorTo(x, y); HWInterface::MoveCursorTo(x, y);
// if (WriteLock()) { // if (LockExclusiveAccess()) {
// TODO: update graphics hardware // TODO: update graphics hardware
// WriteUnlock(); // UnlockExclusiveAccess();
// } // }
} }
+85 -120
View File
@@ -23,7 +23,10 @@
#include "drawing_support.h" #include "drawing_support.h"
#define CRASH_IF_NOT_LOCKED #define CRASH_IF_NOT_LOCKED
//#define CRASH_IF_NOT_LOCKED if (!IsLocked()) debugger("not locked!"); //#define CRASH_IF_NOT_LOCKED if (!IsParallelAccessLocked()) debugger("not parallel locked!");
#define CRASH_IF_NOT_EXCLUSIVE_LOCKED
//#define CRASH_IF_NOT_EXCLUSIVE_LOCKED if (!IsExclusiveAccessLocked()) debugger("not exclusive locked!");
// make_rect_valid // make_rect_valid
static inline void static inline void
@@ -97,6 +100,38 @@ DrawingEngine::~DrawingEngine()
} }
// #pragma mark - locking
bool
DrawingEngine::LockParallelAccess()
{
return fGraphicsCard->LockExclusiveAccess();
}
void
DrawingEngine::UnlockParallelAccess()
{
fGraphicsCard->UnlockExclusiveAccess();
}
bool
DrawingEngine::LockExclusiveAccess()
{
return fGraphicsCard->LockExclusiveAccess();
}
void
DrawingEngine::UnlockExclusiveAccess()
{
fGraphicsCard->UnlockExclusiveAccess();
}
// #pragma mark -
void void
DrawingEngine::FrameBufferChanged() DrawingEngine::FrameBufferChanged()
{ {
@@ -106,11 +141,13 @@ DrawingEngine::FrameBufferChanged()
return; return;
} }
if (WriteLock()) { // NOTE: locking is probably bogus, since we are called
// in the thread that changed the frame buffer...
if (LockExclusiveAccess()) {
fPainter->AttachToBuffer(fGraphicsCard->DrawingBuffer()); fPainter->AttachToBuffer(fGraphicsCard->DrawingBuffer());
// available HW acceleration might have changed // available HW acceleration might have changed
fAvailableHWAccleration = fGraphicsCard->AvailableHWAcceleration(); fAvailableHWAccleration = fGraphicsCard->AvailableHWAcceleration();
WriteUnlock(); UnlockExclusiveAccess();
} }
} }
@@ -212,11 +249,11 @@ DrawingEngine::Sync()
// Since A is to the left of C and B is to the top of C, The "node" // Since A is to the left of C and B is to the top of C, The "node"
// for C will point to the nodes of A and B as its "successors". Therefor, // for C will point to the nodes of A and B as its "successors". Therefor,
// A and B will have an "indegree" of 1 for C pointing to them. C will // A and B will have an "indegree" of 1 for C pointing to them. C will
// have and "indegree" of 0, because there was no rect to which C // have an "indegree" of 0, because there was no rect to which C
// was to the left or top of. When comparing A and B, neither is left // was to the left or top of. When comparing A and B, neither is left
// or top from the other and in the sense that the algorithm cares about. // or top from the other and in the sense that the algorithm cares about.
// NOTE: comparisson of coordinates assumes that rects don't overlap // NOTE: comparison of coordinates assumes that rects don't overlap
// 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 {
@@ -263,12 +300,12 @@ struct node {
int32 next_pointer; int32 next_pointer;
}; };
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);
} }
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);
@@ -279,13 +316,11 @@ void
DrawingEngine::CopyRegion(/*const*/ BRegion* region, DrawingEngine::CopyRegion(/*const*/ BRegion* region,
int32 xOffset, int32 yOffset) int32 xOffset, int32 yOffset)
{ {
// NOTE: Write locking because we might use HW acceleration. CRASH_IF_NOT_EXCLUSIVE_LOCKED
// This needs to be investigated, I'm doing this because of
// gut feeling.
if (WriteLock()) {
BRect frame = region->Frame(); BRect frame = region->Frame();
frame = frame | frame.OffsetByCopy(xOffset, yOffset); frame = frame | frame.OffsetByCopy(xOffset, yOffset);
fGraphicsCard->HideSoftwareCursor(frame); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(frame);
int32 count = region->CountRects(); int32 count = region->CountRects();
@@ -389,24 +424,20 @@ DrawingEngine::CopyRegion(/*const*/ BRegion* region,
delete[] sortedRectList; delete[] sortedRectList;
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
WriteUnlock();
}
} }
// InvertRect // InvertRect
void void
DrawingEngine::InvertRect(BRect r) DrawingEngine::InvertRect(BRect r)
{ {
// NOTE: Write locking because we might use HW acceleration. CRASH_IF_NOT_LOCKED
// This needs to be investigated, I'm doing this because of
// gut feeling.
if (WriteLock()) {
make_rect_valid(r); make_rect_valid(r);
r = fPainter->ClipRect(r); r = fPainter->ClipRect(r);
if (r.IsValid()) { if (r.IsValid()) {
fGraphicsCard->HideSoftwareCursor(r); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(r);
// try hardware optimized version first // try hardware optimized version first
if (fAvailableHWAccleration & HW_ACC_INVERT_REGION) { if (fAvailableHWAccleration & HW_ACC_INVERT_REGION) {
@@ -419,11 +450,9 @@ DrawingEngine::InvertRect(BRect r)
fGraphicsCard->Invalidate(r); fGraphicsCard->Invalidate(r);
} }
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
WriteUnlock();
}
} }
// DrawBitmap // DrawBitmap
@@ -436,12 +465,13 @@ DrawingEngine::DrawBitmap(ServerBitmap *bitmap,
BRect clipped = fPainter->ClipRect(dest); BRect clipped = fPainter->ClipRect(dest);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
fPainter->DrawBitmap(bitmap, source, dest); fPainter->DrawBitmap(bitmap, source, dest);
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -460,7 +490,7 @@ DrawingEngine::DrawArc(BRect r, const float &angle,
extend_by_stroke_width(clipped, d); extend_by_stroke_width(clipped, d);
clipped = fPainter->ClipRect(r); clipped = fPainter->ClipRect(r);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
@@ -475,6 +505,7 @@ DrawingEngine::DrawArc(BRect r, const float &angle,
fPainter->StrokeArc(center, xRadius, yRadius, angle, span); fPainter->StrokeArc(center, xRadius, yRadius, angle, span);
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -516,12 +547,13 @@ DrawingEngine::DrawEllipse(BRect r, const DrawState *d, bool filled)
clipped = fPainter->ClipRect(clipped); clipped = fPainter->ClipRect(clipped);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
fPainter->DrawEllipse(r, filled); fPainter->DrawEllipse(r, filled);
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -539,12 +571,13 @@ DrawingEngine::DrawPolygon(BPoint* ptlist, int32 numpts,
extend_by_stroke_width(bounds, d); extend_by_stroke_width(bounds, d);
bounds = fPainter->ClipRect(bounds); bounds = fPainter->ClipRect(bounds);
if (bounds.IsValid()) { if (bounds.IsValid()) {
fGraphicsCard->HideSoftwareCursor(bounds); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(bounds);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
fPainter->DrawPolygon(ptlist, numpts, filled, closed); fPainter->DrawPolygon(ptlist, numpts, filled, closed);
fGraphicsCard->Invalidate(bounds); fGraphicsCard->Invalidate(bounds);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -562,15 +595,15 @@ DrawingEngine::StrokePoint(const BPoint& pt, const RGBColor &color)
// * 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, const RGBColor &color) DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end,
const RGBColor &color)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
if (Lock()) {
BRect touched(start, end); BRect touched(start, end);
make_rect_valid(touched); make_rect_valid(touched);
touched = fPainter->ClipRect(touched); touched = fPainter->ClipRect(touched);
fGraphicsCard->HideSoftwareCursor(touched); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(touched);
if (!fPainter->StraightLine(start, end, color.GetColor32())) { if (!fPainter->StraightLine(start, end, color.GetColor32())) {
DrawState context; DrawState context;
@@ -580,9 +613,8 @@ DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end, const RGBColor
} else { } else {
fGraphicsCard->Invalidate(touched); fGraphicsCard->Invalidate(touched);
} }
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
Unlock();
}
} }
// this function is used to draw a one pixel wide rect // this function is used to draw a one pixel wide rect
@@ -591,20 +623,17 @@ DrawingEngine::StrokeRect(BRect r, const RGBColor &color)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
if (Lock()) {
make_rect_valid(r); make_rect_valid(r);
BRect clipped = fPainter->ClipRect(r); BRect clipped = fPainter->ClipRect(r);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->StrokeRect(r, color.GetColor32()); fPainter->StrokeRect(r, color.GetColor32());
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
Unlock();
}
} }
@@ -616,7 +645,6 @@ DrawingEngine::FillRect(BRect 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.
if (WriteLock()) {
make_rect_valid(r); make_rect_valid(r);
r = fPainter->ClipRect(r); r = fPainter->ClipRect(r);
if (r.IsValid()) { if (r.IsValid()) {
@@ -638,9 +666,6 @@ DrawingEngine::FillRect(BRect r, const RGBColor& color)
if (cursorTouched) if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
WriteUnlock();
}
} }
@@ -649,11 +674,7 @@ DrawingEngine::FillRegion(BRegion& r, const RGBColor& color)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
// NOTE: Write locking because we might use HW acceleration.
// This needs to be investigated, I'm doing this because of
// gut feeling.
// NOTE: region expected to be already clipped correctly!! // NOTE: region expected to be already clipped correctly!!
if (WriteLock()) {
BRect frame = r.Frame(); BRect frame = r.Frame();
bool cursorTouched = fGraphicsCard->HideSoftwareCursor(frame); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(frame);
@@ -678,9 +699,6 @@ DrawingEngine::FillRegion(BRegion& r, const RGBColor& color)
if (cursorTouched) if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
WriteUnlock();
}
} }
// #pragma mark - DrawState // #pragma mark - DrawState
@@ -697,12 +715,13 @@ DrawingEngine::StrokeRect(BRect r, const DrawState *d)
clipped = fPainter->ClipRect(clipped); clipped = fPainter->ClipRect(clipped);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
fPainter->StrokeRect(r); fPainter->StrokeRect(r);
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -713,10 +732,6 @@ DrawingEngine::FillRect(BRect r, const DrawState *d)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
// NOTE: Write locking because we might use HW acceleration.
// This needs to be investigated, I'm doing this because of
// gut feeling.
if (WriteLock()) {
make_rect_valid(r); make_rect_valid(r);
r = fPainter->ClipRect(r); r = fPainter->ClipRect(r);
if (r.IsValid()) { if (r.IsValid()) {
@@ -757,9 +772,6 @@ DrawingEngine::FillRect(BRect r, const DrawState *d)
if (cursorTouched) if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
WriteUnlock();
}
} }
@@ -768,10 +780,6 @@ DrawingEngine::FillRegion(BRegion& r, const DrawState *d)
{ {
CRASH_IF_NOT_LOCKED CRASH_IF_NOT_LOCKED
// NOTE: Write locking because we might use HW acceleration.
// This needs to be investigated, I'm doing this because of
// gut feeling.
if (WriteLock()) {
BRect clipped = fPainter->ClipRect(r.Frame()); BRect clipped = fPainter->ClipRect(r.Frame());
if (clipped.IsValid()) { if (clipped.IsValid()) {
bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
@@ -813,9 +821,6 @@ DrawingEngine::FillRegion(BRegion& r, const DrawState *d)
if (cursorTouched) if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
WriteUnlock();
}
} }
@@ -836,13 +841,14 @@ DrawingEngine::DrawRoundRect(BRect r, float xrad, float yrad,
clipped.bottom = ceilf(clipped.bottom); clipped.bottom = ceilf(clipped.bottom);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
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);
fGraphicsCard->Invalidate(touched); fGraphicsCard->Invalidate(touched);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -880,7 +886,7 @@ DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds,
extend_by_stroke_width(clipped, d); extend_by_stroke_width(clipped, d);
clipped = fPainter->ClipRect(clipped); clipped = fPainter->ClipRect(clipped);
if (clipped.IsValid()) { if (clipped.IsValid()) {
fGraphicsCard->HideSoftwareCursor(clipped); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(clipped);
fPainter->SetDrawState(d); fPainter->SetDrawState(d);
if (filled) if (filled)
@@ -889,6 +895,7 @@ DrawingEngine::DrawTriangle(BPoint* pts, const BRect& bounds,
fPainter->StrokeTriangle(pts[0], pts[1], pts[2]); fPainter->StrokeTriangle(pts[0], pts[1], pts[2]);
fGraphicsCard->Invalidate(clipped); fGraphicsCard->Invalidate(clipped);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -904,12 +911,13 @@ DrawingEngine::StrokeLine(const BPoint &start, const BPoint &end, DrawState* con
extend_by_stroke_width(touched, context); extend_by_stroke_width(touched, context);
touched = fPainter->ClipRect(touched); touched = fPainter->ClipRect(touched);
if (touched.IsValid()) { if (touched.IsValid()) {
fGraphicsCard->HideSoftwareCursor(touched); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(touched);
fPainter->SetDrawState(context); fPainter->SetDrawState(context);
fPainter->StrokeLine(start, end); fPainter->StrokeLine(start, end);
fGraphicsCard->Invalidate(touched); fGraphicsCard->Invalidate(touched);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -942,7 +950,7 @@ DrawingEngine::StrokeLineArray(int32 numLines,
extend_by_stroke_width(touched, d); extend_by_stroke_width(touched, d);
touched = fPainter->ClipRect(touched); touched = fPainter->ClipRect(touched);
if (touched.IsValid()) { if (touched.IsValid()) {
fGraphicsCard->HideSoftwareCursor(touched); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(touched);
data = (const LineArrayData *)&(linedata[0]); data = (const LineArrayData *)&(linedata[0]);
@@ -964,6 +972,7 @@ DrawingEngine::StrokeLineArray(int32 numLines,
} }
fGraphicsCard->Invalidate(touched); fGraphicsCard->Invalidate(touched);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
} }
@@ -996,13 +1005,14 @@ DrawingEngine::DrawString(const char* string, int32 length,
b = fPainter->ClipRect(b); b = fPainter->ClipRect(b);
if (b.IsValid()) { if (b.IsValid()) {
//printf("bounding box '%s': %lld µs\n", string, system_time() - now); //printf("bounding box '%s': %lld µs\n", string, system_time() - now);
fGraphicsCard->HideSoftwareCursor(b); bool cursorTouched = fGraphicsCard->HideSoftwareCursor(b);
//now = system_time(); //now = system_time();
BRect touched = fPainter->DrawString(string, length, pt, delta); BRect touched = fPainter->DrawString(string, length, pt, delta);
//printf("drawing string: %lld µs\n", system_time() - now); //printf("drawing string: %lld µs\n", system_time() - now);
fGraphicsCard->Invalidate(touched); fGraphicsCard->Invalidate(touched);
if (cursorTouched)
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
} }
@@ -1018,7 +1028,6 @@ DrawingEngine::StringWidth(const char* string, int32 length,
FontLocker locker(d); FontLocker locker(d);
float width = 0.0; float width = 0.0;
// if (Lock()) {
// NOTE: For now it is enough to block on the // NOTE: For now it is enough to block on the
// font style lock, this already prevents multiple // font style lock, this already prevents multiple
// threads from executing this code and avoids a // threads from executing this code and avoids a
@@ -1026,8 +1035,6 @@ DrawingEngine::StringWidth(const char* string, int32 length,
// lock already and then tries to lock the drawing // lock already and then tries to lock the drawing
// engine after it is already locked here (race condition) // engine after it is already locked here (race condition)
width = fPainter->StringWidth(string, length, d); width = fPainter->StringWidth(string, length, d);
// Unlock();
// }
return width; return width;
} }
@@ -1049,7 +1056,6 @@ DrawingEngine::StringHeight(const char *string, int32 length,
FontLocker locker(d); FontLocker locker(d);
float height = 0.0; float height = 0.0;
// if (Lock()) {
// NOTE: For now it is enough to block on the // NOTE: For now it is enough to block on the
// font style lock, this already prevents multiple // font style lock, this already prevents multiple
// threads from executing this code and avoids a // threads from executing this code and avoids a
@@ -1060,55 +1066,17 @@ DrawingEngine::StringHeight(const char *string, int32 length,
BPoint dummy1(0.0, 0.0); BPoint dummy1(0.0, 0.0);
BPoint dummy2(0.0, 0.0); BPoint dummy2(0.0, 0.0);
height = fPainter->BoundingBox(string, length, dummy1, &dummy2).Height(); height = fPainter->BoundingBox(string, length, dummy1, &dummy2).Height();
// Unlock();
// }
return height; return height;
} }
// #pragma mark - // #pragma mark -
// Lock
bool
DrawingEngine::Lock()
{
return fGraphicsCard->WriteLock();
}
// Unlock
void
DrawingEngine::Unlock()
{
fGraphicsCard->WriteUnlock();
}
// IsLocked
bool
DrawingEngine::IsLocked()
{
return fGraphicsCard->IsWriteLocked();
}
// WriteLock
bool
DrawingEngine::WriteLock()
{
return fGraphicsCard->WriteLock();
}
// WriteUnlock
void
DrawingEngine::WriteUnlock()
{
fGraphicsCard->WriteUnlock();
}
// #pragma mark -
// DumpToFile // DumpToFile
bool bool
DrawingEngine::DumpToFile(const char *path) DrawingEngine::DumpToFile(const char *path)
{ {
if (Lock()) { CRASH_IF_NOT_EXCLUSIVE_LOCKED
RenderingBuffer* buffer = fGraphicsCard->DrawingBuffer(); RenderingBuffer* buffer = fGraphicsCard->DrawingBuffer();
if (buffer) { if (buffer) {
BRect bounds(0.0, 0.0, buffer->Width() - 1, buffer->Height() - 1); BRect bounds(0.0, 0.0, buffer->Width() - 1, buffer->Height() - 1);
@@ -1116,10 +1084,9 @@ DrawingEngine::DumpToFile(const char *path)
buffer->Bits(), buffer->Bits(),
buffer->BitsLength(), buffer->BitsLength(),
buffer->BytesPerRow()); buffer->BytesPerRow());
}
Unlock();
}
return true; return true;
}
return false;
} }
// DumpToBitmap // DumpToBitmap
@@ -1132,7 +1099,8 @@ DrawingEngine::DumpToBitmap()
status_t status_t
DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds) DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
{ {
if (Lock()) { CRASH_IF_NOT_EXCLUSIVE_LOCKED
RenderingBuffer *buffer = fGraphicsCard->DrawingBuffer(); RenderingBuffer *buffer = fGraphicsCard->DrawingBuffer();
if (!buffer) if (!buffer)
return B_ERROR; return B_ERROR;
@@ -1182,11 +1150,8 @@ DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
} }
fGraphicsCard->ShowSoftwareCursor(); fGraphicsCard->ShowSoftwareCursor();
Unlock();
return result;
}
return B_ERROR; return result;
} }
// #pragma mark - // #pragma mark -
+9 -8
View File
@@ -44,17 +44,18 @@ public:
// HWInterfaceListener interface // HWInterfaceListener interface
virtual void FrameBufferChanged(); virtual void FrameBufferChanged();
// locking
bool Lock();
void Unlock();
bool IsLocked();
bool WriteLock();
void WriteUnlock();
// for "changing" hardware // for "changing" hardware
void SetHWInterface(HWInterface* interface); void SetHWInterface(HWInterface* interface);
// locking
bool LockParallelAccess();
bool IsParallelAccessLocked();
void UnlockParallelAccess();
bool LockExclusiveAccess();
bool IsExclusiveAccessLocked();
void UnlockExclusiveAccess();
// for screen shots // for screen shots
bool DumpToFile(const char *path); bool DumpToFile(const char *path);
ServerBitmap* DumpToBitmap(); ServerBitmap* DumpToBitmap();
+48 -37
View File
@@ -30,6 +30,7 @@ HWInterfaceListener::~HWInterfaceListener() {}
HWInterface::HWInterface(bool doubleBuffered) HWInterface::HWInterface(bool doubleBuffered)
: MultiLocker("hw interface lock"), : MultiLocker("hw interface lock"),
fCursorAreaBackup(NULL), fCursorAreaBackup(NULL),
fSoftwareCursorLock("software cursor lock"),
fCursor(NULL), fCursor(NULL),
fDragBitmap(NULL), fDragBitmap(NULL),
fDragBitmapOffset(0, 0), fDragBitmapOffset(0, 0),
@@ -78,21 +79,25 @@ HWInterface::GetDriverPath(BString &path)
} }
// SetCursor // #pragma mark -
void void
HWInterface::SetCursor(ServerCursor* cursor) HWInterface::SetCursor(ServerCursor* cursor)
{ {
if (WriteLock()) { if (!fSoftwareCursorLock.Lock())
return;
// TODO: if a bitmap is being dragged, it could // TODO: if a bitmap is being dragged, it could
// be considered iritating to the user to change // be considered iritating to the user to change
// cursor shapes while something is dragged. // cursor shapes while something is dragged.
// The disabled code below would do this (except // The disabled code below would prevent this (except
// for the minor annoyance that the cursor is not // for the minor annoyance that the cursor is not
// updated when the drag is over) // updated when the drag is over)
// if (fDragBitmap) { // if (fDragBitmap) {
// // TODO: like a "+" or "-" sign when dragging some files to indicate // // TODO: like a "+" or "-" sign when dragging some files to indicate
// // the current drag mode? // // the current drag mode?
// WriteUnlock(); // UnlockExclusiveAccess();
// return; // return;
// } // }
if (fCursor != cursor) { if (fCursor != cursor) {
@@ -116,15 +121,16 @@ HWInterface::SetCursor(ServerCursor* cursor)
_AdoptDragBitmap(fDragBitmap, fDragBitmapOffset); _AdoptDragBitmap(fDragBitmap, fDragBitmapOffset);
Invalidate(_CursorFrame()); Invalidate(_CursorFrame());
} }
WriteUnlock(); fSoftwareCursorLock.Unlock();
}
} }
// SetCursorVisible // SetCursorVisible
void void
HWInterface::SetCursorVisible(bool visible) HWInterface::SetCursorVisible(bool visible)
{ {
if (WriteLock()) { if (!fSoftwareCursorLock.Lock())
return;
if (fCursorVisible != visible) { if (fCursorVisible != visible) {
// NOTE: _CursorFrame() will // NOTE: _CursorFrame() will
// return an invalid rect if // return an invalid rect if
@@ -144,8 +150,7 @@ HWInterface::SetCursorVisible(bool visible)
Invalidate(r); Invalidate(r);
} }
} }
WriteUnlock(); fSoftwareCursorLock.Unlock();
}
} }
// IsCursorVisible // IsCursorVisible
@@ -153,9 +158,9 @@ bool
HWInterface::IsCursorVisible() HWInterface::IsCursorVisible()
{ {
bool visible = true; bool visible = true;
if (ReadLock()) { if (fSoftwareCursorLock.Lock()) {
visible = fCursorVisible; visible = fCursorVisible;
ReadUnlock(); fSoftwareCursorLock.Unlock();
} }
return visible; return visible;
} }
@@ -164,26 +169,27 @@ HWInterface::IsCursorVisible()
void void
HWInterface::ObscureCursor() HWInterface::ObscureCursor()
{ {
if (WriteLock()) { if (!fSoftwareCursorLock.Lock())
return;
if (!fCursorObscured) { if (!fCursorObscured) {
SetCursorVisible(false); SetCursorVisible(false);
fCursorObscured = true; fCursorObscured = true;
} }
WriteUnlock(); fSoftwareCursorLock.Unlock();
}
} }
// MoveCursorTo // MoveCursorTo
void void
HWInterface::MoveCursorTo(const float& x, const float& y) HWInterface::MoveCursorTo(const float& x, const float& y)
{ {
if (WriteLock()) { if (!fSoftwareCursorLock.Lock())
return;
BPoint p(x, y); BPoint p(x, y);
if (p != fCursorLocation) { if (p != fCursorLocation) {
// unhide cursor if it is obscured only // unhide cursor if it is obscured only
if (fCursorObscured) { if (fCursorObscured) {
// TODO: causes nested lock, which
// the MultiLocker doesn't actually support?
SetCursorVisible(true); SetCursorVisible(true);
} }
BRect oldFrame = _CursorFrame(); BRect oldFrame = _CursorFrame();
@@ -202,8 +208,7 @@ HWInterface::MoveCursorTo(const float& x, const float& y)
Invalidate(_CursorFrame()); Invalidate(_CursorFrame());
} }
} }
WriteUnlock(); fSoftwareCursorLock.Unlock();
}
} }
@@ -211,25 +216,28 @@ BPoint
HWInterface::CursorPosition() HWInterface::CursorPosition()
{ {
BPoint location; BPoint location;
if (ReadLock()) { if (fSoftwareCursorLock.Lock()) {
location = fCursorLocation; location = fCursorLocation;
ReadUnlock(); fSoftwareCursorLock.Unlock();
} }
return location; return location;
} }
// SetDragBitmap
void void
HWInterface::SetDragBitmap(const ServerBitmap* bitmap, HWInterface::SetDragBitmap(const ServerBitmap* bitmap,
const BPoint& offsetFromCursor) const BPoint& offsetFromCursor)
{ {
if (WriteLock()) { if (fSoftwareCursorLock.Lock()) {
_AdoptDragBitmap(bitmap, offsetFromCursor); _AdoptDragBitmap(bitmap, offsetFromCursor);
WriteUnlock(); fSoftwareCursorLock.Unlock();
} }
} }
// DrawingBuffer
// #pragma mark -
RenderingBuffer* RenderingBuffer*
HWInterface::DrawingBuffer() const HWInterface::DrawingBuffer() const
{ {
@@ -238,14 +246,14 @@ HWInterface::DrawingBuffer() const
return FrontBuffer(); return FrontBuffer();
} }
// IsDoubleBuffered
bool bool
HWInterface::IsDoubleBuffered() const HWInterface::IsDoubleBuffered() const
{ {
return fDoubleBuffered; return fDoubleBuffered;
} }
// Invalidate
// * the object needs to be already locked! // * the object needs to be already locked!
status_t status_t
HWInterface::Invalidate(const BRect& frame) HWInterface::Invalidate(const BRect& frame)
@@ -269,7 +277,7 @@ HWInterface::Invalidate(const BRect& frame)
return B_OK; return B_OK;
} }
// CopyBackToFront
// * the object must already be locked! // * the object must already be locked!
status_t status_t
HWInterface::CopyBackToFront(const BRect& frame) HWInterface::CopyBackToFront(const BRect& frame)
@@ -370,7 +378,9 @@ HWInterface::HideSoftwareCursor(const BRect& area)
fCursorAreaBackup->right, fCursorAreaBackup->right,
fCursorAreaBackup->bottom); fCursorAreaBackup->bottom);
if (area.Intersects(backupArea)) { if (area.Intersects(backupArea)) {
fSoftwareCursorLock.Lock();
_RestoreCursorArea(); _RestoreCursorArea();
// do not unlock the cursor lock
return true; return true;
} }
} }
@@ -381,6 +391,7 @@ HWInterface::HideSoftwareCursor(const BRect& area)
void void
HWInterface::HideSoftwareCursor() HWInterface::HideSoftwareCursor()
{ {
fSoftwareCursorLock.Lock();
_RestoreCursorArea(); _RestoreCursorArea();
} }
@@ -391,6 +402,7 @@ HWInterface::ShowSoftwareCursor()
if (fCursorAreaBackup && fCursorAreaBackup->cursor_hidden) { if (fCursorAreaBackup && fCursorAreaBackup->cursor_hidden) {
_DrawCursor(_CursorFrame()); _DrawCursor(_CursorFrame());
} }
fSoftwareCursorLock.Unlock();
} }
@@ -415,7 +427,7 @@ HWInterface::RemoveListener(HWInterfaceListener* listener)
// #pragma mark - // #pragma mark -
// _DrawCursor
// * default implementation, can be used as fallback or for // * default implementation, can be used as fallback or for
// software cursor // software cursor
// * area is where we potentially draw the cursor, the cursor // * area is where we potentially draw the cursor, the cursor
@@ -433,6 +445,7 @@ HWInterface::_DrawCursor(BRect area) const
area = backBuffer->Bounds() & area; area = backBuffer->Bounds() & area;
if (cf.IsValid() && area.Intersects(cf)) { if (cf.IsValid() && area.Intersects(cf)) {
// clip to common area // clip to common area
area = area & cf; area = area & cf;
@@ -465,7 +478,8 @@ HWInterface::_DrawCursor(BRect area) const
uint8* dst = buffer; uint8* dst = buffer;
if (fCursorAreaBackup && fCursorAreaBackup->buffer) { if (fCursorAreaBackup && fCursorAreaBackup->buffer
&& fSoftwareCursorLock.Lock()) {
fCursorAreaBackup->cursor_hidden = false; fCursorAreaBackup->cursor_hidden = false;
// remember which area the backup contains // remember which area the backup contains
fCursorAreaBackup->left = left; fCursorAreaBackup->left = left;
@@ -501,6 +515,7 @@ HWInterface::_DrawCursor(BRect area) const
dst += width * 4; dst += width * 4;
bup += bupBPR; bup += bupBPR;
} }
fSoftwareCursorLock.Unlock();
} else { } else {
// blending // blending
for (int32 y = top; y <= bottom; y++) { for (int32 y = top; y <= bottom; y++) {
@@ -531,8 +546,7 @@ HWInterface::_DrawCursor(BRect area) const
} }
} }
// _CopyToFront
//
// * source is assumed to be already at the right offset // * source is assumed to be already at the right offset
// * source is assumed to be in B_RGBA32 format // * source is assumed to be in B_RGBA32 format
// * location in front buffer is calculated // * location in front buffer is calculated
@@ -563,8 +577,7 @@ HWInterface::_CopyToFront(uint8* src, uint32 srcBPR,
dst += dstBPR; dst += dstBPR;
src += srcBPR; src += srcBPR;
} }
} else }
printf("nothing to copy\n");
break; break;
} }
// NOTE: on R5, B_RGB24 bitmaps are not supported by DrawBitmap() // NOTE: on R5, B_RGB24 bitmaps are not supported by DrawBitmap()
@@ -679,8 +692,6 @@ printf("nothing to copy\n");
} }
// _CursorFrame
//
// PRE: the object must be locked // PRE: the object must be locked
BRect BRect
HWInterface::_CursorFrame() const HWInterface::_CursorFrame() const
@@ -693,7 +704,7 @@ HWInterface::_CursorFrame() const
return frame; return frame;
} }
// _RestoreCursorArea
void void
HWInterface::_RestoreCursorArea() const HWInterface::_RestoreCursorArea() const
{ {
+12 -1
View File
@@ -16,6 +16,7 @@
#include <Accelerant.h> #include <Accelerant.h>
#include <GraphicsCard.h> #include <GraphicsCard.h>
#include <List.h> #include <List.h>
#include <Locker.h>
#include <OS.h> #include <OS.h>
#include <Region.h> #include <Region.h>
@@ -42,11 +43,20 @@ class HWInterfaceListener {
virtual void FrameBufferChanged() = 0; virtual void FrameBufferChanged() = 0;
}; };
class HWInterface : public MultiLocker { class HWInterface : protected MultiLocker {
public: public:
HWInterface(bool doubleBuffered = false); HWInterface(bool doubleBuffered = false);
virtual ~HWInterface(); virtual ~HWInterface();
// locking
bool LockParallelAccess() { return ReadLock(); }
bool IsParallelAccessLocked() { return IsReadLocked(); }
void UnlockParallelAccess() { ReadUnlock(); }
bool LockExclusiveAccess() { return WriteLock(); }
bool IsExclusiveAccessLocked() { return IsWriteLocked(); }
void UnlockExclusiveAccess() { WriteUnlock(); }
// You need to WriteLock // You need to WriteLock
virtual status_t Initialize(); virtual status_t Initialize();
virtual status_t Shutdown() = 0; virtual status_t Shutdown() = 0;
@@ -200,6 +210,7 @@ class HWInterface : public MultiLocker {
}; };
buffer_clip* fCursorAreaBackup; buffer_clip* fCursorAreaBackup;
mutable BLocker fSoftwareCursorLock;
ServerCursor* fCursor; ServerCursor* fCursor;
const ServerBitmap* fDragBitmap; const ServerBitmap* fDragBitmap;
+5 -12
View File
@@ -84,7 +84,7 @@ Painter::Painter()
fSubpixelPrecise(false), fSubpixelPrecise(false),
fPenSize(1.0), fPenSize(1.0),
fClippingRegion(new BRegion()), fClippingRegion(NULL),
fValidClipping(false), fValidClipping(false),
fDrawingMode(B_OP_COPY), fDrawingMode(B_OP_COPY),
fDrawingText(false), fDrawingText(false),
@@ -96,7 +96,7 @@ Painter::Painter()
fMiterLimit(B_DEFAULT_MITER_LIMIT), fMiterLimit(B_DEFAULT_MITER_LIMIT),
fPatternHandler(new PatternHandler()), fPatternHandler(new PatternHandler()),
fTextRenderer(new AGGTextRenderer()) fTextRenderer(AGGTextRenderer::Default())
{ {
// Usually, the drawing engine will lock the font for us when // Usually, the drawing engine will lock the font for us when
// needed - unfortunately, it can't know we need it here // needed - unfortunately, it can't know we need it here
@@ -114,9 +114,7 @@ Painter::~Painter()
{ {
_MakeEmpty(); _MakeEmpty();
delete fClippingRegion;
delete fPatternHandler; delete fPatternHandler;
delete fTextRenderer;
} }
// #pragma mark - // #pragma mark -
@@ -141,8 +139,6 @@ Painter::AttachToBuffer(RenderingBuffer* buffer)
fPixelFormat->SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode, false); fPixelFormat->SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode, false);
fBaseRenderer = new renderer_base(*fPixelFormat); fBaseRenderer = new renderer_base(*fPixelFormat);
// attach our clipping region to the renderer, it keeps a pointer
fBaseRenderer->set_clipping_region(fClippingRegion);
// These are the AGG renderes and rasterizes which // These are the AGG renderes and rasterizes which
// will be used for stroking paths // will be used for stroking paths
@@ -234,17 +230,14 @@ Painter::SetDrawState(const DrawState* data, bool updateFont)
void void
Painter::ConstrainClipping(const BRegion* region) Painter::ConstrainClipping(const BRegion* region)
{ {
*fClippingRegion = *region; fClippingRegion = region;
fValidClipping = fClippingRegion->Frame().IsValid(); fBaseRenderer->set_clipping_region(const_cast<BRegion*>(region));
fValidClipping = region->Frame().IsValid();
if (fValidClipping) { if (fValidClipping) {
clipping_rect cb = fClippingRegion->FrameInt(); clipping_rect cb = fClippingRegion->FrameInt();
fRasterizer->clip_box(cb.left, cb.top, cb.right + 1, cb.bottom + 1); fRasterizer->clip_box(cb.left, cb.top, cb.right + 1, cb.bottom + 1);
} }
// TODO: would be nice if we didn't need to copy a region
// for *each* drawing command...
//fBaseRenderer->set_clipping_region(const_cast<BRegion*>(region));
//fValidClipping = region->Frame().IsValid();
} }
// SetHighColor // SetHighColor
+1 -1
View File
@@ -273,7 +273,7 @@ mutable agg::conv_curve<agg::path_storage> fCurve;
bool fSubpixelPrecise; bool fSubpixelPrecise;
float fPenSize; float fPenSize;
BRegion* fClippingRegion; const BRegion* fClippingRegion;
bool fValidClipping; bool fValidClipping;
drawing_mode fDrawingMode; drawing_mode fDrawingMode;
bool fDrawingText; bool fDrawingText;
@@ -69,6 +69,10 @@ is_white_space(uint32 charCode)
#define DEFAULT_UNI_CODE_BUFFER_SIZE 2048 #define DEFAULT_UNI_CODE_BUFFER_SIZE 2048
// init default instance
AGGTextRenderer
AGGTextRenderer::sDefaultInstance;
// constructor // constructor
AGGTextRenderer::AGGTextRenderer() AGGTextRenderer::AGGTextRenderer()
: fFontEngine(gFreeTypeLibrary), : fFontEngine(gFreeTypeLibrary),
@@ -97,6 +101,13 @@ AGGTextRenderer::~AGGTextRenderer()
free(fUnicodeBuffer); free(fUnicodeBuffer);
} }
// Default
/*static*/ AGGTextRenderer*
AGGTextRenderer::Default()
{
return &sDefaultInstance;
}
// SetFont // SetFont
bool bool
AGGTextRenderer::SetFont(const ServerFont &font) AGGTextRenderer::SetFont(const ServerFont &font)
@@ -21,6 +21,14 @@ class AGGTextRenderer {
AGGTextRenderer(); AGGTextRenderer();
virtual ~AGGTextRenderer(); virtual ~AGGTextRenderer();
// NOTE: every Painter instance is using the same
// AGGTextRenderer instance, and the only thing that
// protects locking is the fact that every use of a
// ServerFont goes through a global lock... this will
// have to be changed. Maybe every ServerFont should
// have it's own AGGTextRenderer or something
static AGGTextRenderer* Default();
bool SetFont(const ServerFont &font); bool SetFont(const ServerFont &font);
void Unset(); void Unset();
@@ -76,6 +84,8 @@ class AGGTextRenderer {
bool fAntialias; bool fAntialias;
bool fKerning; bool fKerning;
Transformable fEmbeddedTransformation; // rotated or sheared font? Transformable fEmbeddedTransformation; // rotated or sheared font?
static AGGTextRenderer sDefaultInstance;
}; };
#endif // AGG_TEXT_RENDERER_H #endif // AGG_TEXT_RENDERER_H
+2 -2
View File
@@ -85,7 +85,7 @@ UpdateQueue::_ExecuteUpdates()
case B_OK: case B_OK:
case B_TIMED_OUT: case B_TIMED_OUT:
// execute updates // execute updates
if (fInterface->ReadLock()) { if (fInterface->LockParallelAccess()) {
int32 count = fUpdateRegion.CountRects(); int32 count = fUpdateRegion.CountRects();
if (count > 0) { if (count > 0) {
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
@@ -93,7 +93,7 @@ UpdateQueue::_ExecuteUpdates()
} }
fUpdateRegion.MakeEmpty(); fUpdateRegion.MakeEmpty();
} }
fInterface->ReadUnlock(); fInterface->UnlockParallelAccess();
} }
break; break;
case B_BAD_SEM_ID: case B_BAD_SEM_ID: