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