xref: /haiku/src/servers/app/drawing/interface/remote/RemoteDrawingEngine.h (revision 9295c1f645806eca5d7699c985f7b509528c9eaa)
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 									int32 xOffset, int32 yOffset);
60 
61 	// drawing functions
62 	virtual	void				InvertRect(BRect rect);
63 
64 	virtual	void				DrawBitmap(ServerBitmap* bitmap,
65 									const BRect& bitmapRect,
66 									const BRect& viewRect, uint32 options = 0);
67 
68 	// drawing primitives
69 	virtual	void				DrawArc(BRect rect, const float& angle,
70 									const float& span, bool filled);
71 	virtual	void				FillArc(BRect rect, const float& angle,
72 									const float& span,
73 									const BGradient& gradient);
74 
75 	virtual	void				DrawBezier(BPoint* points, bool filled);
76 	virtual	void				FillBezier(BPoint* points,
77 									const BGradient& gradient);
78 
79 	virtual	void				DrawEllipse(BRect rect, bool filled);
80 	virtual	void				FillEllipse(BRect rect,
81 									const BGradient& gradient);
82 
83 	virtual	void				DrawPolygon(BPoint* pointList, int32 numPoints,
84 									BRect bounds, bool filled, bool closed);
85 	virtual	void				FillPolygon(BPoint* pointList, int32 numPoints,
86 									BRect bounds, const BGradient& gradient,
87 									bool closed);
88 
89 	// these rgb_color versions are used internally by the server
90 	virtual	void				StrokePoint(const BPoint& point,
91 									const rgb_color& color);
92 	virtual	void				StrokeRect(BRect rect, const rgb_color &color);
93 	virtual	void				FillRect(BRect rect, const rgb_color &color);
94 	virtual	void				FillRegion(BRegion& region,
95 									const rgb_color& color);
96 
97 	virtual	void				StrokeRect(BRect rect);
98 	virtual	void				FillRect(BRect rect);
99 	virtual	void				FillRect(BRect rect, const BGradient& gradient);
100 
101 	virtual	void				FillRegion(BRegion& region);
102 	virtual	void				FillRegion(BRegion& region,
103 									const BGradient& gradient);
104 
105 	virtual	void				DrawRoundRect(BRect rect, float xRadius,
106 									float yRadius, bool filled);
107 	virtual	void				FillRoundRect(BRect rect, float xRadius,
108 									float yRadius, const BGradient& gradient);
109 
110 	virtual	void				DrawShape(const BRect& bounds,
111 									int32 opCount, const uint32* opList,
112 									int32 pointCount, const BPoint* pointList,
113 									bool filled,
114 									const BPoint& viewToScreenOffset,
115 									float viewScale);
116 	virtual	void				FillShape(const BRect& bounds,
117 									int32 opCount, const uint32* opList,
118 									int32 pointCount, const BPoint* pointList,
119 									const BGradient& gradient,
120 									const BPoint& viewToScreenOffset,
121 									float viewScale);
122 
123 	virtual	void				DrawTriangle(BPoint* points,
124 									const BRect& bounds, bool filled);
125 	virtual	void				FillTriangle(BPoint* points,
126 									const BRect& bounds,
127 									const BGradient& gradient);
128 
129 	// these versions are used by the Decorator
130 	virtual	void				StrokeLine(const BPoint& start,
131 									const BPoint& end, const rgb_color& color);
132 	virtual	void				StrokeLine(const BPoint& start,
133 									const BPoint& end);
134 	virtual	void				StrokeLineArray(int32 numlines,
135 									const ViewLineArrayInfo* data);
136 
137 	// returns the pen position behind the (virtually) drawn string
138 	virtual	BPoint				DrawString(const char* string, int32 length,
139 									const BPoint& point,
140 									escapement_delta* delta = NULL);
141 	virtual	BPoint				DrawString(const char* string, int32 length,
142 									const BPoint* offsets);
143 
144 	virtual	float				StringWidth(const char* string, int32 length,
145 									escapement_delta* delta = NULL);
146 
147 	// software rendering backend invoked by CopyRegion() for the sorted
148 	// individual rects
149 	virtual	BRect				CopyRect(BRect rect, int32 xOffset,
150 									int32 yOffset) const;
151 
152 private:
153 			status_t			_AddCallback();
154 
155 	static	bool				_DrawingEngineResult(void* cookie,
156 									RemoteMessage& message);
157 
158 			BRect				_BuildBounds(BPoint* points, int32 pointCount);
159 			status_t			_ExtractBitmapRegions(ServerBitmap& bitmap,
160 									uint32 options, const BRect& bitmapRect,
161 									const BRect& viewRect, double xScale,
162 									double yScale, BRegion& region,
163 									UtilityBitmap**& bitmaps);
164 
165 			RemoteHWInterface*	fHWInterface;
166 			int32				fToken;
167 
168 			DrawState			fState;
169 			BRegion				fClippingRegion;
170 			float				fExtendWidth;
171 
172 			bool				fCallbackAdded;
173 			sem_id				fResultNotify;
174 			BPoint				fDrawStringResult;
175 			float				fStringWidthResult;
176 			BBitmap*			fReadBitmapResult;
177 
178 			BitmapDrawingEngine*
179 								fBitmapDrawingEngine;
180 };
181 
182 #endif // REMOTE_DRAWING_ENGINE_H
183