BShape: use BShape::Private class to access private methods.

Avoid declaring random friend classes in public header. Allow to access
private methods from arbitrary source if needed.

Change-Id: Iac2cf0ca59e483aa0657e3fe1fc47080c661cf8b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8534
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
X512 2024-11-10 18:08:43 +09:00 committed by waddlesplash
parent e892302909
commit 2b0aa4245b
6 changed files with 37 additions and 24 deletions

View File

@ -87,6 +87,8 @@ public:
const BPoint& point);
status_t Close();
class Private;
private:
// FBC padding
virtual status_t Perform(perform_code code, void* data);
@ -97,17 +99,9 @@ private:
virtual void _ReservedShape4();
private:
friend class Private;
friend class BShapeIterator;
friend class BView;
friend class BFont;
friend class BPrivate::PicturePlayer;
friend class BPrivate::ServerLink;
void GetData(int32* opCount, int32* ptCount,
uint32** opList, BPoint** ptList);
void SetData(int32 opCount, int32 ptCount,
const uint32* opList,
const BPoint* ptList);
void InitData();
bool AllocatePts(int32 count);
bool AllocateOps(int32 count);

View File

@ -9,6 +9,7 @@
#ifndef SHAPE_PRIVATE_H
#define SHAPE_PRIVATE_H
#include <Shape.h>
#include <Point.h>
#include <Rect.h>
#include <Referenceable.h>
@ -97,4 +98,20 @@ public:
};
class BShape::Private {
public:
Private(BShape& shape) : fShape(shape) {}
void GetData(int32* opCount, int32* ptCount,
uint32** opList, BPoint** ptList);
void SetData(int32 opCount, int32 ptCount,
const uint32* opList,
const BPoint* ptList);
shape_data* PrivateData() {return (shape_data*)fShape.fPrivateData;}
private:
BShape& fShape;
};
#endif // SHAPE_PRIVATE_H

View File

@ -25,6 +25,7 @@
#include <GradientConic.h>
#include <Region.h>
#include <Shape.h>
#include <ShapePrivate.h>
#include <StackOrHeapArray.h>
#include <ServerProtocol.h>
@ -105,7 +106,7 @@ ServerLink::ReadShape(BShape* shape)
if (ptCount > 0)
fReceiver->Read(ptList, ptCount * sizeof(BPoint));
shape->SetData(opCount, ptCount, opList, ptList);
BShape::Private(*shape).SetData(opCount, ptCount, opList, ptList);
return B_OK;
}
@ -117,7 +118,7 @@ ServerLink::AttachShape(BShape& shape)
uint32* opList;
BPoint* ptList;
shape.GetData(&opCount, &ptCount, &opList, &ptList);
BShape::Private(shape).GetData(&opCount, &ptCount, &opList, &ptList);
fSender->Attach(&opCount, sizeof(int32));
fSender->Attach(&ptCount, sizeof(int32));

View File

@ -22,6 +22,7 @@
#include <Gradient.h>
#include <PictureProtocol.h>
#include <Shape.h>
#include <ShapePrivate.h>
#include <AutoDeleter.h>
#include <StackOrHeapArray.h>
@ -1062,7 +1063,7 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
// TODO: remove BShape data copying
BShape shape;
shape.SetData(*opCount, *pointCount, opList, pointList);
BShape::Private(shape).SetData(*opCount, *pointCount, opList, pointList);
callbacks.draw_shape(userData, shape,
header->op == B_PIC_FILL_SHAPE);
@ -1163,7 +1164,7 @@ PicturePlayer::_Play(const picture_player_callbacks& callbacks, void* userData,
// TODO: remove BShape data copying
BShape shape;
shape.SetData(*opCount, *pointCount, opList, pointList);
BShape::Private(shape).SetData(*opCount, *pointCount, opList, pointList);
callbacks.draw_shape_gradient(userData, shape, *gradient,
header->op == B_PIC_FILL_SHAPE_GRADIENT);

View File

@ -571,10 +571,10 @@ void BShape::_ReservedShape4() {}
void
BShape::GetData(int32* opCount, int32* ptCount, uint32** opList,
BShape::Private::GetData(int32* opCount, int32* ptCount, uint32** opList,
BPoint** ptList)
{
shape_data* data = (shape_data*)fPrivateData;
shape_data* data = PrivateData();
*opCount = data->opCount;
*ptCount = data->ptCount;
@ -584,22 +584,22 @@ BShape::GetData(int32* opCount, int32* ptCount, uint32** opList,
void
BShape::SetData(int32 opCount, int32 ptCount, const uint32* opList,
BShape::Private::SetData(int32 opCount, int32 ptCount, const uint32* opList,
const BPoint* ptList)
{
Clear();
fShape.Clear();
if (opCount == 0)
return;
shape_data* data = (shape_data*)fPrivateData;
shape_data* data = PrivateData();
if (!AllocateOps(opCount) || !AllocatePts(ptCount))
if (!fShape.AllocateOps(opCount) || !fShape.AllocatePts(ptCount))
return;
memcpy(data->opList, opList, opCount * sizeof(uint32));
data->opCount = opCount;
fBuildingOp = data->opList[data->opCount - 1];
fShape.fBuildingOp = data->opList[data->opCount - 1];
if (ptCount > 0) {
memcpy((void*)data->ptList, ptList, ptCount * sizeof(BPoint));

View File

@ -4067,7 +4067,7 @@ BView::StrokeShape(BShape* shape, ::pattern pattern)
if (shape == NULL || fOwner == NULL)
return;
shape_data* sd = (shape_data*)shape->fPrivateData;
shape_data* sd = BShape::Private(*shape).PrivateData();
if (sd->opCount == 0 || sd->ptCount == 0)
return;
@ -4088,7 +4088,7 @@ BView::FillShape(BShape* shape, ::pattern pattern)
if (shape == NULL || fOwner == NULL)
return;
shape_data* sd = (shape_data*)(shape->fPrivateData);
shape_data* sd = BShape::Private(*shape).PrivateData();
if (sd->opCount == 0 || sd->ptCount == 0)
return;
@ -4109,7 +4109,7 @@ BView::FillShape(BShape* shape, const BGradient& gradient)
if (shape == NULL || fOwner == NULL)
return;
shape_data* sd = (shape_data*)(shape->fPrivateData);
shape_data* sd = BShape::Private(*shape).PrivateData();
if (sd->opCount == 0 || sd->ptCount == 0)
return;
@ -5977,7 +5977,7 @@ BView::_ClipToShape(BShape* shape, bool inverse)
if (shape == NULL)
return;
shape_data* sd = (shape_data*)shape->fPrivateData;
shape_data* sd = BShape::Private(*shape).PrivateData();
if (sd->opCount == 0 || sd->ptCount == 0)
return;