diff --git a/headers/private/app/LinkReceiver.h b/headers/private/app/LinkReceiver.h index 3d1f9ffb11..160136e909 100644 --- a/headers/private/app/LinkReceiver.h +++ b/headers/private/app/LinkReceiver.h @@ -13,9 +13,10 @@ #include + +class BGradient; class BString; class BRegion; -class BGradient; namespace BPrivate { @@ -38,7 +39,7 @@ class LinkReceiver { status_t ReadString(BString& string, size_t* _length = NULL); status_t ReadString(char* buffer, size_t bufferSize); status_t ReadRegion(BRegion* region); - status_t ReadGradient(BGradient *gradient); + status_t ReadGradient(BGradient** gradient); template status_t Read(Type *data) { return Read(data, sizeof(Type)); } diff --git a/headers/private/app/ServerLink.h b/headers/private/app/ServerLink.h index 514e42630f..d295bc4b72 100644 --- a/headers/private/app/ServerLink.h +++ b/headers/private/app/ServerLink.h @@ -66,7 +66,7 @@ class ServerLink { status_t ReadString(char** _string, size_t* _length = NULL); status_t ReadRegion(BRegion *region); status_t ReadShape(BShape *shape); - status_t ReadGradient(BGradient *gradient); + status_t ReadGradient(BGradient **gradient); template status_t Read(Type *data); // convenience methods diff --git a/src/kits/app/LinkReceiver.cpp b/src/kits/app/LinkReceiver.cpp index 2ab6de8858..2e1498af0f 100644 --- a/src/kits/app/LinkReceiver.cpp +++ b/src/kits/app/LinkReceiver.cpp @@ -1,11 +1,12 @@ /* - * Copyright 2001-2007, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: * Pahtz * Axel Dörfler * Stephan Aßmus + * Artur Wyszynski */ /** Class for low-overhead port-based messaging */ @@ -469,79 +470,120 @@ LinkReceiver::ReadRegion(BRegion* region) } +static BGradient* +gradient_for_type(gradient_type type) +{ + switch (type) { + case B_GRADIENT_LINEAR: + return new (std::nothrow) BGradientLinear(); + case B_GRADIENT_RADIAL: + return new (std::nothrow) BGradientRadial(); + case B_GRADIENT_RADIAL_FOCUS: + return new (std::nothrow) BGradientRadialFocus(); + case B_GRADIENT_DIAMOND: + return new (std::nothrow) BGradientDiamond(); + case B_GRADIENT_CONIC: + return new (std::nothrow) BGradientConic(); + case B_GRADIENT_NONE: + return new (std::nothrow) BGradient(); + } + return NULL; +} + + status_t -LinkReceiver::ReadGradient(BGradient *gradient) +LinkReceiver::ReadGradient(BGradient** _gradient) { GTRACE(("LinkReceiver::ReadGradient\n")); gradient_type gradientType; int32 colorsCount; - Read(&gradientType, sizeof(gradient_type)); - Read(&colorsCount, sizeof(int32)); + status_t ret; + if ((ret = Read(&gradientType, sizeof(gradient_type))) != B_OK) + return ret; + if ((ret = Read(&colorsCount, sizeof(int32))) != B_OK) + return ret; + BGradient* gradient = gradient_for_type(gradientType); + if (!gradient) + return B_NO_MEMORY; + + *_gradient = gradient; if (colorsCount > 0) { color_step step; for (int i = 0; i < colorsCount; i++) { - Read(&step, sizeof(color_step)); - gradient->AddColor(step, i); + if ((ret = Read(&step, sizeof(color_step))) != B_OK) + return ret; + if (!gradient->AddColor(step, i)) + return B_NO_MEMORY; } } - + switch(gradientType) { case B_GRADIENT_LINEAR: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_LINEAR\n")); - BGradientLinear* linear = (BGradientLinear*) gradient; + BGradientLinear* linear = (BGradientLinear*)gradient; BPoint start; BPoint end; - Read(&start, sizeof(BPoint)); - Read(&end, sizeof(BPoint)); + if ((ret = Read(&start, sizeof(BPoint))) != B_OK) + return ret; + if ((ret = Read(&end, sizeof(BPoint))) != B_OK) + return ret; linear->SetStart(start); linear->SetEnd(end); - break; + return B_OK; } case B_GRADIENT_RADIAL: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_RADIAL\n")); - BGradientRadial* radial = (BGradientRadial*) gradient; + BGradientRadial* radial = (BGradientRadial*)gradient; BPoint center; float radius; - Read(¢er, sizeof(BPoint)); - Read(&radius, sizeof(float)); + if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) + return ret; + if ((ret = Read(&radius, sizeof(float))) != B_OK) + return ret; radial->SetCenter(center); radial->SetRadius(radius); - break; + return B_OK; } case B_GRADIENT_RADIAL_FOCUS: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_RADIAL_FOCUS\n")); BGradientRadialFocus* radialFocus = - (BGradientRadialFocus*) gradient; + (BGradientRadialFocus*)gradient; BPoint center; BPoint focal; float radius; - Read(¢er, sizeof(BPoint)); - Read(&focal, sizeof(BPoint)); - Read(&radius, sizeof(float)); + if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) + return ret; + if ((ret = Read(&focal, sizeof(BPoint))) != B_OK) + return ret; + if ((ret = Read(&radius, sizeof(float))) != B_OK) + return ret; radialFocus->SetCenter(center); radialFocus->SetFocal(focal); radialFocus->SetRadius(radius); - break; + return B_OK; } case B_GRADIENT_DIAMOND: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_DIAMOND\n")); - BGradientDiamond* diamond = (BGradientDiamond*) gradient; + BGradientDiamond* diamond = (BGradientDiamond*)gradient; BPoint center; - Read(¢er, sizeof(BPoint)); + if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) + return ret; diamond->SetCenter(center); - break; + return B_OK; } case B_GRADIENT_CONIC: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_CONIC\n")); - BGradientConic* conic = (BGradientConic*) gradient; + BGradientConic* conic = (BGradientConic*)gradient; BPoint center; float angle; - Read(¢er, sizeof(BPoint)); - Read(&angle, sizeof(float)); + if ((ret = Read(¢er, sizeof(BPoint))) != B_OK) + return ret; + if ((ret = Read(&angle, sizeof(float))) != B_OK) + return ret; conic->SetCenter(center); conic->SetAngle(angle); - break; + return B_OK; } case B_GRADIENT_NONE: { GTRACE(("LinkReceiver::ReadGradient> type == B_GRADIENT_NONE\n")); @@ -549,7 +591,7 @@ LinkReceiver::ReadGradient(BGradient *gradient) } } - return B_OK; + return B_ERROR; } } // namespace BPrivate diff --git a/src/kits/app/ServerLink.cpp b/src/kits/app/ServerLink.cpp index b0c635e672..5fdaf8ae1e 100644 --- a/src/kits/app/ServerLink.cpp +++ b/src/kits/app/ServerLink.cpp @@ -115,87 +115,10 @@ ServerLink::AttachShape(BShape &shape) status_t -ServerLink::ReadGradient(BGradient *gradient) +ServerLink::ReadGradient(BGradient **gradient) { GTRACE(("ServerLink::ReadGradient\n")); - fReceiver->ReadGradient(gradient); -/* gradient_type gradientType; - int32 colorsCount; - fReceiver->Read(&gradientType, sizeof(gradient_type)); - fReceiver->Read(&colorsCount, sizeof(int32)); - - if (colorsCount > 0) { - color_step step; - for (int i = 0; i < colorsCount; i++) { - fReceiver->Read(&step, sizeof(color_step)); - gradient->AddColor(step, i); - } - } - - switch(gradientType) { - case B_GRADIENT_LINEAR: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_LINEAR\n")); - BGradientLinear* linear = (BGradientLinear*) gradient; - BPoint start; - BPoint end; - fReceiver->Read(&start, sizeof(BPoint)); - fReceiver->Read(&end, sizeof(BPoint)); - linear->SetStart(start); - linear->SetEnd(end); - break; - } - case B_GRADIENT_RADIAL: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_RADIAL\n")); - BGradientRadial* radial = (BGradientRadial*) gradient; - BPoint center; - float radius; - fReceiver->Read(¢er, sizeof(BPoint)); - fReceiver->Read(&radius, sizeof(float)); - radial->SetCenter(center); - radial->SetRadius(radius); - break; - } - case B_GRADIENT_RADIAL_FOCUS: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_RADIAL_FOCUS\n")); - BGradientRadialFocus* radialFocus = - (BGradientRadialFocus*) gradient; - BPoint center; - BPoint focal; - float radius; - fReceiver->Read(¢er, sizeof(BPoint)); - fReceiver->Read(&focal, sizeof(BPoint)); - fReceiver->Read(&radius, sizeof(float)); - radialFocus->SetCenter(center); - radialFocus->SetFocal(focal); - radialFocus->SetRadius(radius); - break; - } - case B_GRADIENT_DIAMOND: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_DIAMOND\n")); - BGradientDiamond* diamond = (BGradientDiamond*) gradient; - BPoint center; - fReceiver->Read(¢er, sizeof(BPoint)); - diamond->SetCenter(center); - break; - } - case B_GRADIENT_CONIC: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_CONIC\n")); - BGradientConic* conic = (BGradientConic*) gradient; - BPoint center; - float angle; - fReceiver->Read(¢er, sizeof(BPoint)); - fReceiver->Read(&angle, sizeof(float)); - conic->SetCenter(center); - conic->SetAngle(angle); - break; - } - case B_GRADIENT_NONE: { - GTRACE(("ServerLink::ReadGradient> type == B_GRADIENT_NONE\n")); - break; - } - } -*/ - return B_OK; + return fReceiver->ReadGradient(gradient); } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index f1c06f35a3..a2822447e1 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -2629,7 +2629,6 @@ BView::FillEllipse(BRect rect, const BGradient& gradient) fOwner->fLink->StartMessage(AS_FILL_ELLIPSE_GRADIENT); fOwner->fLink->Attach(rect); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -2714,7 +2713,6 @@ BView::FillArc(BRect rect, float startAngle, float arcAngle, fOwner->fLink->Attach(rect); fOwner->fLink->Attach(startAngle); fOwner->fLink->Attach(arcAngle); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -2772,7 +2770,6 @@ BView::FillBezier(BPoint *controlPoints, const BGradient& gradient) fOwner->fLink->Attach(controlPoints[1]); fOwner->fLink->Attach(controlPoints[2]); fOwner->fLink->Attach(controlPoints[3]); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -2874,7 +2871,6 @@ BView::FillPolygon(const BPolygon *polygon, const BGradient& gradient) fOwner->fLink->Attach(polygon->fCount); fOwner->fLink->Attach(polygon->fPoints, polygon->fCount * sizeof(BPoint)); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -2987,7 +2983,6 @@ BView::FillRect(BRect rect, const BGradient& gradient) fOwner->fLink->StartMessage(AS_FILL_RECT_GRADIENT); fOwner->fLink->Attach(rect); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -3046,7 +3041,6 @@ BView::FillRoundRect(BRect rect, float xRadius, float yRadius, fOwner->fLink->Attach(rect); fOwner->fLink->Attach(xRadius); fOwner->fLink->Attach(yRadius); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -3080,7 +3074,6 @@ BView::FillRegion(BRegion *region, const BGradient& gradient) fOwner->fLink->StartMessage(AS_FILL_REGION_GRADIENT); fOwner->fLink->AttachRegion(*region); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -3259,7 +3252,6 @@ BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, fOwner->fLink->Attach(pt2); fOwner->fLink->Attach(pt3); fOwner->fLink->Attach(bounds); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); @@ -3359,7 +3351,6 @@ BView::FillShape(BShape *shape, const BGradient& gradient) fOwner->fLink->Attach(sd->ptCount); fOwner->fLink->Attach(sd->opList, sd->opCount * sizeof(int32)); fOwner->fLink->Attach(sd->ptList, sd->ptCount * sizeof(BPoint)); - fOwner->fLink->Attach(gradient.Type()); fOwner->fLink->AttachGradient(gradient); _FlushIfNotInTransaction(); diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index a7d44dcc5a..1e89db15da 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -8,6 +8,7 @@ * Stephan Aßmus * Stefano Ceccherini (burton666@libero.it) * Axel Dörfler, axeld@pinc-software.de + * Artur Wyszynski */ /*! @@ -2139,15 +2140,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li BRect rect; link.Read(&rect); - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(&rect); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRectGradient(rect, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(&rect); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillRectGradient(rect, *gradient); break; } case AS_VIEW_DRAW_BITMAP: @@ -2198,15 +2196,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li link.Read(&r); link.Read(&angle); link.Read(&span); - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(&r); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillArcGradient(r, angle, span, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(&r); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillArcGradient(r, angle, span, *gradient); break; } case AS_STROKE_BEZIER: @@ -2232,14 +2227,11 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li link.Read(&(pts[i])); fCurrentView->ConvertToScreenForDrawing(&pts[i]); } - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillBezierGradient(pts, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillBezierGradient(pts, *gradient); break; } case AS_STROKE_ELLIPSE: @@ -2260,15 +2252,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li BRect rect; link.Read(&rect); - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(&rect); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillEllipseGradient(rect, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(&rect); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillEllipseGradient(rect, *gradient); break; } case AS_STROKE_ROUNDRECT: @@ -2295,15 +2284,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li link.Read(&rect); link.Read(&xrad); link.Read(&yrad); - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(&rect); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRoundRectGradient(rect, xrad, yrad, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(&rect); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillRoundRectGradient(rect, xrad, yrad, *gradient); break; } case AS_STROKE_TRIANGLE: @@ -2336,15 +2322,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li fCurrentView->ConvertToScreenForDrawing(&pts[i]); } link.Read(&rect); - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(&rect); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillTriangleGradient(pts, rect, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(&rect); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillTriangleGradient(pts, rect, *gradient); break; } case AS_STROKE_POLYGON: @@ -2385,19 +2368,16 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li BPoint* pointList = new(nothrow) BPoint[pointCount]; if (link.Read(pointList, pointCount * sizeof(BPoint)) >= B_OK) { - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - for (int32 i = 0; i < pointCount; i++) - fCurrentView->ConvertToScreenForDrawing(&pointList[i]); - fCurrentView->ConvertToScreenForDrawing(&polyFrame); - fCurrentView->ConvertToScreenForDrawing(gradient); - - drawingEngine->FillPolygonGradient(pointList, pointCount, - polyFrame, *gradient, isClosed && pointCount > 2); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + for (int32 i = 0; i < pointCount; i++) + fCurrentView->ConvertToScreenForDrawing(&pointList[i]); + fCurrentView->ConvertToScreenForDrawing(&polyFrame); + fCurrentView->ConvertToScreenForDrawing(gradient); + + drawingEngine->FillPolygonGradient(pointList, pointCount, + polyFrame, *gradient, isClosed && pointCount > 2); } delete[] pointList; break; @@ -2460,15 +2440,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li ptList[i] += penLocation; fCurrentView->ConvertToScreenForDrawing(&ptList[i]); } - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillShapeGradient(shapeFrame, opCount, opList, - ptCount, ptList, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillShapeGradient(shapeFrame, opCount, opList, + ptCount, ptList, *gradient); } delete[] opList; @@ -2495,15 +2472,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, BPrivate::LinkReceiver &li BRegion region; if (link.ReadRegion(®ion) < B_OK) break; - gradient_type gradientType; - link.Read(&gradientType); - BGradient* gradient = _GetNewGradientForType(gradientType); - if (gradient) { - link.ReadGradient(gradient); - fCurrentView->ConvertToScreenForDrawing(®ion); - fCurrentView->ConvertToScreenForDrawing(gradient); - drawingEngine->FillRegionGradient(region, *gradient); - } + BGradient* gradient; + if (link.ReadGradient(&gradient) != B_OK) + break; + fCurrentView->ConvertToScreenForDrawing(®ion); + fCurrentView->ConvertToScreenForDrawing(gradient); + drawingEngine->FillRegionGradient(region, *gradient); break; } case AS_STROKE_LINEARRAY: @@ -3491,30 +3465,3 @@ ServerWindow::PictureToRegion(ServerPicture *picture, BRegion ®ion, region.MakeEmpty(); return B_ERROR; } - - -BGradient* -ServerWindow::_GetNewGradientForType(gradient_type type) -{ - switch (type) { - case B_GRADIENT_LINEAR: { - return new (std::nothrow) BGradientLinear(); - } - case B_GRADIENT_RADIAL: { - return new (std::nothrow) BGradientRadial(); - } - case B_GRADIENT_RADIAL_FOCUS: { - return new (std::nothrow) BGradientRadialFocus(); - } - case B_GRADIENT_DIAMOND: { - return new (std::nothrow) BGradientDiamond(); - } - case B_GRADIENT_CONIC: { - return new (std::nothrow) BGradientConic(); - } - case B_GRADIENT_NONE: { - return new (std::nothrow) BGradient(); - } - } - return NULL; -} diff --git a/src/servers/app/ServerWindow.h b/src/servers/app/ServerWindow.h index b376317957..053a77e4ba 100644 --- a/src/servers/app/ServerWindow.h +++ b/src/servers/app/ServerWindow.h @@ -130,8 +130,6 @@ private: void _UpdateCurrentDrawingRegion(); bool _MessageNeedsAllWindowsLocked(uint32 code) const; - - BGradient* _GetNewGradientForType(gradient_type type); // TODO: Move me elsewhere status_t PictureToRegion(ServerPicture *picture,