xref: /haiku/src/servers/app/drawing/DrawingEngine.h (revision a629567a9001547736cfe892cdf992be16868fed)
1 /*
2  * Copyright 2001-2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Gabe Yoder <gyoder@stny.rr.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 #ifndef DRAWING_ENGINE_H_
11 #define DRAWING_ENGINE_H_
12 
13 
14 #include <Accelerant.h>
15 #include <Font.h>
16 #include <Locker.h>
17 #include <Point.h>
18 #include <Gradient.h>
19 #include <ServerProtocolStructs.h>
20 
21 #include "HWInterface.h"
22 
23 
24 class BPoint;
25 class BRect;
26 class BRegion;
27 
28 class DrawState;
29 class Painter;
30 class ServerBitmap;
31 class ServerCursor;
32 class ServerFont;
33 
34 
35 class DrawingEngine : public HWInterfaceListener {
36 public:
37 							DrawingEngine(HWInterface* interface = NULL);
38 	virtual					~DrawingEngine();
39 
40 	// HWInterfaceListener interface
41 	virtual	void			FrameBufferChanged();
42 
43 	// for "changing" hardware
44 			void			SetHWInterface(HWInterface* interface);
45 
46 	virtual	void			SetCopyToFrontEnabled(bool enable);
47 			bool			CopyToFrontEnabled() const
48 								{ return fCopyToFront; }
49 	virtual	void			CopyToFront(/*const*/ BRegion& region);
50 
51 	// locking
52 			bool			LockParallelAccess();
53 #if DEBUG
54 	virtual	bool			IsParallelAccessLocked() const;
55 #endif
56 			void			UnlockParallelAccess();
57 
58 			bool			LockExclusiveAccess();
59 	virtual	bool			IsExclusiveAccessLocked() const;
60 			void			UnlockExclusiveAccess();
61 
62 	// for screen shots
63 			ServerBitmap*	DumpToBitmap();
64 	virtual	status_t		ReadBitmap(ServerBitmap *bitmap, bool drawCursor,
65 								BRect bounds);
66 
67 	// clipping for all drawing functions, passing a NULL region
68 	// will remove any clipping (drawing allowed everywhere)
69 	virtual	void			ConstrainClippingRegion(const BRegion* region);
70 
71 	virtual	void			SetDrawState(const DrawState* state,
72 								int32 xOffset = 0, int32 yOffset = 0);
73 
74 	virtual	void			SetHighColor(const rgb_color& color);
75 	virtual	void			SetLowColor(const rgb_color& color);
76 	virtual	void			SetPenSize(float size);
77 	virtual	void			SetStrokeMode(cap_mode lineCap, join_mode joinMode,
78 								float miterLimit);
79 	virtual void			SetFillRule(int32 fillRule);
80 	virtual	void			SetPattern(const struct pattern& pattern);
81 	virtual	void			SetDrawingMode(drawing_mode mode);
82 	virtual	void			SetDrawingMode(drawing_mode mode,
83 								drawing_mode& oldMode);
84 	virtual	void			SetBlendingMode(source_alpha srcAlpha,
85 								alpha_function alphaFunc);
86 	virtual	void			SetFont(const ServerFont& font);
87 	virtual	void			SetFont(const DrawState* state);
88 
89 			void			SuspendAutoSync();
90 			void			Sync();
91 
92 	// drawing functions
93 	virtual	void			CopyRegion(/*const*/ BRegion* region,
94 								int32 xOffset, int32 yOffset);
95 
96 	virtual	void			InvertRect(BRect r);
97 
98 	virtual	void			DrawBitmap(ServerBitmap* bitmap,
99 								const BRect& bitmapRect, const BRect& viewRect,
100 								uint32 options = 0);
101 	// drawing primitives
102 	virtual	void			DrawArc(BRect r, const float& angle,
103 								const float& span, bool filled);
104 	virtual	void			FillArc(BRect r, const float& angle,
105 								const float& span, const BGradient& gradient);
106 
107 	virtual	void			DrawBezier(BPoint* pts, bool filled);
108 	virtual	void			FillBezier(BPoint* pts, const BGradient& gradient);
109 
110 	virtual	void			DrawEllipse(BRect r, bool filled);
111 	virtual	void			FillEllipse(BRect r, const BGradient& gradient);
112 
113 	virtual	void			DrawPolygon(BPoint* ptlist, int32 numpts,
114 								BRect bounds, bool filled, bool closed);
115 	virtual	void			FillPolygon(BPoint* ptlist, int32 numpts,
116 								BRect bounds, const BGradient& gradient,
117 								bool closed);
118 
119 	// these rgb_color versions are used internally by the server
120 	virtual	void			StrokePoint(const BPoint& point,
121 								const rgb_color& color);
122 	virtual	void			StrokeRect(BRect rect, const rgb_color &color);
123 	virtual	void			FillRect(BRect rect, const rgb_color &color);
124 	virtual	void			FillRegion(BRegion& region, const rgb_color& color);
125 
126 	virtual	void			StrokeRect(BRect rect);
127 	virtual	void			FillRect(BRect rect);
128 	virtual	void			FillRect(BRect rect, const BGradient& gradient);
129 
130 	virtual	void			FillRegion(BRegion& region);
131 	virtual	void			FillRegion(BRegion& region,
132 								const BGradient& gradient);
133 
134 	virtual	void			DrawRoundRect(BRect rect, float xrad,
135 								float yrad, bool filled);
136 	virtual	void			FillRoundRect(BRect rect, float xrad,
137 								float yrad, const BGradient& gradient);
138 
139 	virtual	void			DrawShape(const BRect& bounds,
140 								int32 opcount, const uint32* oplist,
141 								int32 ptcount, const BPoint* ptlist,
142 								bool filled, const BPoint& viewToScreenOffset,
143 								float viewScale);
144 	virtual	void			FillShape(const BRect& bounds,
145 								int32 opcount, const uint32* oplist,
146 							 	int32 ptcount, const BPoint* ptlist,
147 							 	const BGradient& gradient,
148 							 	const BPoint& viewToScreenOffset,
149 								float viewScale);
150 
151 	virtual	void			DrawTriangle(BPoint* points, const BRect& bounds,
152 								bool filled);
153 	virtual	void			FillTriangle(BPoint* points, const BRect& bounds,
154 								const BGradient& gradient);
155 
156 	// these versions are used by the Decorator
157 	virtual	void			StrokeLine(const BPoint& start,
158 								const BPoint& end, const rgb_color& color);
159 
160 	virtual	void			StrokeLine(const BPoint& start,
161 								const BPoint& end);
162 
163 	virtual	void			StrokeLineArray(int32 numlines,
164 								const ViewLineArrayInfo* data);
165 
166 	// -------- text related calls
167 
168 	// returns the pen position behind the (virtually) drawn
169 	// string
170 	virtual	BPoint			DrawString(const char* string, int32 length,
171 								const BPoint& pt,
172 								escapement_delta* delta = NULL);
173 	virtual	BPoint			DrawString(const char* string, int32 length,
174 								const BPoint* offsets);
175 
176 			float			StringWidth(const char* string, int32 length,
177 								escapement_delta* delta = NULL);
178 
179 	// convenience function which is independent of graphics
180 	// state (to be used by Decorator or ServerApp etc)
181 			float			StringWidth(const char* string,
182 								int32 length, const ServerFont& font,
183 								escapement_delta* delta = NULL);
184 
185 	// software rendering backend invoked by CopyRegion() for the sorted
186 	// individual rects
187 	virtual	BRect			CopyRect(BRect rect, int32 xOffset,
188 								int32 yOffset) const;
189 
190 private:
191 			void			_CopyRect(uint8* bits, uint32 width,
192 								uint32 height, uint32 bytesPerRow,
193 								int32 xOffset, int32 yOffset) const;
194 
195 	inline	void			_CopyToFront(const BRect& frame);
196 
197 			Painter*		fPainter;
198 			HWInterface*	fGraphicsCard;
199 			uint32			fAvailableHWAccleration;
200 			int32			fSuspendSyncLevel;
201 			bool			fCopyToFront;
202 };
203 
204 #endif // DRAWING_ENGINE_H_
205