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:
X512
2025-09-08 16:42:25 +00:00
committed by waddlesplash
parent 0f9d0e5cda
commit 647aba7574
7 changed files with 211 additions and 180 deletions
+2 -2
View File
@@ -10,8 +10,8 @@
namespace BPrivate { namespace BPrivate {
class ServerLink;
class LinkReceiver; class LinkReceiver;
class LinkSender;
}; };
/* Integer rect used to define a clipping rectangle. All bounds are inclusive. */ /* Integer rect used to define a clipping rectangle. All bounds are inclusive. */
@@ -85,8 +85,8 @@ public:
private: private:
friend class BDirectWindow; friend class BDirectWindow;
friend class BPrivate::ServerLink;
friend class BPrivate::LinkReceiver; friend class BPrivate::LinkReceiver;
friend class BPrivate::LinkSender;
class Support; class Support;
friend class Support; friend class Support;
+2
View File
@@ -17,6 +17,7 @@
class BGradient; class BGradient;
class BString; class BString;
class BRegion; class BRegion;
class BShape;
namespace BPrivate { namespace BPrivate {
@@ -39,6 +40,7 @@ class LinkReceiver {
status_t ReadString(BString& string, size_t* _length = NULL); status_t ReadString(BString& string, size_t* _length = NULL);
status_t ReadString(char* buffer, size_t bufferSize); status_t ReadString(char* buffer, size_t bufferSize);
status_t ReadRegion(BRegion* region); status_t ReadRegion(BRegion* region);
status_t ReadShape(BShape* shape);
status_t ReadGradient(BGradient** gradient); status_t ReadGradient(BGradient** gradient);
template <class Type> status_t Read(Type *data) template <class Type> status_t Read(Type *data)
+8
View File
@@ -14,6 +14,11 @@
#include <OS.h> #include <OS.h>
class BGradient;
class BRegion;
class BShape;
namespace BPrivate { namespace BPrivate {
class LinkSender { class LinkSender {
@@ -35,6 +40,9 @@ class LinkSender {
status_t Attach(const void *data, size_t size); status_t Attach(const void *data, size_t size);
status_t AttachString(const char *string, int32 maxLength = -1); 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) template <class Type> status_t Attach(const Type& data)
{ {
return Attach(&data, sizeof(Type)); return Attach(&data, sizeof(Type));
+42
View File
@@ -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 template<class Type> status_t
ServerLink::Attach(const Type& data) 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 template <class Type> status_t
ServerLink::Read(Type* data) ServerLink::Read(Type* data)
{ {
+25
View File
@@ -27,6 +27,10 @@
#include <GradientRadialFocus.h> #include <GradientRadialFocus.h>
#include <GradientDiamond.h> #include <GradientDiamond.h>
#include <GradientConic.h> #include <GradientConic.h>
#include <Shape.h>
#include <ShapePrivate.h>
#include <StackOrHeapArray.h>
#include "link_message.h" #include "link_message.h"
@@ -440,6 +444,7 @@ err:
return status; return status;
} }
status_t status_t
LinkReceiver::ReadRegion(BRegion* region) 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* static BGradient*
gradient_for_type(BGradient::Type type) gradient_for_type(BGradient::Type type)
{ {
+128
View File
@@ -14,6 +14,16 @@
#include <string.h> #include <string.h>
#include <new> #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 <ServerProtocol.h>
#include <LinkSender.h> #include <LinkSender.h>
@@ -28,6 +38,14 @@
# define STRACE(x) ; # define STRACE(x) ;
#endif #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 kMaxStringSize = 4096;
static const size_t kWatermark = kInitialBufferSize - 24; static const size_t kWatermark = kInitialBufferSize - 24;
// if a message is started after this mark, the buffer is flushed automatically // if a message is started after this mark, the buffer is flushed automatically
@@ -227,6 +245,116 @@ LinkSender::AttachString(const char *string, int32 length)
} }
status_t
LinkSender::AttachRegion(const BRegion& region)
{
Attach(&region.fCount, sizeof(int32));
if (region.fCount > 0) {
Attach(&region.fBounds, sizeof(clipping_rect));
return Attach(region.fData,
region.fCount * sizeof(clipping_rect));
}
return Attach(&region.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(&center, 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(&center, 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(&center, 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(&center, sizeof(BPoint));
Attach(&angle, sizeof(float));
break;
}
case BGradient::TYPE_NONE:
{
GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
break;
}
}
return B_OK;
}
status_t status_t
LinkSender::AdjustBuffer(size_t newSize, char **_oldBuffer) LinkSender::AdjustBuffer(size_t newSize, char **_oldBuffer)
{ {
-174
View File
@@ -17,29 +17,9 @@
#include <string.h> #include <string.h>
#include <new> #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> #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 { namespace BPrivate {
@@ -61,160 +41,6 @@ ServerLink::SetTo(port_id sender, port_id receiver)
} }
status_t
ServerLink::ReadRegion(BRegion* region)
{
fReceiver->Read(&region->fCount, sizeof(int32));
if (region->fCount > 0) {
fReceiver->Read(&region->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(&region->fBounds, sizeof(clipping_rect));
}
status_t
ServerLink::AttachRegion(const BRegion& region)
{
fSender->Attach(&region.fCount, sizeof(int32));
if (region.fCount > 0) {
fSender->Attach(&region.fBounds, sizeof(clipping_rect));
return fSender->Attach(region.fData,
region.fCount * sizeof(clipping_rect));
}
return fSender->Attach(&region.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(&center, 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(&center, 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(&center, 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(&center, 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 status_t
ServerLink::FlushWithReply(int32& code) ServerLink::FlushWithReply(int32& code)
{ {