PicturePlayer: Use C++ virtual interface instead of C function table

Also use C function table instead of `void*` table function casts.

Improve type safety and readability.

Change-Id: Ie5f544b5c2bb9f2333fe3353462325dbfb4453ec
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9656
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
X512
2026-01-04 22:56:43 +00:00
committed by waddlesplash
parent ceaf2dd2d6
commit 2a4448e033
4 changed files with 1154 additions and 1263 deletions
+179 -74
View File
@@ -32,78 +32,184 @@ class Layer;
namespace BPrivate {
struct picture_player_callbacks {
void (*move_pen_by)(void* userData, const BPoint& where);
void (*stroke_line)(void* userData, const BPoint& start, const BPoint& end);
void (*draw_rect)(void* userData, const BRect& rect, bool fill);
void (*draw_round_rect)(void* userData, const BRect& rect,
const BPoint& radii, bool fill);
void (*draw_bezier)(void* userData, const BPoint controlPoints[4], bool fill);
void (*draw_arc)(void* userData, const BPoint& center, const BPoint& radii,
float startTheta, float arcTheta, bool fill);
void (*draw_ellipse)(void* userData, const BRect& rect, bool fill);
void (*draw_polygon)(void* userData, size_t numPoints,
const BPoint points[], bool isClosed, bool fill);
void (*draw_shape)(void* userData, const BShape& shape, bool fill);
void (*draw_string)(void* userData, const char* string, size_t length,
float spaceEscapement, float nonSpaceEscapement);
void (*draw_pixels)(void* userData, const BRect& source,
const BRect& destination, uint32 width, uint32 height,
size_t bytesPerRow, color_space pixelFormat, uint32 flags,
const void* data, size_t length);
void (*draw_picture)(void* userData, const BPoint& where, int32 token);
void (*set_clipping_rects)(void* userData, size_t numRects,
const clipping_rect rects[]);
void (*clip_to_picture)(void* userData, int32 token,
const BPoint& where, bool clipToInverse);
void (*push_state)(void* userData);
void (*pop_state)(void* userData);
void (*enter_state_change)(void* userData);
void (*exit_state_change)(void* userData);
void (*enter_font_state)(void* userData);
void (*exit_font_state)(void* userData);
void (*set_origin)(void* userData, const BPoint& origin);
void (*set_pen_location)(void* userData, const BPoint& location);
void (*set_drawing_mode)(void* userData, drawing_mode mode);
void (*set_line_mode)(void* userData, cap_mode capMode, join_mode joinMode,
struct picture_player_callbacks_compat {
/* 0 */ void (*nop)(void* user);
/* 1 */ void (*move_pen_by)(void* user, BPoint delta);
/* 2 */ void (*stroke_line)(void* user, BPoint start, BPoint end);
/* 3 */ void (*stroke_rect)(void* user, BRect rect);
/* 4 */ void (*fill_rect)(void* user, BRect rect);
/* 5 */ void (*stroke_round_rect)(void* user, BRect rect, BPoint radii);
/* 6 */ void (*fill_round_rect)(void* user, BRect rect, BPoint radii);
/* 7 */ void (*stroke_bezier)(void* user, BPoint* control);
/* 8 */ void (*fill_bezier)(void* user, BPoint* control);
/* 9 */ void (*stroke_arc)(void* user, BPoint center, BPoint radii, float startTheta,
float arcTheta);
/* 10 */ void (*fill_arc)(void* user, BPoint center, BPoint radii, float startTheta,
float arcTheta);
/* 11 */ void (*stroke_ellipse)(void* user, BPoint center, BPoint radii);
/* 12 */ void (*fill_ellipse)(void* user, BPoint center, BPoint radii);
/* 13 */ void (*stroke_polygon)(void* user, int32 numPoints, const BPoint* points,
bool isClosed);
/* 14 */ void (*fill_polygon)(void* user, int32 numPoints, const BPoint* points,
bool isClosed);
// Called "Reserved" in BeBook
/* 15 */ void (*stroke_shape)(void* user, const BShape *shape);
// Called "Reserved" in BeBook
/* 16 */ void (*fill_shape)(void* user, const BShape *shape);
/* 17 */ void (*draw_string)(void* user, const char* string, float deltax, float deltay);
/* 18 */ void (*draw_pixels)(void* user, BRect src, BRect dest, int32 width, int32 height,
int32 bytesPerRow, int32 pixelFormat, int32 flags, const void* data);
// Called "Reserved" in BeBook
/* 19 */ void (*draw_picture)(void* user, BPoint where, int32 token);
/* 20 */ void (*set_clipping_rects)(void* user, const BRect* rects, uint32 numRects);
// Called "Reserved" in BeBook
/* 21 */ void (*clip_to_picture)(void* user, int32 token, BPoint point,
bool clip_to_inverse_picture);
/* 22 */ void (*push_state)(void* user);
/* 23 */ void (*pop_state)(void* user);
/* 24 */ void (*enter_state_change)(void* user);
/* 25 */ void (*exit_state_change)(void* user);
/* 26 */ void (*enter_font_state)(void* user);
/* 27 */ void (*exit_font_state)(void* user);
/* 28 */ void (*set_origin)(void* user, BPoint pt);
/* 29 */ void (*set_pen_location)(void* user, BPoint pt);
/* 30 */ void (*set_drawing_mode)(void* user, drawing_mode mode);
/* 31 */ void (*set_line_mode)(void* user, cap_mode capMode, join_mode joinMode,
float miterLimit);
void (*set_pen_size)(void* userData, float size);
void (*set_fore_color)(void* userData, const rgb_color& color);
void (*set_back_color)(void* userData, const rgb_color& color);
void (*set_stipple_pattern)(void* userData, const pattern& patter);
void (*set_scale)(void* userData, float scale);
void (*set_font_family)(void* userData, const char* familyName,
size_t length);
void (*set_font_style)(void* userData, const char* styleName,
size_t length);
void (*set_font_spacing)(void* userData, uint8 spacing);
void (*set_font_size)(void* userData, float size);
void (*set_font_rotation)(void* userData, float rotation);
void (*set_font_encoding)(void* userData, uint8 encoding);
void (*set_font_flags)(void* userData, uint32 flags);
void (*set_font_shear)(void* userData, float shear);
void (*set_font_face)(void* userData, uint16 face);
void (*set_blending_mode)(void* userData, source_alpha alphaSourceMode,
alpha_function alphaFunctionMode);
void (*set_transform)(void* userData, const BAffineTransform& transform);
void (*translate_by)(void* userData, double x, double y);
void (*scale_by)(void* userData, double x, double y);
void (*rotate_by)(void* userData, double angleRadians);
void (*blend_layer)(void* userData, Layer* layer);
void (*clip_to_rect)(void* userData, const BRect& rect, bool inverse);
void (*clip_to_shape)(void* userData, int32 opCount, const uint32 opList[],
int32 ptCount, const BPoint ptList[], bool inverse);
void (*draw_string_locations)(void* userData, const char* string,
size_t length, const BPoint locations[], size_t locationCount);
void (*draw_rect_gradient)(void* userData, const BRect& rect, BGradient& gradient, bool fill);
void (*draw_round_rect_gradient)(void* userData, const BRect& rect, const BPoint& radii, BGradient& gradient, bool fill);
void (*draw_bezier_gradient)(void* userData, const BPoint controlPoints[4], BGradient& gradient, bool fill);
void (*draw_arc_gradient)(void* userData, const BPoint& center, const BPoint& radii, float startTheta, float arcTheta, BGradient& gradient, bool fill);
void (*draw_ellipse_gradient)(void* userData, const BRect& rect, BGradient& gradient, bool fill);
void (*draw_polygon_gradient)(void* userData, size_t numPoints, const BPoint points[], bool isClosed, BGradient& gradient, bool fill);
void (*draw_shape_gradient)(void* userData, const BShape& shape, BGradient& gradient, bool fill);
void (*set_fill_rule)(void* userData, int32 fillRule);
void (*stroke_line_gradient)(void* userData, const BPoint& start, const BPoint& end, const BGradient& gradient);
/* 32 */ void (*set_pen_size)(void* user, float size);
/* 33 */ void (*set_fore_color)(void* user, rgb_color color);
/* 34 */ void (*set_back_color)(void* user, rgb_color color);
/* 35 */ void (*set_stipple_pattern)(void* user, pattern p);
/* 36 */ void (*set_scale)(void* user, float scale);
/* 37 */ void (*set_font_family)(void* user, const char* family);
/* 38 */ void (*set_font_style)(void* user, const char* style);
/* 39 */ void (*set_font_spacing)(void* user, int32 spacing);
/* 40 */ void (*set_font_size)(void* user, float size);
/* 41 */ void (*set_font_rotate)(void* user, float rotation);
/* 42 */ void (*set_font_encoding)(void* user, int32 encoding);
/* 43 */ void (*set_font_flags)(void* user, int32 flags);
/* 44 */ void (*set_font_shear)(void* user, float shear);
// Called "Reserved" in BeBook
/* 45 */ void (*set_font_bpp)(void* user, int32 bpp);
/* 46 */ void (*set_font_face)(void* user, int32 flags);
// New in Haiku
/* 47 */ void (*set_blending_mode)(void* user, source_alpha alphaSrcMode,
alpha_function alphaFncMode);
/* 48 */ void (*set_transform)(void* user, const BAffineTransform& transform);
/* 49 */ void (*translate_by)(void* user, double x, double y);
/* 50 */ void (*scale_by)(void* user, double x, double y);
/* 51 */ void (*rotate_by)(void* user, double angleRadians);
// Broken when saved to file
/* 52 */ void (*blend_layer)(void* user, class Layer* layer);
/* 53 */ void (*clip_to_rect)(void* user, const BRect& rect, bool inverse);
// Why not BShape?
/* 54 */ void (*clip_to_shape)(void* user, int32 opCount, const uint32 opList[], int32 ptCount,
const BPoint ptList[], bool inverse);
/* 55 */ void (*draw_string_locations)(void* user, const char* string, const BPoint* locations,
size_t locationCount);
/* 56 */ void (*fill_rect_gradient)(void* user, BRect rect, const BGradient& gradient);
/* 57 */ void (*stroke_rect_gradient)(void* user, BRect rect, const BGradient& gradient);
/* 58 */ void (*fill_round_rect_gradient)(void* user, BRect rect, BPoint radii,
const BGradient& gradient);
/* 59 */ void (*stroke_round_rect_gradient)(void* user, BRect rect, BPoint radii,
const BGradient& gradient);
/* 60 */ void (*fill_bezier_gradient)(void* user, const BPoint* points,
const BGradient& gradient);
/* 61 */ void (*stroke_bezier_gradient)(void* user, const BPoint* points,
const BGradient& gradient);
/* 62 */ void (*fill_arc_gradient)(void* user, BPoint center, BPoint radii, float startTheta,
float arcTheta, const BGradient& gradient);
/* 63 */ void (*stroke_arc_gradient)(void* user, BPoint center, BPoint radii, float startTheta,
float arcTheta, const BGradient& gradient);
/* 64 */ void (*fill_ellipse_gradient)(void* user, BPoint center, BPoint radii,
const BGradient& gradient);
/* 65 */ void (*stroke_ellipse_gradient)(void* user, BPoint center, BPoint radii,
const BGradient& gradient);
/* 66 */ void (*fill_polygon_gradient)(void* user, int32 numPoints, const BPoint* points,
bool isClosed, const BGradient& gradient);
/* 67 */ void (*stroke_polygon_gradient)(void* user, int32 numPoints, const BPoint* points,
bool isClosed, const BGradient& gradient);
/* 68 */ void (*fill_shape_gradient)(void* user, BShape shape, const BGradient& gradient);
/* 69 */ void (*stroke_shape_gradient)(void* user, BShape shape, const BGradient& gradient);
/* 70 */ void (*set_fill_rule)(void* user, int32 fillRule);
/* 71 */ void (*stroke_line_gradient)(void* user, BPoint start, BPoint end,
const BGradient& gradient);
};
class PicturePlayerCallbacks {
public:
virtual void MovePenBy(const BPoint& where) {}
virtual void StrokeLine(const BPoint& start, const BPoint& end) {}
virtual void DrawRect(const BRect& rect, bool fill) {}
virtual void DrawRoundRect(const BRect& rect, const BPoint& radii, bool fill) {}
virtual void DrawBezier(const BPoint controlPoints[4], bool fill) {}
virtual void DrawArc(const BPoint& center, const BPoint& radii, float startTheta,
float arcTheta, bool fill) {}
virtual void DrawEllipse(const BRect& rect, bool fill) {}
virtual void DrawPolygon(size_t numPoints, const BPoint points[], bool isClosed, bool fill) {}
virtual void DrawShape(const BShape& shape, bool fill) {}
virtual void DrawString(const char* string, size_t length, float spaceEscapement,
float nonSpaceEscapement) {}
virtual void DrawPixels(const BRect& source, const BRect& destination, uint32 width,
uint32 height, size_t bytesPerRow, color_space pixelFormat, uint32 flags, const void* data,
size_t length) {}
virtual void DrawPicture(const BPoint& where, int32 token) {}
virtual void SetClippingRects(size_t numRects, const clipping_rect rects[]) {}
virtual void ClipToPicture(int32 token, const BPoint& where, bool clipToInverse) {}
virtual void PushState() {}
virtual void PopState() {}
virtual void EnterStateChange() {}
virtual void ExitStateChange() {}
virtual void EnterFontState() {}
virtual void ExitFontState() {}
virtual void SetOrigin(const BPoint& origin) {}
virtual void SetPenLocation(const BPoint& location) {}
virtual void SetDrawingMode(drawing_mode mode) {}
virtual void SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit) {}
virtual void SetPenSize(float size) {}
virtual void SetForeColor(const rgb_color& color) {}
virtual void SetBackColor(const rgb_color& color) {}
virtual void SetStipplePattern(const pattern& patter) {}
virtual void SetScale(float scale) {}
virtual void SetFontFamily(const char* familyName, size_t length) {}
virtual void SetFontStyle(const char* styleName, size_t length) {}
virtual void SetFontSpacing(uint8 spacing) {}
virtual void SetFontSize(float size) {}
virtual void SetFontRotation(float rotation) {}
virtual void SetFontEncoding(uint8 encoding) {}
virtual void SetFontFlags(uint32 flags) {}
virtual void SetFontShear(float shear) {}
virtual void SetFontFace(uint16 face) {}
virtual void SetBlendingMode(source_alpha alphaSourceMode, alpha_function alphaFunctionMode) {}
virtual void SetTransform(const BAffineTransform& transform) {}
virtual void TranslateBy(double x, double y) {}
virtual void ScaleBy(double x, double y) {}
virtual void RotateBy(double angleRadians) {}
virtual void BlendLayer(Layer* layer) {}
virtual void ClipToRect(const BRect& rect, bool inverse) {}
virtual void ClipToShape(int32 opCount, const uint32 opList[], int32 ptCount,
const BPoint ptList[], bool inverse) {}
virtual void DrawStringLocations(const char* string, size_t length, const BPoint locations[],
size_t locationCount) {}
virtual void DrawRectGradient(const BRect& rect, BGradient& gradient, bool fill) {}
virtual void DrawRoundRectGradient(const BRect& rect, const BPoint& radii, BGradient& gradient,
bool fill) {}
virtual void DrawBezierGradient(const BPoint controlPoints[4], BGradient& gradient, bool fill)
{}
virtual void DrawArcGradient(const BPoint& center, const BPoint& radii, float startTheta,
float arcTheta, BGradient& gradient, bool fill) {}
virtual void DrawEllipseGradient(const BRect& rect, BGradient& gradient, bool fill) {}
virtual void DrawPolygonGradient(size_t numPoints, const BPoint points[], bool isClosed,
BGradient& gradient, bool fill) {}
virtual void DrawShapeGradient(const BShape& shape, BGradient& gradient, bool fill) {}
virtual void SetFillRule(int32 fillRule) {}
virtual void StrokeLineGradient(const BPoint& start, const BPoint& end,
const BGradient& gradient) {}
};
@@ -115,11 +221,10 @@ public:
status_t Play(void** callbacks, int32 tableEntries,
void* userData);
status_t Play(const picture_player_callbacks& callbacks,
size_t callbacksSize, void* userData);
status_t Play(PicturePlayerCallbacks& callbacks);
private:
status_t _Play(const picture_player_callbacks& callbacks, void* userData,
status_t _Play(PicturePlayerCallbacks& callbacks,
const void* data, size_t length, uint16 parentOp);
const void* fData;
File diff suppressed because it is too large Load Diff
+232 -298
View File
@@ -142,6 +142,71 @@ private:
// #pragma mark - Picture playback hooks
class BoundingBoxCallbacks: public BPrivate::PicturePlayerCallbacks {
public:
BoundingBoxCallbacks(BoundingBoxState* const state);
virtual void MovePenBy(const BPoint& where);
virtual void StrokeLine(const BPoint& start, const BPoint& end);
virtual void DrawRect(const BRect& rect, bool fill);
virtual void DrawRoundRect(const BRect& rect, const BPoint& radii, bool fill);
virtual void DrawBezier(const BPoint controlPoints[4], bool fill);
virtual void DrawArc(const BPoint& center, const BPoint& radii, float startTheta,
float arcTheta, bool fill);
virtual void DrawEllipse(const BRect& rect, bool fill);
virtual void DrawPolygon(size_t numPoints, const BPoint points[], bool isClosed, bool fill);
virtual void DrawShape(const BShape& shape, bool fill);
virtual void DrawString(const char* string, size_t length, float spaceEscapement,
float nonSpaceEscapement);
virtual void DrawPixels(const BRect& source, const BRect& destination, uint32 width,
uint32 height, size_t bytesPerRow, color_space pixelFormat, uint32 flags, const void* data,
size_t length);
virtual void DrawPicture(const BPoint& where, int32 token);
virtual void SetClippingRects(size_t numRects, const clipping_rect rects[]);
virtual void ClipToPicture(int32 token, const BPoint& where, bool clipToInverse);
virtual void PushState();
virtual void PopState();
virtual void EnterStateChange();
virtual void ExitStateChange();
virtual void EnterFontState();
virtual void ExitFontState();
virtual void SetOrigin(const BPoint& origin);
virtual void SetPenLocation(const BPoint& location);
virtual void SetDrawingMode(drawing_mode mode);
virtual void SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit);
virtual void SetPenSize(float size);
virtual void SetForeColor(const rgb_color& color);
virtual void SetBackColor(const rgb_color& color);
virtual void SetStipplePattern(const pattern& patter);
virtual void SetScale(float scale);
virtual void SetFontFamily(const char* familyName, size_t length);
virtual void SetFontStyle(const char* styleName, size_t length);
virtual void SetFontSpacing(uint8 spacing);
virtual void SetFontSize(float size);
virtual void SetFontRotation(float rotation);
virtual void SetFontEncoding(uint8 encoding);
virtual void SetFontFlags(uint32 flags);
virtual void SetFontShear(float shear);
virtual void SetFontFace(uint16 face);
virtual void SetBlendingMode(source_alpha alphaSourceMode, alpha_function alphaFunctionMode);
virtual void SetTransform(const BAffineTransform& transform);
virtual void TranslateBy(double x, double y);
virtual void ScaleBy(double x, double y);
virtual void RotateBy(double angleRadians);
virtual void BlendLayer(Layer* layer);
private:
BoundingBoxState* const fState;
};
BoundingBoxCallbacks::BoundingBoxCallbacks(BoundingBoxState* const state)
:
fState(state)
{
}
static void
get_polygon_frame(const BPoint* points, int32 numPoints, BRect* frame)
{
@@ -180,31 +245,27 @@ expand_rect_for_pen_size(BoundingBoxState* state, RectType& rect)
}
static void
move_pen_by(void* _state, const BPoint& delta)
void
BoundingBoxCallbacks::MovePenBy(const BPoint& delta)
{
TRACE_BB("%p move pen by %.2f %.2f\n", _state, delta.x, delta.y);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetPenLocation(
state->GetDrawState()->PenLocation() + delta);
fState->GetDrawState()->SetPenLocation(
fState->GetDrawState()->PenLocation() + delta);
}
static void
determine_bounds_stroke_line(void* _state, const BPoint& _start,
void
BoundingBoxCallbacks::StrokeLine(const BPoint& _start,
const BPoint& _end)
{
TRACE_BB("%p stroke line %.2f %.2f -> %.2f %.2f\n", _state,
_start.x, _start.y, _end.x, _end.y);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BPoint start = _start;
BPoint end = _end;
const SimpleTransform transform = state->PenToLocalTransform();
const SimpleTransform transform = fState->PenToLocalTransform();
transform.Apply(&start);
transform.Apply(&end);
@@ -224,34 +285,32 @@ determine_bounds_stroke_line(void* _state, const BPoint& _start,
rect.bottom = start.y;
}
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
state->GetDrawState()->SetPenLocation(_end);
fState->GetDrawState()->SetPenLocation(_end);
}
static void
determine_bounds_draw_rect(void* _state, const BRect& _rect, bool fill)
void
BoundingBoxCallbacks::DrawRect(const BRect& _rect, bool fill)
{
TRACE_BB("%p draw rect fill=%d %.2f %.2f %.2f %.2f\n", _state, fill,
_rect.left, _rect.top, _rect.right, _rect.bottom);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BRect rect = _rect;
state->PenToLocalTransform().Apply(&rect);
fState->PenToLocalTransform().Apply(&rect);
if (!fill)
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
}
static void
determine_bounds_draw_round_rect(void* _state, const BRect& _rect,
void
BoundingBoxCallbacks::DrawRoundRect(const BRect& _rect,
const BPoint&, bool fill)
{
determine_bounds_draw_rect(_state, _rect, fill);
DrawRect(_rect, fill);
}
@@ -280,9 +339,8 @@ determine_bounds_bezier(BoundingBoxState* state, const BPoint viewPoints[4],
}
static void
determine_bounds_draw_bezier(void* _state,
const BPoint viewPoints[4], bool fill)
void
BoundingBoxCallbacks::DrawBezier(const BPoint viewPoints[4], bool fill)
{
TRACE_BB("%p draw bezier fill=%d (%.2f %.2f) (%.2f %.2f) "
"(%.2f %.2f) (%.2f %.2f)\n",
@@ -292,40 +350,36 @@ determine_bounds_draw_bezier(void* _state,
viewPoints[1].x, viewPoints[1].y,
viewPoints[2].x, viewPoints[2].y,
viewPoints[3].x, viewPoints[3].y);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BRect rect;
determine_bounds_bezier(state, viewPoints, rect);
determine_bounds_bezier(fState, viewPoints, rect);
if (!fill)
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
}
static void
determine_bounds_draw_ellipse(void* _state, const BRect& _rect, bool fill)
void
BoundingBoxCallbacks::DrawEllipse(const BRect& _rect, bool fill)
{
TRACE_BB("%p draw ellipse fill=%d (%.2f %.2f) (%.2f %.2f)\n", _state, fill,
_rect.left, _rect.top, _rect.right, _rect.bottom);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BRect rect = _rect;
state->PenToLocalTransform().Apply(&rect);
fState->PenToLocalTransform().Apply(&rect);
if (!fill)
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
}
static void
determine_bounds_draw_arc(void* _state, const BPoint& center,
void
BoundingBoxCallbacks::DrawArc(const BPoint& center,
const BPoint& radii, float, float, bool fill)
{
BRect rect(center.x - radii.x, center.y - radii.y,
center.x + radii.x - 1, center.y + radii.y - 1);
determine_bounds_draw_ellipse(_state, rect, fill);
DrawEllipse(rect, fill);
}
@@ -361,481 +415,360 @@ determine_bounds_polygon(BoundingBoxState* state, int32 numPoints,
void
determine_bounds_draw_polygon(void* _state, size_t numPoints,
BoundingBoxCallbacks::DrawPolygon(size_t numPoints,
const BPoint viewPoints[], bool, bool fill)
{
TRACE_BB("%p draw polygon fill=%d (%ld points)\n", _state, fill, numPoints);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p draw polygon fill=%d (%ld points)\n", fState, fill, numPoints);
BRect rect;
determine_bounds_polygon(state, numPoints, viewPoints, rect);
determine_bounds_polygon(fState, numPoints, viewPoints, rect);
if (!fill)
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
}
static void
determine_bounds_draw_shape(void* _state, const BShape& shape, bool fill)
void
BoundingBoxCallbacks::DrawShape(const BShape& shape, bool fill)
{
BRect rect = shape.Bounds();
TRACE_BB("%p stroke shape (bounds %.2f %.2f %.2f %.2f)\n", _state,
TRACE_BB("%p stroke shape (bounds %.2f %.2f %.2f %.2f)\n", fState,
rect.left, rect.top, rect.right, rect.bottom);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->PenToLocalTransform().Apply(&rect);
fState->PenToLocalTransform().Apply(&rect);
if (!fill)
expand_rect_for_pen_size(state, rect);
state->IncludeRect(rect);
expand_rect_for_pen_size(fState, rect);
fState->IncludeRect(rect);
}
static void
determine_bounds_draw_string(void* _state, const char* string, size_t length,
void
BoundingBoxCallbacks::DrawString(const char* string, size_t length,
float deltaSpace, float deltaNonSpace)
{
TRACE_BB("%p string '%s'\n", _state, string);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p string '%s'\n", fState, string);
ServerFont font = state->GetDrawState()->Font();
ServerFont font = fState->GetDrawState()->Font();
escapement_delta delta = { deltaSpace, deltaNonSpace };
BRect rect;
font.GetBoundingBoxesForStrings((char**)&string, &length, 1, &rect,
B_SCREEN_METRIC, &delta);
BPoint location = state->GetDrawState()->PenLocation();
BPoint location = fState->GetDrawState()->PenLocation();
state->PenToLocalTransform().Apply(&location);
fState->PenToLocalTransform().Apply(&location);
rect.OffsetBy(location);
state->IncludeRect(rect);
fState->IncludeRect(rect);
state->PenToLocalTransform().Apply(&location);
state->GetDrawState()->SetPenLocation(location);
fState->PenToLocalTransform().Apply(&location);
fState->GetDrawState()->SetPenLocation(location);
}
static void
determine_bounds_draw_pixels(void* _state, const BRect&, const BRect& _dest,
void
BoundingBoxCallbacks::DrawPixels(const BRect&, const BRect& _dest,
uint32, uint32, size_t, color_space, uint32, const void*, size_t)
{
TRACE_BB("%p pixels (dest %.2f %.2f %.2f %.2f)\n", _state,
TRACE_BB("%p pixels (dest %.2f %.2f %.2f %.2f)\n", fState,
_dest.left, _dest.top, _dest.right, _dest.bottom);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BRect dest = _dest;
state->PenToLocalTransform().Apply(&dest);
state->IncludeRect(dest);
fState->PenToLocalTransform().Apply(&dest);
fState->IncludeRect(dest);
}
static void
draw_picture(void* _state, const BPoint& where, int32 token)
void
BoundingBoxCallbacks::DrawPicture(const BPoint& where, int32 token)
{
TRACE_BB("%p picture (unimplemented)\n", _state);
TRACE_BB("%p picture (unimplemented)\n", fState);
// TODO
(void)_state;
(void)where;
(void)token;
}
static void
set_clipping_rects(void* _state, size_t numRects, const clipping_rect rects[])
void
BoundingBoxCallbacks::SetClippingRects(size_t numRects, const clipping_rect rects[])
{
TRACE_BB("%p cliping rects (%ld rects)\n", _state, numRects);
TRACE_BB("%p cliping rects (%ld rects)\n", fState, numRects);
// TODO
(void)_state;
(void)rects;
(void)numRects;
}
static void
clip_to_picture(void* _state, int32 pictureToken, const BPoint& where,
void
BoundingBoxCallbacks::ClipToPicture(int32 pictureToken, const BPoint& where,
bool clipToInverse)
{
TRACE_BB("%p clip to picture (unimplemented)\n", _state);
TRACE_BB("%p clip to picture (unimplemented)\n", fState);
// TODO
}
static void
push_state(void* _state)
void
BoundingBoxCallbacks::PushState()
{
TRACE_BB("%p push state\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p push state\n", fState);
state->PushDrawState();
fState->PushDrawState();
}
static void
pop_state(void* _state)
void
BoundingBoxCallbacks::PopState()
{
TRACE_BB("%p pop state\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p pop state\n", fState);
state->PopDrawState();
fState->PopDrawState();
}
static void
enter_state_change(void*)
void
BoundingBoxCallbacks::EnterStateChange()
{
}
static void
exit_state_change(void*)
void
BoundingBoxCallbacks::ExitStateChange()
{
}
static void
enter_font_state(void*)
void
BoundingBoxCallbacks::EnterFontState()
{
}
static void
exit_font_state(void*)
void
BoundingBoxCallbacks::ExitFontState()
{
}
static void
set_origin(void* _state, const BPoint& pt)
void
BoundingBoxCallbacks::SetOrigin(const BPoint& pt)
{
TRACE_BB("%p set origin %.2f %.2f\n", _state, pt.x, pt.y);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetOrigin(pt);
TRACE_BB("%p set origin %.2f %.2f\n", , pt.x, pt.y);
fState->GetDrawState()->SetOrigin(pt);
}
static void
set_pen_location(void* _state, const BPoint& pt)
void
BoundingBoxCallbacks::SetPenLocation(const BPoint& pt)
{
TRACE_BB("%p set pen location %.2f %.2f\n", _state, pt.x, pt.y);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetPenLocation(pt);
TRACE_BB("%p set pen location %.2f %.2f\n", fState, pt.x, pt.y);
fState->GetDrawState()->SetPenLocation(pt);
}
static void
set_drawing_mode(void*, drawing_mode)
void
BoundingBoxCallbacks::SetDrawingMode(drawing_mode)
{
}
static void
set_line_mode(void* _state, cap_mode capMode, join_mode joinMode,
void
BoundingBoxCallbacks::SetLineMode(cap_mode capMode, join_mode joinMode,
float miterLimit)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
DrawState* drawState = state->GetDrawState();
DrawState* drawState = fState->GetDrawState();
drawState->SetLineCapMode(capMode);
drawState->SetLineJoinMode(joinMode);
drawState->SetMiterLimit(miterLimit);
}
static void
set_pen_size(void* _state, float size)
void
BoundingBoxCallbacks::SetPenSize(float size)
{
TRACE_BB("%p set pen size %.2f\n", _state, size);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p set pen size %.2f\n", fState, size);
state->GetDrawState()->SetPenSize(size);
fState->GetDrawState()->SetPenSize(size);
}
static void
set_fore_color(void* _state, const rgb_color& color)
void
BoundingBoxCallbacks::SetForeColor(const rgb_color& color)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetHighColor(color);
fState->GetDrawState()->SetHighColor(color);
}
static void
set_back_color(void* _state, const rgb_color& color)
void
BoundingBoxCallbacks::SetBackColor(const rgb_color& color)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetLowColor(color);
fState->GetDrawState()->SetLowColor(color);
}
static void
set_stipple_pattern(void* _state, const pattern& _pattern)
void
BoundingBoxCallbacks::SetStipplePattern(const pattern& _pattern)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetPattern(Pattern(_pattern));
fState->GetDrawState()->SetPattern(Pattern(_pattern));
}
static void
set_scale(void* _state, float scale)
void
BoundingBoxCallbacks::SetScale(float scale)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetScale(scale);
fState->GetDrawState()->SetScale(scale);
}
static void
set_font_family(void* _state, const char* _family, size_t length)
void
BoundingBoxCallbacks::SetFontFamily(const char* _family, size_t length)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BString family(_family, length);
gFontManager->Lock();
FontStyle* fontStyle = gFontManager->GetStyleByIndex(family, 0);
ServerFont font;
font.SetStyle(fontStyle);
gFontManager->Unlock();
state->GetDrawState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
fState->GetDrawState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
}
static void
set_font_style(void* _state, const char* _style, size_t length)
void
BoundingBoxCallbacks::SetFontStyle(const char* _style, size_t length)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BString style(_style, length);
ServerFont font(state->GetDrawState()->Font());
ServerFont font(fState->GetDrawState()->Font());
gFontManager->Lock();
FontStyle* fontStyle = gFontManager->GetStyle(font.Family(), style);
font.SetStyle(fontStyle);
gFontManager->Unlock();
state->GetDrawState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
fState->GetDrawState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
}
static void
set_font_spacing(void* _state, uint8 spacing)
void
BoundingBoxCallbacks::SetFontSpacing(uint8 spacing)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetSpacing(spacing);
state->GetDrawState()->SetFont(font, B_FONT_SPACING);
fState->GetDrawState()->SetFont(font, B_FONT_SPACING);
}
static void
set_font_size(void* _state, float size)
void
BoundingBoxCallbacks::SetFontSize(float size)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetSize(size);
state->GetDrawState()->SetFont(font, B_FONT_SIZE);
fState->GetDrawState()->SetFont(font, B_FONT_SIZE);
}
static void
set_font_rotate(void* _state, float rotation)
void
BoundingBoxCallbacks::SetFontRotation(float rotation)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetRotation(rotation);
state->GetDrawState()->SetFont(font, B_FONT_ROTATION);
fState->GetDrawState()->SetFont(font, B_FONT_ROTATION);
}
static void
set_font_encoding(void* _state, uint8 encoding)
void
BoundingBoxCallbacks::SetFontEncoding(uint8 encoding)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetEncoding(encoding);
state->GetDrawState()->SetFont(font, B_FONT_ENCODING);
fState->GetDrawState()->SetFont(font, B_FONT_ENCODING);
}
static void
set_font_flags(void* _state, uint32 flags)
void
BoundingBoxCallbacks::SetFontFlags(uint32 flags)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetFlags(flags);
state->GetDrawState()->SetFont(font, B_FONT_FLAGS);
fState->GetDrawState()->SetFont(font, B_FONT_FLAGS);
}
static void
set_font_shear(void* _state, float shear)
void
BoundingBoxCallbacks::SetFontShear(float shear)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetShear(shear);
state->GetDrawState()->SetFont(font, B_FONT_SHEAR);
fState->GetDrawState()->SetFont(font, B_FONT_SHEAR);
}
static void
set_font_face(void* _state, uint16 face)
void
BoundingBoxCallbacks::SetFontFace(uint16 face)
{
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
ServerFont font;
font.SetFace(face);
state->GetDrawState()->SetFont(font, B_FONT_FACE);
fState->GetDrawState()->SetFont(font, B_FONT_FACE);
}
static void
set_blending_mode(void*, source_alpha, alpha_function)
void
BoundingBoxCallbacks::SetBlendingMode(source_alpha, alpha_function)
{
}
static void
set_transform(void* _state, const BAffineTransform& transform)
void
BoundingBoxCallbacks::SetTransform(const BAffineTransform& transform)
{
TRACE_BB("%p transform\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
state->GetDrawState()->SetTransform(transform);
TRACE_BB("%p transform\n", fState);
fState->GetDrawState()->SetTransform(transform);
}
static void
translate_by(void* _state, double x, double y)
void
BoundingBoxCallbacks::TranslateBy(double x, double y)
{
TRACE_BB("%p translate\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BAffineTransform transform = state->GetDrawState()->Transform();
TRACE_BB("%p translate\n", fState);
BAffineTransform transform = fState->GetDrawState()->Transform();
transform.PreTranslateBy(x, y);
state->GetDrawState()->SetTransform(transform);
fState->GetDrawState()->SetTransform(transform);
}
static void
scale_by(void* _state, double x, double y)
void
BoundingBoxCallbacks::ScaleBy(double x, double y)
{
TRACE_BB("%p scale\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BAffineTransform transform = state->GetDrawState()->Transform();
TRACE_BB("%p scale\n", fState);
BAffineTransform transform = fState->GetDrawState()->Transform();
transform.PreScaleBy(x, y);
state->GetDrawState()->SetTransform(transform);
fState->GetDrawState()->SetTransform(transform);
}
static void
rotate_by(void* _state, double angleRadians)
void
BoundingBoxCallbacks::RotateBy(double angleRadians)
{
TRACE_BB("%p rotate\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
BAffineTransform transform = state->GetDrawState()->Transform();
TRACE_BB("%p rotate\n", fState);
BAffineTransform transform = fState->GetDrawState()->Transform();
transform.PreRotateBy(angleRadians);
state->GetDrawState()->SetTransform(transform);
fState->GetDrawState()->SetTransform(transform);
}
static void
determine_bounds_nested_layer(void* _state, Layer* layer)
void
BoundingBoxCallbacks::BlendLayer(Layer* layer)
{
TRACE_BB("%p nested layer\n", _state);
BoundingBoxState* const state =
reinterpret_cast<BoundingBoxState*>(_state);
TRACE_BB("%p nested layer\n", fState);
BRect boundingBox;
PictureBoundingBoxPlayer::Play(layer, state->GetDrawState(), &boundingBox);
PictureBoundingBoxPlayer::Play(layer, fState->GetDrawState(), &boundingBox);
if (boundingBox.IsValid())
state->IncludeRect(boundingBox);
fState->IncludeRect(boundingBox);
}
static const BPrivate::picture_player_callbacks
kPictureBoundingBoxPlayerCallbacks = {
move_pen_by,
determine_bounds_stroke_line,
determine_bounds_draw_rect,
determine_bounds_draw_round_rect,
determine_bounds_draw_bezier,
determine_bounds_draw_arc,
determine_bounds_draw_ellipse,
determine_bounds_draw_polygon,
determine_bounds_draw_shape,
determine_bounds_draw_string,
determine_bounds_draw_pixels,
draw_picture,
set_clipping_rects,
clip_to_picture,
push_state,
pop_state,
enter_state_change,
exit_state_change,
enter_font_state,
exit_font_state,
set_origin,
set_pen_location,
set_drawing_mode,
set_line_mode,
set_pen_size,
set_fore_color,
set_back_color,
set_stipple_pattern,
set_scale,
set_font_family,
set_font_style,
set_font_spacing,
set_font_size,
set_font_rotate,
set_font_encoding,
set_font_flags,
set_font_shear,
set_font_face,
set_blending_mode,
set_transform,
translate_by,
scale_by,
rotate_by,
determine_bounds_nested_layer
};
// #pragma mark - PictureBoundingBoxPlayer
@@ -849,9 +782,10 @@ PictureBoundingBoxPlayer::Play(ServerPicture* picture,
if (mallocIO == NULL)
return;
BoundingBoxCallbacks callbacks(&state);
BPrivate::PicturePlayer player(mallocIO->Buffer(),
mallocIO->BufferLength(), ServerPicture::PictureList::Private(
picture->fPictures.Get()).AsBList());
player.Play(kPictureBoundingBoxPlayerCallbacks,
sizeof(kPictureBoundingBoxPlayerCallbacks), &state);
player.Play(callbacks);
}
File diff suppressed because it is too large Load Diff