xref: /haiku/src/servers/app/drawing/DrawingEngine.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
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			SetPattern(const struct pattern& pattern);
80 	virtual	void			SetDrawingMode(drawing_mode mode);
81 	virtual	void			SetDrawingMode(drawing_mode mode,
82 								drawing_mode& oldMode);
83 	virtual	void			SetBlendingMode(source_alpha srcAlpha,
84 								alpha_function alphaFunc);
85 	virtual	void			SetFont(const ServerFont& font);
86 	virtual	void			SetFont(const DrawState* state);
87 
88 			void			SuspendAutoSync();
89 			void			Sync();
90 
91 	// drawing functions
92 	virtual	void			CopyRegion(/*const*/ BRegion* region,
93 								int32 xOffset, int32 yOffset);
94 
95 	virtual	void			InvertRect(BRect r);
96 
97 	virtual	void			DrawBitmap(ServerBitmap* bitmap,
98 								const BRect& bitmapRect, const BRect& viewRect,
99 								uint32 options = 0);
100 	// drawing primitives
101 	virtual	void			DrawArc(BRect r, const float& angle,
102 								const float& span, bool filled);
103 	virtual	void			FillArc(BRect r, const float& angle,
104 								const float& span, const BGradient& gradient);
105 
106 	virtual	void			DrawBezier(BPoint* pts, bool filled);
107 	virtual	void			FillBezier(BPoint* pts, const BGradient& gradient);
108 
109 	virtual	void			DrawEllipse(BRect r, bool filled);
110 	virtual	void			FillEllipse(BRect r, const BGradient& gradient);
111 
112 	virtual	void			DrawPolygon(BPoint* ptlist, int32 numpts,
113 								BRect bounds, bool filled, bool closed);
114 	virtual	void			FillPolygon(BPoint* ptlist, int32 numpts,
115 								BRect bounds, const BGradient& gradient,
116 								bool closed);
117 
118 	// these rgb_color versions are used internally by the server
119 	virtual	void			StrokePoint(const BPoint& point,
120 								const rgb_color& color);
121 	virtual	void			StrokeRect(BRect rect, const rgb_color &color);
122 	virtual	void			FillRect(BRect rect, const rgb_color &color);
123 	virtual	void			FillRegion(BRegion& region, const rgb_color& color);
124 
125 	virtual	void			StrokeRect(BRect rect);
126 	virtual	void			FillRect(BRect rect);
127 	virtual	void			FillRect(BRect rect, const BGradient& gradient);
128 
129 	virtual	void			FillRegion(BRegion& region);
130 	virtual	void			FillRegion(BRegion& region,
131 								const BGradient& gradient);
132 
133 	virtual	void			DrawRoundRect(BRect rect, float xrad,
134 								float yrad, bool filled);
135 	virtual	void			FillRoundRect(BRect rect, float xrad,
136 								float yrad, const BGradient& gradient);
137 
138 	virtual	void			DrawShape(const BRect& bounds,
139 								int32 opcount, const uint32* oplist,
140 								int32 ptcount, const BPoint* ptlist,
141 								bool filled, const BPoint& viewToScreenOffset,
142 								float viewScale);
143 	virtual	void			FillShape(const BRect& bounds,
144 								int32 opcount, const uint32* oplist,
145 							 	int32 ptcount, const BPoint* ptlist,
146 							 	const BGradient& gradient,
147 							 	const BPoint& viewToScreenOffset,
148 								float viewScale);
149 
150 	virtual	void			DrawTriangle(BPoint* points, const BRect& bounds,
151 								bool filled);
152 	virtual	void			FillTriangle(BPoint* points, const BRect& bounds,
153 								const BGradient& gradient);
154 
155 	// these versions are used by the Decorator
156 	virtual	void			StrokeLine(const BPoint& start,
157 								const BPoint& end, const rgb_color& color);
158 
159 	virtual	void			StrokeLine(const BPoint& start,
160 								const BPoint& end);
161 
162 	virtual	void			StrokeLineArray(int32 numlines,
163 								const ViewLineArrayInfo* data);
164 
165 	// -------- text related calls
166 
167 	// returns the pen position behind the (virtually) drawn
168 	// string
169 	virtual	BPoint			DrawString(const char* string, int32 length,
170 								const BPoint& pt,
171 								escapement_delta* delta = NULL);
172 	virtual	BPoint			DrawString(const char* string, int32 length,
173 								const BPoint* offsets);
174 
175 			float			StringWidth(const char* string, int32 length,
176 								escapement_delta* delta = NULL);
177 
178 	// convenience function which is independent of graphics
179 	// state (to be used by Decorator or ServerApp etc)
180 			float			StringWidth(const char* string,
181 								int32 length, const ServerFont& font,
182 								escapement_delta* delta = NULL);
183 
184 	// software rendering backend invoked by CopyRegion() for the sorted
185 	// individual rects
186 	virtual	BRect			CopyRect(BRect rect, int32 xOffset,
187 								int32 yOffset) const;
188 
189 private:
190 			void			_CopyRect(uint8* bits, uint32 width,
191 								uint32 height, uint32 bytesPerRow,
192 								int32 xOffset, int32 yOffset) const;
193 
194 	inline	void			_CopyToFront(const BRect& frame);
195 
196 			Painter*		fPainter;
197 			HWInterface*	fGraphicsCard;
198 			uint32			fAvailableHWAccleration;
199 			int32			fSuspendSyncLevel;
200 			bool			fCopyToFront;
201 };
202 
203 #endif // DRAWING_ENGINE_H_
204