ServerLink: move Read*/Attach* method implementations to LinkSender/Receiver
Change-Id: Ib4dec3348b1438bbdfbaf18146d8aebb1978c39c Reviewed-on: https://review.haiku-os.org/c/haiku/+/9631 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
class ServerLink;
|
||||
class LinkReceiver;
|
||||
class LinkSender;
|
||||
};
|
||||
|
||||
/* Integer rect used to define a clipping rectangle. All bounds are inclusive. */
|
||||
@@ -85,8 +85,8 @@ public:
|
||||
|
||||
private:
|
||||
friend class BDirectWindow;
|
||||
friend class BPrivate::ServerLink;
|
||||
friend class BPrivate::LinkReceiver;
|
||||
friend class BPrivate::LinkSender;
|
||||
|
||||
class Support;
|
||||
friend class Support;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
class BGradient;
|
||||
class BString;
|
||||
class BRegion;
|
||||
class BShape;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
@@ -39,6 +40,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 ReadShape(BShape* shape);
|
||||
status_t ReadGradient(BGradient** gradient);
|
||||
|
||||
template <class Type> status_t Read(Type *data)
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
class BGradient;
|
||||
class BRegion;
|
||||
class BShape;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class LinkSender {
|
||||
public:
|
||||
LinkSender(port_id sendport);
|
||||
@@ -35,6 +40,9 @@ class LinkSender {
|
||||
|
||||
status_t Attach(const void *data, size_t size);
|
||||
status_t AttachString(const char *string, int32 maxLength = -1);
|
||||
status_t AttachRegion(const BRegion& region);
|
||||
status_t AttachShape(BShape& shape);
|
||||
status_t AttachGradient(const BGradient& gradient);
|
||||
template <class Type> status_t Attach(const Type& data)
|
||||
{
|
||||
return Attach(&data, sizeof(Type));
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
status_t ReadRegion(BRegion* region);
|
||||
status_t ReadShape(BShape* shape);
|
||||
status_t ReadGradient(BGradient** _gradient);
|
||||
|
||||
|
||||
template <class Type>
|
||||
status_t Read(Type* data);
|
||||
|
||||
@@ -168,6 +168,27 @@ ServerLink::AttachString(const char* string, int32 length)
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::AttachRegion(const BRegion& region)
|
||||
{
|
||||
return fSender->AttachRegion(region);
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::AttachShape(BShape& shape)
|
||||
{
|
||||
return fSender->AttachShape(shape);
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::AttachGradient(const BGradient& gradient)
|
||||
{
|
||||
return fSender->AttachGradient(gradient);
|
||||
}
|
||||
|
||||
|
||||
template<class Type> status_t
|
||||
ServerLink::Attach(const Type& data)
|
||||
{
|
||||
@@ -234,6 +255,27 @@ ServerLink::ReadString(char** _string, size_t* _length)
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::ReadRegion(BRegion* region)
|
||||
{
|
||||
return fReceiver->ReadRegion(region);
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::ReadShape(BShape* shape)
|
||||
{
|
||||
return fReceiver->ReadShape(shape);
|
||||
}
|
||||
|
||||
|
||||
inline status_t
|
||||
ServerLink::ReadGradient(BGradient** _gradient)
|
||||
{
|
||||
return fReceiver->ReadGradient(_gradient);
|
||||
}
|
||||
|
||||
|
||||
template <class Type> status_t
|
||||
ServerLink::Read(Type* data)
|
||||
{
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
#include <GradientRadialFocus.h>
|
||||
#include <GradientDiamond.h>
|
||||
#include <GradientConic.h>
|
||||
#include <Shape.h>
|
||||
#include <ShapePrivate.h>
|
||||
|
||||
#include <StackOrHeapArray.h>
|
||||
|
||||
#include "link_message.h"
|
||||
|
||||
@@ -440,6 +444,7 @@ err:
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkReceiver::ReadRegion(BRegion* region)
|
||||
{
|
||||
@@ -460,6 +465,26 @@ LinkReceiver::ReadRegion(BRegion* region)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkReceiver::ReadShape(BShape* shape)
|
||||
{
|
||||
int32 opCount, ptCount;
|
||||
Read(&opCount, sizeof(int32));
|
||||
Read(&ptCount, sizeof(int32));
|
||||
|
||||
BStackOrHeapArray<uint32, 64> opList(opCount);
|
||||
if (opCount > 0)
|
||||
Read(opList, opCount * sizeof(uint32));
|
||||
|
||||
BStackOrHeapArray<BPoint, 64> ptList(ptCount);
|
||||
if (ptCount > 0)
|
||||
Read(ptList, ptCount * sizeof(BPoint));
|
||||
|
||||
BShape::Private(*shape).SetData(opCount, ptCount, opList, ptList);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
static BGradient*
|
||||
gradient_for_type(BGradient::Type type)
|
||||
{
|
||||
|
||||
+130
-2
@@ -14,6 +14,16 @@
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
|
||||
#include <Gradient.h>
|
||||
#include <GradientLinear.h>
|
||||
#include <GradientRadial.h>
|
||||
#include <GradientRadialFocus.h>
|
||||
#include <GradientDiamond.h>
|
||||
#include <GradientConic.h>
|
||||
#include <Region.h>
|
||||
#include <Shape.h>
|
||||
#include <ShapePrivate.h>
|
||||
|
||||
#include <ServerProtocol.h>
|
||||
#include <LinkSender.h>
|
||||
|
||||
@@ -28,6 +38,14 @@
|
||||
# define STRACE(x) ;
|
||||
#endif
|
||||
|
||||
//#define TRACE_SERVER_LINK_GRADIENTS
|
||||
#ifdef TRACE_SERVER_LINK_GRADIENTS
|
||||
# include <OS.h>
|
||||
# define GTRACE(x) debug_printf x
|
||||
#else
|
||||
# define GTRACE(x) ;
|
||||
#endif
|
||||
|
||||
static const size_t kMaxStringSize = 4096;
|
||||
static const size_t kWatermark = kInitialBufferSize - 24;
|
||||
// if a message is started after this mark, the buffer is flushed automatically
|
||||
@@ -176,14 +194,14 @@ LinkSender::Attach(const void *passedData, size_t passedSize)
|
||||
|
||||
if (senderArea < B_OK)
|
||||
return senderArea;
|
||||
|
||||
|
||||
data = &senderArea;
|
||||
memcpy(address, passedData, passedSize);
|
||||
|
||||
area_id areaID = senderArea;
|
||||
senderArea = _kern_transfer_area(senderArea, &address,
|
||||
B_ANY_ADDRESS, fTargetTeam);
|
||||
|
||||
|
||||
if (senderArea < B_OK) {
|
||||
delete_area(areaID);
|
||||
return senderArea;
|
||||
@@ -227,6 +245,116 @@ LinkSender::AttachString(const char *string, int32 length)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkSender::AttachRegion(const BRegion& region)
|
||||
{
|
||||
Attach(®ion.fCount, sizeof(int32));
|
||||
if (region.fCount > 0) {
|
||||
Attach(®ion.fBounds, sizeof(clipping_rect));
|
||||
return Attach(region.fData,
|
||||
region.fCount * sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
return Attach(®ion.fBounds, sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkSender::AttachShape(BShape& shape)
|
||||
{
|
||||
int32 opCount, ptCount;
|
||||
uint32* opList;
|
||||
BPoint* ptList;
|
||||
|
||||
BShape::Private(shape).GetData(&opCount, &ptCount, &opList, &ptList);
|
||||
|
||||
Attach(&opCount, sizeof(int32));
|
||||
Attach(&ptCount, sizeof(int32));
|
||||
if (opCount > 0)
|
||||
Attach(opList, opCount * sizeof(uint32));
|
||||
if (ptCount > 0)
|
||||
Attach(ptList, ptCount * sizeof(BPoint));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkSender::AttachGradient(const BGradient& gradient)
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient\n"));
|
||||
BGradient::Type gradientType = gradient.GetType();
|
||||
int32 stopCount = gradient.CountColorStops();
|
||||
GTRACE(("ServerLink::AttachGradient> color stop count == %d\n",
|
||||
(int)stopCount));
|
||||
Attach(&gradientType, sizeof(BGradient::Type));
|
||||
Attach(&stopCount, sizeof(int32));
|
||||
if (stopCount > 0) {
|
||||
for (int i = 0; i < stopCount; i++) {
|
||||
Attach(gradient.ColorStopAtFast(i),
|
||||
sizeof(BGradient::ColorStop));
|
||||
}
|
||||
}
|
||||
|
||||
switch (gradientType) {
|
||||
case BGradient::TYPE_LINEAR:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n"));
|
||||
const BGradientLinear* linear = (BGradientLinear*)&gradient;
|
||||
Attach(linear->Start());
|
||||
Attach(linear->End());
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_RADIAL:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n"));
|
||||
const BGradientRadial* radial = (BGradientRadial*)&gradient;
|
||||
BPoint center = radial->Center();
|
||||
float radius = radial->Radius();
|
||||
Attach(¢er, sizeof(BPoint));
|
||||
Attach(&radius, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_RADIAL_FOCUS:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n"));
|
||||
const BGradientRadialFocus* radialFocus
|
||||
= (BGradientRadialFocus*)&gradient;
|
||||
BPoint center = radialFocus->Center();
|
||||
BPoint focal = radialFocus->Focal();
|
||||
float radius = radialFocus->Radius();
|
||||
Attach(¢er, sizeof(BPoint));
|
||||
Attach(&focal, sizeof(BPoint));
|
||||
Attach(&radius, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_DIAMOND:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n"));
|
||||
const BGradientDiamond* diamond = (BGradientDiamond*)&gradient;
|
||||
BPoint center = diamond->Center();
|
||||
Attach(¢er, sizeof(BPoint));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_CONIC:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n"));
|
||||
const BGradientConic* conic = (BGradientConic*)&gradient;
|
||||
BPoint center = conic->Center();
|
||||
float angle = conic->Angle();
|
||||
Attach(¢er, sizeof(BPoint));
|
||||
Attach(&angle, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_NONE:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LinkSender::AdjustBuffer(size_t newSize, char **_oldBuffer)
|
||||
{
|
||||
|
||||
@@ -17,29 +17,9 @@
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
|
||||
#include <Gradient.h>
|
||||
#include <GradientLinear.h>
|
||||
#include <GradientRadial.h>
|
||||
#include <GradientRadialFocus.h>
|
||||
#include <GradientDiamond.h>
|
||||
#include <GradientConic.h>
|
||||
#include <Region.h>
|
||||
#include <Shape.h>
|
||||
#include <ShapePrivate.h>
|
||||
#include <StackOrHeapArray.h>
|
||||
|
||||
#include <ServerProtocol.h>
|
||||
|
||||
|
||||
//#define TRACE_SERVER_LINK_GRADIENTS
|
||||
#ifdef TRACE_SERVER_LINK_GRADIENTS
|
||||
# include <OS.h>
|
||||
# define GTRACE(x) debug_printf x
|
||||
#else
|
||||
# define GTRACE(x) ;
|
||||
#endif
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
@@ -61,160 +41,6 @@ ServerLink::SetTo(port_id sender, port_id receiver)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::ReadRegion(BRegion* region)
|
||||
{
|
||||
fReceiver->Read(®ion->fCount, sizeof(int32));
|
||||
if (region->fCount > 0) {
|
||||
fReceiver->Read(®ion->fBounds, sizeof(clipping_rect));
|
||||
if (!region->_SetSize(region->fCount))
|
||||
return B_NO_MEMORY;
|
||||
return fReceiver->Read(region->fData,
|
||||
region->fCount * sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
return fReceiver->Read(®ion->fBounds, sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::AttachRegion(const BRegion& region)
|
||||
{
|
||||
fSender->Attach(®ion.fCount, sizeof(int32));
|
||||
if (region.fCount > 0) {
|
||||
fSender->Attach(®ion.fBounds, sizeof(clipping_rect));
|
||||
return fSender->Attach(region.fData,
|
||||
region.fCount * sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
return fSender->Attach(®ion.fBounds, sizeof(clipping_rect));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::ReadShape(BShape* shape)
|
||||
{
|
||||
int32 opCount, ptCount;
|
||||
fReceiver->Read(&opCount, sizeof(int32));
|
||||
fReceiver->Read(&ptCount, sizeof(int32));
|
||||
|
||||
BStackOrHeapArray<uint32, 64> opList(opCount);
|
||||
if (opCount > 0)
|
||||
fReceiver->Read(opList, opCount * sizeof(uint32));
|
||||
|
||||
BStackOrHeapArray<BPoint, 64> ptList(ptCount);
|
||||
if (ptCount > 0)
|
||||
fReceiver->Read(ptList, ptCount * sizeof(BPoint));
|
||||
|
||||
BShape::Private(*shape).SetData(opCount, ptCount, opList, ptList);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::AttachShape(BShape& shape)
|
||||
{
|
||||
int32 opCount, ptCount;
|
||||
uint32* opList;
|
||||
BPoint* ptList;
|
||||
|
||||
BShape::Private(shape).GetData(&opCount, &ptCount, &opList, &ptList);
|
||||
|
||||
fSender->Attach(&opCount, sizeof(int32));
|
||||
fSender->Attach(&ptCount, sizeof(int32));
|
||||
if (opCount > 0)
|
||||
fSender->Attach(opList, opCount * sizeof(uint32));
|
||||
if (ptCount > 0)
|
||||
fSender->Attach(ptList, ptCount * sizeof(BPoint));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::ReadGradient(BGradient** _gradient)
|
||||
{
|
||||
GTRACE(("ServerLink::ReadGradient\n"));
|
||||
return fReceiver->ReadGradient(_gradient);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::AttachGradient(const BGradient& gradient)
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient\n"));
|
||||
BGradient::Type gradientType = gradient.GetType();
|
||||
int32 stopCount = gradient.CountColorStops();
|
||||
GTRACE(("ServerLink::AttachGradient> color stop count == %d\n",
|
||||
(int)stopCount));
|
||||
fSender->Attach(&gradientType, sizeof(BGradient::Type));
|
||||
fSender->Attach(&stopCount, sizeof(int32));
|
||||
if (stopCount > 0) {
|
||||
for (int i = 0; i < stopCount; i++) {
|
||||
fSender->Attach(gradient.ColorStopAtFast(i),
|
||||
sizeof(BGradient::ColorStop));
|
||||
}
|
||||
}
|
||||
|
||||
switch (gradientType) {
|
||||
case BGradient::TYPE_LINEAR:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n"));
|
||||
const BGradientLinear* linear = (BGradientLinear*)&gradient;
|
||||
fSender->Attach(linear->Start());
|
||||
fSender->Attach(linear->End());
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_RADIAL:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n"));
|
||||
const BGradientRadial* radial = (BGradientRadial*)&gradient;
|
||||
BPoint center = radial->Center();
|
||||
float radius = radial->Radius();
|
||||
fSender->Attach(¢er, sizeof(BPoint));
|
||||
fSender->Attach(&radius, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_RADIAL_FOCUS:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n"));
|
||||
const BGradientRadialFocus* radialFocus
|
||||
= (BGradientRadialFocus*)&gradient;
|
||||
BPoint center = radialFocus->Center();
|
||||
BPoint focal = radialFocus->Focal();
|
||||
float radius = radialFocus->Radius();
|
||||
fSender->Attach(¢er, sizeof(BPoint));
|
||||
fSender->Attach(&focal, sizeof(BPoint));
|
||||
fSender->Attach(&radius, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_DIAMOND:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n"));
|
||||
const BGradientDiamond* diamond = (BGradientDiamond*)&gradient;
|
||||
BPoint center = diamond->Center();
|
||||
fSender->Attach(¢er, sizeof(BPoint));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_CONIC:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n"));
|
||||
const BGradientConic* conic = (BGradientConic*)&gradient;
|
||||
BPoint center = conic->Center();
|
||||
float angle = conic->Angle();
|
||||
fSender->Attach(¢er, sizeof(BPoint));
|
||||
fSender->Attach(&angle, sizeof(float));
|
||||
break;
|
||||
}
|
||||
case BGradient::TYPE_NONE:
|
||||
{
|
||||
GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerLink::FlushWithReply(int32& code)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user