xref: /haiku/src/servers/app/drawing/interface/remote/RemoteDrawingEngine.h (revision 5ac9b506412b11afb993bb52d161efe7666958a5)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 #ifndef REMOTE_DRAWING_ENGINE_H
9 #define REMOTE_DRAWING_ENGINE_H
10 
11 #include "DrawingEngine.h"
12 #include "DrawState.h"
13 #include "RemoteHWInterface.h"
14 #include "ServerFont.h"
15 
16 class BPoint;
17 class BRect;
18 class BRegion;
19 
20 class BitmapDrawingEngine;
21 class ServerBitmap;
22 
23 class RemoteDrawingEngine : public DrawingEngine {
24 public:
25 								RemoteDrawingEngine(
26 									RemoteHWInterface* interface);
27 	virtual						~RemoteDrawingEngine();
28 
29 	// HWInterfaceListener interface
30 	virtual	void				FrameBufferChanged();
31 
32 	virtual	void				SetCopyToFrontEnabled(bool enabled);
33 
34 	// for screen shots
35 	virtual	status_t			ReadBitmap(ServerBitmap* bitmap,
36 									bool drawCursor, BRect bounds);
37 
38 	// clipping for all drawing functions, passing a NULL region
39 	// will remove any clipping (drawing allowed everywhere)
40 	virtual	void				ConstrainClippingRegion(const BRegion* region);
41 
42 	virtual	void				SetDrawState(const DrawState* state,
43 									int32 xOffset = 0, int32 yOffset = 0);
44 
45 	virtual	void				SetHighColor(const rgb_color& color);
46 	virtual	void				SetLowColor(const rgb_color& color);
47 	virtual	void				SetPenSize(float size);
48 	virtual	void				SetStrokeMode(cap_mode lineCap,
49 									join_mode joinMode, float miterLimit);
50 	virtual	void				SetPattern(const struct pattern& pattern);
51 	virtual	void				SetDrawingMode(drawing_mode mode);
52 	virtual	void				SetDrawingMode(drawing_mode mode,
53 									drawing_mode& oldMode);
54 	virtual	void				SetBlendingMode(source_alpha srcAlpha,
55 									alpha_function alphaFunc);
56 	virtual	void				SetFont(const ServerFont& font);
57 	virtual	void				SetFont(const DrawState* state);
58 	virtual	void				SetTransform(const BAffineTransform& transform);
59 
60 	// drawing functions
61 	virtual	void				InvertRect(BRect rect);
62 
63 	virtual	void				DrawBitmap(ServerBitmap* bitmap,
64 									const BRect& bitmapRect,
65 									const BRect& viewRect, uint32 options = 0);
66 
67 	// drawing primitives
68 	virtual	void				DrawArc(BRect rect, const float& angle,
69 									const float& span, bool filled);
70 	virtual	void				FillArc(BRect rect, const float& angle,
71 									const float& span,
72 									const BGradient& gradient);
73 
74 	virtual	void				DrawBezier(BPoint* points, bool filled);
75 	virtual	void				FillBezier(BPoint* points,
76 									const BGradient& gradient);
77 
78 	virtual	void				DrawEllipse(BRect rect, bool filled);
79 	virtual	void				FillEllipse(BRect rect,
80 									const BGradient& gradient);
81 
82 	virtual	void				DrawPolygon(BPoint* pointList, int32 numPoints,
83 									BRect bounds, bool filled, bool closed);
84 	virtual	void				FillPolygon(BPoint* pointList, int32 numPoints,
85 									BRect bounds, const BGradient& gradient,
86 									bool closed);
87 
88 	// these rgb_color versions are used internally by the server
89 	virtual	void				StrokePoint(const BPoint& point,
90 									const rgb_color& color);
91 	virtual	void				StrokeRect(BRect rect, const rgb_color &color);
92 	virtual	void				FillRect(BRect rect, const rgb_color &color);
93 	virtual	void				FillRegion(BRegion& region,
94 									const rgb_color& color);
95 
96 	virtual	void				StrokeRect(BRect rect);
97 	virtual	void				FillRect(BRect rect);
98 	virtual	void				FillRect(BRect rect, const BGradient& gradient);
99 
100 	virtual	void				FillRegion(BRegion& region);
101 	virtual	void				FillRegion(BRegion& region,
102 									const BGradient& gradient);
103 
104 	virtual	void				DrawRoundRect(BRect rect, float xRadius,
105 									float yRadius, bool filled);
106 	virtual	void				FillRoundRect(BRect rect, float xRadius,
107 									float yRadius, const BGradient& gradient);
108 
109 	virtual	void				DrawShape(const BRect& bounds,
110 									int32 opCount, const uint32* opList,
111 									int32 pointCount, const BPoint* pointList,
112 									bool filled,
113 									const BPoint& viewToScreenOffset,
114 									float viewScale);
115 	virtual	void				FillShape(const BRect& bounds,
116 									int32 opCount, const uint32* opList,
117 									int32 pointCount, const BPoint* pointList,
118 									const BGradient& gradient,
119 									const BPoint& viewToScreenOffset,
120 									float viewScale);
121 
122 	virtual	void				DrawTriangle(BPoint* points,
123 									const BRect& bounds, bool filled);
124 	virtual	void				FillTriangle(BPoint* points,
125 									const BRect& bounds,
126 									const BGradient& gradient);
127 
128 	// these versions are used by the Decorator
129 	virtual	void				StrokeLine(const BPoint& start,
130 									const BPoint& end, const rgb_color& color);
131 	virtual	void				StrokeLine(const BPoint& start,
132 									const BPoint& end);
133 	virtual	void				StrokeLineArray(int32 numlines,
134 									const ViewLineArrayInfo* data);
135 
136 	// returns the pen position behind the (virtually) drawn string
137 	virtual	BPoint				DrawString(const char* string, int32 length,
138 									const BPoint& point,
139 									escapement_delta* delta = NULL);
140 	virtual	BPoint				DrawString(const char* string, int32 length,
141 									const BPoint* offsets);
142 
143 	virtual	float				StringWidth(const char* string, int32 length,
144 									escapement_delta* delta = NULL);
145 
146 	// software rendering backend invoked by CopyRegion() for the sorted
147 	// individual rects
148 	virtual	BRect				CopyRect(BRect rect, int32 xOffset,
149 									int32 yOffset) const;
150 
151 private:
152 			status_t			_AddCallback();
153 
154 	static	bool				_DrawingEngineResult(void* cookie,
155 									RemoteMessage& message);
156 
157 			BRect				_BuildBounds(BPoint* points, int32 pointCount);
158 			status_t			_ExtractBitmapRegions(ServerBitmap& bitmap,
159 									uint32 options, const BRect& bitmapRect,
160 									const BRect& viewRect, double xScale,
161 									double yScale, BRegion& region,
162 									UtilityBitmap**& bitmaps);
163 
164 			RemoteHWInterface*	fHWInterface;
165 			int32				fToken;
166 
167 			DrawState			fState;
168 			BRegion				fClippingRegion;
169 			float				fExtendWidth;
170 
171 			bool				fCallbackAdded;
172 			sem_id				fResultNotify;
173 			BPoint				fDrawStringResult;
174 			float				fStringWidthResult;
175 			BBitmap*			fReadBitmapResult;
176 
177 			BitmapDrawingEngine*
178 								fBitmapDrawingEngine;
179 };
180 
181 #endif // REMOTE_DRAWING_ENGINE_H
182