haiku/headers/private/interface/PicturePlayer.h

132 lines
5.5 KiB
C
Raw Normal View History

/*
Fix some cases of updating draw state while recording a BPicture * Also implemented recording DrawString(string, length, BPoint[] locations), which was previously not recorded at all. * Also implemented playing back recently added drawing commands in PicturePlayer.cpp. I don't quite understand what this is actually used for, but it seemed it was forgotten. I just followed the pattern already established in the code. * The other important bit in this change is to update the pen location when it is needed while recording a BPicture. Often the BView will use PenLocation() in order to transmit drawing commands to the app_server which use absolute coordinates only. This isn't actually so nice, since it means the client has to wait for the server to transmit the current pen location. If there were dedicated link-commands for pen-relative drawing commands, the client could just keep sending without waiting for the server. In any case, the app_server needs to update the pen location in the current DrawState and even the DrawingEngine even while recording a picture, because some next command may need up-2-date state information, such as the font state and the pen location. * I have not yet tried to find /all/ instances where the DrawState needs to be updated while recording. This change should repair /all/ font state changes, all versions of drawing a string, and all versions of StrokeLine(). Change-Id: Ia0f23e7b1cd058f70f76a5849acb2d02e0f0da09 Reviewed-on: https://review.haiku-os.org/c/817 Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
2019-01-02 20:48:12 +03:00
* Copyright 2001-2018, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Marc Flerackers (mflerackers@androme.be)
* Stefano Ceccherini (stefano.ceccherini@gmail.com)
* Marcus Overhagen (marcus@overhagen.de)
Fix some cases of updating draw state while recording a BPicture * Also implemented recording DrawString(string, length, BPoint[] locations), which was previously not recorded at all. * Also implemented playing back recently added drawing commands in PicturePlayer.cpp. I don't quite understand what this is actually used for, but it seemed it was forgotten. I just followed the pattern already established in the code. * The other important bit in this change is to update the pen location when it is needed while recording a BPicture. Often the BView will use PenLocation() in order to transmit drawing commands to the app_server which use absolute coordinates only. This isn't actually so nice, since it means the client has to wait for the server to transmit the current pen location. If there were dedicated link-commands for pen-relative drawing commands, the client could just keep sending without waiting for the server. In any case, the app_server needs to update the pen location in the current DrawState and even the DrawingEngine even while recording a picture, because some next command may need up-2-date state information, such as the font state and the pen location. * I have not yet tried to find /all/ instances where the DrawState needs to be updated while recording. This change should repair /all/ font state changes, all versions of drawing a string, and all versions of StrokeLine(). Change-Id: Ia0f23e7b1cd058f70f76a5849acb2d02e0f0da09 Reviewed-on: https://review.haiku-os.org/c/817 Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
2019-01-02 20:48:12 +03:00
* Stephan Aßmus <superstippi@gmx.de>
*/
#ifndef _PICTURE_PLAYER_H
#define _PICTURE_PLAYER_H
/*! PicturePlayer is used to play picture data. */
#include <GraphicsDefs.h>
#include <InterfaceDefs.h>
#include <Point.h>
#include <Rect.h>
class BAffineTransform;
class BGradient;
class BList;
class BPicture;
class BShape;
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, size_t numControlPoints,
const BPoint controlPoints[], 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 BRect 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,
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);
Fix some cases of updating draw state while recording a BPicture * Also implemented recording DrawString(string, length, BPoint[] locations), which was previously not recorded at all. * Also implemented playing back recently added drawing commands in PicturePlayer.cpp. I don't quite understand what this is actually used for, but it seemed it was forgotten. I just followed the pattern already established in the code. * The other important bit in this change is to update the pen location when it is needed while recording a BPicture. Often the BView will use PenLocation() in order to transmit drawing commands to the app_server which use absolute coordinates only. This isn't actually so nice, since it means the client has to wait for the server to transmit the current pen location. If there were dedicated link-commands for pen-relative drawing commands, the client could just keep sending without waiting for the server. In any case, the app_server needs to update the pen location in the current DrawState and even the DrawingEngine even while recording a picture, because some next command may need up-2-date state information, such as the font state and the pen location. * I have not yet tried to find /all/ instances where the DrawState needs to be updated while recording. This change should repair /all/ font state changes, all versions of drawing a string, and all versions of StrokeLine(). Change-Id: Ia0f23e7b1cd058f70f76a5849acb2d02e0f0da09 Reviewed-on: https://review.haiku-os.org/c/817 Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
2019-01-02 20:48:12 +03:00
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, size_t numControlPoints, const BPoint controlPoints[], 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);
};
class PicturePlayer {
public:
PicturePlayer();
PicturePlayer(const void* data, size_t size, BList* pictures);
virtual ~PicturePlayer();
status_t Play(void** callbacks, int32 tableEntries,
void* userData);
status_t Play(const picture_player_callbacks& callbacks,
size_t callbacksSize, void* userData);
private:
status_t _Play(const picture_player_callbacks& callbacks, void* userData,
const void* data, size_t length, uint16 parentOp);
const void* fData;
size_t fSize;
BList* fPictures;
};
} // namespace BPrivate
#endif // _PICTURE_PLAYER_H