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