Added "const" to many parameters.

Removed most data allocations/copying from PicturePlayer, ServerPicture now has to do this when converting coordinates.
Added additional functions to ViewLayer to copy&convert multiple BPoint, BRect, BRegion to Screen coordinates, those should be further optimized.
Removed some function call overhead.
Note: some functions of PicturePlayer don't appear to be implented by PictureDataWriter,


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20292 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen
2007-03-01 23:17:40 +00:00
parent 533b9a69a7
commit 0b0ecfab90
8 changed files with 255 additions and 343 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ virtual void _ReservedShape4();
friend class BPrivate::ServerLink; friend class BPrivate::ServerLink;
void GetData(int32 *opCount, int32 *ptCount, uint32 **opList, BPoint **ptList); void GetData(int32 *opCount, int32 *ptCount, uint32 **opList, BPoint **ptList);
void SetData(int32 opCount, int32 ptCount, uint32 *opList, BPoint *ptList); void SetData(int32 opCount, int32 ptCount, const uint32 *opList, const BPoint *ptList);
void InitData(); void InitData();
void AllocatePts(int32 count); void AllocatePts(int32 count);
void AllocateOps(int32 count); void AllocateOps(int32 count);
+6 -48
View File
@@ -1,13 +1,14 @@
/* /*
* Copyright 2001-2006, Haiku Inc. * Copyright 2001-2007, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected]) * Stefano Ceccherini ([email protected])
* Marcus Overhagen ([email protected])
*/ */
/** PicturePlayer is used to create and play picture data. */ /** PicturePlayer is used to play picture data. */
#ifndef _TPICTURE_H #ifndef _TPICTURE_H
#define _TPICTURE_H #define _TPICTURE_H
@@ -22,51 +23,9 @@
class PicturePlayer { class PicturePlayer {
public: public:
PicturePlayer(); PicturePlayer();
PicturePlayer(const void *data, int32 size, BList *pictures); PicturePlayer(const void *data, size_t size, BList *pictures);
virtual ~PicturePlayer(); virtual ~PicturePlayer();
int16 GetOp();
int8 GetInt8();
int16 GetInt16();
int32 GetInt32();
int64 GetInt64();
float GetFloat();
BPoint GetCoord();
BRect GetRect();
rgb_color GetColor();
//void GetString(char *);
void *GetData(int32);
void GetData(void *data, int32 size);
void AddInt8(int8);
void AddInt16(int16);
void AddInt32(int32);
void AddInt64(int64);
void AddFloat(float);
void AddCoord(BPoint);
void AddRect(BRect);
void AddColor(rgb_color);
void AddString(char *);
void AddData(void *data, int32 size);
// SwapOp();
// SwapInt8();
// SwapInt16();
// SwapInt32();
// SwapInt64();
// SwapFloat();
// SwapCoord();
// SwapRect();
// SwapIRect();
// SwapColor();
// SwapString();
// Swap();
// CheckPattern();
void BeginOp(int32); void BeginOp(int32);
void EndOp(); void EndOp();
@@ -78,11 +37,10 @@ virtual ~PicturePlayer();
status_t Play(void **callBackTable, int32 tableEntries, status_t Play(void **callBackTable, int32 tableEntries,
void *userData); void *userData);
status_t Rewind();
private: private:
BMemoryIO fData; const void *fData;
int32 fSize; size_t fSize;
BList *fPictures; BList *fPictures;
}; };
+6 -4
View File
@@ -173,10 +173,11 @@ PictureDataWriter::WriteDrawString(const BPoint &where, const char *string,
EndOp(); EndOp();
BeginOp(B_PIC_DRAW_STRING); BeginOp(B_PIC_DRAW_STRING);
Write<int32>(length);
WriteData(string, length);
Write<float>(escapement.space); Write<float>(escapement.space);
Write<float>(escapement.nonspace); Write<float>(escapement.nonspace);
//WriteData(string, length + 1); // TODO: is string 0 terminated? why is length given?
WriteData(string, length);
Write<uint8>(0);
EndOp(); EndOp();
return B_OK; return B_OK;
@@ -189,8 +190,8 @@ PictureDataWriter::WriteDrawShape(const int32 &opCount, const void *opList,
{ {
BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE); BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE);
Write<int32>(opCount); Write<int32>(opCount);
WriteData(opList, opCount * sizeof(uint32));
Write<int32>(ptCount); Write<int32>(ptCount);
WriteData(opList, opCount * sizeof(uint32));
WriteData(ptList, ptCount * sizeof(BPoint)); WriteData(ptList, ptCount * sizeof(BPoint));
EndOp(); EndOp();
@@ -203,6 +204,8 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, c
const int32 &bytesPerRow, const int32 &colorSpace, const int32 &flags, const int32 &bytesPerRow, const int32 &colorSpace, const int32 &flags,
const void *data, const int32 &length) const void *data, const int32 &length)
{ {
if (length != height * bytesPerRow)
debugger("PictureDataWriter::WriteDrawBitmap: invalid length");
BeginOp(B_PIC_DRAW_PIXELS); BeginOp(B_PIC_DRAW_PIXELS);
Write<BRect>(srcRect); Write<BRect>(srcRect);
Write<BRect>(dstRect); Write<BRect>(dstRect);
@@ -211,7 +214,6 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, c
Write<int32>(bytesPerRow); Write<int32>(bytesPerRow);
Write<int32>(colorSpace); Write<int32>(colorSpace);
Write<int32>(flags); Write<int32>(flags);
Write<int32>(length);
WriteData(data, length); WriteData(data, length);
EndOp(); EndOp();
return B_OK; return B_OK;
+129 -249
View File
@@ -1,10 +1,11 @@
/* /*
* Copyright 2001-2006, Haiku Inc. * Copyright 2001-2007, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected]) * Stefano Ceccherini ([email protected])
* Marcus Overhagen ([email protected])
*/ */
/** PicturePlayer is used to create and play picture data. */ /** PicturePlayer is used to create and play picture data. */
@@ -21,12 +22,12 @@ typedef void (*fnc_BPoint)(void*, BPoint);
typedef void (*fnc_BPointBPoint)(void*, BPoint, BPoint); typedef void (*fnc_BPointBPoint)(void*, BPoint, BPoint);
typedef void (*fnc_BRect)(void*, BRect); typedef void (*fnc_BRect)(void*, BRect);
typedef void (*fnc_BRectBPoint)(void*, BRect, BPoint); typedef void (*fnc_BRectBPoint)(void*, BRect, BPoint);
typedef void (*fnc_PBPoint)(void*, BPoint*); typedef void (*fnc_PBPoint)(void*, const BPoint*);
typedef void (*fnc_i)(void*, int32); typedef void (*fnc_i)(void*, int32);
typedef void (*fnc_iPBPointb)(void*, int32, BPoint*, bool); typedef void (*fnc_iPBPointb)(void*, int32, const BPoint*, bool);
typedef void (*fnc_iPBPoint)(void*, int32, BPoint*); typedef void (*fnc_iPBPoint)(void*, int32, const BPoint*);
typedef void (*fnc_Pc)(void*, char*); typedef void (*fnc_Pc)(void*, const char*);
typedef void (*fnc_Pcff)(void*, char*, float, float); typedef void (*fnc_Pcff)(void*, const char*, float, float);
typedef void (*fnc_BPointBPointff)(void*, BPoint, BPoint, float, float); typedef void (*fnc_BPointBPointff)(void*, BPoint, BPoint, float, float);
typedef void (*fnc_s)(void*, int16); typedef void (*fnc_s)(void*, int16);
typedef void (*fnc_ssf)(void*, int16, int16, float); typedef void (*fnc_ssf)(void*, int16, int16, float);
@@ -34,14 +35,15 @@ typedef void (*fnc_f)(void*, float);
typedef void (*fnc_Color)(void*, rgb_color); typedef void (*fnc_Color)(void*, rgb_color);
typedef void (*fnc_Pattern)(void*, pattern); typedef void (*fnc_Pattern)(void*, pattern);
typedef void (*fnc_ss)(void *, int16, int16); typedef void (*fnc_ss)(void *, int16, int16);
typedef void (*fnc_PBRecti)(void*, BRect*, int32); typedef void (*fnc_PBRecti)(void*, const BRect*, int32);
typedef void (*fnc_DrawPixels)(void *, BRect, BRect, int32, int32, int32, typedef void (*fnc_DrawPixels)(void *, BRect, BRect, int32, int32, int32,
int32, int32, void*); int32, int32, const void *);
typedef void (*fnc_BShape)(void*, BShape*); typedef void (*fnc_BShape)(void*, BShape*);
PicturePlayer::PicturePlayer(const void *data, int32 size, BList *pictures) PicturePlayer::PicturePlayer(const void *data, size_t size, BList *pictures)
: fData(data, size), : fData(data),
fSize(size),
fPictures(pictures) fPictures(pictures)
{ {
} }
@@ -52,290 +54,177 @@ PicturePlayer::~PicturePlayer()
} }
int16
PicturePlayer::GetOp()
{
int16 data;
fData.Read(&data, sizeof(int16));
return data;
}
int8
PicturePlayer::GetInt8()
{
int8 data;
fData.Read(&data, sizeof(int8));
return data;
}
int16
PicturePlayer::GetInt16()
{
int16 data;
fData.Read(&data, sizeof(int16));
return data;
}
int32
PicturePlayer::GetInt32()
{
int32 data;
fData.Read(&data, sizeof(int32));
return data;
}
float
PicturePlayer::GetFloat()
{
float data;
fData.Read(&data, sizeof(float));
return data;
}
BPoint
PicturePlayer::GetCoord()
{
BPoint data;
fData.Read(&data, sizeof(BPoint));
return data;
}
BRect
PicturePlayer::GetRect()
{
BRect data;
fData.Read(&data, sizeof(BRect));
return data;
}
rgb_color
PicturePlayer::GetColor()
{
rgb_color data;
fData.Read(&data, sizeof(rgb_color));
return data;
}
void
PicturePlayer::GetData(void *data, int32 size)
{
fData.Read(data, size);
}
status_t status_t
PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData) PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
{ {
// TODO: we should probably check if the functions in the table are not NULL // TODO: we should probably check if the functions in the table are not NULL
// before calling them. // before calling them.
// lenght of the stream const char *data = reinterpret_cast<const char *>(fData);
size_t length = fData.Seek(0, SEEK_END); size_t pos = 0;
fData.Seek(0, SEEK_SET);
while (fData.Position() < length) { while ((pos + 6) <= fSize) {
int16 op = GetOp(); int16 op = *reinterpret_cast<const int16 *>(data);
int32 size = GetInt32(); int32 size = *reinterpret_cast<const int32 *>(data + 2);
off_t pos = fData.Position(); pos += 6;
data += 6;
if (pos + size > fSize)
debugger("PicturePlayer::Play: buffer overrun\n");
switch (op) { switch (op) {
case B_PIC_MOVE_PEN_BY: case B_PIC_MOVE_PEN_BY:
{ {
BPoint where = GetCoord(); ((fnc_BPoint)callBackTable[1])(userData,
((fnc_BPoint)callBackTable[1])(userData, where); *reinterpret_cast<const BPoint *>(data)); /* where */
break; break;
} }
case B_PIC_STROKE_LINE: case B_PIC_STROKE_LINE:
{ {
BPoint start = GetCoord(); ((fnc_BPointBPoint)callBackTable[2])(userData,
BPoint end = GetCoord(); *reinterpret_cast<const BPoint *>(data), /* start */
((fnc_BPointBPoint)callBackTable[2])(userData, start, end); *reinterpret_cast<const BPoint *>(data + sizeof(BPoint))); /* end */
break; break;
} }
case B_PIC_STROKE_RECT: case B_PIC_STROKE_RECT:
{ {
BRect rect = GetRect(); ((fnc_BRect)callBackTable[3])(userData,
((fnc_BRect)callBackTable[3])(userData, rect); *reinterpret_cast<const BRect *>(data)); /* rect */
break; break;
} }
case B_PIC_FILL_RECT: case B_PIC_FILL_RECT:
{ {
BRect rect = GetRect(); ((fnc_BRect)callBackTable[4])(userData,
((fnc_BRect)callBackTable[4])(userData, rect); *reinterpret_cast<const BRect *>(data)); /* rect */
break; break;
} }
case B_PIC_STROKE_ROUND_RECT: case B_PIC_STROKE_ROUND_RECT:
{ {
BRect rect = GetRect(); ((fnc_BRectBPoint)callBackTable[5])(userData,
BPoint radii = GetCoord(); *reinterpret_cast<const BRect *>(data), /* rect */
((fnc_BRectBPoint)callBackTable[5])(userData, rect, radii); *reinterpret_cast<const BPoint *>(data + sizeof(BRect))); /* radii */
break; break;
} }
case B_PIC_FILL_ROUND_RECT: case B_PIC_FILL_ROUND_RECT:
{ {
BRect rect = GetRect(); ((fnc_BRectBPoint)callBackTable[6])(userData,
BPoint radii = GetCoord(); *reinterpret_cast<const BRect *>(data), /* rect */
((fnc_BRectBPoint)callBackTable[6])(userData, rect, radii); *reinterpret_cast<const BPoint *>(data + sizeof(BRect))); /* radii */
break; break;
} }
case B_PIC_STROKE_BEZIER: case B_PIC_STROKE_BEZIER:
{ {
BPoint control[4]; ((fnc_PBPoint)callBackTable[7])(userData,
GetData(control, sizeof(control)); reinterpret_cast<const BPoint *>(data));
((fnc_PBPoint)callBackTable[7])(userData, control);
break; break;
} }
case B_PIC_FILL_BEZIER: case B_PIC_FILL_BEZIER:
{ {
BPoint control[4]; ((fnc_PBPoint)callBackTable[8])(userData,
GetData(control, sizeof(control)); reinterpret_cast<const BPoint *>(data));
((fnc_PBPoint)callBackTable[8])(userData, control);
break; break;
} }
case B_PIC_STROKE_ARC: case B_PIC_STROKE_ARC:
{ {
BPoint center = GetCoord(); ((fnc_BPointBPointff)callBackTable[9])(userData,
BPoint radii = GetCoord(); *reinterpret_cast<const BPoint *>(data), /* center */
float startTheta = GetFloat(); *reinterpret_cast<const BPoint *>(data + sizeof(BPoint)), /* radii */
float arcTheta = GetFloat(); *reinterpret_cast<const float *>(data + 2 * sizeof(BPoint)), /* startTheta */
((fnc_BPointBPointff)callBackTable[9])(userData, center, radii, *reinterpret_cast<const float *>(data + 2 * sizeof(BPoint) + sizeof(float))); /* arcTheta */
startTheta, arcTheta);
break; break;
} }
case B_PIC_FILL_ARC: case B_PIC_FILL_ARC:
{ {
BPoint center = GetCoord(); ((fnc_BPointBPointff)callBackTable[10])(userData,
BPoint radii = GetCoord(); *reinterpret_cast<const BPoint *>(data), /* center */
float startTheta = GetFloat(); *reinterpret_cast<const BPoint *>(data + sizeof(BPoint)), /* radii */
float arcTheta = GetFloat(); *reinterpret_cast<const float *>(data + 2 * sizeof(BPoint)), /* startTheta */
((fnc_BPointBPointff)callBackTable[10])(userData, center, radii, *reinterpret_cast<const float *>(data + 2 * sizeof(BPoint) + sizeof(float))); /* arcTheta */
startTheta, arcTheta);
break; break;
} }
case B_PIC_STROKE_ELLIPSE: case B_PIC_STROKE_ELLIPSE:
{ {
BRect rect = GetRect(); const BRect *rect = reinterpret_cast<const BRect *>(data);
BPoint radii((rect.Width() + 1) / 2.0f, (rect.Height() + 1) / 2.0f); BPoint radii((rect->Width() + 1) / 2.0f, (rect->Height() + 1) / 2.0f);
BPoint center = rect.LeftTop() + radii; BPoint center = rect->LeftTop() + radii;
((fnc_BPointBPoint)callBackTable[11])(userData, center, radii); ((fnc_BPointBPoint)callBackTable[11])(userData, center, radii);
break; break;
} }
case B_PIC_FILL_ELLIPSE: case B_PIC_FILL_ELLIPSE:
{ {
BRect rect = GetRect(); const BRect *rect = reinterpret_cast<const BRect *>(data);
BPoint radii((rect.Width() + 1) / 2.0f, (rect.Height() + 1) / 2.0f); BPoint radii((rect->Width() + 1) / 2.0f, (rect->Height() + 1) / 2.0f);
BPoint center = rect.LeftTop() + radii; BPoint center = rect->LeftTop() + radii;
((fnc_BPointBPoint)callBackTable[12])(userData, center, radii); ((fnc_BPointBPoint)callBackTable[12])(userData, center, radii);
break; break;
} }
case B_PIC_STROKE_POLYGON: case B_PIC_STROKE_POLYGON:
{ {
int32 numPoints = GetInt32(); int32 numPoints = *reinterpret_cast<const int32 *>(data);
BPoint *points = new BPoint[numPoints]; ((fnc_iPBPointb)callBackTable[13])(userData,
GetData(points, numPoints * sizeof(BPoint)); numPoints,
bool isClosed = (bool)GetInt8(); reinterpret_cast<const BPoint *>(data + sizeof(int32)), /* points */
((fnc_iPBPointb)callBackTable[13])(userData, numPoints, points, isClosed); *reinterpret_cast<const uint8 *>(data + sizeof(int32) + numPoints * sizeof(BPoint))); /* is-closed */
delete[] points;
break; break;
} }
case B_PIC_FILL_POLYGON: case B_PIC_FILL_POLYGON:
{ {
int32 numPoints = GetInt32(); ((fnc_iPBPoint)callBackTable[14])(userData,
BPoint *points = new BPoint[numPoints]; *reinterpret_cast<const int32 *>(data), /* numPoints */
GetData(points, numPoints * sizeof(BPoint)); reinterpret_cast<const BPoint *>(data + sizeof(int32))); /* points */
((fnc_iPBPoint)callBackTable[14])(userData, numPoints, points);
delete[] points;
break; break;
} }
case B_PIC_STROKE_SHAPE: case B_PIC_STROKE_SHAPE:
case B_PIC_FILL_SHAPE: case B_PIC_FILL_SHAPE:
{ {
int32 opCount = GetInt32(); int32 opCount = *reinterpret_cast<const int32 *>(data);
uint32 *opList = new uint32[opCount]; int32 ptCount = *reinterpret_cast<const int32 *>(data + sizeof(int32));
GetData(opList, opCount * sizeof(uint32)); const uint32 *opList = reinterpret_cast<const uint32 *>(data + 2 * sizeof(int32));
const BPoint *ptList = reinterpret_cast<const BPoint *>(data + 2 * sizeof(int32) + opCount * sizeof(uint32));
int32 ptCount = GetInt32();
BPoint *ptList = new BPoint[ptCount];
GetData(ptList, ptCount * sizeof(BPoint));
// TODO: remove BShape data copying
BShape shape; BShape shape;
shape.SetData(opCount, ptCount, opList, ptList); shape.SetData(opCount, ptCount, opList, ptList);
const int32 tableIndex = (op == B_PIC_STROKE_SHAPE) ? 15 : 16; const int32 tableIndex = (op == B_PIC_STROKE_SHAPE) ? 15 : 16;
((fnc_BShape)callBackTable[tableIndex])(userData, &shape); ((fnc_BShape)callBackTable[tableIndex])(userData, &shape);
delete[] opList;
delete[] ptList;
break; break;
} }
case B_PIC_DRAW_STRING: case B_PIC_DRAW_STRING:
{ {
int32 len = GetInt32(); ((fnc_Pcff)callBackTable[17])(userData,
char *string = new char[len + 1]; reinterpret_cast<const char *>(data + 2 * sizeof(float)), /* string */
GetData(string, len); *reinterpret_cast<const float *>(data), /* escapement.space */
string[len] = '\0'; *reinterpret_cast<const float *>(data + sizeof(float))); /* escapement.nonspace */
float deltax = GetFloat();
float deltay = GetFloat();
((fnc_Pcff)callBackTable[17])(userData, string, deltax, deltay);
delete[] string;
break; break;
} }
case B_PIC_DRAW_PIXELS: case B_PIC_DRAW_PIXELS:
{ {
BRect src = GetRect(); ((fnc_DrawPixels)callBackTable[18])(userData,
BRect dest = GetRect(); *reinterpret_cast<const BRect *>(data), /* src */
int32 width = GetInt32(); *reinterpret_cast<const BRect *>(data + 1 * sizeof(BRect)), /* dst */
int32 height = GetInt32(); *reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect)), /* width */
int32 bytesPerRow = GetInt32(); *reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 1 * sizeof(int32)), /* height */
int32 pixelFormat = GetInt32(); *reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 2 * sizeof(int32)), /* bytesPerRow */
int32 flags = GetInt32(); *reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 3 * sizeof(int32)), /* pixelFormat */
int32 length = GetInt32(); *reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 4 * sizeof(int32)), /* flags */
char *data = new char[length]; reinterpret_cast<const void *>(data + 2 * sizeof(BRect) + 5 * sizeof(int32))); /* data */
GetData(data, length);
((fnc_DrawPixels)callBackTable[18])(userData, src, dest,
width, height, bytesPerRow, pixelFormat, flags, data);
delete[] data;
break; break;
} }
@@ -386,148 +275,142 @@ PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
case B_PIC_SET_ORIGIN: case B_PIC_SET_ORIGIN:
{ {
BPoint pt = GetCoord(); ((fnc_BPoint)callBackTable[28])(userData,
((fnc_BPoint)callBackTable[28])(userData, pt); *reinterpret_cast<const BPoint *>(data)); /* origin */
break; break;
} }
case B_PIC_SET_PEN_LOCATION: case B_PIC_SET_PEN_LOCATION:
{ {
BPoint pt = GetCoord(); ((fnc_BPoint)callBackTable[29])(userData,
((fnc_BPoint)callBackTable[29])(userData, pt); *reinterpret_cast<const BPoint *>(data)); /* location */
break; break;
} }
case B_PIC_SET_DRAWING_MODE: case B_PIC_SET_DRAWING_MODE:
{ {
int16 mode = GetInt16(); ((fnc_s)callBackTable[30])(userData,
((fnc_s)callBackTable[30])(userData, mode); *reinterpret_cast<const int16 *>(data)); /* mode */
break; break;
} }
case B_PIC_SET_LINE_MODE: case B_PIC_SET_LINE_MODE:
{ {
int16 capMode = GetInt16(); ((fnc_ssf)callBackTable[31])(userData,
int16 joinMode = GetInt16(); *reinterpret_cast<const int16 *>(data), /* cap-mode */
float miterLimit = GetFloat(); *reinterpret_cast<const int16 *>(data + 1 * sizeof(int16)), /* join-mode */
((fnc_ssf)callBackTable[31])(userData, capMode, joinMode, miterLimit); *reinterpret_cast<const float *>(data + 2 * sizeof(int16))); /* miter-limit */
break; break;
} }
case B_PIC_SET_PEN_SIZE: case B_PIC_SET_PEN_SIZE:
{ {
float size = GetFloat(); ((fnc_f)callBackTable[32])(userData,
((fnc_f)callBackTable[32])(userData, size); *reinterpret_cast<const float *>(data)); /* size */
break; break;
} }
case B_PIC_SET_FORE_COLOR: case B_PIC_SET_FORE_COLOR:
{ {
rgb_color color = GetColor(); ((fnc_Color)callBackTable[33])(userData,
((fnc_Color)callBackTable[33])(userData, color); *reinterpret_cast<const rgb_color *>(data)); /* color */
break; break;
} }
case B_PIC_SET_BACK_COLOR: case B_PIC_SET_BACK_COLOR:
{ {
rgb_color color = GetColor(); ((fnc_Color)callBackTable[34])(userData,
((fnc_Color)callBackTable[34])(userData, color); *reinterpret_cast<const rgb_color *>(data)); /* color */
break; break;
} }
case B_PIC_SET_STIPLE_PATTERN: case B_PIC_SET_STIPLE_PATTERN:
{ {
pattern p; ((fnc_Pattern)callBackTable[35])(userData,
GetData(&p, sizeof(p)); *reinterpret_cast<const pattern *>(data)); /* pattern */
((fnc_Pattern)callBackTable[35])(userData, p);
break; break;
} }
case B_PIC_SET_SCALE: case B_PIC_SET_SCALE:
{ {
float scale = GetFloat(); ((fnc_f)callBackTable[36])(userData,
((fnc_f)callBackTable[36])(userData, scale); *reinterpret_cast<const float *>(data)); /* scale */
break; break;
} }
case B_PIC_SET_FONT_FAMILY: case B_PIC_SET_FONT_FAMILY:
{ {
int32 len = GetInt32(); debugger("B_PIC_SET_FONT_FAMILY"); // TODO: is this unused?
char *string = new char[len + 1]; ((fnc_Pc)callBackTable[37])(userData,
GetData(string, len); reinterpret_cast<const char *>(data)); /* string */
string[len] = '\0';
((fnc_Pc)callBackTable[37])(userData, string);
delete[] string;
break; break;
} }
case B_PIC_SET_FONT_STYLE: case B_PIC_SET_FONT_STYLE:
{ {
int32 len = GetInt32(); debugger("B_PIC_SET_FONT_STYLE"); // TODO: is this unused?
char *string = new char[len + 1]; ((fnc_Pc)callBackTable[38])(userData,
GetData(string, len); reinterpret_cast<const char *>(data)); /* string */
string[len] = '\0';
((fnc_Pc)callBackTable[38])(userData, string);
delete[] string;
break; break;
} }
case B_PIC_SET_FONT_SPACING: case B_PIC_SET_FONT_SPACING:
{ {
int32 spacing = GetInt32(); ((fnc_i)callBackTable[39])(userData,
((fnc_i)callBackTable[39])(userData, spacing); *reinterpret_cast<const int32 *>(data)); /* spacing */
break; break;
} }
case B_PIC_SET_FONT_SIZE: case B_PIC_SET_FONT_SIZE:
{ {
float size = GetFloat(); ((fnc_f)callBackTable[40])(userData,
((fnc_f)callBackTable[40])(userData, size); *reinterpret_cast<const float *>(data)); /* size */
break; break;
} }
case B_PIC_SET_FONT_ROTATE: case B_PIC_SET_FONT_ROTATE:
{ {
float rotation = GetFloat(); ((fnc_f)callBackTable[41])(userData,
((fnc_f)callBackTable[41])(userData, rotation); *reinterpret_cast<const float *>(data)); /* rotation */
break; break;
} }
case B_PIC_SET_FONT_ENCODING: case B_PIC_SET_FONT_ENCODING:
{ {
int32 encoding = GetInt32(); ((fnc_i)callBackTable[42])(userData,
((fnc_i)callBackTable[42])(userData, encoding); *reinterpret_cast<const int32 *>(data)); /* encoding */
break; break;
} }
case B_PIC_SET_FONT_FLAGS: case B_PIC_SET_FONT_FLAGS:
{ {
int32 flags = GetInt32(); ((fnc_i)callBackTable[43])(userData,
((fnc_i)callBackTable[43])(userData, flags); *reinterpret_cast<const int32 *>(data)); /* flags */
break; break;
} }
case B_PIC_SET_FONT_SHEAR: case B_PIC_SET_FONT_SHEAR:
{ {
float shear = GetFloat(); ((fnc_f)callBackTable[44])(userData,
((fnc_f)callBackTable[44])(userData, shear); *reinterpret_cast<const float *>(data)); /* shear */
break; break;
} }
case B_PIC_SET_FONT_FACE: case B_PIC_SET_FONT_FACE:
{ {
int32 flags = GetInt32(); ((fnc_i)callBackTable[46])(userData,
((fnc_i)callBackTable[46])(userData, flags); *reinterpret_cast<const int32 *>(data)); /* flags */
break; break;
} }
// TODO: Looks like R5 function table only exports 47 functions... // TODO: Looks like R5 function table only exports 47 functions...
// I added this here as a temporary workaround, because there seems to be // I added this here as a temporary workaround, because there seems to be
// no room for this op, although it's obviously implemented in some way... // no room for this op, although it's obviously implemented in some way...
case B_PIC_SET_BLENDING_MODE: case B_PIC_SET_BLENDING_MODE:
{ {
int16 alphaSrcMode = GetInt16(); ((fnc_ss)callBackTable[47])(userData,
int16 alphaFncMode = GetInt16(); *reinterpret_cast<const int16 *>(data), /* alphaSrcMode */
((fnc_ss)callBackTable[47])(userData, alphaSrcMode, alphaFncMode); *reinterpret_cast<const int16 *>(data + sizeof(int16))); /* alphaFncMode */
break; break;
} }
@@ -535,11 +418,8 @@ PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
break; break;
} }
// If we didn't read enough bytes, skip them. This is not a error pos += size;
// since the instructions can change over time. data += size;
// Don't do that for state change ops, they don't have a fixed size
if (op != B_PIC_ENTER_STATE_CHANGE && op != B_PIC_ENTER_FONT_STATE && fData.Position() - pos < size)
fData.Seek(size - (fData.Position() - pos), SEEK_CUR);
// TODO: what if too much was read, should we return B_ERROR? // TODO: what if too much was read, should we return B_ERROR?
} }
+4 -3
View File
@@ -1,11 +1,12 @@
/* /*
* Copyright (c) 2001-2006, Haiku, Inc. * Copyright (c) 2001-2007, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Michael Lotz <[email protected]> * Michael Lotz <[email protected]>
* Marcus Overhagen <[email protected]>
*/ */
/*! BShape encapsulates a Postscript-style "path" */ /*! BShape encapsulates a Postscript-style "path" */
@@ -410,8 +411,8 @@ BShape::GetData(int32 *opCount, int32 *ptCount, uint32 **opList,
void void
BShape::SetData(int32 opCount, int32 ptCount, uint32 *opList, BShape::SetData(int32 opCount, int32 ptCount, const uint32 *opList,
BPoint *ptList) const BPoint *ptList)
{ {
Clear(); Clear();
+41 -27
View File
@@ -1,10 +1,11 @@
/* /*
* Copyright 2001-2006, Haiku. * Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected]) * Stefano Ceccherini ([email protected])
* Marcus Overhagen <[email protected]>
*/ */
@@ -34,6 +35,8 @@ class ShapePainter : public BShapeIterator {
ShapePainter(); ShapePainter();
virtual ~ShapePainter(); virtual ~ShapePainter();
status_t Iterate(const BShape *shape);
virtual status_t IterateMoveTo(BPoint *point); virtual status_t IterateMoveTo(BPoint *point);
virtual status_t IterateLineTo(int32 lineCount, BPoint *linePts); virtual status_t IterateLineTo(int32 lineCount, BPoint *linePts);
virtual status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPts); virtual status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPts);
@@ -55,6 +58,13 @@ ShapePainter::~ShapePainter()
{ {
} }
status_t
ShapePainter::Iterate(const BShape *shape)
{
// this class doesn't modify the shape data
return BShapeIterator::Iterate(const_cast<BShape *>(shape));
}
status_t status_t
ShapePainter::IterateMoveTo(BPoint *point) ShapePainter::IterateMoveTo(BPoint *point)
{ {
@@ -178,20 +188,20 @@ fill_round_rect(ViewLayer *view, BRect rect, BPoint radii)
static void static void
stroke_bezier(ViewLayer *view, BPoint *points) stroke_bezier(ViewLayer *view, const BPoint *viewPoints)
{ {
for (int32 i = 0; i < 4; i++) BPoint points[4];
view->ConvertToScreenForDrawing(&points[i]); view->ConvertToScreenForDrawing(points, viewPoints, 4);
view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), false); view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), false);
} }
static void static void
fill_bezier(ViewLayer *view, BPoint *points) fill_bezier(ViewLayer *view, const BPoint *viewPoints)
{ {
for (int32 i = 0; i < 4; i++) BPoint points[4];
view->ConvertToScreenForDrawing(&points[i]); view->ConvertToScreenForDrawing(points, viewPoints, 4);
view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), true); view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), true);
} }
@@ -240,10 +250,13 @@ fill_ellipse(ViewLayer *view, BPoint center, BPoint radii)
static void static void
stroke_polygon(ViewLayer *view, int32 numPoints, BPoint *points, bool isClosed) stroke_polygon(ViewLayer *view, int32 numPoints, const BPoint *viewPoints, bool isClosed)
{ {
for (int32 i = 0; i < numPoints; i++) BPoint *points = (BPoint *)malloc(numPoints * sizeof(BPoint));
view->ConvertToScreenForDrawing(&points[i]); if (!points)
return;
view->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame = BRect(points[0], points[0]); BRect polyFrame = BRect(points[0], points[0]);
@@ -260,14 +273,19 @@ stroke_polygon(ViewLayer *view, int32 numPoints, BPoint *points, bool isClosed)
view->Window()->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, view->CurrentState(), view->Window()->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, view->CurrentState(),
false, isClosed && numPoints > 2); false, isClosed && numPoints > 2);
free(points);
} }
static void static void
fill_polygon(ViewLayer *view, int32 numPoints, BPoint *points) fill_polygon(ViewLayer *view, int32 numPoints, const BPoint *viewPoints)
{ {
for (int32 i = 0; i < numPoints; i++) BPoint *points = (BPoint *)malloc(numPoints * sizeof(BPoint));
view->ConvertToScreenForDrawing(&points[i]); if (!points)
return;
view->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame = BRect(points[0], points[0]); BRect polyFrame = BRect(points[0], points[0]);
@@ -284,11 +302,13 @@ fill_polygon(ViewLayer *view, int32 numPoints, BPoint *points)
view->Window()->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, view->CurrentState(), view->Window()->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, view->CurrentState(),
true, true); true, true);
free(points);
} }
static void static void
stroke_shape(ViewLayer *view, BShape *shape) stroke_shape(ViewLayer *view, const BShape *shape)
{ {
ShapePainter drawShape; ShapePainter drawShape;
@@ -298,7 +318,7 @@ stroke_shape(ViewLayer *view, BShape *shape)
static void static void
fill_shape(ViewLayer *view, BShape *shape) fill_shape(ViewLayer *view, const BShape *shape)
{ {
ShapePainter drawShape; ShapePainter drawShape;
@@ -308,7 +328,7 @@ fill_shape(ViewLayer *view, BShape *shape)
static void static void
draw_string(ViewLayer *view, char *string, float deltaSpace, float deltaNonSpace) draw_string(ViewLayer *view, const char *string, float deltaSpace, float deltaNonSpace)
{ {
BPoint location = view->CurrentState()->PenLocation(); BPoint location = view->CurrentState()->PenLocation();
escapement_delta delta = {deltaSpace, deltaNonSpace }; escapement_delta delta = {deltaSpace, deltaNonSpace };
@@ -322,7 +342,7 @@ draw_string(ViewLayer *view, char *string, float deltaSpace, float deltaNonSpace
static void static void
draw_pixels(ViewLayer *view, BRect src, BRect dest, int32 width, int32 height, draw_pixels(ViewLayer *view, BRect src, BRect dest, int32 width, int32 height,
int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) int32 bytesPerRow, int32 pixelFormat, int32 flags, const void *data)
{ {
// TODO: Review this // TODO: Review this
UtilityBitmap bitmap(BRect(0, 0, width - 1, height - 1), (color_space)pixelFormat, flags, bytesPerRow); UtilityBitmap bitmap(BRect(0, 0, width - 1, height - 1), (color_space)pixelFormat, flags, bytesPerRow);
@@ -330,13 +350,7 @@ draw_pixels(ViewLayer *view, BRect src, BRect dest, int32 width, int32 height,
if (!bitmap.IsValid()) if (!bitmap.IsValid())
return; return;
uint8 *pixels = (uint8 *)data; memcpy(bitmap.Bits(), data, height * bytesPerRow);
uint8 *destPixels = (uint8 *)bitmap.Bits();
for (int32 h = 0; h < height; h++) {
memcpy(destPixels, pixels, bytesPerRow);
pixels += bytesPerRow;
destPixels += bytesPerRow;
}
view->ConvertToScreenForDrawing(&dest); view->ConvertToScreenForDrawing(&dest);
@@ -345,7 +359,7 @@ draw_pixels(ViewLayer *view, BRect src, BRect dest, int32 width, int32 height,
static void static void
set_clipping_rects(ViewLayer *view, BRect *rects, uint32 numRects) set_clipping_rects(ViewLayer *view, const BRect *rects, uint32 numRects)
{ {
// TODO: This is too slow, we should copy the rects directly to BRegion's internal data // TODO: This is too slow, we should copy the rects directly to BRegion's internal data
BRegion region; BRegion region;
@@ -473,14 +487,14 @@ set_scale(ViewLayer *view, float scale)
static void static void
set_font_family(ViewLayer *view, char *family) set_font_family(ViewLayer *view, const char *family)
{ {
printf("SetFontFamily(%s)\n", family); printf("SetFontFamily(%s)\n", family);
} }
static void static void
set_font_style(ViewLayer *view, char *style) set_font_style(ViewLayer *view, const char *style)
{ {
printf("SetFontStyle(%s)\n", style); printf("SetFontStyle(%s)\n", style);
} }
+56 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001-2006, Haiku, Inc. * Copyright (c) 2001-2007, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -7,6 +7,7 @@
* Adi Oanca <adioanca@gmail.com> * Adi Oanca <adioanca@gmail.com>
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Marcus Overhagen <marcus@overhagen.de>
*/ */
@@ -645,7 +646,7 @@ ViewLayer::ConvertToScreen(BRegion* region) const
BPoint offset(0.0, 0.0); BPoint offset(0.0, 0.0);
ConvertToScreen(&offset); ConvertToScreen(&offset);
region->OffsetBy(offset.x, offset.y); region->OffsetBy((int)offset.x, (int)offset.y);
} }
@@ -689,7 +690,7 @@ ViewLayer::ConvertFromScreen(IntRect* rect) const
BPoint offset(0.0, 0.0); BPoint offset(0.0, 0.0);
ConvertFromScreen(&offset); ConvertFromScreen(&offset);
rect->OffsetBy(offset.x, offset.y); rect->OffsetBy((int)offset.x, (int)offset.y);
} }
@@ -700,7 +701,7 @@ ViewLayer::ConvertFromScreen(BRegion* region) const
BPoint offset(0.0, 0.0); BPoint offset(0.0, 0.0);
ConvertFromScreen(&offset); ConvertFromScreen(&offset);
region->OffsetBy(offset.x, offset.y); region->OffsetBy((int)offset.x, (int)offset.y);
} }
@@ -737,6 +738,57 @@ ViewLayer::ConvertToScreenForDrawing(BRegion* region) const
} }
//! converts points from local *drawing* to screen coordinate system
void
ViewLayer::ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const
{
// TODO: optimize this, it should be smarter
while (num--) {
*dst = *src;
fDrawState->Transform(dst);
// NOTE: from here on, don't use the
// "*ForDrawing()" versions of the parent!
ConvertToScreen(dst);
src++;
dst++;
}
}
//! converts rects from local *drawing* to screen coordinate system
void
ViewLayer::ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const
{
// TODO: optimize this, it should be smarter
while (num--) {
*dst = *src;
fDrawState->Transform(dst);
// NOTE: from here on, don't use the
// "*ForDrawing()" versions of the parent!
ConvertToScreen(dst);
src++;
dst++;
}
}
//! converts regions from local *drawing* to screen coordinate system
void
ViewLayer::ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const
{
// TODO: optimize this, it should be smarter
while (num--) {
*dst = *src;
fDrawState->Transform(dst);
// NOTE: from here on, don't use the
// "*ForDrawing()" versions of the parent!
ConvertToScreen(dst);
src++;
dst++;
}
}
//! converts a point from screen to local coordinate system //! converts a point from screen to local coordinate system
void void
ViewLayer::ConvertFromScreenForDrawing(BPoint* point) const ViewLayer::ConvertFromScreenForDrawing(BPoint* point) const
+6 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001-2006, Haiku, Inc. * Copyright (c) 2001-2007, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -7,6 +7,7 @@
* Adi Oanca <adioanca@gmail.com> * Adi Oanca <adioanca@gmail.com>
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Marcus Overhagen <marcus@overhagen.de>
*/ */
#ifndef VIEW_LAYER_H #ifndef VIEW_LAYER_H
#define VIEW_LAYER_H #define VIEW_LAYER_H
@@ -132,6 +133,10 @@ class ViewLayer {
void ConvertToScreenForDrawing(BRect* rect) const; void ConvertToScreenForDrawing(BRect* rect) const;
void ConvertToScreenForDrawing(BRegion* region) const; void ConvertToScreenForDrawing(BRegion* region) const;
void ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const;
void ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const;
void ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const;
void ConvertFromScreenForDrawing(BPoint* point) const; void ConvertFromScreenForDrawing(BPoint* point) const;
// used when updating the pen position // used when updating the pen position