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