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

View File

@ -81,7 +81,7 @@ virtual void _ReservedShape4();
friend class BPrivate::ServerLink;
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 AllocatePts(int32 count);
void AllocateOps(int32 count);

View File

@ -1,13 +1,14 @@
/*
* Copyright 2001-2006, Haiku Inc.
* Copyright 2001-2007, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers (mflerackers@androme.be)
* Stefano Ceccherini (burton666@libero.it)
* Marcus Overhagen (marcus@overhagen.de)
*/
/** PicturePlayer is used to create and play picture data. */
/** PicturePlayer is used to play picture data. */
#ifndef _TPICTURE_H
#define _TPICTURE_H
@ -22,51 +23,9 @@
class PicturePlayer {
public:
PicturePlayer();
PicturePlayer(const void *data, int32 size, BList *pictures);
PicturePlayer(const void *data, size_t size, BList *pictures);
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 EndOp();
@ -78,11 +37,10 @@ virtual ~PicturePlayer();
status_t Play(void **callBackTable, int32 tableEntries,
void *userData);
status_t Rewind();
private:
BMemoryIO fData;
int32 fSize;
const void *fData;
size_t fSize;
BList *fPictures;
};

View File

@ -1,9 +1,9 @@
/*
* Copyright 2006, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini (burton666@libero.it)
* Copyright 2006, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini (burton666@libero.it)
*/
#include <DataIO.h>
@ -173,10 +173,11 @@ PictureDataWriter::WriteDrawString(const BPoint &where, const char *string,
EndOp();
BeginOp(B_PIC_DRAW_STRING);
Write<int32>(length);
WriteData(string, length);
Write<float>(escapement.space);
Write<float>(escapement.nonspace);
//WriteData(string, length + 1); // TODO: is string 0 terminated? why is length given?
WriteData(string, length);
Write<uint8>(0);
EndOp();
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);
Write<int32>(opCount);
WriteData(opList, opCount * sizeof(uint32));
Write<int32>(ptCount);
WriteData(opList, opCount * sizeof(uint32));
WriteData(ptList, ptCount * sizeof(BPoint));
EndOp();
@ -203,6 +204,8 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, c
const int32 &bytesPerRow, const int32 &colorSpace, const int32 &flags,
const void *data, const int32 &length)
{
if (length != height * bytesPerRow)
debugger("PictureDataWriter::WriteDrawBitmap: invalid length");
BeginOp(B_PIC_DRAW_PIXELS);
Write<BRect>(srcRect);
Write<BRect>(dstRect);
@ -211,7 +214,6 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, c
Write<int32>(bytesPerRow);
Write<int32>(colorSpace);
Write<int32>(flags);
Write<int32>(length);
WriteData(data, length);
EndOp();
return B_OK;

View File

@ -1,10 +1,11 @@
/*
* Copyright 2001-2006, Haiku Inc.
* Copyright 2001-2007, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers (mflerackers@androme.be)
* Stefano Ceccherini (burton666@libero.it)
* Marcus Overhagen (marcus@overhagen.de)
*/
/** 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_BRect)(void*, BRect);
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_iPBPointb)(void*, int32, BPoint*, bool);
typedef void (*fnc_iPBPoint)(void*, int32, BPoint*);
typedef void (*fnc_Pc)(void*, char*);
typedef void (*fnc_Pcff)(void*, char*, float, float);
typedef void (*fnc_iPBPointb)(void*, int32, const BPoint*, bool);
typedef void (*fnc_iPBPoint)(void*, int32, const BPoint*);
typedef void (*fnc_Pc)(void*, const char*);
typedef void (*fnc_Pcff)(void*, const char*, float, float);
typedef void (*fnc_BPointBPointff)(void*, BPoint, BPoint, float, float);
typedef void (*fnc_s)(void*, int16);
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_Pattern)(void*, pattern);
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,
int32, int32, void*);
int32, int32, const void *);
typedef void (*fnc_BShape)(void*, BShape*);
PicturePlayer::PicturePlayer(const void *data, int32 size, BList *pictures)
: fData(data, size),
PicturePlayer::PicturePlayer(const void *data, size_t size, BList *pictures)
: fData(data),
fSize(size),
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
PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
{
// TODO: we should probably check if the functions in the table are not NULL
// before calling them.
// lenght of the stream
size_t length = fData.Seek(0, SEEK_END);
fData.Seek(0, SEEK_SET);
const char *data = reinterpret_cast<const char *>(fData);
size_t pos = 0;
while (fData.Position() < length) {
int16 op = GetOp();
int32 size = GetInt32();
off_t pos = fData.Position();
while ((pos + 6) <= fSize) {
int16 op = *reinterpret_cast<const int16 *>(data);
int32 size = *reinterpret_cast<const int32 *>(data + 2);
pos += 6;
data += 6;
if (pos + size > fSize)
debugger("PicturePlayer::Play: buffer overrun\n");
switch (op) {
case B_PIC_MOVE_PEN_BY:
{
BPoint where = GetCoord();
((fnc_BPoint)callBackTable[1])(userData, where);
((fnc_BPoint)callBackTable[1])(userData,
*reinterpret_cast<const BPoint *>(data)); /* where */
break;
}
case B_PIC_STROKE_LINE:
{
BPoint start = GetCoord();
BPoint end = GetCoord();
((fnc_BPointBPoint)callBackTable[2])(userData, start, end);
((fnc_BPointBPoint)callBackTable[2])(userData,
*reinterpret_cast<const BPoint *>(data), /* start */
*reinterpret_cast<const BPoint *>(data + sizeof(BPoint))); /* end */
break;
}
case B_PIC_STROKE_RECT:
{
BRect rect = GetRect();
((fnc_BRect)callBackTable[3])(userData, rect);
((fnc_BRect)callBackTable[3])(userData,
*reinterpret_cast<const BRect *>(data)); /* rect */
break;
}
case B_PIC_FILL_RECT:
{
BRect rect = GetRect();
((fnc_BRect)callBackTable[4])(userData, rect);
((fnc_BRect)callBackTable[4])(userData,
*reinterpret_cast<const BRect *>(data)); /* rect */
break;
}
case B_PIC_STROKE_ROUND_RECT:
{
BRect rect = GetRect();
BPoint radii = GetCoord();
((fnc_BRectBPoint)callBackTable[5])(userData, rect, radii);
((fnc_BRectBPoint)callBackTable[5])(userData,
*reinterpret_cast<const BRect *>(data), /* rect */
*reinterpret_cast<const BPoint *>(data + sizeof(BRect))); /* radii */
break;
}
case B_PIC_FILL_ROUND_RECT:
{
BRect rect = GetRect();
BPoint radii = GetCoord();
((fnc_BRectBPoint)callBackTable[6])(userData, rect, radii);
((fnc_BRectBPoint)callBackTable[6])(userData,
*reinterpret_cast<const BRect *>(data), /* rect */
*reinterpret_cast<const BPoint *>(data + sizeof(BRect))); /* radii */
break;
}
case B_PIC_STROKE_BEZIER:
{
BPoint control[4];
GetData(control, sizeof(control));
((fnc_PBPoint)callBackTable[7])(userData, control);
((fnc_PBPoint)callBackTable[7])(userData,
reinterpret_cast<const BPoint *>(data));
break;
}
case B_PIC_FILL_BEZIER:
{
BPoint control[4];
GetData(control, sizeof(control));
((fnc_PBPoint)callBackTable[8])(userData, control);
((fnc_PBPoint)callBackTable[8])(userData,
reinterpret_cast<const BPoint *>(data));
break;
}
case B_PIC_STROKE_ARC:
{
BPoint center = GetCoord();
BPoint radii = GetCoord();
float startTheta = GetFloat();
float arcTheta = GetFloat();
((fnc_BPointBPointff)callBackTable[9])(userData, center, radii,
startTheta, arcTheta);
((fnc_BPointBPointff)callBackTable[9])(userData,
*reinterpret_cast<const BPoint *>(data), /* center */
*reinterpret_cast<const BPoint *>(data + sizeof(BPoint)), /* radii */
*reinterpret_cast<const float *>(data + 2 * sizeof(BPoint)), /* startTheta */
*reinterpret_cast<const float *>(data + 2 * sizeof(BPoint) + sizeof(float))); /* arcTheta */
break;
}
case B_PIC_FILL_ARC:
{
BPoint center = GetCoord();
BPoint radii = GetCoord();
float startTheta = GetFloat();
float arcTheta = GetFloat();
((fnc_BPointBPointff)callBackTable[10])(userData, center, radii,
startTheta, arcTheta);
((fnc_BPointBPointff)callBackTable[10])(userData,
*reinterpret_cast<const BPoint *>(data), /* center */
*reinterpret_cast<const BPoint *>(data + sizeof(BPoint)), /* radii */
*reinterpret_cast<const float *>(data + 2 * sizeof(BPoint)), /* startTheta */
*reinterpret_cast<const float *>(data + 2 * sizeof(BPoint) + sizeof(float))); /* arcTheta */
break;
}
case B_PIC_STROKE_ELLIPSE:
{
BRect rect = GetRect();
BPoint radii((rect.Width() + 1) / 2.0f, (rect.Height() + 1) / 2.0f);
BPoint center = rect.LeftTop() + radii;
const BRect *rect = reinterpret_cast<const BRect *>(data);
BPoint radii((rect->Width() + 1) / 2.0f, (rect->Height() + 1) / 2.0f);
BPoint center = rect->LeftTop() + radii;
((fnc_BPointBPoint)callBackTable[11])(userData, center, radii);
break;
}
case B_PIC_FILL_ELLIPSE:
{
BRect rect = GetRect();
BPoint radii((rect.Width() + 1) / 2.0f, (rect.Height() + 1) / 2.0f);
BPoint center = rect.LeftTop() + radii;
const BRect *rect = reinterpret_cast<const BRect *>(data);
BPoint radii((rect->Width() + 1) / 2.0f, (rect->Height() + 1) / 2.0f);
BPoint center = rect->LeftTop() + radii;
((fnc_BPointBPoint)callBackTable[12])(userData, center, radii);
break;
}
case B_PIC_STROKE_POLYGON:
{
int32 numPoints = GetInt32();
BPoint *points = new BPoint[numPoints];
GetData(points, numPoints * sizeof(BPoint));
bool isClosed = (bool)GetInt8();
((fnc_iPBPointb)callBackTable[13])(userData, numPoints, points, isClosed);
delete[] points;
int32 numPoints = *reinterpret_cast<const int32 *>(data);
((fnc_iPBPointb)callBackTable[13])(userData,
numPoints,
reinterpret_cast<const BPoint *>(data + sizeof(int32)), /* points */
*reinterpret_cast<const uint8 *>(data + sizeof(int32) + numPoints * sizeof(BPoint))); /* is-closed */
break;
}
case B_PIC_FILL_POLYGON:
{
int32 numPoints = GetInt32();
BPoint *points = new BPoint[numPoints];
GetData(points, numPoints * sizeof(BPoint));
((fnc_iPBPoint)callBackTable[14])(userData, numPoints, points);
delete[] points;
((fnc_iPBPoint)callBackTable[14])(userData,
*reinterpret_cast<const int32 *>(data), /* numPoints */
reinterpret_cast<const BPoint *>(data + sizeof(int32))); /* points */
break;
}
case B_PIC_STROKE_SHAPE:
case B_PIC_FILL_SHAPE:
{
int32 opCount = GetInt32();
uint32 *opList = new uint32[opCount];
GetData(opList, opCount * sizeof(uint32));
int32 ptCount = GetInt32();
BPoint *ptList = new BPoint[ptCount];
GetData(ptList, ptCount * sizeof(BPoint));
int32 opCount = *reinterpret_cast<const int32 *>(data);
int32 ptCount = *reinterpret_cast<const int32 *>(data + sizeof(int32));
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));
BShape shape;
// TODO: remove BShape data copying
BShape shape;
shape.SetData(opCount, ptCount, opList, ptList);
const int32 tableIndex = (op == B_PIC_STROKE_SHAPE) ? 15 : 16;
((fnc_BShape)callBackTable[tableIndex])(userData, &shape);
delete[] opList;
delete[] ptList;
break;
}
case B_PIC_DRAW_STRING:
{
int32 len = GetInt32();
char *string = new char[len + 1];
GetData(string, len);
string[len] = '\0';
float deltax = GetFloat();
float deltay = GetFloat();
((fnc_Pcff)callBackTable[17])(userData, string, deltax, deltay);
delete[] string;
((fnc_Pcff)callBackTable[17])(userData,
reinterpret_cast<const char *>(data + 2 * sizeof(float)), /* string */
*reinterpret_cast<const float *>(data), /* escapement.space */
*reinterpret_cast<const float *>(data + sizeof(float))); /* escapement.nonspace */
break;
}
case B_PIC_DRAW_PIXELS:
{
BRect src = GetRect();
BRect dest = GetRect();
int32 width = GetInt32();
int32 height = GetInt32();
int32 bytesPerRow = GetInt32();
int32 pixelFormat = GetInt32();
int32 flags = GetInt32();
int32 length = GetInt32();
char *data = new char[length];
GetData(data, length);
((fnc_DrawPixels)callBackTable[18])(userData, src, dest,
width, height, bytesPerRow, pixelFormat, flags, data);
delete[] data;
((fnc_DrawPixels)callBackTable[18])(userData,
*reinterpret_cast<const BRect *>(data), /* src */
*reinterpret_cast<const BRect *>(data + 1 * sizeof(BRect)), /* dst */
*reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect)), /* width */
*reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 1 * sizeof(int32)), /* height */
*reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 2 * sizeof(int32)), /* bytesPerRow */
*reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 3 * sizeof(int32)), /* pixelFormat */
*reinterpret_cast<const int32 *>(data + 2 * sizeof(BRect) + 4 * sizeof(int32)), /* flags */
reinterpret_cast<const void *>(data + 2 * sizeof(BRect) + 5 * sizeof(int32))); /* data */
break;
}
@ -386,148 +275,142 @@ PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
case B_PIC_SET_ORIGIN:
{
BPoint pt = GetCoord();
((fnc_BPoint)callBackTable[28])(userData, pt);
((fnc_BPoint)callBackTable[28])(userData,
*reinterpret_cast<const BPoint *>(data)); /* origin */
break;
}
case B_PIC_SET_PEN_LOCATION:
{
BPoint pt = GetCoord();
((fnc_BPoint)callBackTable[29])(userData, pt);
((fnc_BPoint)callBackTable[29])(userData,
*reinterpret_cast<const BPoint *>(data)); /* location */
break;
}
case B_PIC_SET_DRAWING_MODE:
{
int16 mode = GetInt16();
((fnc_s)callBackTable[30])(userData, mode);
((fnc_s)callBackTable[30])(userData,
*reinterpret_cast<const int16 *>(data)); /* mode */
break;
}
case B_PIC_SET_LINE_MODE:
{
int16 capMode = GetInt16();
int16 joinMode = GetInt16();
float miterLimit = GetFloat();
((fnc_ssf)callBackTable[31])(userData, capMode, joinMode, miterLimit);
((fnc_ssf)callBackTable[31])(userData,
*reinterpret_cast<const int16 *>(data), /* cap-mode */
*reinterpret_cast<const int16 *>(data + 1 * sizeof(int16)), /* join-mode */
*reinterpret_cast<const float *>(data + 2 * sizeof(int16))); /* miter-limit */
break;
}
case B_PIC_SET_PEN_SIZE:
{
float size = GetFloat();
((fnc_f)callBackTable[32])(userData, size);
((fnc_f)callBackTable[32])(userData,
*reinterpret_cast<const float *>(data)); /* size */
break;
}
case B_PIC_SET_FORE_COLOR:
{
rgb_color color = GetColor();
((fnc_Color)callBackTable[33])(userData, color);
((fnc_Color)callBackTable[33])(userData,
*reinterpret_cast<const rgb_color *>(data)); /* color */
break;
}
case B_PIC_SET_BACK_COLOR:
{
rgb_color color = GetColor();
((fnc_Color)callBackTable[34])(userData, color);
((fnc_Color)callBackTable[34])(userData,
*reinterpret_cast<const rgb_color *>(data)); /* color */
break;
}
case B_PIC_SET_STIPLE_PATTERN:
{
pattern p;
GetData(&p, sizeof(p));
((fnc_Pattern)callBackTable[35])(userData, p);
((fnc_Pattern)callBackTable[35])(userData,
*reinterpret_cast<const pattern *>(data)); /* pattern */
break;
}
case B_PIC_SET_SCALE:
{
float scale = GetFloat();
((fnc_f)callBackTable[36])(userData, scale);
((fnc_f)callBackTable[36])(userData,
*reinterpret_cast<const float *>(data)); /* scale */
break;
}
case B_PIC_SET_FONT_FAMILY:
{
int32 len = GetInt32();
char *string = new char[len + 1];
GetData(string, len);
string[len] = '\0';
((fnc_Pc)callBackTable[37])(userData, string);
delete[] string;
debugger("B_PIC_SET_FONT_FAMILY"); // TODO: is this unused?
((fnc_Pc)callBackTable[37])(userData,
reinterpret_cast<const char *>(data)); /* string */
break;
}
case B_PIC_SET_FONT_STYLE:
{
int32 len = GetInt32();
char *string = new char[len + 1];
GetData(string, len);
string[len] = '\0';
((fnc_Pc)callBackTable[38])(userData, string);
delete[] string;
debugger("B_PIC_SET_FONT_STYLE"); // TODO: is this unused?
((fnc_Pc)callBackTable[38])(userData,
reinterpret_cast<const char *>(data)); /* string */
break;
}
case B_PIC_SET_FONT_SPACING:
{
int32 spacing = GetInt32();
((fnc_i)callBackTable[39])(userData, spacing);
((fnc_i)callBackTable[39])(userData,
*reinterpret_cast<const int32 *>(data)); /* spacing */
break;
}
case B_PIC_SET_FONT_SIZE:
{
float size = GetFloat();
((fnc_f)callBackTable[40])(userData, size);
((fnc_f)callBackTable[40])(userData,
*reinterpret_cast<const float *>(data)); /* size */
break;
}
case B_PIC_SET_FONT_ROTATE:
{
float rotation = GetFloat();
((fnc_f)callBackTable[41])(userData, rotation);
((fnc_f)callBackTable[41])(userData,
*reinterpret_cast<const float *>(data)); /* rotation */
break;
}
case B_PIC_SET_FONT_ENCODING:
{
int32 encoding = GetInt32();
((fnc_i)callBackTable[42])(userData, encoding);
((fnc_i)callBackTable[42])(userData,
*reinterpret_cast<const int32 *>(data)); /* encoding */
break;
}
case B_PIC_SET_FONT_FLAGS:
{
int32 flags = GetInt32();
((fnc_i)callBackTable[43])(userData, flags);
((fnc_i)callBackTable[43])(userData,
*reinterpret_cast<const int32 *>(data)); /* flags */
break;
}
case B_PIC_SET_FONT_SHEAR:
{
float shear = GetFloat();
((fnc_f)callBackTable[44])(userData, shear);
((fnc_f)callBackTable[44])(userData,
*reinterpret_cast<const float *>(data)); /* shear */
break;
}
case B_PIC_SET_FONT_FACE:
{
int32 flags = GetInt32();
((fnc_i)callBackTable[46])(userData, flags);
((fnc_i)callBackTable[46])(userData,
*reinterpret_cast<const int32 *>(data)); /* flags */
break;
}
// TODO: Looks like R5 function table only exports 47 functions...
// 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...
case B_PIC_SET_BLENDING_MODE:
{
int16 alphaSrcMode = GetInt16();
int16 alphaFncMode = GetInt16();
((fnc_ss)callBackTable[47])(userData, alphaSrcMode, alphaFncMode);
((fnc_ss)callBackTable[47])(userData,
*reinterpret_cast<const int16 *>(data), /* alphaSrcMode */
*reinterpret_cast<const int16 *>(data + sizeof(int16))); /* alphaFncMode */
break;
}
@ -535,11 +418,8 @@ PicturePlayer::Play(void **callBackTable, int32 tableEntries, void *userData)
break;
}
// If we didn't read enough bytes, skip them. This is not a error
// since the instructions can change over time.
// 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);
pos += size;
data += size;
// TODO: what if too much was read, should we return B_ERROR?
}

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.
*
* Authors:
* Marc Flerackers (mflerackers@androme.be)
* Stephan Aßmus <superstippi@gmx.de>
* Michael Lotz <mmlr@mlotz.ch>
* Marcus Overhagen <marcus@overhagen.de>
*/
/*! BShape encapsulates a Postscript-style "path" */
@ -410,8 +411,8 @@ BShape::GetData(int32 *opCount, int32 *ptCount, uint32 **opList,
void
BShape::SetData(int32 opCount, int32 ptCount, uint32 *opList,
BPoint *ptList)
BShape::SetData(int32 opCount, int32 ptCount, const uint32 *opList,
const BPoint *ptList)
{
Clear();

View File

@ -1,10 +1,11 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers (mflerackers@androme.be)
* Stefano Ceccherini (burton666@libero.it)
* Marcus Overhagen <marcus@overhagen.de>
*/
@ -34,6 +35,8 @@ class ShapePainter : public BShapeIterator {
ShapePainter();
virtual ~ShapePainter();
status_t Iterate(const BShape *shape);
virtual status_t IterateMoveTo(BPoint *point);
virtual status_t IterateLineTo(int32 lineCount, BPoint *linePts);
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
ShapePainter::IterateMoveTo(BPoint *point)
{
@ -178,20 +188,20 @@ fill_round_rect(ViewLayer *view, BRect rect, BPoint radii)
static void
stroke_bezier(ViewLayer *view, BPoint *points)
stroke_bezier(ViewLayer *view, const BPoint *viewPoints)
{
for (int32 i = 0; i < 4; i++)
view->ConvertToScreenForDrawing(&points[i]);
BPoint points[4];
view->ConvertToScreenForDrawing(points, viewPoints, 4);
view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), false);
}
static void
fill_bezier(ViewLayer *view, BPoint *points)
fill_bezier(ViewLayer *view, const BPoint *viewPoints)
{
for (int32 i = 0; i < 4; i++)
view->ConvertToScreenForDrawing(&points[i]);
BPoint points[4];
view->ConvertToScreenForDrawing(points, viewPoints, 4);
view->Window()->GetDrawingEngine()->DrawBezier(points, view->CurrentState(), true);
}
@ -240,10 +250,13 @@ fill_ellipse(ViewLayer *view, BPoint center, BPoint radii)
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++)
view->ConvertToScreenForDrawing(&points[i]);
BPoint *points = (BPoint *)malloc(numPoints * sizeof(BPoint));
if (!points)
return;
view->ConvertToScreenForDrawing(points, viewPoints, numPoints);
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(),
false, isClosed && numPoints > 2);
free(points);
}
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++)
view->ConvertToScreenForDrawing(&points[i]);
BPoint *points = (BPoint *)malloc(numPoints * sizeof(BPoint));
if (!points)
return;
view->ConvertToScreenForDrawing(points, viewPoints, numPoints);
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(),
true, true);
free(points);
}
static void
stroke_shape(ViewLayer *view, BShape *shape)
stroke_shape(ViewLayer *view, const BShape *shape)
{
ShapePainter drawShape;
@ -298,7 +318,7 @@ stroke_shape(ViewLayer *view, BShape *shape)
static void
fill_shape(ViewLayer *view, BShape *shape)
fill_shape(ViewLayer *view, const BShape *shape)
{
ShapePainter drawShape;
@ -308,7 +328,7 @@ fill_shape(ViewLayer *view, BShape *shape)
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();
escapement_delta delta = {deltaSpace, deltaNonSpace };
@ -322,7 +342,7 @@ draw_string(ViewLayer *view, char *string, float deltaSpace, float deltaNonSpace
static void
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
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())
return;
uint8 *pixels = (uint8 *)data;
uint8 *destPixels = (uint8 *)bitmap.Bits();
for (int32 h = 0; h < height; h++) {
memcpy(destPixels, pixels, bytesPerRow);
pixels += bytesPerRow;
destPixels += bytesPerRow;
}
memcpy(bitmap.Bits(), data, height * bytesPerRow);
view->ConvertToScreenForDrawing(&dest);
@ -345,7 +359,7 @@ draw_pixels(ViewLayer *view, BRect src, BRect dest, int32 width, int32 height,
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
BRegion region;
@ -473,14 +487,14 @@ set_scale(ViewLayer *view, float scale)
static void
set_font_family(ViewLayer *view, char *family)
set_font_family(ViewLayer *view, const char *family)
{
printf("SetFontFamily(%s)\n", family);
}
static void
set_font_style(ViewLayer *view, char *style)
set_font_style(ViewLayer *view, const char *style)
{
printf("SetFontStyle(%s)\n", style);
}

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.
*
* Authors:
@ -7,6 +7,7 @@
* Adi Oanca <adioanca@gmail.com>
* Axel Dörfler, axeld@pinc-software.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);
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);
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);
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
void
ViewLayer::ConvertFromScreenForDrawing(BPoint* point) const

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.
*
* Authors:
@ -7,6 +7,7 @@
* Adi Oanca <adioanca@gmail.com>
* Axel Dörfler, axeld@pinc-software.de
* Stephan Aßmus <superstippi@gmx.de>
* Marcus Overhagen <marcus@overhagen.de>
*/
#ifndef VIEW_LAYER_H
#define VIEW_LAYER_H
@ -132,6 +133,10 @@ class ViewLayer {
void ConvertToScreenForDrawing(BRect* rect) 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;
// used when updating the pen position