2 * Copyright 2001-2009, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Pahtz <pahtz@yahoo.com.au>
7 * Axel Dörfler, axeld@pinc-software.de
11 /*! Class for low-overhead port-based messaging */
14 #include <ServerLink.h>
21 #include <GradientLinear.h>
22 #include <GradientRadial.h>
23 #include <GradientRadialFocus.h>
24 #include <GradientDiamond.h>
25 #include <GradientConic.h>
28 #include <StackOrHeapArray.h>
30 #include <ServerProtocol.h>
33 //#define TRACE_SERVER_LINK_GRADIENTS
34 #ifdef TRACE_SERVER_LINK_GRADIENTS
36 # define GTRACE(x) debug_printf x
45 ServerLink::ServerLink()
50 ServerLink::~ServerLink()
56 ServerLink::SetTo(port_id sender
, port_id receiver
)
58 fSender
->SetPort(sender
);
59 fReceiver
->SetPort(receiver
);
64 ServerLink::ReadRegion(BRegion
* region
)
66 fReceiver
->Read(®ion
->fCount
, sizeof(int32
));
67 if (region
->fCount
> 0) {
68 fReceiver
->Read(®ion
->fBounds
, sizeof(clipping_rect
));
69 if (!region
->_SetSize(region
->fCount
))
71 return fReceiver
->Read(region
->fData
,
72 region
->fCount
* sizeof(clipping_rect
));
75 return fReceiver
->Read(®ion
->fBounds
, sizeof(clipping_rect
));
80 ServerLink::AttachRegion(const BRegion
& region
)
82 fSender
->Attach(®ion
.fCount
, sizeof(int32
));
83 if (region
.fCount
> 0) {
84 fSender
->Attach(®ion
.fBounds
, sizeof(clipping_rect
));
85 return fSender
->Attach(region
.fData
,
86 region
.fCount
* sizeof(clipping_rect
));
89 return fSender
->Attach(®ion
.fBounds
, sizeof(clipping_rect
));
94 ServerLink::ReadShape(BShape
* shape
)
96 int32 opCount
, ptCount
;
97 fReceiver
->Read(&opCount
, sizeof(int32
));
98 fReceiver
->Read(&ptCount
, sizeof(int32
));
100 BStackOrHeapArray
<uint32
, 64> opList(opCount
);
102 fReceiver
->Read(opList
, opCount
* sizeof(uint32
));
104 BStackOrHeapArray
<BPoint
, 64> ptList(ptCount
);
106 fReceiver
->Read(ptList
, ptCount
* sizeof(BPoint
));
108 shape
->SetData(opCount
, ptCount
, opList
, ptList
);
114 ServerLink::AttachShape(BShape
& shape
)
116 int32 opCount
, ptCount
;
120 shape
.GetData(&opCount
, &ptCount
, &opList
, &ptList
);
122 fSender
->Attach(&opCount
, sizeof(int32
));
123 fSender
->Attach(&ptCount
, sizeof(int32
));
125 fSender
->Attach(opList
, opCount
* sizeof(uint32
));
127 fSender
->Attach(ptList
, ptCount
* sizeof(BPoint
));
133 ServerLink::ReadGradient(BGradient
** _gradient
)
135 GTRACE(("ServerLink::ReadGradient\n"));
136 return fReceiver
->ReadGradient(_gradient
);
141 ServerLink::AttachGradient(const BGradient
& gradient
)
143 GTRACE(("ServerLink::AttachGradient\n"));
144 BGradient::Type gradientType
= gradient
.GetType();
145 int32 stopCount
= gradient
.CountColorStops();
146 GTRACE(("ServerLink::AttachGradient> color stop count == %d\n",
148 fSender
->Attach(&gradientType
, sizeof(BGradient::Type
));
149 fSender
->Attach(&stopCount
, sizeof(int32
));
151 for (int i
= 0; i
< stopCount
; i
++) {
152 fSender
->Attach(gradient
.ColorStopAtFast(i
),
153 sizeof(BGradient::ColorStop
));
157 switch (gradientType
) {
158 case BGradient::TYPE_LINEAR
:
160 GTRACE(("ServerLink::AttachGradient> type == TYPE_LINEAR\n"));
161 const BGradientLinear
* linear
= (BGradientLinear
*)&gradient
;
162 fSender
->Attach(linear
->Start());
163 fSender
->Attach(linear
->End());
166 case BGradient::TYPE_RADIAL
:
168 GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL\n"));
169 const BGradientRadial
* radial
= (BGradientRadial
*)&gradient
;
170 BPoint center
= radial
->Center();
171 float radius
= radial
->Radius();
172 fSender
->Attach(¢er
, sizeof(BPoint
));
173 fSender
->Attach(&radius
, sizeof(float));
176 case BGradient::TYPE_RADIAL_FOCUS
:
178 GTRACE(("ServerLink::AttachGradient> type == TYPE_RADIAL_FOCUS\n"));
179 const BGradientRadialFocus
* radialFocus
180 = (BGradientRadialFocus
*)&gradient
;
181 BPoint center
= radialFocus
->Center();
182 BPoint focal
= radialFocus
->Focal();
183 float radius
= radialFocus
->Radius();
184 fSender
->Attach(¢er
, sizeof(BPoint
));
185 fSender
->Attach(&focal
, sizeof(BPoint
));
186 fSender
->Attach(&radius
, sizeof(float));
189 case BGradient::TYPE_DIAMOND
:
191 GTRACE(("ServerLink::AttachGradient> type == TYPE_DIAMOND\n"));
192 const BGradientDiamond
* diamond
= (BGradientDiamond
*)&gradient
;
193 BPoint center
= diamond
->Center();
194 fSender
->Attach(¢er
, sizeof(BPoint
));
197 case BGradient::TYPE_CONIC
:
199 GTRACE(("ServerLink::AttachGradient> type == TYPE_CONIC\n"));
200 const BGradientConic
* conic
= (BGradientConic
*)&gradient
;
201 BPoint center
= conic
->Center();
202 float angle
= conic
->Angle();
203 fSender
->Attach(¢er
, sizeof(BPoint
));
204 fSender
->Attach(&angle
, sizeof(float));
207 case BGradient::TYPE_NONE
:
209 GTRACE(("ServerLink::AttachGradient> type == TYPE_NONE\n"));
218 ServerLink::FlushWithReply(int32
& code
)
220 status_t status
= Flush(B_INFINITE_TIMEOUT
, true);
224 return GetNextMessage(code
);
228 } // namespace BPrivate