diff --git a/headers/os/interface/Shape.h b/headers/os/interface/Shape.h index 5c4232f318..65aa277147 100644 --- a/headers/os/interface/Shape.h +++ b/headers/os/interface/Shape.h @@ -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); diff --git a/headers/private/interface/PicturePlayer.h b/headers/private/interface/PicturePlayer.h index c3beac6c0c..5cfa47ed41 100644 --- a/headers/private/interface/PicturePlayer.h +++ b/headers/private/interface/PicturePlayer.h @@ -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; }; diff --git a/src/kits/interface/PictureDataWriter.cpp b/src/kits/interface/PictureDataWriter.cpp index 85d67d9161..100155056a 100644 --- a/src/kits/interface/PictureDataWriter.cpp +++ b/src/kits/interface/PictureDataWriter.cpp @@ -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 @@ -173,10 +173,11 @@ PictureDataWriter::WriteDrawString(const BPoint &where, const char *string, EndOp(); BeginOp(B_PIC_DRAW_STRING); - Write(length); - WriteData(string, length); Write(escapement.space); Write(escapement.nonspace); + //WriteData(string, length + 1); // TODO: is string 0 terminated? why is length given? + WriteData(string, length); + Write(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(opCount); - WriteData(opList, opCount * sizeof(uint32)); Write(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(srcRect); Write(dstRect); @@ -211,7 +214,6 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, c Write(bytesPerRow); Write(colorSpace); Write(flags); - Write(length); WriteData(data, length); EndOp(); return B_OK; diff --git a/src/kits/interface/PicturePlayer.cpp b/src/kits/interface/PicturePlayer.cpp index 4ded1b4ea9..15addc9bdc 100644 --- a/src/kits/interface/PicturePlayer.cpp +++ b/src/kits/interface/PicturePlayer.cpp @@ -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(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(data); + int32 size = *reinterpret_cast(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(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(data), /* start */ + *reinterpret_cast(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(data)); /* rect */ break; } case B_PIC_FILL_RECT: { - BRect rect = GetRect(); - ((fnc_BRect)callBackTable[4])(userData, rect); + ((fnc_BRect)callBackTable[4])(userData, + *reinterpret_cast(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(data), /* rect */ + *reinterpret_cast(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(data), /* rect */ + *reinterpret_cast(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(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(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(data), /* center */ + *reinterpret_cast(data + sizeof(BPoint)), /* radii */ + *reinterpret_cast(data + 2 * sizeof(BPoint)), /* startTheta */ + *reinterpret_cast(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(data), /* center */ + *reinterpret_cast(data + sizeof(BPoint)), /* radii */ + *reinterpret_cast(data + 2 * sizeof(BPoint)), /* startTheta */ + *reinterpret_cast(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(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(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(data); + ((fnc_iPBPointb)callBackTable[13])(userData, + numPoints, + reinterpret_cast(data + sizeof(int32)), /* points */ + *reinterpret_cast(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(data), /* numPoints */ + reinterpret_cast(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(data); + int32 ptCount = *reinterpret_cast(data + sizeof(int32)); + const uint32 *opList = reinterpret_cast(data + 2 * sizeof(int32)); + const BPoint *ptList = reinterpret_cast(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(data + 2 * sizeof(float)), /* string */ + *reinterpret_cast(data), /* escapement.space */ + *reinterpret_cast(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(data), /* src */ + *reinterpret_cast(data + 1 * sizeof(BRect)), /* dst */ + *reinterpret_cast(data + 2 * sizeof(BRect)), /* width */ + *reinterpret_cast(data + 2 * sizeof(BRect) + 1 * sizeof(int32)), /* height */ + *reinterpret_cast(data + 2 * sizeof(BRect) + 2 * sizeof(int32)), /* bytesPerRow */ + *reinterpret_cast(data + 2 * sizeof(BRect) + 3 * sizeof(int32)), /* pixelFormat */ + *reinterpret_cast(data + 2 * sizeof(BRect) + 4 * sizeof(int32)), /* flags */ + reinterpret_cast(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(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(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(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(data), /* cap-mode */ + *reinterpret_cast(data + 1 * sizeof(int16)), /* join-mode */ + *reinterpret_cast(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(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(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(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(data)); /* pattern */ break; } case B_PIC_SET_SCALE: { - float scale = GetFloat(); - ((fnc_f)callBackTable[36])(userData, scale); + ((fnc_f)callBackTable[36])(userData, + *reinterpret_cast(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(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(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(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(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(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(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(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(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(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(data), /* alphaSrcMode */ + *reinterpret_cast(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? } diff --git a/src/kits/interface/Shape.cpp b/src/kits/interface/Shape.cpp index e0b73f037a..1b2b6a2aec 100644 --- a/src/kits/interface/Shape.cpp +++ b/src/kits/interface/Shape.cpp @@ -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 * Michael Lotz + * Marcus Overhagen */ /*! 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(); diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index dc41e6b483..15e8b1c2e6 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -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 */ @@ -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(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); } diff --git a/src/servers/app/ViewLayer.cpp b/src/servers/app/ViewLayer.cpp index eb5319bd43..d180899c42 100644 --- a/src/servers/app/ViewLayer.cpp +++ b/src/servers/app/ViewLayer.cpp @@ -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 * Axel Dörfler, axeld@pinc-software.de * Stephan Aßmus + * Marcus Overhagen */ @@ -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 diff --git a/src/servers/app/ViewLayer.h b/src/servers/app/ViewLayer.h index 581e44b487..a182bcf2e9 100644 --- a/src/servers/app/ViewLayer.h +++ b/src/servers/app/ViewLayer.h @@ -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 * Axel Dörfler, axeld@pinc-software.de * Stephan Aßmus + * Marcus Overhagen */ #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